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)); }
private void pushInitializerMethodInfo(FieldDeclaration x, MethodScope scope) { JMethod initMeth; if (x.isStatic()) { initMeth = curClass.type.getClinitMethod(); } else { initMeth = curClass.type.getInitMethod(); } pushMethodInfo(new MethodInfo(initMeth, (JMethodBody) initMeth.getBody(), scope)); }
@Override public void onUnifyAstStart(TreeLogger logger, UnifyAstView ast, UnifyVisitor visitor, Queue<JMethod> todo) { for (final JMethod method : ast.getProgram().getEntryMethods()) { if (method.getBody() instanceof JMethodBody) { JMethodBody body = (JMethodBody) method.getBody(); // obtain the entry point EntryPointFinder finder = findEntryPoint(logger); body.traverse(finder, finder.getContext()); // find a default strategy if (finder.result == null) { strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } else { com.google.gwt.core.ext.typeinfo.JClassType type = ast.getTypeOracle().findType(finder.result.getName()); strategy = type.getAnnotation(ReflectionStrategy.class); if (strategy == null) { strategy = type.getPackage().getAnnotation(ReflectionStrategy.class); if (strategy == null) { // Nothing on the entry point or it's package; // use a default instance of the ReflectionStrategy annotation strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } } } assert strategy != null; } } }
@Override public void onUnifyAstStart(final TreeLogger logger, final UnifyAstView ast, final UnifyVisitor visitor, final Queue<JMethod> todo) { for (final JMethod method : ast.getProgram().getEntryMethods()) { if (method.getBody() instanceof JMethodBody) { final JMethodBody body = (JMethodBody) method.getBody(); // obtain the entry point final EntryPointFinder finder = findEntryPoint(logger); body.traverse(finder, finder.getContext()); // find a default strategy if (finder.result == null) { strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } else { final com.google.gwt.core.ext.typeinfo.JClassType type = ast.getTypeOracle().findType(finder.result.getName()); strategy = type.getAnnotation(ReflectionStrategy.class); if (strategy == null) { strategy = type.getPackage().getAnnotation(ReflectionStrategy.class); if (strategy == null) { // Nothing on the entry point or it's package; // use a default instance of the ReflectionStrategy annotation strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } } } assert strategy != null; } } }
@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 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; }
target = ast.translate(target); JAbstractMethodBody method = target.getBody();
block.addStmt(invoke.makeStatement()); block.addStmts(((JMethodBody)methodCall.getTarget().getBody()).getStatements()); methodCall.getTarget().getEnclosingType().addMethod(newMethod); JMethodCall call = new JMethodCall(methodSource, null, newMethod);
JMethod superClinit = type.getSuperClass().getClinitMethod(); JMethodCall superClinitCall = new JMethodCall(myClinit.getSourceInfo(), null, superClinit); JMethodBody body = (JMethodBody) myClinit.getBody(); body.getBlock().addStmt(0, superClinitCall.makeStatement());
block.addStmts(((JMethodBody) methodCall.getTarget().getBody()) .getStatements()); methodCall.getTarget().getEnclosingType().addMethod(newMethod);
JMethodBody body = (JMethodBody) bridgeMethod.getBody(); if (bridgeMethod.getType() == JPrimitiveType.VOID) { body.getBlock().addStmt(call.makeStatement());
createSyntheticMethod(info, "$clinit", mapClass, JPrimitiveType.VOID, false, true, true, AccessModifier.PRIVATE); JBlock clinitBlock = ((JMethodBody) clinit.getBody()).getBlock(); clinitBlock.addStmt(declStmt);