List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope getJavaLangObject
public final ReferenceBinding getJavaLangObject()
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.RoleFileCache.java
License:Open Source License
/** * Setup this structure after the enclosing type's binding is initialized. * * @param environment use this to look up the binary role file cache. *///ww w . j av a 2 s . com public void createTypeAndBinding(Scope scope, LookupEnvironment environment) { this._ast = new TypeDeclaration(this.teamDecl.compilationResult); this._ast.modifiers = ExtraCompilerModifiers.AccRole; this._ast.isGenerated = true; this._ast.bits |= ASTNode.IsLocalType; // no regular member, not reachable on regular traversals. this._ast.name = IOTConstants.ROFI_CACHE; this.teamDecl.scope.addGeneratedType(this._ast); // set manually because connectTypeHierarchy will not be called for this type. this._ast.binding.superInterfaces = Binding.NO_SUPERINTERFACES; this._ast.binding.superclass = scope.getJavaLangObject(); readBinary(environment); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting.java
License:Open Source License
/** * @param baseClassBinding//from www .j a v a 2s .c om * @param liftToConstructorDeclaration * @param gen */ public static Statement[] genRoleRegistrationStatements(Scope scope, RoleModel boundRootRoleModel, ReferenceBinding baseClassBinding, ConstructorDeclaration liftToConstructorDeclaration, AstGenerator gen) { Statement[] statements = new Statement[2]; // _OT$cache_OT$RootRole.put(<baseArgName>, this); Expression _this = gen.thisReference(); if (scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5) { _this = gen.castExpression(_this, gen.typeReference(boundRootRoleModel.getBinding()), CastExpression.DO_WRAP); } statements[0] = gen.messageSend( gen.singleNameReference(LiftingEnvironment.getCacheName(boundRootRoleModel)), PUT, new Expression[] { gen.baseNameReference(_OT_BASE), _this }); // ((IBoundBase)_OT$base).addRole(this); // prevent premature garbage collection Expression roleExpression = gen.thisReference(); if (TypeAnalyzer.isConfined(boundRootRoleModel.getBinding())) { // pretend this were compatible to Object: roleExpression.resolvedType = scope.getJavaLangObject(); roleExpression.constant = Constant.NotAConstant; } else { // here an (unnecessary) cast to j.l.Object prevents a warning re OTJLD 2.2(f): roleExpression = gen.castExpression(roleExpression, gen.qualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT), CastExpression.RAW); } statements[1] = // OTDYN: Slightly different methods depending on the weaving strategy: boundRootRoleModel.getWeavingScheme() == WeavingScheme.OTDRE ? gen.messageSend(gen.castExpression(gen.singleNameReference(_OT_BASE), gen.qualifiedTypeReference(ORG_OBJECTTEAMS_IBOUNDBASE2), CastExpression.RAW), ADD_REMOVE_ROLE, new Expression[] { roleExpression, gen.booleanLiteral(true) }) // isAdding : gen.messageSend( gen.castExpression(gen.singleNameReference(_OT_BASE), gen.qualifiedTypeReference(ORG_OBJECTTEAMS_IBOUNDBASE), CastExpression.RAW), ADD_ROLE, new Expression[] { roleExpression }); return statements; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementorDyn.java
License:Open Source License
public static MethodBinding ensureAccessor(Scope scope, ReferenceBinding baseType, boolean isStatic) { if (baseType.isRoleType()) baseType = baseType.getRealClass(); char[] selector = isStatic ? OT_ACCESS_STATIC : OT_ACCESS; MethodBinding[] methods = baseType.getMethods(selector); if (methods != null && methods.length == 1) { return methods[0]; } else {//w ww. ja va2 s . c o m int modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccSynthetic; if (isStatic) modifiers |= ClassFileConstants.AccStatic; MethodBinding method = new MethodBinding(modifiers, selector, scope.getJavaLangObject(), new TypeBinding[] { TypeBinding.INT, TypeBinding.INT, scope.environment().createArrayType(scope.getJavaLangObject(), 1), scope.getOrgObjectteamsITeam() }, Binding.NO_EXCEPTIONS, baseType); baseType.addMethod(method); return method; } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer.java
License:Open Source License
/** Get Typebindings for all enhancing arguments. */ private static TypeBinding[] getEnhancingArgTypes(Scope scope) { //{OTDyn: configurable: if (scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE) return new TypeBinding[] { scope.getType(IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE2, 3), // _OT$baseArg scope.createArrayType(scope.getOrgObjectteamsITeam(), 1), // _OT$teams TypeBinding.INT, // _OT$index scope.createArrayType(TypeBinding.INT, 1), // _OT$callinIds TypeBinding.INT, // _OT$boundMethodId scope.createArrayType(scope.getJavaLangObject(), 1), // _OT$args };/*from w ww . ja v a2s. c o m*/ // SH} // {OT/JamVM support: else if (JAMVM_ASPECTBI) return new TypeBinding[] { scope.getJavaLangObject(), // _OT$teamIterator TypeBinding.INT, // _OT$bindIdx TypeBinding.INT, // _OT$baseMethodTag scope.createArrayType(scope.getJavaLangObject(), 1), // _OT$unusedArgs }; // CH} return new TypeBinding[] { scope.createArrayType(scope.getOrgObjectteamsITeam(), 1), // _OT$teams scope.createArrayType(TypeBinding.INT, 1), // _OT$teamIDs TypeBinding.INT, // _OT$idx TypeBinding.INT, // _OT$bindIdx TypeBinding.INT, // _OT$baseMethodTag scope.createArrayType(scope.getJavaLangObject(), 1), // _OT$unusedArgs }; }
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//w w w.ja va 2 s. c om * @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.AstGenerator.java
License:Open Source License
/** * A type reference for the cache of a given bound root role. * If source level >= 1.5 use a generic type for the cache! * Generic type respects different status for base/role types: * - base is resolved via base import scope and supports decapsulation. *///from www .j ava 2s. c om public QualifiedTypeReference getCacheTypeReference(Scope scope, RoleModel boundRootRole) { if ((scope.compilerOptions().sourceLevel >= ClassFileConstants.JDK1_5)) { ReferenceBinding baseTypeBinding = boundRootRole.getBaseTypeBinding(); if (baseTypeBinding == null) baseTypeBinding = scope.getJavaLangObject(); ReferenceBinding rootRoleBinding = boundRootRole.getInterfacePartBinding(); ParameterizedQualifiedTypeReference fieldTypeRef; TypeReference[] typeArguments = new TypeReference[] { baseclassReference(baseTypeBinding, true/*erase*/), singleTypeReference(rootRoleBinding.sourceName()) }; fieldTypeRef = (ParameterizedQualifiedTypeReference) parameterizedQualifiedTypeReference(WEAK_HASH_MAP, typeArguments); return fieldTypeRef; } else { return new QualifiedTypeReference(WEAK_HASH_MAP, new long[] { this.pos, this.pos, this.pos }); } }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer.java
License:Open Source License
/** * Find a method in type or one of its super types. * @param scope where the method shall be invoked from * @param type where to search//www.j a v a2 s . co m * @param selector name of the method * @param params params * @param decapsulationAllowed whether or not invisible methods should be found, too * @param site invocation site if available */ public static @Nullable MethodBinding findMethod(final Scope scope, ReferenceBinding type, char[] selector, TypeBinding[] params, boolean decapsulationAllowed, @Nullable InvocationSite site) { if (type == null || scope == null) return null; if (site == null) { final Expression[] fakeArguments = new Expression[params.length]; for (int i = 0; i < params.length; i++) { fakeArguments[i] = new SingleNameReference(("fakeArg" + i).toCharArray(), 0L); //$NON-NLS-1$ fakeArguments[i].resolvedType = params[i]; } site = new InvocationSite() { @Override public int sourceStart() { return 0; } @Override public int sourceEnd() { return 0; } @Override public void setFieldIndex(int depth) { /* nop */ } @Override public void setDepth(int depth) { /* nop */ } @Override public void setActualReceiverType(ReferenceBinding receiverType) { /* nop */ } @Override public boolean receiverIsImplicitThis() { return false; } @Override public boolean isTypeAccess() { return false; } @Override public boolean isSuperAccess() { return false; } @Override public boolean isQualifiedSuper() { return false; } @Override public boolean checkingPotentialCompatibility() { return false; } @Override public void acceptPotentiallyCompatibleMethods(MethodBinding[] methods) { /* nop */ } @Override public TypeBinding invocationTargetType() { return scope.getJavaLangObject(); } @Override public ExpressionContext getExpressionContext() { return ExpressionContext.ASSIGNMENT_CONTEXT; } @Override public TypeBinding[] genericTypeArguments() { return null; } @Override public InferenceContext18 freshInferenceContext(Scope someScope) { return new InferenceContext18(someScope, fakeArguments, this, null); } }; } return scope.getMethod(type, selector, params, site); }