List of usage examples for org.eclipse.jdt.internal.compiler.lookup TypeBinding dimensions
public int dimensions()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.BytecodeTransformer.java
License:Open Source License
/** * Get the liftmethod for lifting the arg-th argument of mModel. * * @param dstClassFile/*from w w w . j ava2 s . c om*/ * @param mModel * @param arg * @return a wrapper for the liftmethod. */ private ConstantPoolObject getLiftMethod(ClassFile dstClassFile, MethodModel mModel, int arg) { // find the role type: TypeBinding[] adjustedArgs = mModel.liftedParams; TypeBinding roleOrig = adjustedArgs[arg - 1]; AbstractMethodDeclaration mDecl = mModel.getDecl(); TypeBinding role = TeamModel.getRoleToLiftTo(mDecl.scope, mDecl.binding.parameters[arg - 1], roleOrig, true, mDecl.arguments[arg - 1]); // find the method: char[] liftName = null; if (role.isArrayType()) { liftName = ArrayTranslations.getTransformMethodName((ReferenceBinding) role.leafComponentType(), role.dimensions(), true); } else { liftName = Lifting.getLiftMethodName(role); } MethodBinding[] lifters = dstClassFile.referenceBinding.getMethods(liftName); if (lifters.length != 1) { assert RoleModel.hasTagBit(((ReferenceBinding) role.leafComponentType()).getRealClass(), RoleModel.HasLiftingProblem) : "must have lift method unless lifting problem was detected"; //$NON-NLS-1$ return null; } // wrap it: ConstantPoolObject dst_cpo = new ConstantPoolObject(MethodRefTag, lifters[0]); return dst_cpo; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.ArrayLowering.java
License:Open Source License
public MethodBinding ensureTransformMethod(BlockScope scope, Expression teamExpr, TypeBinding providedType, TypeBinding requiredType, boolean isLifting) { TypeBinding providedLeaf = providedType.leafComponentType(); TypeBinding matchingBase = ((ReferenceBinding) providedLeaf).baseclass(); TypeBinding requiredLeaf = requiredType.leafComponentType(); if (TypeBinding.notEquals(matchingBase, requiredLeaf) && matchingBase.isCompatibleWith(requiredLeaf, scope)) { requiredType = scope.environment().createArrayType(matchingBase, requiredType.dimensions()); }/*from w w w . ja va 2 s . c o m*/ return super.ensureTransformMethod(scope, teamExpr, providedType, requiredType, isLifting); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.ArrayTranslations.java
License:Open Source License
public MethodBinding ensureTransformMethod(BlockScope scope, Expression teamExpr, TypeBinding providedType, TypeBinding requiredType, boolean isLifting) { this._providedType = providedType; this._requiredType = requiredType; this._isLifting = isLifting; this._teamExpr = teamExpr; this._scope = scope; ReferenceBinding roleType = isLifting ? ((ReferenceBinding) requiredType.leafComponentType()) : ((ReferenceBinding) providedType.leafComponentType()); char[] transformMethodName = getTransformMethodName(roleType, providedType.dimensions(), isLifting); ReferenceBinding enclosingTeam = roleType.enclosingType().getRealType(); MethodBinding[] transformMethods = enclosingTeam.getMethods(transformMethodName); MethodBinding methodBinding = null;/*w w w .j ava 2 s. c o m*/ if ((transformMethods != null) && (transformMethods.length != 0)) { if (transformMethods.length > 1) { throw new InternalCompilerError("duplicate transform methods generated"); //$NON-NLS-1$ } methodBinding = transformMethods[0]; } else { TeamModel teamModel = roleType.roleModel.getTeamModel(); TypeDeclaration teamDecl = teamModel.getAst(); if (teamDecl == null) throw new InternalCompilerError("need to create transform method, but have no source type: " //$NON-NLS-1$ + new String(teamModel.getBinding().readableName())); MethodDeclaration transformMethod = generateTransformArrayMethod(teamDecl, transformMethodName, providedType.dimensions()); if (teamDecl.isRole()) transformMethod.modifiers |= ClassFileConstants.AccPublic; AstEdit.addMethod(teamDecl, transformMethod); methodBinding = transformMethod.binding; if (teamDecl.isRole()) { // if team is a role, also generate a ifc-part for the method and use that TypeDeclaration ifcPart = teamDecl.getRoleModel().getInterfaceAst(); MethodDeclaration ifcMethod = AstConverter.genRoleIfcMethod(ifcPart, transformMethod); AstEdit.addMethod(ifcPart, ifcMethod); methodBinding = ifcMethod.binding; } } return methodBinding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.DeclaredLifting.java
License:Open Source License
private static void prepareArgLifting(TypeDeclaration teamDecl, ConstructorDeclaration ctor) { if (ctor.arguments == null || ctor.ignoreFurtherInvestigation) return; // nothing to do List<LocalDeclaration> localVariables = new LinkedList<LocalDeclaration>(); boolean changeSuperCallToCopiedThis = false; boolean chainArgAdded = false; for (int idx = 0; idx < ctor.arguments.length; idx++) { Argument argument = ctor.arguments[idx]; TypeBinding param = ctor.binding.parameters[idx]; int dims = param.dimensions(); param = param.leafComponentType(); // don't use RoleTypeBinding.isRoleWithoutExplicitAnchor, because // type wrapping in signature has not been done yet. if (isLiftableRoleOf(param, teamDecl.binding) && !ctor.isTSuper) { int start = argument.type.sourceStart; int end = argument.type.sourceEnd; AstGenerator gen = new AstGenerator(start, end); if (!chainArgAdded) { // do this only once: // reserve space for a marker arg that could be added during copying: LocalDeclaration chainVar = gen.localVariable("_OT$chainArg".toCharArray(), //$NON-NLS-1$ teamDecl.scope.getJavaLangObject(), null); chainVar.isPlaceHolder = true; localVariables.add(chainVar); chainArgAdded = true;// w w w.j a v a 2s . c o m } // create local variable similar as for declared lifting char[] oldName = argument.name; char[] newName = CharOperation.concat(OT_DOLLAR_NAME, oldName); // cast might be needed if this collides with signature weakening // (cf. CopyInheritance.weakenSignature) Expression rhs = gen.castExpression(gen.singleNameReference(newName), gen.createArrayTypeReference(((ReferenceBinding) param).getRealType(), dims), // cast is guarded by isLiftableRoleOf() above CastExpression.RAW); argument.updateName(newName); // only potentially need lifting in a constructor (once copied) LocalDeclaration declaration = gen.localVariable(oldName, AstClone.copyTypeReference(argument.type), rhs); // assign real argument declaration.isPreparingForLifting = true; localVariables.add(declaration); // replace references in super-call: if (ctor.constructorCall != null) { // replace argn with _OT$argn in ctor call: ReplaceSingleNameVisitor.performReplacement(ctor.constructorCall, ctor.scope, oldName, newName); changeSuperCallToCopiedThis = (ctor.constructorCall.accessMode != ExplicitConstructorCall.This); } } if (changeSuperCallToCopiedThis) { // add a marker argument to this call: ExplicitConstructorCall call = ctor.constructorCall; call.accessMode = ExplicitConstructorCall.This; AstGenerator gen = new AstGenerator(call.sourceStart, call.sourceEnd); int numArgs = 0; if (call.arguments == null) { call.arguments = new Expression[1]; } else { numArgs = call.arguments.length; System.arraycopy(call.arguments, 0, call.arguments = new Expression[numArgs + 1], 0, numArgs); } call.arguments[numArgs] = TSuperHelper.createMarkerArgExpr(teamDecl.binding.superclass, gen); MethodModel.getModel(ctor); // side effect. } } if (!localVariables.isEmpty()) { // add local variable declartions to the front of statements int statsLen = (ctor.statements == null) ? 0 : ctor.statements.length; Statement[] statements = new Statement[localVariables.size() + statsLen]; int i = 0; for (Iterator<LocalDeclaration> iter = localVariables.iterator(); iter.hasNext();) { statements[i++] = iter.next(); } if (ctor.statements != null) System.arraycopy(ctor.statements, 0, statements, i, statsLen); ctor.setStatements(statements); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementor.java
License:Open Source License
private void createWrapperMethod(final CallinMappingDeclaration callinBindingDeclaration, final MethodBinding roleMethodBinding, final MethodSpec baseMethodSpec) { TypeDeclaration teamDecl = this._role.getTeamModel().getAst(); final AstGenerator gen = new AstGenerator(callinBindingDeclaration.roleMethodSpec.sourceStart, callinBindingDeclaration.roleMethodSpec.sourceEnd); gen.replaceableEnclosingClass = teamDecl.binding; if (this._role.getClassPartBinding() != null) gen.replaceableBaseAnchor = this._role.getClassPartBinding().getField(IOTConstants._OT_BASE, true); // ---------- useful names: ------------ //MyRole//from w w w . j a v a2 s.c om final char[] roleName = this._role.getName(); //myRoleMethod char[] roleMethodName = roleMethodBinding.selector; //_OT$MyRole$myRoleMethod$myBaseMethod char[] newMethodName = makeWrapperName(callinBindingDeclaration, roleName, roleMethodName, baseMethodSpec.selector); //_OT$base_arg char[] otBaseArg = IOTConstants.BASE; TypeParameter[] typeParams = getTypeParameters(callinBindingDeclaration.hasSignature, roleMethodBinding, callinBindingDeclaration.roleMethodSpec, gen); // ----------- method arguments --------------- Argument[] arguments = copyArguments(gen, callinBindingDeclaration.scope, baseMethodSpec.resolvedParameters(), baseMethodSpec); if (arguments != null && typeParams != null) { TypeBinding[] roleParams = callinBindingDeclaration.roleMethodSpec.resolvedParameters(); Pair<Expression, Integer>[] mappingExpressions = callinBindingDeclaration.mappingExpressions; // for each arg in arguments: replace if corresponding role argument is type variable: for (int i = 0; i < arguments.length; i++) { TypeBinding mappedRoleParam = null; if (mappingExpressions != null) { // search mapped role parameter (j is role-signature index): for (int j = 0; j < mappingExpressions.length; j++) { if (mappingExpressions[j].second == i) { mappedRoleParam = roleParams[j]; break; } } } else if (i < roleParams.length) { mappedRoleParam = roleParams[i]; } if (mappedRoleParam != null && mappedRoleParam.isTypeVariable()) arguments[i].type = gen.singleTypeReference(mappedRoleParam.internalName()); } } // wrapper receives all base args (might filter them using param-mappings, or cut-off trailing unneeded) // prepend base argument into slot 0. if (arguments != null) { int len = arguments.length; System.arraycopy(arguments, 0, (arguments = new Argument[len + 1]), 1, len); } else { arguments = new Argument[1]; } final ReferenceBinding baseTypeBinding = this._role.getBaseTypeBinding(); TypeReference baseTypeReference = gen.baseclassReference(baseTypeBinding); Argument baseArgument = gen.argument(otBaseArg, baseTypeReference); baseArgument.modifiers |= ClassFileConstants.AccFinal; // possibly the anchor for a role type baseArgument.isGenerated = true; arguments[0] = baseArgument; // ----------- return type ---------------- // Only wrappers for replace callin mappings have a result: TypeBinding wrapperReturnType = callinBindingDeclaration.isReplaceCallin() ? wrapperReturnType = MethodModel.getReturnType(roleMethodBinding) : TypeBinding.VOID; if (baseMethodSpec.returnNeedsTranslation) { TypeBinding roleReturn = callinBindingDeclaration.realRoleReturn; // accounts for weakening int dims = wrapperReturnType.dimensions(); // fail safe (without a witness): if (roleReturn == null) roleReturn = wrapperReturnType; // lowered return: wrapperReturnType = ((ReferenceBinding) roleReturn.leafComponentType()).baseclass(); char[] liftCallSelector; // array? if (dims > 0) { wrapperReturnType = this._roleScope.createArrayType(wrapperReturnType, dims); liftCallSelector = new ArrayLifting().ensureTransformMethod(callinBindingDeclaration.scope, gen.thisReference(), wrapperReturnType, roleReturn, true).selector; } else { liftCallSelector = Lifting.getLiftMethodName(roleReturn); } // now find the lift method for use in the CallinMethodMappings attribute TypeDeclaration teamType = this._roleScope.referenceContext; AbstractMethodDeclaration liftMethod = null; while (liftMethod == null) { if (teamType == null) throw new InternalCompilerError("Required lift method " + String.valueOf(liftCallSelector) + //$NON-NLS-1$ " not found in scope of role " + String.valueOf(this._roleScope.referenceContext.name)); //$NON-NLS-1$ if (teamType.isRole()) teamType = teamType.getRoleModel().getInterfaceAst(); liftMethod = TypeAnalyzer.findMethodDecl(teamType, liftCallSelector, 1); teamType = teamType.enclosingType; } callinBindingDeclaration.liftMethod = liftMethod.binding; } // enhance arguments to pass runtime team-activation arguments: boolean isReturnBoxed = false; // has a basic type been converted to "Object"? TypeBinding baseReturnType = baseMethodSpec.resolvedMethod.returnType; if (callinBindingDeclaration.isReplaceCallin()) { arguments = MethodSignatureEnhancer.enhanceArguments(arguments, new char[0], true, // isWrapper gen, this._role.getWeavingScheme()); if (wrapperReturnType.isBaseType()) { TypeBinding baseReturn = baseReturnType; isReturnBoxed = (baseReturn.isBaseType() && baseReturn != TypeBinding.VOID); wrapperReturnType = callinBindingDeclaration.scope.getJavaLangObject(); } // (note that message send arguments are enhanced automatically, // because for replace callins they are constructed from the wrapper signature) } else if (callinBindingDeclaration.callinModifier == TerminalTokens.TokenNameafter) { // pass result of base method. arguments = addResultArgument(arguments, callinBindingDeclaration, baseMethodSpec, gen); } for (Argument argument : arguments) argument.type.setBaseclassDecapsulation(DecapsulationState.REPORTED); // ----------- the method declaration --------------- int modifiers = ClassFileConstants.AccPublic; if (callinBindingDeclaration.isReplaceCallin()) modifiers |= ExtraCompilerModifiers.AccCallin; MethodDeclaration newMethod = gen.method(teamDecl.compilationResult, modifiers, wrapperReturnType, newMethodName, arguments); newMethod.thrownExceptions = AstClone.copyExceptions(baseMethodSpec.resolvedMethod, gen); newMethod.isMappingWrapper = WrapperKind.CALLIN; newMethod.returnType.setBaseclassDecapsulation(DecapsulationState.REPORTED); newMethod.typeParameters = typeParams; gen.maybeAddTypeParametersToMethod(baseTypeBinding, newMethod); int iProblem = teamDecl.getTeamModel().canLiftingFail(this._role.getBinding()); if (iProblem != 0) callinBindingDeclaration.addRoleLiftingProblem(this._role.getBinding(), iProblem); if (callinBindingDeclaration.rolesWithLiftingProblem != null) declareLiftingFailedException(callinBindingDeclaration, newMethod, gen); // ----- add and build and link the method ----- AstEdit.addMethod(teamDecl, newMethod); callinBindingDeclaration.setWrapper(baseMethodSpec, newMethod); // TODO(SH): could optimize MethodInfo.maybeRegister() // by marking callin to private role method (only they need copying). MethodModel.addCallinFlag(newMethod, IOTConstants.CALLIN_FLAG_WRAPPER); newMethod.model._declaringMappings = Collections.singletonList(callinBindingDeclaration); if (newMethod.hasErrors()) { // problems detected during creation of MethodBinding? // CLOVER: never reached in jacks suite AstEdit.removeMethod(teamDecl, newMethod.binding); // may be incomplete. return; } setBaseArgBestName(newMethod, baseArgument); // ---------- deferred generation of statements: ---------- // make values available to anonymous class: final TypeBinding finalWrapperReturnType = wrapperReturnType; final boolean finalIsReturnBoxed = isReturnBoxed; final RoleModel finalRole = this._role; MethodModel.getModel(newMethod).setStatementsGenerator(new AbstractStatementsGenerator() { public boolean generateStatements(AbstractMethodDeclaration methodDecl) { return generateCallinStatements((MethodDeclaration) methodDecl, callinBindingDeclaration, finalRole, roleMethodBinding, baseTypeBinding, baseMethodSpec, finalWrapperReturnType, finalIsReturnBoxed, gen); } }); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java
License:Open Source License
/** * Note that as a side effect, this method modifies methodMapping.mappings! * @param methodMapping lookup method spec and parameter mapping here * @param wrapperDeclaration use these if no mapping is involved * @param implParameters parameters of the implemented method to invoke * @param idx argument position on the target side * @param hasResultArgument (ignored)/* ww w . j ava 2 s . c o m*/ * @param sourceMethodSpec this signature defines the provided args * @return a mapped argument expression or null */ Expression getArgument(AbstractMethodMappingDeclaration methodMapping, MethodDeclaration wrapperDeclaration, TypeBinding[] implParameters, int idx, boolean hasResultArgument, MethodSpec sourceMethodSpec) { MethodSpec implementationMethodSpec = methodMapping.getImplementationMethodSpec(); Argument[] specifiedArgs = implementationMethodSpec.arguments; ParameterMapping[] parameterMappings = methodMapping.mappings; Expression mappedArgExpr = null; char[] targetArgName = null; if (parameterMappings == null) { targetArgName = wrapperDeclaration.arguments[idx].name; mappedArgExpr = genSimpleArgExpr(targetArgName, ((CalloutMappingDeclaration) methodMapping).baseMethodSpec); // if parameters are not mapped, identify provided and expected args. // Note that expected args means those of the baseMethodSpec // which are otherwise unreachable. // (stored in a temporary scope, see AbstractMethodMappingDeclaration.resolveMethodSpecs) if (idx < specifiedArgs.length) // CLOVER: never false in jacks suite specifiedArgs[idx].binding.setBestNameFromStat(wrapperDeclaration.arguments[idx]); } else { if (methodMapping.mappingExpressions == null) { assert !methodMapping.hasParsedParamMappings : "expect lack of parsing as cause for missing expressions"; //$NON-NLS-1$ return null; // this indicates an error (required param mappings have not been parsed) } targetArgName = implementationMethodSpec.arguments[idx].name; Pair<Expression, Integer> mapper = methodMapping.mappingExpressions[idx]; mappedArgExpr = mapper.first; } if (mappedArgExpr != null) { if (idx >= implParameters.length) // CLOVER: never true in jacks suite return mappedArgExpr; // arg is invisible to receiver, don't lower TypeBinding expectedType = implParameters[idx]; // if type is anchored to another arg of the same binding, we have to translate: // 1.) is it a param-anchored type? if (expectedType.leafComponentType() instanceof DependentTypeBinding) { DependentTypeBinding dependentExpectedLeaf = (DependentTypeBinding) expectedType .leafComponentType(); int anchorArgPos = dependentExpectedLeaf._argumentPosition; if (anchorArgPos != -1) { // 2.) need to translate the position using the param mapping? if (methodMapping.positions != null) anchorArgPos = methodMapping.positions[anchorArgPos] - 1; // 3.) with this position retrieve the source argument and re-anchor the type to this anchor: ITeamAnchor mappedAnchor = sourceMethodSpec.arguments[anchorArgPos].binding; expectedType = mappedAnchor.getRoleTypeBinding(dependentExpectedLeaf, expectedType.dimensions()); } } return new PotentialLowerExpression(mappedArgExpr, adjustBaseSideType(expectedType)); } wrapperDeclaration.scope.problemReporter().unmappedParameter(targetArgName, implementationMethodSpec, methodMapping.isCallout()); return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor.java
License:Open Source License
TypeBinding adjustBaseSideType(TypeBinding givenType) { ReferenceBinding baseBinding = this._role.getBaseTypeBinding(); if (baseBinding == null) return givenType; if (givenType.leafComponentType().isBaseType()) return givenType; ReferenceBinding givenLeaf = (ReferenceBinding) givenType.leafComponentType(); int dimensions = givenType.dimensions(); TypeVariableBinding[] arguments = null; if (givenType.isParameterizedType()) arguments = ((ParameterizedTypeBinding) givenType).typeVariables(); if (baseBinding instanceof DependentTypeBinding) { ITeamAnchor anchor = ((DependentTypeBinding) baseBinding).getAnchor(); if (anchor.isTeamContainingRole(givenLeaf)) { if (TypeBinding.notEquals(anchor.getResolvedType(), givenLeaf.enclosingType())) givenLeaf = (ReferenceBinding) TeamModel .strengthenRoleType((ReferenceBinding) anchor.getResolvedType(), givenLeaf); return anchor.getDependentTypeBinding(givenLeaf, -1, arguments, dimensions); }//from ww w.j a v a 2s.c o m } return givenType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.MethodMappingImplementor.java
License:Open Source License
/** * Try whether type is a role type to be interpreted relative to the anchor of a "playedBy t.R" * @param gen//from w w w. j av a 2 s . c o m * @param baseSideAnchor * @param type * @return an anchored type reference or null */ TypeReference getAnchoredTypeReference(AstGenerator gen, ITeamAnchor baseSideAnchor, TypeBinding type) { TypeReference argTypeReference = null; int dims = type.dimensions(); type = type.leafComponentType(); if (type instanceof RoleTypeBinding) { RoleTypeBinding roleTypeArg = (RoleTypeBinding) type; if (roleTypeArg.hasExplicitAnchor()) { // originally anchored to _OT$base? change to 'base' now: if (roleTypeArg._teamAnchor.isBaseAnchor()) { // witness: 4.3.1-otjld-parameter-mapping-11a TypeReference anchorRef = new TypeAnchorReference(gen.singleNameReference(IOTConstants.BASE), gen.sourceStart); argTypeReference = new ParameterizedSingleTypeReference(roleTypeArg.internalName(), new TypeReference[] { anchorRef }, dims, gen.pos); } } else if (baseSideAnchor != null) { // witness in 1.1.22-otjld-layered-teams-1, B.1.1-otjld-sh-42 ReferenceBinding baseSideTeam = (ReferenceBinding) baseSideAnchor.getResolvedType(); if (TeamModel.isTeamContainingRole(baseSideTeam, roleTypeArg)) argTypeReference = gen.roleTypeReference(baseSideAnchor, roleTypeArg, dims); } } return argTypeReference; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel.java
License:Open Source License
/** * Get the most suitable RoleTypeBinding for roleType in a tthis context defined by scope. * Strengthening reverses the effect of signature weakening. * * (Used for determining the statically known role type for lifting) * * @param site (guaranteed to be within the context of a team) * @param roleType (guaranteed to be a role or an array thereof) * @return found role - need not be a RoleTypeBinding *//*from ww w.java 2 s. c o m*/ public static TypeBinding strengthenRoleType(ReferenceBinding site, TypeBinding roleType) { ReferenceBinding enclosingTeam = site; enclosingTeam = normalizeTeam(enclosingTeam); if (!enclosingTeam.isTeam()) enclosingTeam = getEnclosingTeam(site); if (enclosingTeam == null) return roleType; // this site cannot strengthen the role type. if (roleType.isLocalType()) return roleType; int dimensions = roleType.dimensions(); ReferenceBinding roleRefType = (ReferenceBinding) roleType.leafComponentType(); ReferenceBinding roleEnclosing = roleRefType.enclosingType(); if (roleEnclosing.isRole() && TypeBinding.notEquals(roleEnclosing.erasure(), site.erasure())) { // first strengthen enclosing team if it is nested: ReferenceBinding strengthenedEnclosing = null; if (TypeBinding.notEquals(roleEnclosing.erasure().enclosingType(), enclosingTeam.erasure().enclosingType())) strengthenedEnclosing = (ReferenceBinding) strengthenRoleType(site, roleEnclosing); if (strengthenedEnclosing != null && TypeBinding.notEquals(strengthenedEnclosing.erasure(), site.erasure())) { // we indeed found a better site, so start over: return strengthenRoleType(strengthenedEnclosing, roleType); } } // check success: if (!(roleRefType.isRole() // need a role && areCompatibleEnclosings(enclosingTeam, roleEnclosing))) // teams must be compatible { if (enclosingTeam.isRole()) // try via outer team: return strengthenRoleType(enclosingTeam.enclosingType(), roleType); return roleType; } if (roleRefType instanceof RoleTypeBinding) { RoleTypeBinding rtb = (RoleTypeBinding) roleRefType; if (!(rtb._teamAnchor instanceof TThisBinding)) return roleType; // don't instantiate explicit team anchor. } // lookup adjusted role type: roleRefType = enclosingTeam.getMemberType(roleRefType.internalName()); if (roleRefType == null) { if (enclosingTeam.isBinaryBinding()) { ReferenceBinding current = enclosingTeam; // search a role type to report against (for aborting): while (current != null && current.isBinaryBinding()) current = current.enclosingType(); if (current != null) { Scope scope = ((SourceTypeBinding) current).scope; if (scope != null) { scope.problemReporter().missingRoleInBinaryTeam(roleType.constantPoolName(), enclosingTeam); return null; } } } if (Protections.hasClassKindProblem(enclosingTeam)) return roleType; // can't do better.. if (!enclosingTeam.isBinaryBinding()) { Scope scope = ((SourceTypeBinding) enclosingTeam.getRealType()).scope; scope.problemReporter().missingCopiedRole(roleType, enclosingTeam); } else if (!site.isBinaryBinding()) { Scope scope = ((SourceTypeBinding) site.getRealType()).scope; scope.problemReporter().missingCopiedRole(roleType, enclosingTeam); } else { throw new InternalCompilerError("could not find role " + String.valueOf(roleType.constantPoolName()) //$NON-NLS-1$ + " in " + String.valueOf(site.constantPoolName()) + " and could not report regularly"); //$NON-NLS-1$ //$NON-NLS-2$ } return roleType; // can't do better, but shouldn't reach here, because missingCopiedRole triggers AbortType. } VariableBinding anchor = enclosingTeam.getTeamModel().getTThis(); if (roleType.isParameterizedType()) { // consult original role type for type arguments & type annotations: ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) roleType; TypeBinding parameterized = ptb.environment.createParameterizedType(roleRefType, ptb.arguments, anchor, -1, roleRefType.enclosingType(), ptb.getTypeAnnotations()); if (dimensions > 0) return ptb.environment.createArrayType(parameterized, dimensions); return parameterized; } return anchor.getRoleTypeBinding(roleRefType, dimensions); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel.java
License:Open Source License
/** * performs role type strengthening, preforms static adjustment (OTJLD 2.3.3(a). * Respects arrays and checks compatibility. * @param scope client context, guaranteed to be a team or a role * @param provided/* w w w.j a v a 2 s . c o m*/ * @param required * @param doAdjust should the adjusted role be returned (as opposed to just the strengthened)? * @param location where to report errors against * @return an exact role or null */ public static TypeBinding getRoleToLiftTo(Scope scope, TypeBinding provided, TypeBinding required, boolean doAdjust, ASTNode location) { ReferenceBinding requiredRef = null; if (required.isArrayType() && (required.leafComponentType() instanceof ReferenceBinding)) { requiredRef = (ReferenceBinding) required.leafComponentType(); } else if (required instanceof ReferenceBinding) { requiredRef = (ReferenceBinding) required; } if (requiredRef != null && requiredRef.isRole()) { requiredRef = (ReferenceBinding) strengthenRoleType(scope.enclosingSourceType(), requiredRef); ReferenceBinding foundRole = null; if (requiredRef.baseclass() == null) { foundRole = adjustRoleToLiftTo(scope, provided, requiredRef, location); if (foundRole != null && !doAdjust) foundRole = requiredRef; // successful but revert to unadjusted } else { if (!provided.leafComponentType().isBaseType()) { ReferenceBinding providedLeaf = (ReferenceBinding) provided.leafComponentType(); providedLeaf = RoleTypeCreator.maybeInstantiateFromPlayedBy(scope, providedLeaf); if (providedLeaf.isCompatibleWith(requiredRef.baseclass()) && required.dimensions() == provided.dimensions()) { foundRole = requiredRef; } } // FIXME(SH): unneeded? // // just check definite binding ambiguity: // adjustRoleToLiftTo(scope, provided, requiredRef, location); } if (foundRole != null) { // success by translation if (required.dimensions() == 0) return foundRole; else return scope.createArrayType(foundRole, required.dimensions()); } } return null; }