List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope compilationUnitScope
public final CompilationUnitScope compilationUnitScope()
From source file:com.google.gwt.dev.jdt.FindDeferredBindingSitesVisitor.java
License:Open Source License
public static void reportRebindProblem(MessageSendSite site, String message) { MessageSend messageSend = site.messageSend; Scope scope = site.scope; // Safe since CUS.referenceContext is set in its constructor. CompilationUnitDeclaration cud = scope.compilationUnitScope().referenceContext; GWTProblem.recordError(messageSend, cud, message, null); }
From source file:org.eclipse.jdt.core.dom.ASTConverter.java
License:Open Source License
private boolean scannerAvailable(Scope scope) { if (!this.scannerUsable) { return false; }//from ww w . ja v a2 s. c o m if (scope != null) { CompilationUnitScope cuScope = scope.compilationUnitScope(); if (cuScope != null) { return cuScope.scannerAvailable(); } } return true; }
From source file:org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding.java
License:Open Source License
/** * Answer true if the receiver is visible to the type provided by the scope. *//*from w ww.j av a 2 s . c om*/ public final boolean canBeSeenBy(Scope scope) { // GROOVY start if (scope.compilationUnitScope() != null && scope.compilationUnitScope().canSeeEverything()) { return true; } // GROOVY end if (isPublic()) return true; SourceTypeBinding invocationType = scope.enclosingSourceType(); if (invocationType == this) return true; if (invocationType == null) // static import call return !isPrivate() && scope.getCurrentPackage() == this.fPackage; if (isProtected()) { // answer true if the invocationType is the declaringClass or they are in the same package // OR the invocationType is a subclass of the declaringClass // AND the invocationType is the invocationType or its subclass // OR the type is a static method accessed directly through a type // OR previous assertions are true for one of the enclosing type if (invocationType.fPackage == this.fPackage) return true; TypeBinding declaringClass = enclosingType(); // protected types always have an enclosing one if (declaringClass == null) return false; // could be null if incorrect top-level protected type declaringClass = declaringClass.erasure();// erasure cannot be null TypeBinding currentType = invocationType.erasure(); // int depth = 0; do { if (declaringClass == invocationType) return true; if (currentType.findSuperTypeOriginatingFrom(declaringClass) != null) return true; // depth++; currentType = currentType.enclosingType(); } while (currentType != null); return false; } if (isPrivate()) { // answer true if the receiver and the invocationType have a common enclosingType // already know they are not the identical type ReferenceBinding outerInvocationType = invocationType; ReferenceBinding temp = outerInvocationType.enclosingType(); while (temp != null) { outerInvocationType = temp; temp = temp.enclosingType(); } ReferenceBinding outerDeclaringClass = (ReferenceBinding) erasure(); temp = outerDeclaringClass.enclosingType(); while (temp != null) { outerDeclaringClass = temp; temp = temp.enclosingType(); } return outerInvocationType == outerDeclaringClass; } // isDefault() return invocationType.fPackage == this.fPackage; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference.java
License:Open Source License
ITeamAnchor resolveAnchor(Scope scope, Reference reference) { ITeamAnchor prefix = null;/*ww w. j a va 2 s . c om*/ ITeamAnchor currentAnchor = null; char[] currentToken = null; // for lookup and creation of problem binding // be careful not to trigger fields() which may be where we are called from! if (reference instanceof SingleNameReference) { SingleNameReference singleAnchor = (SingleNameReference) reference; currentToken = singleAnchor.token; currentAnchor = findVariable(scope, currentToken, scope.isStatic(), singleAnchor.sourceStart, singleAnchor.sourceEnd); this.anchor.bits |= (this.bits & DepthMASK); // could be ProblemAnchorBinding } else if (reference instanceof FieldReference) { FieldReference fieldRef = (FieldReference) reference; Expression prefixExpr = fieldRef.receiver; if (!(prefixExpr instanceof Reference)) throw new InternalCompilerError("Unexpected anchor prefix " + prefixExpr); //$NON-NLS-1$ prefix = resolveAnchor(scope, (Reference) prefixExpr); currentToken = fieldRef.token; // fieldRef holds on to problem binding: fieldRef.binding = TypeAnalyzer.findField(((ReferenceBinding) prefix.getResolvedType()).getRealClass(), currentToken, false/*static*/, true/*outer*/); currentAnchor = checkAnchor(scope, reference, currentToken, reference.sourceStart, reference.sourceEnd, fieldRef.binding); } else if (reference instanceof QualifiedBaseReference) { QualifiedBaseReference baseRef = (QualifiedBaseReference) reference; if (scope instanceof BlockScope) baseRef.resolveType((BlockScope) scope); else baseRef.resolveType((ClassScope) scope); currentAnchor = baseRef.baseField; } else if (reference instanceof QualifiedThisReference) { QualifiedThisReference thisRef = (QualifiedThisReference) reference; if (scope instanceof BlockScope) thisRef.resolveType((BlockScope) scope); else thisRef.resolveType((ClassScope) scope); if (thisRef.resolvedType.isTeam()) currentAnchor = ((ReferenceBinding) thisRef.resolvedType).getTeamModel().getTThis(); } else { boolean haveReportedProblem = false; long currentPos = 0; QualifiedNameReference qualifiedAnchor = (QualifiedNameReference) reference; char[][] tokens = qualifiedAnchor.tokens; currentToken = tokens[tokens.length - 1]; // default, so we never use null name for problem binding // check maximal static prefix: Binding staticPrefix = null; int j; for (j = 1; j <= tokens.length; j++) { Binding current = scope.getTypeOrPackage(CharOperation.subarray(tokens, 0, j)); if (current == null || !current.isValidBinding()) break; else staticPrefix = current; } if (j > tokens.length) { scope.problemReporter().typeAnchorReferenceNotAValue(reference); haveReportedProblem = true; } else { // find first field: if (staticPrefix != null) { currentPos = qualifiedAnchor.sourcePositions[j - 1]; currentToken = tokens[j - 1]; if (staticPrefix instanceof ReferenceBinding) { currentAnchor = TypeAnalyzer.findField(((ReferenceBinding) staticPrefix).getRealClass(), currentToken, /*static*/true, /*outer*/true); } else { scope.problemReporter().typeAnchorReferenceNotAnObjectRef((int) (currentPos >>> 32), (int) currentPos); haveReportedProblem = true; } } else { currentPos = qualifiedAnchor.sourcePositions[0]; currentToken = tokens[0]; currentAnchor = findVariable(scope, currentToken, scope.isStatic(), (int) (currentPos >>> 32), (int) currentPos); haveReportedProblem = currentAnchor == null; } if (currentAnchor != null) { if (!currentAnchor.hasValidReferenceType()) { if (j < tokens.length) // would need to process more tokens? currentAnchor = null; // replace with problem binding below } else { // find more fields: for (int i = j; i < tokens.length; i++) { TypeBinding fieldType = currentAnchor.getResolvedType().leafComponentType(); if (fieldType instanceof SourceTypeBinding) { SourceTypeBinding stb = (SourceTypeBinding) fieldType; if ((stb.scope != null) && (stb.scope.compilationUnitScope() != scope.compilationUnitScope()) && (stb.tagBits & (TagBits.BeginHierarchyCheck | TagBits.EndHierarchyCheck)) == (TagBits.BeginHierarchyCheck | TagBits.EndHierarchyCheck) && StateHelper.isReadyToProcess(stb, ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS)) Dependencies.ensureBindingState(stb, ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS); } currentPos = qualifiedAnchor.sourcePositions[i]; currentToken = tokens[i]; FieldBinding nextField = currentAnchor.getFieldOfType(currentToken, /*static*/false, true); if (nextField == null || !nextField.hasValidReferenceType()) { currentAnchor = null; // replace with problem binding below break; } currentAnchor = nextField.setPathPrefix(currentAnchor); } } } } if (!haveReportedProblem) { if (currentAnchor == null) { scope.problemReporter().typeAnchorNotFound(currentToken, (int) (currentPos >>> 32), (int) currentPos); } else if (!currentAnchor.hasValidReferenceType()) { scope.problemReporter().typeAnchorReferenceNotAnObjectRef((int) (currentPos >>> 32), (int) currentPos); } } } if (currentAnchor == null) { currentAnchor = new ProblemFieldBinding(scope.enclosingReceiverType(), currentToken, ProblemReasons.NotFound); ((FieldBinding) currentAnchor).type = reference.resolvedType = new ProblemReferenceBinding( "UnresolvedType".toCharArray(), null, ProblemReasons.NotFound); //$NON-NLS-1$ } else if (currentAnchor.isValidBinding()) { if (prefix != null && !(prefix instanceof TThisBinding)) currentAnchor = currentAnchor.setPathPrefix(prefix); // fill anchor with resolved data: reference.resolvedType = currentAnchor.getResolvedType(); reference.bits &= ~RestrictiveFlagMASK; // clear bits if (currentAnchor instanceof FieldBinding) { reference.bits |= Binding.FIELD; // TODO(SH): must we remember a previous anchor to set this correctly?: if (reference instanceof NameReference) ((NameReference) reference).actualReceiverType = ((FieldBinding) currentAnchor).declaringClass; if (reference instanceof FieldReference) ((FieldReference) reference).actualReceiverType = ((FieldBinding) currentAnchor).declaringClass; } else { reference.bits |= Binding.LOCAL; } reference.constant = Constant.NotAConstant; } if (reference instanceof NameReference) { ((NameReference) reference).binding = (Binding) currentAnchor; ((NameReference) reference).resolveFinished(); } else if (reference instanceof FieldReference) { ((FieldReference) reference).binding = (FieldBinding) currentAnchor; //TODO(SH): this method doesn't exist, is the call needed? //((FieldReference)this.anchor).resolveFinished(); } return currentAnchor; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel.java
License:Open Source License
/** * A local type was read from source code. * Record it as part (though not member) of this role. * @param local/*w w w.ja v a 2s . c o m*/ */ public void addLocalType(char[] constantPoolName, RoleModel local) { this._localTypes.add(local); local._isLocalType = true; if (constantPoolName != null) { if (this._ast != null) { Scope scope = this._ast.scope; if (scope != null) { CompilationUnitScope cuScope = scope.compilationUnitScope(); cuScope.registerLocalType(constantPoolName, local.getAst()); } } } if (this._attributes != null) for (AbstractAttribute attribute : this._attributes) if (attribute.nameEquals(IOTConstants.ROLE_LOCAL_TYPES)) return; addAttribute(new RoleLocalTypesAttribute(this)); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel.java
License:Open Source License
public TypeBinding getMarkerInterfaceBinding(Scope scope) { if (this.markerInterface != null) return this.markerInterface.binding; if (this._binding != null && this._binding.superclass() != null) { // has not been generated yet, but perhaps this can indeed by repaired now: TSuperHelper.addMarkerInterface(this, this._binding.superclass()); return this.markerInterface.binding; }//from w ww . j av a 2 s . c o m PackageBinding pkgBinding = scope.compilationUnitScope().fPackage; char[] markerName = "MissingTSuperMarker".toCharArray(); //$NON-NLS-1$ char[][] compoundName = this._binding != null ? CharOperation.arrayConcat(this._binding.compoundName, markerName) : new char[][] { markerName }; return scope.compilationUnitScope().environment.createMissingType(pkgBinding, compoundName); }