List of usage examples for org.eclipse.jdt.internal.compiler.lookup ProblemFieldBinding ProblemFieldBinding
public ProblemFieldBinding(ReferenceBinding declaringClass, char[] name, int problemId)
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public FieldBinding findField(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite, boolean needResolve, boolean invisibleFieldsOk) { CompilationUnitScope unitScope = compilationUnitScope(); unitScope.recordTypeReference(receiverType); checkArrayField: {/*w w w . j ava 2s .com*/ TypeBinding leafType; switch (receiverType.kind()) { case Binding.BASE_TYPE: return null; case Binding.WILDCARD_TYPE: case Binding.INTERSECTION_TYPE: case Binding.TYPE_PARAMETER: // capture TypeBinding receiverErasure = receiverType.erasure(); if (!receiverErasure.isArrayType()) break checkArrayField; leafType = receiverErasure.leafComponentType(); break; case Binding.ARRAY_TYPE: leafType = receiverType.leafComponentType(); break; default: break checkArrayField; } if (leafType instanceof ReferenceBinding) if (!((ReferenceBinding) leafType).canBeSeenBy(this)) return new ProblemFieldBinding((ReferenceBinding) leafType, fieldName, ProblemReasons.ReceiverTypeNotVisible); if (CharOperation.equals(fieldName, TypeConstants.LENGTH)) { if ((leafType.tagBits & TagBits.HasMissingType) != 0) { return new ProblemFieldBinding(ArrayBinding.ArrayLength, null, fieldName, ProblemReasons.NotFound); } return ArrayBinding.ArrayLength; } return null; } ReferenceBinding currentType = (ReferenceBinding) receiverType; if (!currentType.canBeSeenBy(this)) return new ProblemFieldBinding(currentType, fieldName, ProblemReasons.ReceiverTypeNotVisible); currentType.initializeForStaticImports(); FieldBinding field = currentType.getField(fieldName, needResolve); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=316456 boolean insideTypeAnnotations = this instanceof MethodScope && ((MethodScope) this).insideTypeAnnotation; if (field != null) { if (invisibleFieldsOk) { return field; } if (invocationSite == null || insideTypeAnnotations ? field.canBeSeenBy(getCurrentPackage()) : field.canBeSeenBy(currentType, invocationSite, this)) return field; return new ProblemFieldBinding(field /* closest match*/, field.declaringClass, fieldName, ProblemReasons.NotVisible); } // collect all superinterfaces of receiverType until the field is found in a supertype ReferenceBinding[] interfacesToVisit = null; int nextPosition = 0; FieldBinding visibleField = null; boolean keepLooking = true; FieldBinding notVisibleField = null; // we could hold onto the not visible field for extra error reporting while (keepLooking) { ReferenceBinding[] itsInterfaces = currentType.superInterfaces(); if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { if (interfacesToVisit == null) { interfacesToVisit = itsInterfaces; nextPosition = interfacesToVisit.length; } else { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } if ((currentType = currentType.superclass()) == null) break; unitScope.recordTypeReference(currentType); currentType.initializeForStaticImports(); currentType = (ReferenceBinding) currentType.capture(this, invocationSite == null ? 0 : invocationSite.sourceEnd()); if ((field = currentType.getField(fieldName, needResolve)) != null) { if (invisibleFieldsOk) { return field; } keepLooking = false; if (field.canBeSeenBy(receiverType, invocationSite, this)) { if (visibleField == null) visibleField = field; else return new ProblemFieldBinding(visibleField /* closest match*/, visibleField.declaringClass, fieldName, ProblemReasons.Ambiguous); } else { if (notVisibleField == null) notVisibleField = field; } } } // walk all visible interfaces to find ambiguous references if (interfacesToVisit != null) { ProblemFieldBinding ambiguous = null; done: for (int i = 0; i < nextPosition; i++) { ReferenceBinding anInterface = interfacesToVisit[i]; unitScope.recordTypeReference(anInterface); // no need to capture rcv interface, since member field is going to be static anyway if ((field = anInterface.getField(fieldName, true /*resolve*/)) != null) { if (invisibleFieldsOk) { return field; } if (visibleField == null) { visibleField = field; } else { ambiguous = new ProblemFieldBinding(visibleField /* closest match*/, visibleField.declaringClass, fieldName, ProblemReasons.Ambiguous); break done; } } else { ReferenceBinding[] itsInterfaces = anInterface.superInterfaces(); if (itsInterfaces != null && itsInterfaces != Binding.NO_SUPERINTERFACES) { int itsLength = itsInterfaces.length; if (nextPosition + itsLength >= interfacesToVisit.length) System.arraycopy(interfacesToVisit, 0, interfacesToVisit = new ReferenceBinding[nextPosition + itsLength + 5], 0, nextPosition); nextInterface: for (int a = 0; a < itsLength; a++) { ReferenceBinding next = itsInterfaces[a]; for (int b = 0; b < nextPosition; b++) if (next == interfacesToVisit[b]) continue nextInterface; interfacesToVisit[nextPosition++] = next; } } } } if (ambiguous != null) return ambiguous; } if (visibleField != null) return visibleField; if (notVisibleField != null) { return new ProblemFieldBinding(notVisibleField, currentType, fieldName, ProblemReasons.NotVisible); } return null; }
From source file:org.eclipse.jdt.internal.compiler.lookup.Scope.java
License:Open Source License
public FieldBinding getField(TypeBinding receiverType, char[] fieldName, InvocationSite invocationSite) { LookupEnvironment env = environment(); try {// w w w.j av a 2 s . c o m env.missingClassFileLocation = invocationSite; FieldBinding field = findField(receiverType, fieldName, invocationSite, true /*resolve*/); if (field != null) return field; return new ProblemFieldBinding( receiverType instanceof ReferenceBinding ? (ReferenceBinding) receiverType : null, fieldName, ProblemReasons.NotFound); } catch (AbortCompilation e) { e.updateContext(invocationSite, referenceCompilationUnit().compilationResult); throw e; } finally { env.missingClassFileLocation = null; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.FieldAccessSpec.java
License:Open Source License
@Override // if an access method is needed, return that accessor, else null public MethodBinding resolveFeature(final ReferenceBinding baseType, final BlockScope scope, boolean callinExpected, boolean isBaseSide, boolean allowEnclosing) { // find field in type or superclass: this.resolvedField = TypeAnalyzer.findField(baseType, this.selector, /*don't check static*/false, /*outer*/false); if (this.resolvedField == null) this.resolvedField = new ProblemFieldBinding(baseType, this.selector, ProblemReasons.NotFound); // Note: if more resilience is desired, try to set resolvedField.resolvedType and proceed if (!this.resolvedField.isValidBinding()) return null; this.fieldType = resolvedType(); // may be improved below final TypeBinding fieldLeafType = this.fieldType.leafComponentType(); if (fieldLeafType instanceof ReferenceBinding) { final int outerDimensions = this.fieldType.dimensions(); TypeArgumentUpdater updater = new TypeArgumentUpdater() { @Override// www . java2s. c o m public TypeBinding updateArg(ReferenceBinding type) { boolean atTopLevel = type == fieldLeafType; //$IDENTITY-COMPARISON$ if (type.isRole()) { // find team anchor for role type of base field: ITeamAnchor newAnchor = null; if (baseType instanceof RoleTypeBinding) { // base class is already a role: construct the full team anchor: RoleTypeBinding baseRole = (RoleTypeBinding) baseType; if (type instanceof RoleTypeBinding) { RoleTypeBinding fieldRole = (RoleTypeBinding) type; if (fieldRole.hasExplicitAnchor()) newAnchor = fieldRole._teamAnchor.setPathPrefix(baseRole._teamAnchor); else newAnchor = baseRole._teamAnchor; } else { newAnchor = baseRole._teamAnchor; } } else if (baseType.isTeam()) { // base class is a team, construct simple anchor ReferenceBinding enclRole = scope.enclosingSourceType(); newAnchor = TypeAnalyzer.findField(enclRole, IOTConstants._OT_BASE, /*don't check static*/false, /*outer*/false); } // else fieldLeafType might already be a anchored type, // independent of _OT$base, leave it as it is if (newAnchor != null && newAnchor.isValidBinding()) return newAnchor.getRoleTypeBinding(type, atTopLevel ? outerDimensions : 0); } return atTopLevel ? FieldAccessSpec.this.fieldType : type; } }; this.fieldType = updater.updateArg((ReferenceBinding) fieldLeafType).maybeWrapRoleType(this, updater); } if (!baseType.isRole() && this.resolvedField.canBeSeenBy(scope.enclosingReceiverType().baseclass(), this, scope)) { // no accessor method needed this.implementationStrategy = ImplementationStrategy.DIRECT; if (!this.isSetter()) this.parameters = Binding.NO_PARAMETERS; else this.parameters = new TypeBinding[] { this.fieldType }; return null; } this.implementationStrategy = scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE ? ImplementationStrategy.DYN_ACCESS : ImplementationStrategy.DECAPS_WRAPPER; // find accessor method which might have been generated already. char[] accessorSelector = getSelector(); MethodBinding result = null; if (!this.resolvedField.isPrivate()) // don't reuse accessor to private field from super-base (see Trac #232) result = baseType.getMethod(scope, accessorSelector); // NOTE: could be optimized if type has no such method but exact type already has. // but the the OTRE would need to be informed.. if (result == null || !isMethodCompatible(result)) { // record this field access for Attribute generation: RoleModel roleModel = scope.enclosingSourceType().roleModel; // find appropriate target class FieldBinding field = this.resolvedField; ReferenceBinding targetClass = field.declaringClass; // default: the class declaring the field (could be super of bound base) if (!field.isStatic() && (field.isProtected() || field.isPublic())) targetClass = roleModel.getBaseTypeBinding(); // use the specific declared bound class (avoids weaving into possibly inaccessible super base) // create accessor method: result = createMethod(scope, targetClass, accessorSelector); } this.selector = accessorSelector; this.resolvedMethod = result; this.parameters = this.resolvedMethod.getSourceParameters(); return this.resolvedMethod; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.FieldAccessSpec.java
License:Open Source License
public void checkResolutionSuccess(ReferenceBinding type, CallinCalloutScope scope) { if (this.resolvedField == null) this.resolvedField = new ProblemFieldBinding(type, this.selector, ProblemReasons.NotFound); else if (this.resolvedField.isValidBinding()) return; // OK scope.problemReporter().boundMethodProblem(this, type, true/*isCallout*/); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.QualifiedBaseReference.java
License:Open Source License
@Override public TypeBinding resolveType(BlockScope scope) { TypeBinding superResult = super.resolveType(scope); if (superResult == null || !superResult.isValidBinding()) return null; ReferenceBinding currentType = this.currentCompatibleType; while (currentType != null && currentType.isValidBinding() && currentType.isRole()) { this.baseField = currentType.getField(IOTConstants._OT_BASE, true); if (this.baseField != null) { if (this.baseField.isValidBinding()) return this.resolvedType = this.baseField.type; }/*w w w.ja v a2s . co m*/ currentType = currentType.superclass(); // base field may be inherited } if (this.baseField == null) this.baseField = new ProblemFieldBinding((ReferenceBinding) this.resolvedType, IOTConstants.BASE, ProblemReasons.NotFound); scope.problemReporter().unboundQualifiedBase((ReferenceBinding) this.qualification.resolvedType, this); return null; }
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;/*from ww w.jav a 2 s .com*/
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.lookup.SyntheticRoleFieldAccess.java
License:Open Source License
/** For binary type: recover target field information from the encoded selector. */ public FieldBinding resolvedField() { if (this.targetReadField != null) return this.targetReadField; if (this.targetWriteField != null) return this.targetWriteField; char[][] splitName = CharOperation.splitOn('$', this.selector); // "_OT fieldget/set Role field" ReferenceBinding roleType = this.declaringClass.getMemberType(splitName[2]); FieldBinding field = roleType.getRealClass().getField(splitName[3], true); if (field == null) { field = roleType.getRealType().getField(splitName[3], true); if (field == null || !field.isStatic()) field = new ProblemFieldBinding(roleType, splitName[3], ProblemReasons.NotFound); }/*from w w w .ja v a 2s . c o m*/ if (CharOperation.equals(FIELD_GET_NAME, splitName[1])) { this.targetReadField = field; this.purpose = FieldReadAccess; } else { this.targetWriteField = field; this.purpose = FieldWriteAccess; } return field; }