private void addFactoryMethod(EclipseNode singletonClass, TypeDeclaration astNode, TypeReference typeReference, TypeDeclaration innerClass, FieldDeclaration field) { MethodDeclaration factoryMethod = new MethodDeclaration(astNode.compilationResult); factoryMethod.modifiers = AccStatic | ClassFileConstants.AccPublic; factoryMethod.returnType = typeReference; factoryMethod.sourceStart = astNode.sourceStart; factoryMethod.sourceEnd = astNode.sourceEnd; factoryMethod.selector = "getInstance".toCharArray(); factoryMethod.bits = ECLIPSE_DO_NOT_TOUCH_FLAG; long pS = factoryMethod.sourceStart; long pE = factoryMethod.sourceEnd; long p = (long) pS << 32 | pE; FieldReference ref = new FieldReference(field.name, p); ref.receiver = new SingleNameReference(innerClass.name, p); ReturnStatement statement = new ReturnStatement(ref, astNode.sourceStart, astNode.sourceEnd); factoryMethod.statements = new Statement[]{statement}; EclipseHandlerUtil.injectMethod(singletonClass, factoryMethod); }
boolean alreadyGeneratedExpression = false; if (needValueStore()) { alreadyGeneratedExpression = true; this.expression.generateCode(currentScope, codeStream, needValue()); // no value needed if non-returning subroutine generateStoreSaveValueIfNecessary(codeStream); this.expression.generateCode(currentScope, codeStream, true); generateStoreSaveValueIfNecessary(codeStream); generateReturnBytecode(codeStream); if (this.saveValueVariable != null) { codeStream.removeVariable(this.saveValueVariable);
checkAgainstNullAnnotation(currentScope, flowContext, this.expression.nullStatus(flowInfo)); if (currentScope.compilerOptions().analyseResourceLeaks) { FakedTrackingVariable trackingVariable = FakedTrackingVariable.getCloseTrackingVariable(this.expression); int subCount = 0; boolean saveValueNeeded = false; boolean hasValueToSave = needValueStore(); boolean noAutoCloseables = true; do { prepareSaveValueLocation(tryStatement);
new ReturnStatement(expression, expression.sourceStart, expression.sourceEnd, true).resolve(this.scope); // :-) ;-) } else { this.body.resolve(this.scope);
public StringBuffer printStatement(int tab, StringBuffer output){ printIndent(tab, output).append("return "); //$NON-NLS-1$ if (this.expression != null ) this.expression.printExpression(0, output) ; return output.append(';'); }
} else if (isBoxingCompatible(expressionType, methodType, this.expression, scope)) { this.expression.computeConversion(scope, methodType, expressionType); if (this.expression instanceof CastExpression
int subCount = 0; boolean saveValueNeeded = false; boolean hasValueToSave = needValueStore(); do { SubRoutineStatement sub; prepareSaveValueLocation(tryStatement);
void checkAgainstNullAnnotation(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) { int nullStatus = this.expression.nullStatus(flowInfo, flowContext); long tagBits; MethodBinding methodBinding = null; boolean useTypeAnnotations = scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8; try { methodBinding = scope.methodScope().referenceMethodBinding(); tagBits = (useTypeAnnotations) ? methodBinding.returnType.tagBits : methodBinding.tagBits; } catch (NullPointerException npe) { // chain of references in try-block has several potential nulls; // any null means we cannot perform the following check return; } if (useTypeAnnotations) { checkAgainstNullTypeAnnotation(scope, methodBinding.returnType, this.expression, flowContext, flowInfo); } else if (nullStatus != FlowInfo.NON_NULL) { // if we can't prove non-null check against declared null-ness of the enclosing method: if ((tagBits & TagBits.AnnotationNonNull) != 0) { flowContext.recordNullityMismatch(scope, this.expression, this.expression.resolvedType, methodBinding.returnType, nullStatus); } } }
boolean alreadyGeneratedExpression = false; if (needValueStore()) { alreadyGeneratedExpression = true; this.expression.generateCode(currentScope, codeStream, needValue()); // no value needed if non-returning subroutine generateStoreSaveValueIfNecessary(codeStream); this.expression.generateCode(currentScope, codeStream, true); generateStoreSaveValueIfNecessary(codeStream); generateReturnBytecode(codeStream); if (this.saveValueVariable != null) { codeStream.removeVariable(this.saveValueVariable);
this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo); if (flowInfo.reachMode() == FlowInfo.REACHABLE && currentScope.compilerOptions().isAnnotationBasedNullAnalysisEnabled) checkAgainstNullAnnotation(currentScope, flowContext, flowInfo); if (currentScope.compilerOptions().analyseResourceLeaks) { FakedTrackingVariable trackingVariable = FakedTrackingVariable.getCloseTrackingVariable(this.expression, flowInfo, flowContext); int subCount = 0; boolean saveValueNeeded = false; boolean hasValueToSave = needValueStore(); boolean noAutoCloseables = true; do { prepareSaveValueLocation(tryStatement);
new ReturnStatement(expression, expression.sourceStart, expression.sourceEnd, true).resolve(this.scope); // :-) ;-) } else { this.body.resolve(this.scope);
public StringBuffer printStatement(int tab, StringBuffer output){ printIndent(tab, output).append("return "); //$NON-NLS-1$ if (this.expression != null ) this.expression.printExpression(0, output) ; return output.append(';'); }
} else if (isBoxingCompatible(expressionType, methodType, this.expression, scope)) { this.expression.computeConversion(scope, methodType, expressionType); if (this.expression instanceof CastExpression
int subCount = 0; boolean saveValueNeeded = false; boolean hasValueToSave = needValueStore(); do { SubRoutineStatement sub; prepareSaveValueLocation(tryStatement);
void checkAgainstNullAnnotation(BlockScope scope, FlowContext flowContext, FlowInfo flowInfo) { int nullStatus = this.expression.nullStatus(flowInfo, flowContext); long tagBits; MethodBinding methodBinding = null; boolean useTypeAnnotations = scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_8; try { methodBinding = scope.methodScope().referenceMethodBinding(); tagBits = (useTypeAnnotations) ? methodBinding.returnType.tagBits : methodBinding.tagBits; } catch (NullPointerException npe) { // chain of references in try-block has several potential nulls; // any null means we cannot perform the following check return; } if (useTypeAnnotations) { checkAgainstNullTypeAnnotation(scope, methodBinding.returnType, this.expression, flowContext, flowInfo); } else if (nullStatus != FlowInfo.NON_NULL) { // if we can't prove non-null check against declared null-ness of the enclosing method: if ((tagBits & TagBits.AnnotationNonNull) != 0) { flowContext.recordNullityMismatch(scope, this.expression, this.expression.resolvedType, methodBinding.returnType, nullStatus); } } }
boolean alreadyGeneratedExpression = false; if (needValueStore()) { alreadyGeneratedExpression = true; this.expression.generateCode(currentScope, codeStream, needValue()); // no value needed if non-returning subroutine generateStoreSaveValueIfNecessary(codeStream); this.expression.generateCode(currentScope, codeStream, true); generateStoreSaveValueIfNecessary(codeStream); generateReturnBytecode(codeStream); if (this.saveValueVariable != null) { codeStream.removeVariable(this.saveValueVariable);
this.expression.checkNPEbyUnboxing(currentScope, flowContext, flowInfo); if (flowInfo.reachMode() == FlowInfo.REACHABLE && currentScope.compilerOptions().isAnnotationBasedNullAnalysisEnabled) checkAgainstNullAnnotation(currentScope, flowContext, flowInfo); if (currentScope.compilerOptions().analyseResourceLeaks) { FakedTrackingVariable trackingVariable = FakedTrackingVariable.getCloseTrackingVariable(this.expression, flowInfo, flowContext); int subCount = 0; boolean saveValueNeeded = false; boolean hasValueToSave = needValueStore(); boolean noAutoCloseables = true; do { prepareSaveValueLocation(tryStatement);
protected void consumeStatementReturn() { // ReturnStatement ::= 'return' Expressionopt ';' // return pushs a position on this.intStack in case there is no expression if (this.expressionLengthStack[this.expressionLengthPtr--] != 0) { pushOnAstStack( new ReturnStatement( this.expressionStack[this.expressionPtr--], this.intStack[this.intPtr--], this.endStatementPosition) ); } else { pushOnAstStack(new ReturnStatement(null, this.intStack[this.intPtr--], this.endStatementPosition)); } } protected void consumeStatementSwitch() {
new ReturnStatement(expression, expression.sourceStart, expression.sourceEnd, true).resolve(this.scope); // :-) ;-) } else { this.body.resolve(this.scope);
public StringBuffer printStatement(int tab, StringBuffer output){ printIndent(tab, output).append("return "); //$NON-NLS-1$ if (this.expression != null ) this.expression.printExpression(0, output) ; return output.append(';'); }