List of usage examples for org.eclipse.jdt.internal.compiler.codegen CodeStream ifeq
public void ifeq(BranchLabel lbl)
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lifting.java
License:Open Source License
/** * API for AbstractMethodDeclaration:// w ww . j a v a2 s . co m * * 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 }