public MethodBinding getEnclosingMethod() { BlockScope blockScope = this.declaringScope; if (blockScope != null) { ReferenceContext referenceContext = blockScope.referenceContext(); if (referenceContext instanceof Initializer) { return null; } if (referenceContext instanceof AbstractMethodDeclaration) { return ((AbstractMethodDeclaration) referenceContext).binding; } } return null; } }
public int record(FunctionalExpression expression) { if (this.functionalExpressionsCount == 0) { this.functionalExpressions = new FunctionalExpression[5]; } else if (this.functionalExpressionsCount == this.functionalExpressions.length) { System.arraycopy(this.functionalExpressions, 0, (this.functionalExpressions = new FunctionalExpression[this.functionalExpressionsCount * 2]), 0, this.functionalExpressionsCount); } this.functionalExpressions[this.functionalExpressionsCount++] = expression; return expression.enclosingScope.classScope().referenceContext.record(expression); }
@Override public CompilationUnitDeclaration getCompilationUnitDeclaration() { return this.enclosingScope == null ? null : this.enclosingScope.compilationUnitScope().referenceContext; }
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; if (!checkAccess(scope.methodScope())) return null; ReferenceBinding enclosingReceiverType = scope.enclosingReceiverType(); if (enclosingReceiverType.id == T_JavaLangObject) { scope.problemReporter().cannotUseSuperInJavaLangObject(this); return null; } return this.resolvedType = enclosingReceiverType.superclass(); }
public TypeBinding resolveType(BlockScope scope) { this.constant = Constant.NotAConstant; if (!isImplicitThis() &&!checkAccess(scope.methodScope())) { return null; } return this.resolvedType = scope.enclosingReceiverType(); }
public final void addLocalType(TypeDeclaration localType) { ClassScope localTypeScope = new ClassScope(this, localType); addSubscope(localTypeScope); localTypeScope.buildLocalTypeBinding(enclosingSourceType()); }
private ReferenceExpression copy() { final Parser parser = new Parser(this.enclosingScope.problemReporter(), false); final ICompilationUnit compilationUnit = this.compilationResult.getCompilationUnit(); final char[] source = compilationUnit != null ? compilationUnit.getContents() : this.text; ReferenceExpression copy = (ReferenceExpression) parser.parseExpression(source, compilationUnit != null ? this.sourceStart : 0, this.sourceEnd - this.sourceStart + 1, this.enclosingScope.referenceCompilationUnit(), false /* record line separators */); copy.original = this; copy.sourceStart = this.sourceStart; copy.sourceEnd = this.sourceEnd; return copy; }
@Override public boolean visit(Argument argument, BlockScope scope) { Annotation[] annotations = argument.annotations; ReferenceContext referenceContext = scope.referenceContext(); if (referenceContext instanceof AbstractMethodDeclaration) { MethodBinding binding = ((AbstractMethodDeclaration) referenceContext).binding; if (binding != null) { TypeDeclaration typeDeclaration = scope.referenceType(); typeDeclaration.binding.resolveTypesFor(binding); if (argument.binding != null) { argument.binding = new AptSourceLocalVariableBinding(argument.binding, binding); } } if (annotations != null && argument.binding != null) { this.resolveAnnotations( scope, annotations, argument.binding); } } return false; }
public final void addLocalType(TypeDeclaration localType) { ClassScope localTypeScope = new ClassScope(this, localType); addSubscope(localTypeScope); localTypeScope.buildLocalTypeBinding(enclosingSourceType()); // See comment in addAnonymousType. MethodScope methodScope = methodScope(); while (methodScope != null && methodScope.referenceContext instanceof LambdaExpression) { LambdaExpression lambda = (LambdaExpression) methodScope.referenceContext; if (!lambda.scope.isStatic && !lambda.scope.isConstructorCall) { lambda.shouldCaptureInstance = true; } methodScope = methodScope.enclosingMethodScope(); } }
public void resolve(BlockScope upperScope) { if ((this.bits & UndocumentedEmptyBlock) != 0) { upperScope.problemReporter().undocumentedEmptyBlock(this.sourceStart, this.sourceEnd); } if (this.statements != null) { this.scope = this.explicitDeclarations == 0 ? upperScope : new BlockScope(upperScope, this.explicitDeclarations); for (int i = 0, length = this.statements.length; i < length; i++) { this.statements[i].resolve(this.scope); } } }
/** * Bytecode generation for a local inner type (API as a normal statement code gen) */ public void generateCode(BlockScope blockScope, CodeStream codeStream) { if ((this.bits & ASTNode.IsReachable) == 0) { return; } if ((this.bits & ASTNode.HasBeenGenerated) != 0) return; int pc = codeStream.position; if (this.binding != null) { SyntheticArgumentBinding[] enclosingInstances = ((NestedTypeBinding) this.binding).syntheticEnclosingInstances(); for (int i = 0, slotSize = 0, count = enclosingInstances == null ? 0 : enclosingInstances.length; i < count; i++){ SyntheticArgumentBinding enclosingInstance = enclosingInstances[i]; enclosingInstance.resolvedPosition = ++slotSize; // shift by 1 to leave room for aload0==this if (slotSize > 0xFF) { // no more than 255 words of arguments blockScope.problemReporter().noMoreAvailableSpaceForArgument(enclosingInstance, blockScope.referenceType()); } } } generateCode(codeStream.classFile); codeStream.recordPositionsFrom(pc, this.sourceStart); }
/** * Code responsible to generate the suitable code to supply values for the synthetic outer local * variable arguments of a constructor invocation of a nested type. * (bug 26122) - synthetic values for outer locals must be passed after user arguments, e.g. new X(i = 1){} */ public void generateSyntheticOuterArgumentValues(BlockScope currentScope, ReferenceBinding targetType, ASTNode invocationSite) { // generate the synthetic outer arguments then SyntheticArgumentBinding syntheticArguments[]; if ((syntheticArguments = targetType.syntheticOuterLocalVariables()) != null) { for (int i = 0, max = syntheticArguments.length; i < max; i++) { LocalVariableBinding targetVariable = syntheticArguments[i].actualOuterLocalVariable; VariableBinding[] emulationPath = currentScope.getEmulationPath(targetVariable); generateOuterAccess(emulationPath, invocationSite, targetVariable, currentScope); } } }
public void manageEnclosingInstanceAccessIfNecessary(BlockScope currentScope, FlowInfo flowInfo) { if ((flowInfo.tagBits & FlowInfo.UNREACHABLE_OR_DEAD) == 0) { ReferenceBinding allocatedTypeErasure = (ReferenceBinding) this.binding.declaringClass.erasure(); // perform some extra emulation work in case there is some and we are inside a local type only if (allocatedTypeErasure.isNestedType() && (currentScope.enclosingSourceType().isLocalType() || currentScope.isLambdaSubscope())) { if (allocatedTypeErasure.isLocalType()) { ((LocalTypeBinding) allocatedTypeErasure).addInnerEmulationDependent(currentScope, this.enclosingInstance != null); } else { // locally propagate, since we already now the desired shape for sure currentScope.propagateInnerEmulation(allocatedTypeErasure, this.enclosingInstance != null); } } } }
private JavaElement getJavaElement(LocalVariableBinding binding) { LocalDeclaration local = binding.declaration; JavaElement parent = null; ReferenceContext referenceContext = binding.declaringScope.isLambdaSubscope() ? binding.declaringScope.namedMethodScope().referenceContext() : binding.declaringScope.referenceContext(); if (referenceContext instanceof AbstractMethodDeclaration) { AbstractMethodDeclaration methodDeclaration = (AbstractMethodDeclaration) referenceContext; parent = this.getJavaElementOfCompilationUnit(methodDeclaration, methodDeclaration.binding); } else if (referenceContext instanceof TypeDeclaration){ // Local variable is declared inside an initializer TypeDeclaration typeDeclaration = (TypeDeclaration) referenceContext; JavaElement type = this.getJavaElementOfCompilationUnit(typeDeclaration, typeDeclaration.binding); parent = Util.getUnresolvedJavaElement(local.sourceStart, local.sourceEnd, type); } if (parent == null) return null; return new LocalVariable( parent, new String(local.name), local.declarationSourceStart, local.declarationSourceEnd, local.sourceStart, local.sourceEnd, local.type == null ? Signature.createTypeSignature(binding.type.signableName(), true) : Util.typeSignature(local.type), binding.declaration.annotations, local.modifiers, local.getKind() == AbstractVariableDeclaration.PARAMETER); }
private boolean methodHasMissingSwitchDefault() { MethodScope methodScope = null; if (this.referenceContext instanceof Block) { methodScope = ((Block)this.referenceContext).scope.methodScope(); } else if (this.referenceContext instanceof AbstractMethodDeclaration) { methodScope = ((AbstractMethodDeclaration)this.referenceContext).scope; } return methodScope != null && methodScope.hasMissingSwitchDefault; } public void unmatchedBracket(int position, ReferenceContext context, CompilationResult compilationResult) {
public void setAnnotations(AnnotationBinding[] annotations) { if (this.declaringScope == null) return; SourceTypeBinding sourceType = this.declaringScope.enclosingSourceType(); if (sourceType != null) sourceType.storeAnnotations(this, annotations); }
private boolean shouldGenerateImplicitLambda(BlockScope currentScope) { // these cases are either too complicated, impossible to handle or result in significant code duplication return (this.binding.isVarargs() || (isConstructorReference() && this.receiverType.syntheticOuterLocalVariables() != null && currentScope.methodScope().isStatic) || this.expectedType instanceof IntersectionCastTypeBinding || // marker interfaces require alternate meta factory. this.expectedType.findSuperTypeOriginatingFrom(currentScope.getJavaIoSerializable()) != null || // serialization support. this.requiresBridges()); // bridges. // To fix: We should opt for direct code generation wherever possible. }
@Override public CompilationUnitDeclaration getCompilationUnitDeclaration() { return this.scope.referenceCompilationUnit(); }
public void resolve(BlockScope upperScope) { // use the scope that will hold the init declarations this.scope = (this.bits & ASTNode.NeededScope) != 0 ? new BlockScope(upperScope) : upperScope; if (this.initializations != null) for (int i = 0, length = this.initializations.length; i < length; i++) this.initializations[i].resolve(this.scope); if (this.condition != null) { TypeBinding type = this.condition.resolveTypeExpecting(this.scope, TypeBinding.BOOLEAN); this.condition.computeConversion(this.scope, type, type); } if (this.increments != null) for (int i = 0, length = this.increments.length; i < length; i++) this.increments[i].resolve(this.scope); if (this.action != null) this.action.resolve(this.scope); }
LambdaExpression copy() { final Parser parser = new Parser(this.enclosingScope.problemReporter(), false); final char[] source = this.compilationResult.getCompilationUnit().getContents(); LambdaExpression copy = (LambdaExpression) parser.parseLambdaExpression(source, this.sourceStart, this.sourceEnd - this.sourceStart + 1, this.enclosingScope.referenceCompilationUnit(), false /* record line separators */); if (copy != null) { // ==> syntax errors == null copy.original = this; } return copy; }