List of usage examples for org.eclipse.jdt.internal.compiler.lookup Scope getType
public final TypeBinding getType(char[][] compoundName, int typeNameLength)
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseCallMessageSend.java
License:Open Source License
@Override public void computeConversion(Scope scope, TypeBinding runtimeTimeType, TypeBinding compileTimeType) { if (this._sendOrig.binding instanceof SyntheticBaseCallSurrogate && this._sendOrig == this._wrappee // otherwise wrappee contains conversion && this.resolvedType.isBaseType() && this.resolvedType != TypeBinding.VOID) { ReferenceBinding boxType = (ReferenceBinding) scope .getType(AstGenerator.boxTypeName((BaseTypeBinding) this.resolvedType), 3); this._sendOrig.valueCast = boxType; // triggers insertion of checkcast to boxType compileTimeType = boxType; // triggers unboxing conversion }// ww w .j a v a 2 s . com super.computeConversion(scope, runtimeTimeType, compileTimeType); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting.java
License:Open Source License
/** * API for AbstractMethodDeclaration:// ww w . j a v a 2s. c om * * Create a byte code sequence for a runtime check in a creation method: * R _OT$create_OT$R(B b) { * if (this._OT$cache_OT$R.contains(b)) * throw new DuplicateRoleException("R"); * // continue regular code. * } * * Note, the need for this runtime check is detected quite late. * At this point it is easier to create the byte code sequence directly, * rather the creating AST first. */ public static void createDuplicateRoleCheck(CodeStream codeStream, AbstractMethodDeclaration method) { MethodBinding binding = method.binding; Scope scope = method.scope; ReferenceBinding roleType = (ReferenceBinding) binding.returnType; String roleName = new String(roleType.readableName()); // TODO(SH): check why roleType.getRoleModel().getClassPartBinding().roleModel may yield a different result. // I think it occured in haeder/stopwatch from smile-CVS. //RoleModel role = roleType.getRealClass().roleModel; char[] cacheName = LiftingEnvironment.getCacheName(roleType.roleModel.getBoundRootRole()); ReferenceBinding teamBinding = roleType.enclosingType();//role.getTeamModel().getBinding(); FieldBinding cache = TypeAnalyzer.findField(teamBinding, cacheName, /*static*/false, /*outer*/false, ITranslationStates.STATE_FULL_LIFTING); // generated by this state if (cache == null) throw new InternalCompilerError("generated cache field not found: " + new String(cacheName)); //$NON-NLS-1$ ReferenceBinding map = (ReferenceBinding) scope.getType(IOTConstants.WEAK_HASH_MAP, 3); MethodBinding contains = map.getMethod(scope, IOTConstants.CONTAINS_KEY); ReferenceBinding exc = (ReferenceBinding) scope.getType(IOTConstants.ORG_OBJECTTEAMS_DUPLICATE_ROLE, 3); TypeBinding[] types = new TypeBinding[] { scope.getJavaLangString() }; MethodBinding excInit = exc.getExactConstructor(types); BranchLabel normalCase = new BranchLabel(codeStream); codeStream.aload_0(); // this codeStream.fieldAccess(Opcodes.OPC_getfield, cache, teamBinding); // getfield MyTeam._OT$cache_OT$R Ljava/util/WeakHashMap; codeStream.aload_1(); // arg0 codeStream.invoke(Opcodes.OPC_invokevirtual, contains, map); // invokevirtual java.util.WeakHashMap.containsKey (Ljava/lang/Object;)Z codeStream.ifeq(normalCase); // false -> #endif codeStream.new_(exc); // new <org.objectteams.DuplicateRoleException> codeStream.dup(); // dup codeStream.ldc(roleName); // ldc "R" codeStream.invoke(Opcodes.OPC_invokespecial, excInit, exc); // invokespecial org.objectteams.DuplicateRoleException.<init> (Ljava/lang/String;)V codeStream.athrow(); // athrow normalCase.place(); // #endif }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticBaseCallSurrogate.java
License:Open Source License
/** * Create a binding for a synthetic base-call surrogate. * //w w w .j a v a 2s .c o m * @param callinMethod the callin method potentially holding base-calls * @param declaringClass the class that will hold the surrogate implementation: normally the role, for static callin methods: the team. */ public SyntheticBaseCallSurrogate(MethodBinding callinMethod, SourceTypeBinding declaringClass) { super(declaringClass, ClassFileConstants.AccProtected | ClassFileConstants.AccSynthetic, callinMethod.selector, callinMethod.parameters, callinMethod.returnType); this.selector = SyntheticBaseCallSurrogate.genSurrogateName(callinMethod.selector, callinMethod.declaringClass.sourceName(), callinMethod.isStatic()); if (!callinMethod.isStatic() && callinMethod.isCallin()) { // don't change paramaters if enhancement is absent // additional arg "boolean isSuperAccess": this.parameters = addIsSuperAccessArg(this.parameters, declaringClass.scope.compilerOptions().weavingScheme); } this.purpose = MethodAccess; this.targetMethod = callinMethod; TypeBinding origReturnType = MethodModel.getReturnType(callinMethod); MethodModel.saveReturnType(this, origReturnType); // fetch type bindings while we have a scope: Scope scope = declaringClass.scope; this.errorType = scope.getType(IOTConstants.OTRE_INTERNAL_ERROR, 3); this.stringType = scope.getJavaLangString(); // the synthetic methods of a class will be sorted according to a per-class index, find the index now: SyntheticMethodBinding[] knownAccessMethods = declaringClass.syntheticMethods(); this.index = knownAccessMethods == null ? 0 : knownAccessMethods.length; this.sourceStart = declaringClass.scope.referenceContext.sourceStart; retrieveLineNumber(declaringClass); }
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 w w . ja v a2s . co 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.RoleMigrationImplementor.java
License:Open Source License
static void genMigrateToBaseInstructions(CodeStream codeStream, SourceTypeBinding roleBinding, Scope scope, char[] cacheName) { FieldBinding baseField = roleBinding.getField(IOTConstants._OT_BASE, true); // accessing the cache (using remove() and put()): ReferenceBinding cacheTypeBinding = (ReferenceBinding) scope.getType(IOTConstants.WEAK_HASH_MAP, 3); MethodBinding remove = getMethod(cacheTypeBinding, "remove".toCharArray(), 1); //$NON-NLS-1$ MethodBinding put = cacheTypeBinding.getMethod(scope, "put".toCharArray()); //$NON-NLS-1$ // accessing the base object (using _OT$removeRole() and _OT$addRole()): WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme; ReferenceBinding iboundBase = (ReferenceBinding) scope .getType(weavingScheme == WeavingScheme.OTDRE ? IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE2 : IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE, 3); // remove old from cache codeStream.aload_0(); // this codeStream.fieldAccess(Opcodes.OPC_getfield, enclosingInstanceField(roleBinding), // this.this$n roleBinding);/*w w w . j a v a 2s . c om*/ codeStream.fieldAccess(Opcodes.OPC_getfield, roleBinding.enclosingType().getField(cacheName, true), // this.this$n._OT$cache$R roleBinding.enclosingType()); codeStream.dup(); // for use in put() below codeStream.aload_0(); // this codeStream.fieldAccess(Opcodes.OPC_getfield, baseField, // this._OT$base roleBinding); codeStream.dup(); // share for nested method call // this._OT$base // remove role from this (old) base genAddOrRemoveRole(codeStream, scope, iboundBase, false);// -> void // -> base._OT$removeRole(this) codeStream.invoke(Opcodes.OPC_invokevirtual, remove, // -> cache.remove(base) cacheTypeBinding); codeStream.pop(); // discard result // this._OT$base = (MyBase)otherBase codeStream.aload_0(); // this codeStream.aload_1(); // otherBase codeStream.checkcast(roleBinding.baseclass()); codeStream.fieldAccess(Opcodes.OPC_putfield, baseField, roleBinding); // add new to cache (cache is still on the stack) codeStream.aload_1(); // otherBase codeStream.aload_0(); // this (role) codeStream.invoke(Opcodes.OPC_invokevirtual, put, cacheTypeBinding); // add to new base: codeStream.aload_1(); // otherBase genAddOrRemoveRole(codeStream, scope, iboundBase, true); // -> void // -> base._OT$addRemoveRole(this, false) codeStream.return_(); }