List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope problemReporter
public abstract ProblemReporter problemReporter();
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.FieldAccessSpec.java
License:Open Source License
@Override void checkDecapsulation(ReferenceBinding baseClass, Scope scope) { if (this.implementationStrategy != ImplementationStrategy.DIRECT) { this.accessId = createAccessAttribute(scope.enclosingSourceType().roleModel); scope.problemReporter().decapsulation(this, baseClass, scope, isSetter()); }/*from w w w . j ava 2s. co m*/ }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.MethodSpec.java
License:Open Source License
void checkDecapsulation(ReferenceBinding baseClass, Scope scope) { if (!this.resolvedMethod.canBeSeenBy(baseClass, this, scope)) { WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme; this.implementationStrategy = weavingScheme == WeavingScheme.OTDRE ? ImplementationStrategy.DYN_ACCESS : ImplementationStrategy.DECAPS_WRAPPER; this.accessId = createAccessAttribute(scope.enclosingSourceType().roleModel); scope.problemReporter().decapsulation(this, baseClass, scope); } else {/*from w w w . j a v a 2 s . c om*/ this.implementationStrategy = ImplementationStrategy.DIRECT; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PrecedenceDeclaration.java
License:Open Source License
/** * Does list of bindings contain a pair of callins, of which one overrides the other? * Signal a problem if so.//from w ww . java2 s .c om * * @param bindingNames */ private static void checkOverriding(NameReference[] bindingNames, Scope scope) { for (int i = 1; i < bindingNames.length; i++) { NameReference ref_i = bindingNames[i]; if (ref_i.binding != null && ref_i.binding.kind() == Binding.BINDING) { for (int j = 0; j < i; j++) { NameReference ref_j = bindingNames[j]; if (ref_j.binding != null && ref_j.binding.kind() == Binding.BINDING) { CallinCalloutBinding callin_i = (CallinCalloutBinding) ref_i.binding; CallinCalloutBinding callin_j = (CallinCalloutBinding) ref_j.binding; if (!CharOperation.equals(callin_i.name, callin_j.name)) continue; ReferenceBinding role_i = callin_i._declaringRoleClass; ReferenceBinding role_j = callin_j._declaringRoleClass; if (role_i.isCompatibleWith(role_j)) scope.problemReporter().precedenceForOverriding(ref_i, ref_j); if (role_j.isCompatibleWith(role_i)) scope.problemReporter().precedenceForOverriding(ref_j, ref_i); } } } } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PrecedenceDeclaration.java
License:Open Source License
/** * Resolve an element of a precedence declaration. * * @param scope/*from w w w . j a v a 2 s .c om*/ * @param type * @param name * @return either CallinCalloutBinding or ReferenceBinding or null */ private Binding findCallinInType(Scope scope, ReferenceBinding type, char[] name, boolean typeAllowed) { if (type.isRole()) { Binding found = findCallinInRole(type, name); if (found != null) return found; } type = type.getRealClass(); if (type.isTeam()) { ReferenceBinding roleBinding = type.getMemberType(name); if (roleBinding != null) { if (!typeAllowed) { scope.problemReporter().illegalDeepRoleReferenceInPrecedence(this, type, roleBinding); return new ProblemReferenceBinding(name, roleBinding, ProblemReasons.NotVisible); } return roleBinding; } return null; } if (type.isRole()) return null; // tried before, no success. scope.problemReporter().illegalEnclosingForCallinName(this, type, name); 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;/* w w w . j a va 2 s . c o m*/ 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.ast.TypeAnchorReference.java
License:Open Source License
/** * If this reference has a static prefix return its resolved type. * (obviously only for qualified anchors). *///from ww w . j av a 2 s . c om public ReferenceBinding resolveStaticPart(Scope scope) { // extract from above method: // (but cannot use this above, because more than one local variable // would need to be returned to the caller). if (!(this.anchor instanceof QualifiedNameReference)) return null; QualifiedNameReference qualifiedAnchor = (QualifiedNameReference) this.anchor; char[][] tokens = qualifiedAnchor.tokens; // 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(this.anchor); return null; } if (staticPrefix instanceof ReferenceBinding) return (ReferenceBinding) staticPrefix; return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference.java
License:Open Source License
private ITeamAnchor findVariable(Scope scope, char[] token, boolean isStaticScope, int start, int end) { if (scope instanceof ClassScope && ((ClassScope) scope).superTypeReference != null) { scope.problemReporter().extendingExternalizedRole(((ClassScope) scope).superTypeReference); return null; }//from w w w .j a va 2 s .com VariableBinding anchorBinding = null; switch (scope.kind) { case Scope.METHOD_SCOPE: // check arguments for possible anchor: AbstractMethodDeclaration method = ((MethodScope) scope).referenceMethod(); if (method != null) { Argument[] arguments = method.arguments; if (arguments != null) for (int i = 0; i < arguments.length; i++) if (CharOperation.equals(arguments[i].name, token)) return RoleTypeCreator.resolveTypeAnchoredToArgument(method, i); } //$FALL-THROUGH$ case Scope.BLOCK_SCOPE: case Scope.BINDING_SCOPE: anchorBinding = scope.findVariable(token); break; } if (anchorBinding == null) { Binding binding = scope.getBinding(token, Binding.VARIABLE, this, true); if (binding instanceof VariableBinding) anchorBinding = (VariableBinding) binding; } return checkAnchor(scope, this.anchor, token, start, end, anchorBinding); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference.java
License:Open Source License
private ITeamAnchor checkAnchor(Scope scope, Reference reference, char[] token, int start, int end, ITeamAnchor anchorBinding) {/*from w ww . j a va2 s. c o m*/ if (anchorBinding == null) { scope.problemReporter().typeAnchorNotFound(token, start, end); return null; } if (anchorBinding instanceof ProblemFieldBinding) { if (reference instanceof NameReference) scope.problemReporter().invalidField((NameReference) reference, (FieldBinding) anchorBinding); else if (reference instanceof FieldReference) scope.problemReporter().invalidField((FieldReference) reference, ((FieldReference) reference).actualReceiverType); return null; } if (!anchorBinding.hasValidReferenceType()) { scope.problemReporter().typeAnchorReferenceNotAnObjectRef(start, end); return null; } return anchorBinding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference.java
License:Open Source License
/** * Create a DependentTypeBinding from a type reference and a TypeAnchorReference. * Performs the following checks://from w ww. ja v a 2s . c o m * - does the type denoted by typeReference have a value parameter? * - does this anchor reference match the declared type of the corresponding value parameter? * * PRE: this.anchor and typeReference have already been resolved, * however, resolving of typeReference has not yet considered any parameters. * * @param scope * @param typeReference the type reference decorated with this type anchor. * @param typeParamPosition position within the type parameter list of the generic type * @return a DependentTypeBinding, or and array thereof or null; */ public TypeBinding createDependentTypeBinding(Scope scope, TypeReference typeReference, int typeParamPosition) { TypeBinding type = typeReference.resolvedType; ITeamAnchor anchorBinding = null; if (this.anchor instanceof NameReference) anchorBinding = (ITeamAnchor) ((NameReference) this.anchor).binding; else if (this.anchor instanceof FieldReference) anchorBinding = ((FieldReference) this.anchor).binding; if (anchorBinding != null && type instanceof ReferenceBinding && type.isValidBinding()) { ReferenceBinding refBinding = (ReferenceBinding) type; VariableBinding currentParam = refBinding.valueParamSynthArgAt(typeParamPosition); if (currentParam == null) { scope.problemReporter().typeHasNoValueParamAt(typeReference, refBinding, typeParamPosition); return null; } if (currentParam.type instanceof UnresolvedReferenceBinding) { currentParam.type = ((UnresolvedReferenceBinding) currentParam.type).resolve(scope.environment(), false); } if (currentParam.isValidBinding() && !anchorBinding.isTypeCompatibleWith((ReferenceBinding) currentParam.type)) { scope.problemReporter().incompatibleValueParameter(this, currentParam); return null; } TypeBinding[] typeArguments = refBinding.isParameterizedType() ? ((ParameterizedTypeBinding) refBinding).arguments : null; return anchorBinding.getDependentTypeBinding(refBinding, typeParamPosition, typeArguments, typeReference.dimensions()); } else { scope.problemReporter().invalidType(typeReference, new ProblemReferenceBinding(typeReference.getTypeName(), null, ProblemReasons.NotFound)); return null; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.CopyInheritanceSourceAttribute.java
License:Open Source License
public void evaluateLateAttribute(ReferenceBinding roleBinding, int state) { switch (state) { case ITranslationStates.STATE_ROLE_FEATURES_COPIED: break; // go aheady and evaluate case ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED: if (this.method == null) return; // can't work if (this.method.copyInheritanceSrc != null) return; // have already worked break;//ww w .ja v a 2 s . co m default: return; // only in above to states } // will need a method binding from a tsuper role: ReferenceBinding teamBinding = this.method.declaringClass.enclosingType(); if (teamBinding != null && teamBinding.superclass() != null) Dependencies.ensureBindingState(teamBinding.superclass(), ITranslationStates.STATE_LENV_DONE_FIELDS_AND_METHODS); else assert this.method.declaringClass.isLocalType(); // enclosing type not set for these. int dotPos = CharOperation.indexOf('.', this.sourceMethodDesignator); int lparPos = CharOperation.indexOf('(', this.sourceMethodDesignator); char[] selector = CharOperation.subarray(this.sourceMethodDesignator, dotPos + 1, lparPos); char[] signature = CharOperation.subarray(this.sourceMethodDesignator, lparPos, -1); ReferenceBinding type = this.environment.getTypeFromConstantPoolName(this.sourceMethodDesignator, 0, dotPos, false, null); // FIXME(GENERIC): determine last params! if (type == null) return; if (type instanceof UnresolvedReferenceBinding) type = resolveReferenceType(this.environment, (UnresolvedReferenceBinding) type); if (type instanceof MissingTypeBinding) { ProblemReporter problemReporter = this.environment.problemReporter; ReferenceBinding current = roleBinding; // search a source type to report against: while (current != null && current.isBinaryBinding()) current = current.enclosingType(); if (current != null) { Scope scope = ((SourceTypeBinding) current).scope; if (scope != null) problemReporter = scope.problemReporter(); } problemReporter.staleTSuperRole(roleBinding, type, new String(CharOperation.concat(selector, signature))); return; } if (roleBinding.roleModel.hasTSuperRole(type)) { Dependencies.ensureBindingState(type, ITranslationStates.STATE_LATE_ATTRIBUTES_EVALUATED); if (this.method.isAnyCallin()) signature = MethodSignatureEnhancer.generalizeReturnInSignature(signature); MethodBinding[] methods = type.getMethods(selector); for (int i = 0; i < methods.length; i++) { if (CharOperation.equals(methods[i].signature(), signature)) { MethodBinding origin = methods[i].copyInheritanceSrc; if (origin == null) origin = methods[i]; this.method.setCopyInheritanceSrc(origin); return; } } } else { if (roleBinding.isBinaryBinding()) return; // silently ignore ;-) } this.environment.problemReporter.staleTSuperRole(roleBinding, type, new String(CharOperation.concat(selector, signature))); }