List of usage examples for org.eclipse.jdt.internal.compiler.lookup ReferenceBinding isPublic
public final boolean isPublic()
From source file:com.google.gwt.dev.javac.Shared.java
License:Open Source License
public static int bindingToModifierBits(ReferenceBinding binding) { int bits = 0; bits |= (binding.isPublic() ? MOD_PUBLIC : 0); bits |= (binding.isPrivate() ? MOD_PRIVATE : 0); bits |= (binding.isProtected() ? MOD_PROTECTED : 0); bits |= (binding.isStatic() ? MOD_STATIC : 0); bits |= (binding.isFinal() ? MOD_FINAL : 0); bits |= (binding.isAbstract() ? MOD_ABSTRACT : 0); return bits;/*from w w w .jav a2 s . c o m*/ }
From source file:com.redhat.ceylon.eclipse.core.model.mirror.UnknownClassMirror.java
License:Open Source License
public JDTClass(ReferenceBinding klass, IType type) { this.type = type; bindingRef = new WeakReference<ReferenceBinding>(klass); pkg = new JDTPackage(klass.getPackage()); simpleName = new String(klass.sourceName()); qualifiedName = JDTUtils.getFullyQualifiedName(klass); isPublic = klass.isPublic(); isInterface = klass.isInterface();//w w w . java 2 s.com isAbstract = klass.isAbstract(); isProtected = klass.isProtected(); isDefaultAccess = klass.isDefault(); isLocalType = klass.isLocalType(); isStatic = (klass.modifiers & ClassFileConstants.AccStatic) != 0; isFinal = klass.isFinal(); isEnum = klass.isEnum(); isBinary = klass.isBinaryBinding(); isAnonymous = klass.isAnonymousType(); isJavaSource = (klass instanceof SourceTypeBinding) && new String(((SourceTypeBinding) klass).getFileName()).endsWith(".java"); isAnnotationType = klass.isAnnotationType(); bindingKey = klass.computeUniqueKey(); char[] bindingFileName = klass.getFileName(); int start = CharOperation.lastIndexOf('/', bindingFileName) + 1; if (start == 0 || start < CharOperation.lastIndexOf('\\', bindingFileName)) start = CharOperation.lastIndexOf('\\', bindingFileName) + 1; fileName = new String(CharOperation.subarray(bindingFileName, start, -1)); int jarFileEntrySeparatorIndex = CharOperation.indexOf(IDependent.JAR_FILE_ENTRY_SEPARATOR, bindingFileName); if (jarFileEntrySeparatorIndex > 0) { char[] jarPart = CharOperation.subarray(bindingFileName, 0, jarFileEntrySeparatorIndex); IJavaElement jarPackageFragmentRoot = JavaCore.create(new String(jarPart)); String jarPath = jarPackageFragmentRoot.getPath().toOSString(); char[] entryPart = CharOperation.subarray(bindingFileName, jarFileEntrySeparatorIndex + 1, bindingFileName.length); fullPath = new StringBuilder(jarPath).append("!/").append(entryPart).toString(); } else { fullPath = new String(bindingFileName); } ReferenceBinding sourceOrClass = klass; if (!klass.isBinaryBinding()) { sourceOrClass = klass.outermostEnclosingType(); } char[] classFullName = new char[0]; for (char[] part : sourceOrClass.compoundName) { classFullName = CharOperation.concat(classFullName, part, '/'); } char[][] temp = CharOperation.splitOn('.', sourceOrClass.getFileName()); String extension = temp.length > 1 ? "." + new String(temp[temp.length - 1]) : ""; javaModelPath = new String(classFullName) + extension; if (type == null) { annotations = new HashMap<>(); methods = Collections.emptyList(); interfaces = Collections.emptyList(); typeParams = Collections.emptyList(); fields = Collections.emptyList(); innerClasses = Collections.emptyList(); } }
From source file:lombok.eclipse.handlers.HandleActionFunctionAndPredicate.java
License:Open Source License
private TemplateData templateDataFor(final AbstractMethodDeclaration methodDecl, final ReferenceBinding template, final String forcedReturnType) { if (!template.isPublic()) return null; if (!template.isInterface() && !template.isAbstract()) return null; final List<TypeVariableBinding> templateTypeArguments = As.list(template.typeVariables()); final List<MethodBinding> enclosedMethods = enclosedMethodsOf(template); if (enclosedMethods.size() != 1) return null; final MethodBinding enclosedMethod = enclosedMethods.get(0); if (!matchesReturnType(enclosedMethod, forcedReturnType)) return null; final List<TypeBinding> methodTypeArguments = As.list(enclosedMethod.parameters); if (forcedReturnType == null) methodTypeArguments.add(enclosedMethod.returnType); if (!templateTypeArguments.equals(methodTypeArguments)) return null; if (forcedReturnType == null) { if ((numberOfParameters(methodDecl) + 1) != templateTypeArguments.size()) return null; } else {//from w w w. j a v a 2 s . co m if (numberOfParameters(methodDecl) != templateTypeArguments.size()) return null; } return new TemplateData(qualifiedName(template), As.string(enclosedMethod.selector), forcedReturnType); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies.java
License:Open Source License
private static boolean establishMethodsCreated(RoleModel clazz) { TypeDeclaration teamType = clazz.getTeamModel().getAst(); ReferenceBinding subRole = clazz.getBinding(); TypeDeclaration subRoleDecl = clazz.getAst(); if (subRole == null) { // extra caution, none of the code below would work clazz.setState(STATE_METHODS_CREATED); return false; }// ww w. j a v a 2 s. c o m if (OTNameUtils.isTSuperMarkerInterface(clazz.getInternalName()) || teamType == null) { // 0. binary only: create OTRE-generated methods: if (subRole.isBinaryBinding()) ((BinaryTypeBinding) subRole).createOTREMethods(clazz); clazz.setState(STATE_METHODS_CREATED); return true; // nothing to do } SourceTypeBinding subTeam = teamType.binding; if (subRoleDecl == null) { // 1. create creation methods from constructors (binding version): // TODO (SH): currently, this is only invoked for roles that are // explicitly mentioned in classes being compiled. // Need a place to store a list of previously compiled roles! if (subRole.isClass() // interfaces have not constructores, don't bother. && !subRole.isLocalType()) // local types need no creators, are only copied along with their containing method { createCreators(clazz, teamType, subRole, subTeam); } // no steps 2.+3. } // Next translations only for source types (no role nested types) if (subRoleDecl != null && subRole.isDirectRole()) { // 1. create creation methods from constructors (AST version) if (subRole.isClass()) // interfaces have not constructores, don't bother. createCtorsAndCreators(clazz, teamType, subRoleDecl, subTeam); // 2. create getTeam methods: if (subRoleDecl.isInterface()) { // process class and ifc at the same time, because otherwise an error // somewhere along the line may cause inconsistency between them two. StandardElementGenerator.createGetTeamMethod(subRoleDecl); TypeDeclaration classPart = clazz.getClassPartAst(); if (classPart != null) StandardElementGenerator.createGetTeamMethod(classPart); } // 3. add methods from non-role super-class to the ifc-part if (!subRole.isInterface()) RoleSplitter.setupInterfaceForExtends(clazz.getTeamModel().getAst(), subRoleDecl, clazz.getInterfaceAst()); } // 4. cast and getClass methods (independent of the source/binary difference): if (subRole.isInterface() && (subRoleDecl == null || needMethodBodies(subRoleDecl) || subRoleDecl.isRoleFile())) { TypeDeclaration sourceType = subRoleDecl != null ? subRoleDecl : teamType; TypeDeclaration classPart = clazz.getClassPartAst(); if (classPart != null) StandardElementGenerator.createCastMethod(clazz.getTeamModel(), classPart, /*dims*/ 0); // FIXME dimensions else // difference is only in source positions used. StandardElementGenerator.getCastMethod(clazz.getTeamModel(), subRole, teamType.scope, /*dims*/ 0, false, sourceType.sourceStart, sourceType.sourceEnd); // FIXME dimensions if (subRole.isPublic()) RoleClassLiteralAccess.ensureGetClassMethod(teamType.getTeamModel(), clazz); } // 5. special case roles which need an abstract _OT$getBase() method: StandardElementGenerator.createGetBaseForUnboundLowerable(clazz); // 6. resolve method mappings and create callout methods: MethodMappingResolver resolver = resolveCalloutMappings(clazz); CalloutImplementor.transformCallouts(clazz); if (resolver != null) resolver.resolve(false/*doCallout*/); // callins last so all methods incl. callout are already in place if (subRoleDecl != null) checkMissingMethods(subRole, subRoleDecl); clazz.setState(STATE_METHODS_CREATED); return true; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.StandardElementGenerator.java
License:Open Source License
/** * Retreive (or create) a team level method used for casting an expression to a role. * After casting also check the containingInstance against the current team. * @param teamModel//from w w w.j av a 2 s . co m * @param roleType * @param scope (used only for lookup of j.l.Object) * @param searchSuper should super classes of teamClass be search, too? * @param sourceStart * @param sourceEnd * @return the method */ public static MethodBinding getCastMethod(TeamModel teamModel, ReferenceBinding roleType, Scope scope, int dimensions, boolean searchSuper, int sourceStart, int sourceEnd) { /* * protected <role> _OT$castTo$<role> (Object _OT$arg1) { * if (_OT$arg1 == null) return null; * __OT__<role> role = (__OT__<role>) _OT$arg1; * if (role._OT$getTeam() != this) * throw new RuntimeException(); * return role; * } *OR FOR ARRAY: * protected <role>[].. _OT$castTo$<role>$<dims> (Object[].. _OT$arg1) { * if (_OT$arg1 == null) return null; * <role>[].. role = (<role>[]..) _OT$arg1; * if (role.length > 0 && ((__OT__<role>)role[0])._OT$getTeam() != this) // TODO(SH): extract through several dims * throw new RuntimeException(); * return role; * } * NOTE(SH): it suffices to check team equivalence for one element, since at this point it * must already be a role-array, which cannot mix roles from different teams ;-) */ boolean shouldWeaken = (teamModel.getState() >= ITranslationStates.STATE_TYPES_ADJUSTED); // weakening for other methods already done? MethodBinding superMethod = null; roleType = roleType.getRealType(); char[] methodName = CharOperation.concat(CAST_PREFIX, roleType.sourceName()); if (dimensions > 0) methodName = CharOperation.concat(methodName, String.valueOf(dimensions).toCharArray(), '$'); ReferenceBinding teamBinding = teamModel.getBinding(); while (teamBinding != null) { MethodBinding[] methods = teamBinding.getMethods(methodName); if (methods != null && methods.length == 1) { if (TypeBinding.equalsEquals(methods[0].declaringClass, teamModel.getBinding()) || searchSuper) return methods[0]; // go ahead and generate a new method, but use superMethod for weakening after generating: superMethod = methods[0]; break; } if (!searchSuper && !shouldWeaken) break; teamBinding = teamBinding.superclass(); } TypeDeclaration teamClass = teamModel.getAst(); if (teamClass == null) { if (true) {// FIXME(SH): team has error? MethodBinding castMethod = new MethodBinding(AccPublic, methodName, roleType, new TypeBinding[] { scope.getJavaLangObject() }, null, teamModel.getBinding()); teamModel.getBinding().addMethod(castMethod); return castMethod; } throw new InternalCompilerError("Required cast method not found."); //$NON-NLS-1$ } AstGenerator gen = new AstGenerator(sourceStart, sourceEnd); // --- method header --- int modifiers = 0; boolean clearPrivateModifier = false; if (roleType.isPublic()) { modifiers = AccPublic; } else { // this weird combination allows to return a non-public role and will // grant access across packages in the byte code. modifiers = AccProtected; clearPrivateModifier = true; // See also BinaryTypeBinding.resolveTypesFor(MethodBinding) where the Protected flag is restored. } // args char[] argName = OT_DOLLAR_ARG.toCharArray(); // find the appropriate top-level-super-type: ReferenceBinding exprType = teamClass.scope.getJavaLangObject(); // if (!roleType.isStrictlyCompatibleWith(exprType)) { // exprType = (ReferenceBinding)teamClass.scope.getType(ORG_OBJECTTEAMS_ICONFINED, 3); // if (!roleType.isCompatibleWith(exprType)) // exprType = (ReferenceBinding)teamClass.scope.getType( // ORG_OBJECTTEAMS_TEAM_DOT_CONFINED, // 4); // } TypeReference exprTypeRef = gen.typeReference(exprType); MethodDeclaration castMethod = gen.method(teamClass.compilationResult(), modifiers, gen.createArrayTypeReference(roleType, dimensions), methodName, new Argument[] { gen.argument(argName, exprTypeRef) }); // see org.eclipse.objectteams.otdt.tests.otjld.regression.ReportedBugs.testB11_sh15(): // pre-set return type to prevent problems with resolving lateron TypeBinding returnType = dimensions == 0 ? roleType : scope.environment().createArrayType(roleType, dimensions); castMethod.returnType.resolvedType = RoleTypeCreator.maybeWrapUnqualifiedRoleType(returnType, teamBinding); // <role> role = (<role>)_OT$arg; TypeReference arrayCastType = gen.createArrayTypeReference(roleType, dimensions); LocalDeclaration castedLocalVar = gen.localVariable(ROLE, arrayCastType, gen.castExpression(gen.singleNameReference(argName), arrayCastType, CastExpression.RAW)); //STATEMENTS: // if (_OT$arg1 == null) return null; //AND // if (role._OT$getTeam() != this) // throw new RuntimeException(); // OR // if (role.length > 0 && ((<roleClass>)role[0])._OT$getTeam() != this) // throw new RuntimeException(); Statement nullCheck = gen.ifStatement(gen.nullCheck(gen.singleNameReference(argName)), gen.returnStatement(gen.nullLiteral())); Expression teamCheckCondition; teamCheckCondition = genTeamCheck(gen, OperatorIds.NOT_EQUAL, gen.singleNameReference(ROLE), gen.thisReference(), dimensions); if (dimensions > 0) teamCheckCondition = gen .setPos(new AND_AND_Expression( gen.equalExpression(gen.qualifiedNameReference(new char[][] { ROLE, LENGTH }), gen.intLiteral(0), OperatorIds.GREATER), teamCheckCondition, OperatorIds.AND_AND)); // here we go: castMethod.setStatements(new Statement[] { nullCheck, castedLocalVar, gen.ifStatement(teamCheckCondition, gen.throwStatement( gen.allocation(gen.qualifiedTypeReference(ROLE_CAST_EXCEPTION), new Expression[0]))), // return role; gen.returnStatement(gen.singleNameReference(ROLE)) }); castMethod.isGenerated = true; AstEdit.addGeneratedMethod(teamClass, castMethod); if (clearPrivateModifier) castMethod.binding.tagBits = TagBits.ClearPrivateModifier; if (superMethod != null) CopyInheritance.weakenSignature(castMethod, superMethod); return castMethod.binding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
static TypeBinding internalWrapQualifiedRoleType(final Scope scope, final Expression anchorExpr, TypeBinding originalType, final ASTNode typedNode, ReferenceBinding refBinding, int dimensions) { ReferenceBinding site = scope.enclosingSourceType(); assert (!(site == null)); boolean needAnchor = true; // already wrapped? ITeamAnchor existingAnchor = retrieveAnchor(refBinding); if (existingAnchor == null) { if (!refBinding.isDirectRole()) return originalType.maybeWrapRoleType(typedNode, new TypeArgumentUpdater() { public TypeBinding updateArg(ReferenceBinding arg) { return maybeWrapQualifiedRoleType(scope, anchorExpr, arg, typedNode); }/* w w w . j a v a 2 s. c om*/ }); } else { if (!(existingAnchor instanceof TThisBinding)) { // possibly have two significant anchors.. // if a relevant anchor exists, we could well be content with typeToWrap! needAnchor = false; } else { // do handle tthis RoleTypeBindings, too, because we might need to // set a new anchor // (report errors only, if this type is not already acceptable). needAnchor = (TeamModel.findEnclosingTeamContainingRole(site, refBinding) == null); } } ProblemReporter problemReporter = scope.problemReporter(); ITeamAnchor variableBinding = getAnchorVariableBinding(site, anchorExpr, refBinding, needAnchor ? problemReporter : null, // no reporting if not needed typedNode); // only report one error (referenceContext is reset during reporting) if (problemReporter.referenceContext == null) { class NullReporter extends ProblemReporter { NullReporter(ProblemReporter orig) { super(orig.policy, orig.options, orig.problemFactory); } @Override public void handle(int problemId, String[] problemArguments, int elaborationId, String[] messageArguments, int severity, int problemStartPosition, int problemEndPosition, ReferenceContext context, CompilationResult unitResult) { /* NO-OP! */ } } problemReporter = new NullReporter(problemReporter); } // report errors: boolean decapsulationAllowed = false; if (typedNode instanceof Expression) decapsulationAllowed = ((Expression) typedNode).getBaseclassDecapsulation().isAllowed(); if ((variableBinding instanceof LocalVariableBinding) // note that for FieldBinding Bit63L has a different meaning! && (((LocalVariableBinding) variableBinding).tagBits & TagBits.IsFreshTeamInstance) != 0) { if (!refBinding.isRoleType()) return variableBinding.getDependentTypeBinding(refBinding, -1, null, dimensions); return originalType; } else if (variableBinding == null) { if (needAnchor) problemReporter.missingTypeAnchor(typedNode, refBinding); } else if (variableBinding == RoleTypeBinding.NoAnchor) { if (existingAnchor != null) { variableBinding = TeamAnchor.maybeImproveAnchor(site, existingAnchor, anchorExpr); if (variableBinding != null && variableBinding != existingAnchor) return variableBinding.getRoleTypeBinding(refBinding, dimensions); return originalType; } if (needAnchor) problemReporter.noTeamAnchorInScope(anchorExpr, refBinding); } else { if (!variableBinding.isFinal()) { // old version: directly report: //problemReporter.anchorPathNotFinal(anchorExpr, variableBinding, refBinding.sourceName()); // new version: don't complain now but use a non-compatible anchor: TypeBinding variableType = variableBinding.getResolvedType(); if (variableType.isRole()) variableType = ((ReferenceBinding) variableType).getRealClass(); // will be asked for members later variableBinding = new LocalVariableBinding(variableBinding.internalName(), variableType, ClassFileConstants.AccFinal, false) { @Override public int problemId() { return IProblem.AnchorNotFinal; } }; } if (!(variableBinding instanceof TThisBinding) && !isThisLike(anchorExpr) && !refBinding.isPublic() && !decapsulationAllowed) { problemReporter.externalizingNonPublicRole(typedNode, refBinding); } else { if (existingAnchor != null && !(existingAnchor instanceof TThisBinding) && !existingAnchor.hasSameBestNameAs(variableBinding)) { variableBinding = TeamAnchor.maybeImproveAnchor(site, existingAnchor, anchorExpr); if (variableBinding == null) return originalType; // cannot merge anchors -> original type cannot be improved. } // delegate to the principal function: TypeBinding[] typeArguments = refBinding.isParameterizedType() ? ((ParameterizedTypeBinding) refBinding).arguments : null; return getAnchoredType(scope, typedNode, variableBinding, refBinding, typeArguments, dimensions); } } return originalType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * Version to use by MessageSend.//from w ww .j av a 2 s . co m * May specialize role type to revert signature weakening. * * @param send retrieve all relevant information from this message send. * @param scope * @return wrapped type or original or null */ public static TypeBinding maybeWrapQualifiedRoleType(MessageSend send, BlockScope scope) { Expression receiver = send.receiver; TypeBinding returnType = send.binding.returnType; if (returnType == null || !(returnType.leafComponentType() instanceof ReferenceBinding) || returnType.leafComponentType().isEnum()) return returnType; int dimensions = returnType.dimensions(); ReferenceBinding refReturn = (ReferenceBinding) returnType.leafComponentType(); // don't try externalized non-public role if compatibility can be established with plain types: if (send.expectedType != null && !(send.expectedType instanceof DependentTypeBinding)) if (refReturn.isRole() && !refReturn.isPublic() && returnType.isCompatibleWith(send.expectedType)) return returnType; boolean isCalloutGet = CharOperation.prefixEquals(IOTConstants.OT_GETFIELD, send.selector); // // FIXME(SH): test with field of role type { AbstractMethodDeclaration referenceMethod = scope.methodScope().referenceMethod(); if (referenceMethod != null) isCalloutGet &= (referenceMethod.isMappingWrapper.callout()); } if (!isCalloutGet) { if (refReturn instanceof WeakenedTypeBinding) { WeakenedTypeBinding weakenedReturn = (WeakenedTypeBinding) refReturn; if (dimensions > 0) throw new InternalCompilerError("array not yet supported in this position"); //$NON-NLS-1$ ReferenceBinding strongType = weakenedReturn.getStrongType(); if (TypeBinding.notEquals(strongType.getRealType(), weakenedReturn.weakenedType)) { if (send.expectedType == null || !weakenedReturn.weakenedType.isCompatibleWith(send.expectedType)) send.valueCast = strongType; } TypeBinding instantiated = maybeWrapQualifiedRoleType(scope, send.receiver, strongType, send); return instantiated; } if (refReturn instanceof RoleTypeBinding) { RoleTypeBinding roleReturn = (RoleTypeBinding) refReturn; if (roleReturn._argumentPosition > -1 && send.binding.original() == roleReturn._declaringMethod.getMethod()) { ReferenceBinding roleEnclosing = roleReturn.enclosingType(); // anchored to argument, instantiate directly: Expression anchorExpr = send.arguments[roleReturn._argumentPosition]; TypeBinding anchorType = anchorExpr.resolvedType; ITeamAnchor anchor = null; if (anchorType.isRole() && ((ReferenceBinding) anchorType).isCompatibleViaLowering(roleEnclosing)) { // see 1.1.31-otjld-stacked-teams-1 f. if (anchorExpr.isThis()) anchor = ((ReferenceBinding) anchorType).getField(IOTConstants._OT_BASE, true); else return returnType; // cannot improve, error will be reported upstream } else { if (anchorType.isRole()) anchorType = ((ReferenceBinding) anchorType).getRealClass(); // ignore role-ness of team anchor if (!anchorType.isCompatibleWith(roleEnclosing)) return returnType; // cannot improve, anchor doesn't match expected team. anchor = (ITeamAnchor) ((NameReference) anchorExpr).binding; } return anchor.getRoleTypeBinding(roleReturn, returnType.dimensions()); } // retrieve existing information: ITeamAnchor anchor = roleReturn._teamAnchor; ReferenceBinding receiverType = (ReferenceBinding) send.actualReceiverType; if (anchor instanceof TThisBinding // not yet instantiated && (receiverType.isTeam() || receiverType.isRole())) { roleReturn = (RoleTypeBinding) TeamModel.strengthenRoleType(receiverType, roleReturn); if (dimensions > 0) returnType = roleReturn.getArrayType(dimensions); else returnType = roleReturn; } if (avoidWrapRoleType(scope, receiver)) // don't use synthetic _OT$role as additional anchor return returnType; } } else { if (send.arguments != null && send.arguments.length > 0) { // no arguments if accessed field is static // for wrapping types of a field access method, fake a _OT$base receiver // (although method is actually static) // see also comment in FieldAccessSpec.createMethod(). receiver = new SingleNameReference(IOTConstants._OT_BASE, 0); receiver.resolve(scope); } } return maybeWrapQualifiedRoleType(scope, receiver, returnType, send); }
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;//www . j ava 2 s . c o 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
/** * This function does the actual wrapper creation after the anchor and the role type have * been prepared.//from ww w . ja v a 2 s. co m * * PRE: anchor actually refers to a team. * * @param scope for error reporting * @param typedNode used for baseclass decapsulation * @param variableBinding anchor the type to this variable (full path), * this variableBinding is never merged with an anchor of roleBinding. * @param roleBinding * @param arguments * @param dimensions if > 0 create an array of role type with these dimensions * * @return valid type or a ProblemReferenceBinding with one of the following reasons: * NotVisible, AnchorNotFinal */ public static TypeBinding getAnchoredType(Scope scope, ASTNode typedNode, ITeamAnchor variableBinding, ReferenceBinding roleBinding, TypeBinding[] arguments, int dimensions) { if (!(variableBinding instanceof TThisBinding)) { DecapsulationState decapsulation = DecapsulationState.NONE; if (typedNode instanceof Expression) { Expression expr = ((Expression) typedNode); decapsulation = expr.getBaseclassDecapsulation(roleBinding); } int problemReason = 0; if (!roleBinding.isPublic()) { if (decapsulation.isAllowed()) { if (scope != null) scope.problemReporter().decapsulation((Expression) typedNode, roleBinding); } else { problemReason = ProblemReasons.NotVisible; } } else if (!variableBinding.isFinal()) { problemReason = ProblemReasons.AnchorNotFinal; } if (problemReason != 0) return new ProblemReferenceBinding(variableBinding, roleBinding.sourceName(), roleBinding, problemReason); } if (roleBinding instanceof DependentTypeBinding) { DependentTypeBinding wrappedRole = (DependentTypeBinding) roleBinding; if (wrappedRole._teamAnchor != variableBinding) return wrappedRole.maybeInstantiate(variableBinding, dimensions); if (dimensions > 0) return wrappedRole.getArrayType(dimensions); return wrappedRole; // TODO (SH): check compatibility of anchors! } if (!variableBinding.isTeam()) { throw new InternalCompilerError("ANCHOR IS NOT A TEAM"); //$NON-NLS-1$ } if (!roleBinding.isInterface()) { roleBinding = roleBinding.roleModel.getInterfacePartBinding(); if (roleBinding == null) throw new InternalCompilerError("Role class has no interface"); //$NON-NLS-1$ } TypeBinding typeBinding = variableBinding.getRoleTypeBinding(roleBinding, arguments, dimensions); return typeBinding; }