List of usage examples for org.eclipse.jdt.internal.compiler.lookup VariableBinding isFinal
public final boolean isFinal()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
public static TypeBinding maybeWrapUnqualifiedRoleType(final Scope scope, final ReferenceBinding site, TypeBinding typeToWrap, final ASTNode typedNode, ProblemReporter problemReporter) { assert (!(site == null)); if (typeToWrap == null) return null; if (!typeToWrap.isValidBinding()) return typeToWrap; // don't tamper with already broken type if (TSuperHelper.isMarkerInterface(typeToWrap)) return typeToWrap; final TypeBinding originalType = typeToWrap; // consider arrays: int dimensions = typeToWrap.dimensions(); typeToWrap = typeToWrap.leafComponentType(); // consider parameterized: TypeBinding[] arguments = null;// ww w . j av a 2 s . co m if (typeToWrap.isParameterizedType()) arguments = ((ParameterizedTypeBinding) typeToWrap).arguments; // easy problems first: if (!(typeToWrap instanceof ReferenceBinding) || typeToWrap.isEnum()) return originalType; if (typeToWrap instanceof UnresolvedReferenceBinding) { // defer wrapping until resolve(): final UnresolvedReferenceBinding rawUnresolved = (UnresolvedReferenceBinding) typeToWrap; final ProblemReporter originalReporter = problemReporter; return new UnresolvedReferenceBinding(rawUnresolved.compoundName, rawUnresolved.getPackage()) { @Override public ReferenceBinding resolve(LookupEnvironment environment, boolean convertGenericToRawType) { ReferenceBinding type = rawUnresolved.resolve(environment, convertGenericToRawType); return (ReferenceBinding) maybeWrapUnqualifiedRoleType(scope, site, type, typedNode, originalReporter); } @Override public boolean hasTypeAnnotations() { return rawUnresolved.hasTypeAnnotations(); } @Override public boolean hasNullTypeAnnotations() { return rawUnresolved.hasNullTypeAnnotations(); } @Override public AnnotationBinding[] getAnnotations() { return rawUnresolved.getAnnotations(); } { this.tagBits = rawUnresolved.tagBits; } }; } if (typeToWrap instanceof IntersectionTypeBinding18) { // FIXME (recurse?) return originalType; } ReferenceBinding refBinding = (ReferenceBinding) typeToWrap; if (!refBinding.isDirectRole()) { final ProblemReporter reporter = problemReporter; return originalType.maybeWrapRoleType(typedNode, new TypeArgumentUpdater() { public TypeBinding updateArg(ReferenceBinding arg) { return maybeWrapUnqualifiedRoleType(scope, site, arg, typedNode, reporter); } }); } // already wrapped: if (typeToWrap instanceof RoleTypeBinding) { RoleTypeBinding roleType = (RoleTypeBinding) typeToWrap; if (!(roleType._teamAnchor instanceof TThisBinding)) { return originalType; // cannot improve } else { // do handle tthis RoleTypeBindings, too, because we might need to // set a new anchor // (but don't report errors, if this type is already acceptable). if (TeamModel.findEnclosingTeamContainingRole(site, roleType) != null) problemReporter = null; } } VariableBinding variableBinding = null; ReferenceBinding teamBinding = TeamModel.findEnclosingTeamContainingRole(site, refBinding); if (teamBinding != null) variableBinding = TThisBinding.getTThisForRole(refBinding, teamBinding); if (variableBinding == null) variableBinding = cannotWrapType(refBinding, problemReporter, typedNode); // handle problems (reported ones and yet unreported ones): assert (variableBinding != null); if (variableBinding == RoleTypeBinding.NoAnchor) { return originalType; } else if (!variableBinding.isFinal()) { if (problemReporter != null) problemReporter.anchorPathNotFinal(null, variableBinding, refBinding.sourceName()); // TODO return null; } else if (!(variableBinding instanceof TThisBinding) && !refBinding.isPublic()) { if (problemReporter != null) problemReporter.externalizingNonPublicRole(typedNode, refBinding); return null; } // delegate to the principal function: return getAnchoredType(scope, typedNode, variableBinding, refBinding, arguments, dimensions); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * Try to resolve an argument or return type as an anchored type. * * PRE: Regular type resolution has already failed. * * Currently only handles references of two components: anchor and Type. * (for parameters this is probably OK?) * NO: TODO(SH): arguments could also be anchored to arbitrary expressions/paths! * * @param type type reference to be analyzed (resolvedType is null or invalid) * @param arguments the arguments of the current method * @param index position of the argument to be analyzed * == arguments.length means: analyzing return type. * @param scope scope of the current method. * @return a RoleTypeBinding or null (after reporting error) *///from w ww .j a v a 2 s.c om public static TypeBinding getTypeAnchoredToParameter(TypeReference type, Argument[] arguments, int index, MethodScope scope, CheckPoint cp) { // we only handle QualifiedTypeReferences of length 2, or QualifiedArrayTypeReferences. if (!(type instanceof QualifiedTypeReference)) { return null; // not better than before } QualifiedTypeReference argType = (QualifiedTypeReference) type; // look for anchor in argument list: VariableBinding anchor = null; char[] anchorName = argType.tokens[0]; int argPos; for (argPos = 0; argPos < index; argPos++) { Argument argument = arguments[argPos]; // ensure arguments are bound, which must happen in correct order. argument.bind(scope, argument.type.resolvedType, /*used*/false); if (CharOperation.equals(argument.name, anchorName)) // compare possible anchor { argument.binding.useFlag = LocalVariableBinding.USED; // used as anchor anchor = argument.binding; if (scope.classScope().referenceContext.isConverted) anchor.modifiers |= ClassFileConstants.AccFinal; // lost during conversion. break; } } if (anchor == null) { argPos = -1; // mark as not found in argument list anchor = findAnchorInScope(scope, anchorName); } if (anchor == null) return null; // not better than before. if (!anchor.isFinal()) { char[][] typeName = type.getTypeName(); scope.problemReporter().anchorPathNotFinal(argType, anchor, typeName[typeName.length - 1]); return null; } // defensive programming: if (anchor.type == null) return null; // anchor must be a team: if (!anchor.type.isTeam()) { if (!anchor.type.isValidBinding()) return null; //can't decide whether this is a valid team or not. reportAnchorIsNotATeam(scope, argType); return null; } // delegate for role type lookup: TypeBinding anchoredType = resolveOtherPathElements(scope, type, anchor, argType.tokens, 1, argType.dimensions()); if (anchoredType != null) { if (!anchoredType.isValidBinding()) { scope.problemReporter().invalidType(type, anchoredType); return null; } if (anchoredType.leafComponentType().isRoleType()) { // prepare for creating an AnchorListAttribute RoleTypeBinding leafRoleType = (RoleTypeBinding) anchoredType.leafComponentType(); leafRoleType._argumentPosition = argPos; final AbstractMethodDeclaration methodDecl = scope.referenceMethod(); leafRoleType._declaringMethod = new DependentTypeBinding.IMethodProvider() { public MethodBinding getMethod() { return methodDecl.binding; } }; } scope.referenceContext.compilationResult().rollBack(cp); scope.problemReporter().deprecatedPathSyntax(type); } return anchoredType; }