List of usage examples for org.eclipse.jdt.internal.compiler.lookup Binding FIELD
int FIELD
To view the source code for org.eclipse.jdt.internal.compiler.lookup Binding FIELD.
Click Source Link
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PackageReferenceLocator.java
License:Open Source License
protected void matchReportReference(ASTNode reference, IJavaElement element, IJavaElement localElement, IJavaElement[] otherElements, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { long[] positions = null; int last = -1; if (reference instanceof ImportReference) { ImportReference importRef = (ImportReference) reference; positions = importRef.sourcePositions; last = (importRef.bits & ASTNode.OnDemand) != 0 ? positions.length : positions.length - 1; } else {/*from w w w .java 2 s .c o m*/ TypeBinding typeBinding = null; if (reference instanceof QualifiedNameReference) { QualifiedNameReference qNameRef = (QualifiedNameReference) reference; positions = qNameRef.sourcePositions; switch (qNameRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD: // reading a field typeBinding = qNameRef.actualReceiverType; break; case Binding.TYPE: //=============only type ============== if (qNameRef.binding instanceof TypeBinding) typeBinding = (TypeBinding) qNameRef.binding; break; case Binding.VARIABLE: //============unbound cases=========== case Binding.TYPE | Binding.VARIABLE: Binding binding = qNameRef.binding; if (binding instanceof TypeBinding) { typeBinding = (TypeBinding) binding; } else if (binding instanceof ProblemFieldBinding) { typeBinding = qNameRef.actualReceiverType; last = qNameRef.tokens.length - (qNameRef.otherBindings == null ? 2 : qNameRef.otherBindings.length + 2); } else if (binding instanceof ProblemBinding) { ProblemBinding pbBinding = (ProblemBinding) binding; typeBinding = pbBinding.searchType; last = CharOperation.occurencesOf('.', pbBinding.name); } break; } } else if (reference instanceof QualifiedTypeReference) { QualifiedTypeReference qTypeRef = (QualifiedTypeReference) reference; positions = qTypeRef.sourcePositions; typeBinding = qTypeRef.resolvedType; } else if (reference instanceof JavadocSingleTypeReference) { JavadocSingleTypeReference jsTypeRef = (JavadocSingleTypeReference) reference; positions = new long[1]; positions[0] = (((long) jsTypeRef.sourceStart) << 32) + jsTypeRef.sourceEnd; typeBinding = jsTypeRef.resolvedType; } if (positions == null) return; if (typeBinding instanceof ArrayBinding) typeBinding = ((ArrayBinding) typeBinding).leafComponentType; if (typeBinding instanceof ProblemReferenceBinding) typeBinding = ((ProblemReferenceBinding) typeBinding).closestMatch(); if (typeBinding instanceof ReferenceBinding) { PackageBinding pkgBinding = ((ReferenceBinding) typeBinding).fPackage; if (pkgBinding != null) last = pkgBinding.compoundName.length; } // Do not report qualified references which are only enclosing type // (see bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=91078) ReferenceBinding enclosingType = typeBinding == null ? null : typeBinding.enclosingType(); if (enclosingType != null) { int length = positions.length; while (enclosingType != null && length > 0) { length--; enclosingType = enclosingType.enclosingType(); } if (length <= 1) return; } } if (last == -1) { last = this.pattern.segments.length; } if (last == 0) return; if (last > positions.length) last = positions.length; int sourceStart = (int) (positions[0] >>> 32); int sourceEnd = ((int) positions[last - 1]); PackageReferenceMatch packageReferenceMatch = locator.newPackageReferenceMatch(element, accuracy, sourceStart, sourceEnd - sourceStart + 1, reference); packageReferenceMatch.setLocalElement(localElement); this.match = packageReferenceMatch; locator.report(this.match); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.PackageReferenceLocator.java
License:Open Source License
protected int resolveLevel(QualifiedNameReference qNameRef) { TypeBinding typeBinding = null;//from w w w . j a v a 2s . co m switch (qNameRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD: // reading a field if (qNameRef.tokens.length < (qNameRef.otherBindings == null ? 3 : qNameRef.otherBindings.length + 3)) return IMPOSSIBLE_MATCH; // must be at least p1.A.x typeBinding = qNameRef.actualReceiverType; break; case Binding.LOCAL: // reading a local variable return IMPOSSIBLE_MATCH; // no package match in it case Binding.TYPE: //=============only type ============== if (qNameRef.binding instanceof TypeBinding) typeBinding = (TypeBinding) qNameRef.binding; break; /* * Handling of unbound qualified name references. The match may reside in the resolved fragment, * which is recorded inside the problem binding, along with the portion of the name until it became a problem. */ case Binding.VARIABLE: //============unbound cases=========== case Binding.TYPE | Binding.VARIABLE: Binding binding = qNameRef.binding; if (binding instanceof ProblemReferenceBinding) { typeBinding = (TypeBinding) binding; } else if (binding instanceof ProblemFieldBinding) { if (qNameRef.tokens.length < (qNameRef.otherBindings == null ? 3 : qNameRef.otherBindings.length + 3)) return IMPOSSIBLE_MATCH; // must be at least p1.A.x typeBinding = qNameRef.actualReceiverType; } else if (binding instanceof ProblemBinding) { ProblemBinding pbBinding = (ProblemBinding) binding; if (CharOperation.occurencesOf('.', pbBinding.name) <= 0) // index of last bound token is one before the pb token return INACCURATE_MATCH; typeBinding = pbBinding.searchType; } break; } return resolveLevel(typeBinding); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected void matchReportReference(QualifiedNameReference qNameRef, IJavaElement element, Binding elementBinding, int accuracy, MatchLocator locator) throws CoreException { Binding binding = qNameRef.binding; TypeBinding typeBinding = null;/*from w w w .j av a2 s . c o m*/ int lastIndex = qNameRef.tokens.length - 1; switch (qNameRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD: // reading a field typeBinding = qNameRef.actualReceiverType; lastIndex -= qNameRef.otherBindings == null ? 1 : qNameRef.otherBindings.length + 1; break; case Binding.TYPE: //=============only type ============== if (binding instanceof TypeBinding) typeBinding = (TypeBinding) binding; break; case Binding.VARIABLE: //============unbound cases=========== case Binding.TYPE | Binding.VARIABLE: if (binding instanceof ProblemReferenceBinding) { typeBinding = (TypeBinding) binding; } else if (binding instanceof ProblemFieldBinding) { typeBinding = qNameRef.actualReceiverType; lastIndex -= qNameRef.otherBindings == null ? 1 : qNameRef.otherBindings.length + 1; } else if (binding instanceof ProblemBinding) { typeBinding = ((ProblemBinding) binding).searchType; } break; } if (typeBinding instanceof ProblemReferenceBinding) { ProblemReferenceBinding pbBinding = (ProblemReferenceBinding) typeBinding; typeBinding = pbBinding.closestMatch(); lastIndex = pbBinding.compoundName.length - 1; } // Create search match to report if (this.match == null) { this.match = locator.newTypeReferenceMatch(element, elementBinding, accuracy, qNameRef); } // try to match all enclosing types for which the token matches as well. if (typeBinding instanceof ReferenceBinding) { ReferenceBinding refBinding = (ReferenceBinding) typeBinding; while (refBinding != null && lastIndex >= 0) { if (resolveLevelForType(refBinding) == ACCURATE_MATCH) { if (locator.encloses(element)) { long[] positions = qNameRef.sourcePositions; // index now depends on pattern type signature int index = lastIndex; if (this.pattern.qualification != null) { index = lastIndex - this.pattern.segmentsSize; } if (index < 0) index = 0; int start = (int) ((positions[index]) >>> 32); int end = (int) positions[lastIndex]; this.match.setOffset(start); this.match.setLength(end - start + 1); // Look if there's a need to special report for parameterized type matchReportReference(qNameRef, lastIndex, refBinding, locator); } return; } lastIndex--; refBinding = refBinding.enclosingType(); } } locator.reportAccurateTypeReference(this.match, qNameRef, this.pattern.simpleName); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected void reportDeclaration(ASTNode reference, IJavaElement element, MatchLocator locator, SimpleSet knownTypes) throws CoreException { int maxType = -1; TypeBinding typeBinding = null;//w w w . j a v a 2s .c o m if (reference instanceof TypeReference) { typeBinding = ((TypeReference) reference).resolvedType; maxType = Integer.MAX_VALUE; } else if (reference instanceof QualifiedNameReference) { QualifiedNameReference qNameRef = (QualifiedNameReference) reference; Binding binding = qNameRef.binding; maxType = qNameRef.tokens.length - 1; switch (qNameRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD: // reading a field typeBinding = qNameRef.actualReceiverType; maxType -= qNameRef.otherBindings == null ? 1 : qNameRef.otherBindings.length + 1; break; case Binding.TYPE: //=============only type ============== if (binding instanceof TypeBinding) typeBinding = (TypeBinding) binding; break; case Binding.VARIABLE: //============unbound cases=========== case Binding.TYPE | Binding.VARIABLE: if (binding instanceof ProblemFieldBinding) { typeBinding = qNameRef.actualReceiverType; maxType -= qNameRef.otherBindings == null ? 1 : qNameRef.otherBindings.length + 1; } else if (binding instanceof ProblemBinding) { ProblemBinding pbBinding = (ProblemBinding) binding; typeBinding = pbBinding.searchType; // second chance with recorded type so far char[] partialQualifiedName = pbBinding.name; maxType = CharOperation.occurencesOf('.', partialQualifiedName) - 1; // index of last bound token is one before the pb token if (typeBinding == null || maxType < 0) return; } break; } } else if (reference instanceof SingleNameReference) { typeBinding = (TypeBinding) ((SingleNameReference) reference).binding; maxType = 1; } if (typeBinding instanceof ArrayBinding) typeBinding = ((ArrayBinding) typeBinding).leafComponentType; if (typeBinding == null || typeBinding instanceof BaseTypeBinding) return; if (typeBinding instanceof ProblemReferenceBinding) { TypeBinding original = typeBinding.closestMatch(); if (original == null) return; // original may not be set (bug 71279) typeBinding = original; } typeBinding = typeBinding.erasure(); reportDeclaration((ReferenceBinding) typeBinding, maxType, locator, knownTypes); }
From source file:com.codenvy.ide.ext.java.server.internal.core.search.matching.TypeReferenceLocator.java
License:Open Source License
protected int resolveLevel(NameReference nameRef) { Binding binding = nameRef.binding; if (nameRef instanceof SingleNameReference) { if (binding instanceof ProblemReferenceBinding) binding = ((ProblemReferenceBinding) binding).closestMatch(); if (binding instanceof ReferenceBinding) return resolveLevelForType((ReferenceBinding) binding); return binding == null || binding instanceof ProblemBinding ? INACCURATE_MATCH : IMPOSSIBLE_MATCH; }//from www.j av a2 s .co m TypeBinding typeBinding = null; QualifiedNameReference qNameRef = (QualifiedNameReference) nameRef; switch (qNameRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.FIELD: // reading a field if (qNameRef.tokens.length < (qNameRef.otherBindings == null ? 2 : qNameRef.otherBindings.length + 2)) return IMPOSSIBLE_MATCH; // must be at least A.x typeBinding = nameRef.actualReceiverType; break; case Binding.LOCAL: // reading a local variable return IMPOSSIBLE_MATCH; // no type match in it case Binding.TYPE: //=============only type ============== if (binding instanceof TypeBinding) typeBinding = (TypeBinding) binding; break; /* * Handling of unbound qualified name references. The match may reside in the resolved fragment, * which is recorded inside the problem binding, along with the portion of the name until it became a problem. */ case Binding.VARIABLE: //============unbound cases=========== case Binding.TYPE | Binding.VARIABLE: if (binding instanceof ProblemReferenceBinding) { typeBinding = (TypeBinding) binding; } else if (binding instanceof ProblemFieldBinding) { if (qNameRef.tokens.length < (qNameRef.otherBindings == null ? 2 : qNameRef.otherBindings.length + 2)) return IMPOSSIBLE_MATCH; // must be at least A.x typeBinding = nameRef.actualReceiverType; } else if (binding instanceof ProblemBinding) { ProblemBinding pbBinding = (ProblemBinding) binding; if (CharOperation.occurencesOf('.', pbBinding.name) <= 0) // index of last bound token is one before the pb token return INACCURATE_MATCH; typeBinding = pbBinding.searchType; } break; } return resolveLevel(typeBinding); }
From source file:org.eclipse.ajdt.core.parserbridge.AJSourceElementParser2.java
License:Open Source License
public NameReference getUnspecifiedReferenceOptimized() { /* build a (unspecified) NameReference which may be qualified The optimization occurs for qualified reference while we are certain in this case the last item of the qualified name is a field access. This optimization is IMPORTANT while it results that when a NameReference is build, the type checker should always look for that it is not a type reference */ int length;//from ww w .j a v a2 s . c o m if ((length = identifierLengthStack[identifierLengthPtr--]) == 1) { // single variable reference SingleNameReference ref = newSingleNameReference(identifierStack[identifierPtr], identifierPositionStack[identifierPtr--]); ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.LOCAL | Binding.FIELD; if (reportReferenceInfo) { this.addUnknownRef(ref); } return ref; } //Qualified-variable-reference //In fact it is variable-reference DOT field-ref , but it would result in a type //conflict tha can be only reduce by making a superclass (or inetrface ) between //nameReference and FiledReference or putting FieldReference under NameReference //or else..........This optimisation is not really relevant so just leave as it is char[][] tokens = new char[length][]; identifierPtr -= length; System.arraycopy(identifierStack, identifierPtr + 1, tokens, 0, length); long[] positions = new long[length]; System.arraycopy(identifierPositionStack, identifierPtr + 1, positions, 0, length); QualifiedNameReference ref = newQualifiedNameReference(tokens, positions, (int) (identifierPositionStack[identifierPtr + 1] >> 32), // sourceStart (int) identifierPositionStack[identifierPtr + length]); // sourceEnd ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.LOCAL | Binding.FIELD; if (reportReferenceInfo) { this.addUnknownRef(ref); } return ref; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public Binding getBinding(char[] name, int mask, InvocationSite invocationSite, boolean needResolve) { CompilationUnitScope unitScope = compilationUnitScope(); LookupEnvironment env = unitScope.environment; try {/*w w w.j a va2 s.c om*/ env.missingClassFileLocation = invocationSite; Binding binding = null; FieldBinding problemField = null; if ((mask & Binding.VARIABLE) != 0) { boolean insideStaticContext = false; boolean insideConstructorCall = false; boolean insideTypeAnnotation = false; FieldBinding foundField = null; // can be a problem field which is answered if a valid field is not found ProblemFieldBinding foundInsideProblem = null; // inside Constructor call or inside static context Scope scope = this; int depth = 0; int foundDepth = 0; ReferenceBinding foundActualReceiverType = null; done: while (true) { // done when a COMPILATION_UNIT_SCOPE is found switch (scope.kind) { case METHOD_SCOPE: MethodScope methodScope = (MethodScope) scope; insideStaticContext |= methodScope.isStatic; insideConstructorCall |= methodScope.isConstructorCall; insideTypeAnnotation = methodScope.insideTypeAnnotation; //$FALL-THROUGH$ could duplicate the code below to save a cast - questionable optimization case BLOCK_SCOPE: LocalVariableBinding variableBinding = scope.findVariable(name); // looks in this scope only if (variableBinding != null) { if (foundField != null && foundField.isValidBinding()) return new ProblemFieldBinding(foundField, // closest match foundField.declaringClass, name, ProblemReasons.InheritedNameHidesEnclosingName); if (depth > 0) invocationSite.setDepth(depth); return variableBinding; } break; case CLASS_SCOPE: ClassScope classScope = (ClassScope) scope; ReferenceBinding receiverType = classScope.enclosingReceiverType(); if (!insideTypeAnnotation) { FieldBinding fieldBinding = classScope.findField(receiverType, name, invocationSite, needResolve); // Use next line instead if willing to enable protected access accross inner types // FieldBinding fieldBinding = findField(enclosingType, name, invocationSite); if (fieldBinding != null) { // skip it if we did not find anything if (fieldBinding.problemId() == ProblemReasons.Ambiguous) { if (foundField == null || foundField.problemId() == ProblemReasons.NotVisible) // supercedes any potential InheritedNameHidesEnclosingName problem return fieldBinding; // make the user qualify the field, likely wants the first inherited field (javac generates an ambiguous error instead) return new ProblemFieldBinding(foundField, // closest match foundField.declaringClass, name, ProblemReasons.InheritedNameHidesEnclosingName); } ProblemFieldBinding insideProblem = null; if (fieldBinding.isValidBinding()) { if (!fieldBinding.isStatic()) { if (insideConstructorCall) { insideProblem = new ProblemFieldBinding(fieldBinding, // closest match fieldBinding.declaringClass, name, ProblemReasons.NonStaticReferenceInConstructorInvocation); } else if (insideStaticContext) { insideProblem = new ProblemFieldBinding(fieldBinding, // closest match fieldBinding.declaringClass, name, ProblemReasons.NonStaticReferenceInStaticContext); } } if (receiverType == fieldBinding.declaringClass || compilerOptions().complianceLevel >= ClassFileConstants.JDK1_4) { // found a valid field in the 'immediate' scope (i.e. not inherited) // OR in 1.4 mode (inherited shadows enclosing) if (foundField == null) { if (depth > 0) { invocationSite.setDepth(depth); invocationSite.setActualReceiverType(receiverType); } // return the fieldBinding if it is not declared in a superclass of the scope's binding (that is, inherited) return insideProblem == null ? fieldBinding : insideProblem; } if (foundField.isValidBinding()) // if a valid field was found, complain when another is found in an 'immediate' enclosing type (that is, not inherited) // but only if "valid field" was inherited in the first place. if (foundField.declaringClass != fieldBinding.declaringClass && foundField.declaringClass != foundActualReceiverType) // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316956 // i.e. have we found the same field - do not trust field identity yet return new ProblemFieldBinding(foundField, // closest match foundField.declaringClass, name, ProblemReasons.InheritedNameHidesEnclosingName); } } if (foundField == null || (foundField.problemId() == ProblemReasons.NotVisible && fieldBinding.problemId() != ProblemReasons.NotVisible)) { // only remember the fieldBinding if its the first one found or the previous one was not visible & fieldBinding is... foundDepth = depth; foundActualReceiverType = receiverType; foundInsideProblem = insideProblem; foundField = fieldBinding; } } } insideTypeAnnotation = false; depth++; insideStaticContext |= receiverType.isStatic(); // 1EX5I8Z - accessing outer fields within a constructor call is permitted // in order to do so, we change the flag as we exit from the type, not the method // itself, because the class scope is used to retrieve the fields. MethodScope enclosingMethodScope = scope.methodScope(); insideConstructorCall = enclosingMethodScope == null ? false : enclosingMethodScope.isConstructorCall; break; case COMPILATION_UNIT_SCOPE: break done; } scope = scope.parent; } if (foundInsideProblem != null) return foundInsideProblem; if (foundField != null) { if (foundField.isValidBinding()) { if (foundDepth > 0) { invocationSite.setDepth(foundDepth); invocationSite.setActualReceiverType(foundActualReceiverType); } return foundField; } problemField = foundField; foundField = null; } if (compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { // at this point the scope is a compilation unit scope & need to check for imported static fields unitScope.faultInImports(); // ensure static imports are resolved ImportBinding[] imports = unitScope.imports; if (imports != null) { // check single static imports for (int i = 0, length = imports.length; i < length; i++) { ImportBinding importBinding = imports[i]; if (importBinding.isStatic() && !importBinding.onDemand) { if (CharOperation.equals( importBinding.compoundName[importBinding.compoundName.length - 1], name)) { if (unitScope.resolveSingleImport(importBinding, Binding.TYPE | Binding.FIELD | Binding.METHOD) != null && importBinding.resolvedImport instanceof FieldBinding) { foundField = (FieldBinding) importBinding.resolvedImport; ImportReference importReference = importBinding.reference; if (importReference != null && needResolve) { importReference.bits |= ASTNode.Used; } invocationSite.setActualReceiverType(foundField.declaringClass); if (foundField.isValidBinding()) { return foundField; } if (problemField == null) problemField = foundField; } } } } // check on demand imports boolean foundInImport = false; for (int i = 0, length = imports.length; i < length; i++) { ImportBinding importBinding = imports[i]; if (importBinding.isStatic() && importBinding.onDemand) { Binding resolvedImport = importBinding.resolvedImport; if (resolvedImport instanceof ReferenceBinding) { FieldBinding temp = findField((ReferenceBinding) resolvedImport, name, invocationSite, needResolve); if (temp != null) { if (!temp.isValidBinding()) { if (problemField == null) problemField = temp; } else if (temp.isStatic()) { if (foundField == temp) continue; ImportReference importReference = importBinding.reference; if (importReference != null && needResolve) { importReference.bits |= ASTNode.Used; } if (foundInImport) // Answer error binding -- import on demand conflict; name found in two import on demand packages. return new ProblemFieldBinding(foundField, // closest match foundField.declaringClass, name, ProblemReasons.Ambiguous); foundField = temp; foundInImport = true; } } } } } if (foundField != null) { invocationSite.setActualReceiverType(foundField.declaringClass); return foundField; } } } } // We did not find a local or instance variable. if ((mask & Binding.TYPE) != 0) { if ((binding = getBaseType(name)) != null) return binding; binding = getTypeOrPackage(name, (mask & Binding.PACKAGE) == 0 ? Binding.TYPE : Binding.TYPE | Binding.PACKAGE, needResolve); if (binding.isValidBinding() || mask == Binding.TYPE) return binding; // answer the problem type binding if we are only looking for a type } else if ((mask & Binding.PACKAGE) != 0) { unitScope.recordSimpleReference(name); if ((binding = env.getTopLevelPackage(name)) != null) return binding; } if (problemField != null) return problemField; if (binding != null && binding.problemId() != ProblemReasons.NotFound) return binding; // answer the better problem binding return new ProblemBinding(name, enclosingSourceType(), ProblemReasons.NotFound); } catch (AbortCompilation e) { e.updateContext(invocationSite, referenceCompilationUnit().compilationResult); throw e; } finally { env.missingClassFileLocation = null; } }
From source file:org.eclipse.jdt.internal.compiler.parser.Parser.java
License:Open Source License
protected NameReference getUnspecifiedReferenceOptimized() { /* build a (unspecified) NameReference which may be qualified The optimization occurs for qualified reference while we are certain in this case the last item of the qualified name is a field access. This optimization is IMPORTANT while it results that when a NameReference is build, the type checker should always look for that it is not a type reference */ int length;/* w w w. java2s. c o m*/ NameReference ref; if ((length = this.identifierLengthStack[this.identifierLengthPtr--]) == 1) { // single variable reference ref = new SingleNameReference(this.identifierStack[this.identifierPtr], this.identifierPositionStack[this.identifierPtr--]); ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.LOCAL | Binding.FIELD; return ref; } //Qualified-variable-reference //In fact it is variable-reference DOT field-ref , but it would result in a type //conflict tha can be only reduce by making a superclass (or inetrface ) between //nameReference and FiledReference or putting FieldReference under NameReference //or else..........This optimisation is not really relevant so just leave as it is char[][] tokens = new char[length][]; this.identifierPtr -= length; System.arraycopy(this.identifierStack, this.identifierPtr + 1, tokens, 0, length); long[] positions = new long[length]; System.arraycopy(this.identifierPositionStack, this.identifierPtr + 1, positions, 0, length); ref = new QualifiedNameReference(tokens, positions, (int) (this.identifierPositionStack[this.identifierPtr + 1] >> 32), // sourceStart (int) this.identifierPositionStack[this.identifierPtr + length]); // sourceEnd ref.bits &= ~ASTNode.RestrictiveFlagMASK; ref.bits |= Binding.LOCAL | Binding.FIELD; return ref; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.OTQualifiedAllocationExpression.java
License:Open Source License
/** * During resolve we make the decision which variant to use. *///from w ww .ja v a 2 s.com public TypeBinding resolveType(BlockScope scope) { if (this.anonymousType == null && this.creatorCall == null && this.enclosingInstance == null) // special case during code assist return super.resolveType(scope); CompilationResult compilationResult = scope.referenceContext().compilationResult(); CheckPoint cp = compilationResult.getCheckPoint(scope.referenceContext()); this.hasEnclosingInstanceProblem = false; if (this.anonymousType == null && this.creatorCall == null) { // no double processing if (this.enclosingInstance instanceof CastExpression) this.enclosingInstance.bits |= DisableUnnecessaryCastCheck; // will check later on (within super.resolveType()) TypeBinding enclosingInstanceType = this.enclosingInstance.resolveType(scope); this.hasEnclosingInstanceProblem = enclosingInstanceType == null; if (!scope.isGeneratedScope() && enclosingInstanceType != null && enclosingInstanceType.isTeam()) // non reference types will trigger error reporting via super.resolveType() { if (this.enclosingInstance instanceof NameReference) { final NameReference anchorRef = (NameReference) this.enclosingInstance; if (!((VariableBinding) anchorRef.binding).isFinal()) { // replace non-final anchor with fake-binding, // so that this type is not compatibly to anything else: char[] variableName = ((VariableBinding) anchorRef.binding).name; switch (anchorRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.LOCAL: final LocalVariableBinding localOrig = (LocalVariableBinding) anchorRef.binding; // mark the original as used before we procede with a fake copy: localOrig.useFlag = LocalVariableBinding.USED; anchorRef.binding = new LocalVariableBinding(variableName, enclosingInstanceType, ClassFileConstants.AccFinal, false) { @Override public int problemId() { return IProblem.AnchorNotFinal; } }; this.preGenerateTask = new Runnable() { public void run() { // need to transfer this info from the real local to the fake one (don't have that info yet): ((LocalVariableBinding) anchorRef.binding).resolvedPosition = localOrig.resolvedPosition; } }; break; case Binding.FIELD: anchorRef.binding = new FieldBinding(variableName, enclosingInstanceType, ClassFileConstants.AccFinal, scope.referenceType().binding, Constant.NotAConstant) { @Override public int problemId() { return IProblem.AnchorNotFinal; } }; break; default: throw new InternalCompilerError("Unexpected bits, neither local nor field " //$NON-NLS-1$ + anchorRef.bits + ": " + anchorRef); //$NON-NLS-1$ } } } if (this.type.getTypeName().length > 1) { scope.problemReporter().roleCreationNotRelativeToEnclosingTeam(this); return null; } // now it's finally time to create the alternate version: this.creatorCall = CopyInheritance.createConstructorMethodInvocationExpression(scope, this); if (this.creatorCall == null) return null; } } if (this.creatorCall == null) { TypeBinding typ = super.resolveType(scope); if (typ == null || typ instanceof PolyTypeBinding) return typ; if (!this.hasEnclosingInstanceProblem) { // more checks only if no error already // if enclosing is a role request a cast to the class part as required by the inner constructor if (this.enclosingInstance != null) { TypeBinding enclosingType = this.enclosingInstance.resolvedType; if (enclosingType instanceof ReferenceBinding && ((ReferenceBinding) enclosingType).isDirectRole()) this.enclosingInstanceCast = ((ReferenceBinding) enclosingType).getRealClass(); } ReferenceBinding superType = null; if (this.resolvedType instanceof ReferenceBinding) superType = ((ReferenceBinding) this.resolvedType).superclass(); if (superType != null && (superType instanceof RoleTypeBinding)) { RoleTypeBinding superRole = (RoleTypeBinding) superType; if (superRole.hasExplicitAnchor()) scope.problemReporter().extendingExternalizedRole(superRole, this.type); } } } else { // === with creatorCall === this.constant = Constant.NotAConstant; this.resolvedType = this.creatorCall.resolveType(scope); // when creating role nested instance, no cast of enclosing role needed in this branch, // because creator call is routed via the interface of the enclosing role. if (this.resolvedType != null) { if (((ReferenceBinding) this.resolvedType).isAbstract()) { if (!((ReferenceBinding) enclosingInstance().resolvedType).isAbstract()) scope.problemReporter().abstractRoleIsRelevant(this, (ReferenceBinding) this.creatorCall.resolvedType); } if (this.resolvedType.isValidBinding()) { // FIXME(SH): remove cast unwrapping Expression createExpr = this.creatorCall; while (createExpr instanceof CastExpression) // may have been wrapped using CollectedReplacementsTransformer createExpr = ((CastExpression) createExpr).expression; this.binding = ((MessageSend) createExpr).binding; // store the method binding // using lift-ctor in a qualified way? (OTJDL 2.4.1(a)) ReferenceBinding role = (ReferenceBinding) this.resolvedType; MethodBinding creator = this.binding; if (creator != null) { MethodBinding ctor = role.getExactConstructor(creator.parameters); if (Lifting.isLiftToConstructor(ctor, role)) scope.problemReporter().qualifiedUseOfLiftingConstructor(ctor, this.creatorCall); } } } } return this.resolvedType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference.java
License:Open Source License
@Override public TypeBinding resolveType(BlockScope scope, boolean checkBounds, int location) { if (!this.isExpression) { scope.problemReporter().valueParamWrongPosition(this); return null; }//from ww w . j av a 2 s .c om // support to interpret this reference as an expression (see CalloutImplementor) ITeamAnchor binding = resolveAnchor(scope); if (binding == null) return null; if (binding.isValidBinding()) { ReferenceBinding receiverType = null; int bit = Binding.LOCAL; if (binding instanceof FieldBinding) { bit = Binding.FIELD; receiverType = ((FieldBinding) binding).declaringClass; } this.bits &= ~RestrictiveFlagMASK; this.bits |= bit; this.anchor.bits &= ~RestrictiveFlagMASK; this.anchor.bits |= bit; this.constant = Constant.NotAConstant; this.anchor.constant = Constant.NotAConstant; int depth = 0; if (receiverType != null && this.anchor instanceof InvocationSite) { // could be QualifiedBaseReference which sets its depth during resolveAnchor ReferenceBinding currentType = scope.enclosingSourceType(); while (!currentType.isCompatibleWith(receiverType)) { depth++; currentType = currentType.enclosingType(); if (currentType == null) return null; // shouldn't happen, if callout was constructed correctly. } ((InvocationSite) this.anchor).setDepth(depth); } } return this.resolvedType = binding.getResolvedType(); }