List of usage examples for org.eclipse.jdt.internal.compiler.lookup MethodBinding MethodBinding
public MethodBinding(int modifiers, TypeBinding[] parameters, ReferenceBinding[] thrownExceptions, ReferenceBinding declaringClass)
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseAllocationExpression.java
License:Open Source License
public static Expression convertToDynAccess(BlockScope scope, AllocationExpression expression, int accessId) { TypeBinding baseclass = expression.resolvedType; AstGenerator gen = new AstGenerator(expression); Expression receiver = gen.typeReference(baseclass); char[] selector = CalloutImplementorDyn.OT_ACCESS_STATIC; int modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; Expression[] arguments = expression.arguments; Expression enclosingInstance = null; if (expression instanceof QualifiedAllocationExpression) { enclosingInstance = ((QualifiedAllocationExpression) expression).enclosingInstance; } else if (baseclass.isMemberType()) { // extract the enclosing base instance from an outer playedBy: ReferenceBinding enclosingTeam = scope.enclosingReceiverType().enclosingType(); if (enclosingTeam != null && TypeBinding.equalsEquals(baseclass.enclosingType(), enclosingTeam.baseclass)) { enclosingInstance = gen.fieldReference(gen.qualifiedThisReference(gen.typeReference(enclosingTeam)), IOTConstants._OT_BASE); enclosingInstance.resolve(scope); }/* w w w. jav a 2 s. co m*/ } if (enclosingInstance != null) { if (arguments == null) { arguments = new Expression[] { enclosingInstance }; } else { int len = arguments.length; System.arraycopy(arguments, 0, arguments = new Expression[len + 1], 1, len); arguments[0] = enclosingInstance; } } MessageSend allocSend = new MessageSend() { @Override public boolean isDecapsulationAllowed(Scope scope2) { // this message send can decapsulate independent of scope return true; } @Override public DecapsulationState getBaseclassDecapsulation() { return DecapsulationState.ALLOWED; } }; gen.setPositions(allocSend); allocSend.receiver = receiver; allocSend.selector = selector; allocSend.constant = Constant.NotAConstant; allocSend.actualReceiverType = baseclass; allocSend.accessId = accessId; allocSend.arguments = createResolvedAccessArguments(gen, accessId, arguments, scope); allocSend.binding = new MethodBinding(modifiers, new TypeBinding[] { TypeBinding.INT, TypeBinding.INT, scope.createArrayType(scope.getJavaLangObject(), 1), scope.getOrgObjectteamsITeam() }, Binding.NO_EXCEPTIONS, (ReferenceBinding) baseclass); allocSend.binding.returnType = scope.getJavaLangObject(); allocSend.binding.selector = selector; return gen.resolvedCastExpression(allocSend, baseclass, CastExpression.RAW); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.DeclaredLifting.java
License:Open Source License
/** * Copy a team constructor such that the copy is suitable for chaining * previous super calls through a chain of tsuper-calls. This enables * a team to insert lifting calls at all required locations. * * In a subteam where the role is bound, the role parameter has to be replaced * with the bound base class (signature & selfcall). * * @param scope scope of location triggering this copy operation * @param superTeamCtor constructor to be copied * @param providedArgs this are the types of arguments passed by the ExplicitConstructorCall * @param needsLifting has the context (initiating constructor decl) declared lifting? *//* www .j a v a2s .c o m*/ public static MethodBinding copyTeamConstructorForDeclaredLifting(Scope scope, MethodBinding superTeamCtor, TypeBinding[] providedArgs, boolean needsLifting) { TypeDeclaration teamDecl = scope.referenceType(); AstGenerator gen = new AstGenerator(scope.methodScope().referenceMethod().sourceStart, scope.methodScope().referenceMethod().sourceEnd); if (scope.isOrgObjectteamsTeam(superTeamCtor.declaringClass)) return maybeCreateTurningCtor(teamDecl, superTeamCtor, gen); // Parameter list with marker arg TypeBinding[] providedWithMarker = providedArgs; if (providedArgs.length == 0 || !TSuperHelper.isMarkerInterface(providedArgs[providedArgs.length - 1])) { // need to extend the param list TypeBinding lastParam = null; if (superTeamCtor.parameters.length > 0) lastParam = superTeamCtor.parameters[superTeamCtor.parameters.length - 1]; TypeBinding marker = (lastParam != null && TSuperHelper.isMarkerInterface(lastParam)) ? // prefer existing marker lastParam : TSuperHelper.getMarkerInterface(scope, superTeamCtor.declaringClass); providedWithMarker = AstEdit.extendTypeArray(providedArgs, marker); } // Inner self call: MethodBinding selfcall = null; AbstractMethodDeclaration src = superTeamCtor.sourceMethod(); if (src != null) { if (src.ignoreFurtherInvestigation) return null; // can't create ctor // src means: look in the AST ConstructorDeclaration srcCtor = (ConstructorDeclaration) src; if (src.isCopied) { if (src.model != null) selfcall = src.model.adjustedSelfcall; } else if (srcCtor.constructorCall != null) { Dependencies.ensureTeamState(superTeamCtor.declaringClass.getTeamModel(), ITranslationStates.STATE_RESOLVED); selfcall = srcCtor.constructorCall.binding; } else { if (!src.scope.compilationUnitScope().referenceContext.parseMethodBodies) { // that's why we have no constructorCall: CU is on diet (parse); use a fake (see Trac #142): MethodBinding result = new MethodBinding(ClassFileConstants.AccPublic, providedArgs, null, superTeamCtor.declaringClass); return result; } selfcall = superTeamCtor.declaringClass.superclass().getExactConstructor(Binding.NO_PARAMETERS); } } else if (superTeamCtor.bytecodeMissing || superTeamCtor.model == null) { return null; // can't create ctor. } else { // no src means: peek the byte code: selfcall = (new BytecodeTransformer()).peekConstructorCall(teamDecl.getTeamModel(), superTeamCtor.model, scope.environment()); } MethodBinding adjustedSelfcall = null; if (selfcall == null) { if (!superTeamCtor.bytecodeMissing) // may have been set by peedConstructorCall above scope.problemReporter().unsupportedRoleDataflow(scope.methodScope().referenceMethod(), superTeamCtor); // be sure to continue below, because client needs the new ctor. } else { TypeBinding[] selfCallProvidedArgs = providedWithMarker;// TODO(SH): fetch argument order from bytecode adjustedSelfcall = maybeCopyCtorForSelfCall(scope, selfcall, selfCallProvidedArgs, needsLifting, gen); // Check for presence of desired constructor: MethodBinding existingConstructor = teamDecl.binding.getExactConstructor(providedWithMarker); if (existingConstructor != null) { if (adjustedSelfcall != null) { MethodModel model = MethodModel.getModel(existingConstructor); model.adjustSelfcall(selfcall, adjustedSelfcall); } return existingConstructor; } } // Create new constructor: ConstructorDeclaration newCtor = gen.constructor(teamDecl.compilationResult, ClassFileConstants.AccPublic, teamDecl.name, AstConverter.createArgumentsFromParameters(providedWithMarker, gen)); // adjust argument-anchored types in this signature: for (int i = 0; i < superTeamCtor.parameters.length; i++) if (RoleTypeBinding.isRoleWithExplicitAnchor(superTeamCtor.parameters[i])) { RoleTypeBinding requiredRTB = (RoleTypeBinding) superTeamCtor.parameters[i]; if (requiredRTB._argumentPosition > -1) { // we have an arg-anchored type, adjust the anchor within this signature: Argument newArgument = newCtor.arguments[requiredRTB._argumentPosition]; // argument positions from the declared (super) ctor. newArgument.modifiers |= ClassFileConstants.AccFinal; newArgument.name = ((RoleTypeBinding) providedArgs[i])._teamAnchor.internalName(); // argument names from the provided types/arguments } } newCtor.isTSuper = true; // ?? newCtor.isCopied = true; AstEdit.addMethod(teamDecl, newCtor, false /*not synthetic*/, false/*addToFront*/, superTeamCtor); // incl. resolve MethodModel model = MethodModel.getModel(newCtor); // already connect binding. if (needsLifting) model.liftedParams = superTeamCtor.parameters; // instructions for BytecodeTransformer if (adjustedSelfcall != null) model.adjustSelfcall(selfcall, adjustedSelfcall); // be it only strengthening newCtor.binding.copiedInContext = teamDecl.binding; newCtor.sourceMethodBinding = superTeamCtor; return newCtor.binding; }