@Override public void endVisit(Initializer x, MethodScope scope) { try { JBlock block = pop(x.block); if (block != null) { curMethod.body.getBlock().addStmt(block); } popMethodInfo(); } catch (Throwable e) { throw translateException(x, e); } }
private void implementMagicMethod(JMethod method, JExpression returnValue) { JMethodBody body = (JMethodBody) method.getBody(); JBlock block = body.getBlock(); SourceInfo info; if (block.getStatements().size() > 0) { info = block.getStatements().get(0).getSourceInfo(); } else { info = method.getSourceInfo(); } block.clear(); block.addStmt(new JReturnStatement(info, returnValue)); }
private void implementMethod(JMethod method, JExpression returnValue) { JMethodBody body = (JMethodBody) method.getBody(); JBlock block = body.getBlock(); SourceInfo info; if (block.getStatements().size() > 0) { info = block.getStatements().get(0).getSourceInfo(); } else { info = method.getSourceInfo(); } block.clear(); block.addStmt(new JReturnStatement(info, returnValue)); }
@Override public boolean visit(JConstructor x, Context ctx) { if (pastRebound) { for (JMethod m : x.getEnclosingType().getMethods()) { if (m.getName().equals("createNewTestCase")) { for (JStatement statement : ((JMethodBody)m.getBody()).getBlock().getStatements()) { if (statement instanceof JIfStatement) { pastConstructor = true; ((JIfStatement)statement).getThenStmt().traverse(this, ctx); return false; } } } } } return super.visit(x, ctx); }
@Override public void endVisit(MethodDeclaration x, ClassScope scope) { try { if (x.isNative()) { processNativeMethod(x); } else { List<JStatement> statements = pop(x.statements); curMethod.body.getBlock().addStmts(statements); } popMethodInfo(); } catch (Throwable e) { throw translateException(x, e); } }
@Override public boolean visit(JConstructor x, Context ctx) { if (pastRebound) { for (JMethod m : x.getEnclosingType().getMethods()) { if (m.getName().equals("createNewTestCase")) { for (JStatement statement : ((JMethodBody)m.getBody()).getBlock().getStatements()) { if (statement instanceof JIfStatement) { pastConstructor = true; ((JIfStatement)statement).getThenStmt().traverse(this, ctx); return false; } } } } } return super.visit(x, ctx); }
private JField createEnumValuesField(JEnumType type) { // $VALUES = new E[]{A,B,B}; JArrayType enumArrayType = new JArrayType(type); JField valuesField = new JField(type.getSourceInfo(), "$VALUES", type, enumArrayType, true, Disposition.FINAL); type.addField(valuesField); SourceInfo info = type.getSourceInfo(); List<JExpression> initializers = new ArrayList<JExpression>(); for (JEnumField field : type.getEnumList()) { JFieldRef fieldRef = new JFieldRef(info, null, field, type); initializers.add(fieldRef); } JNewArray newExpr = JNewArray.createInitializers(info, enumArrayType, initializers); JFieldRef valuesRef = new JFieldRef(info, null, valuesField, type); JDeclarationStatement declStmt = new JDeclarationStatement(info, valuesRef, newExpr); JBlock clinitBlock = ((JMethodBody) type.getClinitMethod().getBody()).getBlock(); /* * HACKY: the $VALUES array must be initialized immediately after all of * the enum fields, but before any user initialization (which might rely * on $VALUES). The "1 + " is the statement containing the call to * Enum.$clinit(). */ int insertionPoint = 1 + type.getEnumList().size(); assert clinitBlock.getStatements().size() >= initializers.size() + 1; clinitBlock.addStmt(insertionPoint, declStmt); return valuesField; }
assert (JProgram.isClinit(clinitMethod)); final JMethodCall doClinit = new JMethodCall(clinit.getSourceInfo(), null, clinitMethod); body.getBlock().addStmt(doClinit.makeStatement()); body.getBlock().addStmt(value); if (logger.isLoggable(Type.DEBUG)) { logger = logger.branch(Type.DEBUG, "Generated magic singleton: ");
@Override public void endVisit(FieldDeclaration x, MethodScope scope) { try { JExpression initialization = pop(x.initialization); JField field = typeMap.get(x.binding); if (field instanceof JEnumField) { // An enum field must be initialized! assert (initialization instanceof JNewInstance); } if (initialization != null) { SourceInfo info = makeSourceInfo(x); JExpression instance = null; if (!x.isStatic()) { instance = makeThisRef(info); } // JDeclarationStatement's ctor sets up the field's initializer. JStatement decl = new JDeclarationStatement(info, new JFieldRef(info, instance, field, curClass.type), initialization); // will either be init or clinit curMethod.body.getBlock().addStmt(decl); } popMethodInfo(); } catch (Throwable e) { throw translateException(x, e); } }
JMethodBody body = new JMethodBody(methodSource); newMethod.setBody(body); JBlock block = body.getBlock(); for (Entry<JClassType,ReflectionStrategy> type : retained.entrySet()) { JClassType cls = type.getKey();
JMethodCall superClinitCall = new JMethodCall(myClinit.getSourceInfo(), null, superClinit); JMethodBody body = (JMethodBody) myClinit.getBody(); body.getBlock().addStmt(0, superClinitCall.makeStatement());
final JMethodBody body = new JMethodBody(methodSource); newMethod.setBody(body); final JBlock block = body.getBlock(); for (final Entry<JClassType, ReflectionStrategy> type : retained.entrySet()) { final JClassType cls = type.getKey();
createSyntheticMethod(info, "$clinit", mapClass, JPrimitiveType.VOID, false, true, true, AccessModifier.PRIVATE); JBlock clinitBlock = ((JMethodBody) clinit.getBody()).getBlock(); clinitBlock.addStmt(declStmt);
List<JStatement> statements = pop(x.statements); JStatement constructorCall = pop(x.constructorCall); JBlock block = curMethod.body.getBlock(); SourceInfo info = curMethod.method.getSourceInfo();