@Override public Node visit(BlockStmt _n, Object _arg) { List<Statement> stmts = visit(_n.getStmts(), _arg); Comment comment = cloneNodes(_n.getComment(), _arg); BlockStmt r = new BlockStmt( _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), stmts ); r.setComment(comment); return r; }
@Override public Node visit(final TryStmt n, final A arg) { n.setTryBlock((BlockStmt) n.getTryBlock().accept(this, arg)); final List<CatchClause> catchs = n.getCatchs(); if (catchs != null) { for (int i = 0; i < catchs.size(); i++) { catchs.set(i, (CatchClause) catchs.get(i).accept(this, arg)); } removeNulls(catchs); } if (n.getFinallyBlock() != null) { n.setFinallyBlock((BlockStmt) n.getFinallyBlock().accept(this, arg)); } return n; }
@Override public void visit(MethodDeclaration n, ExecutableElement element) { if (element.getSimpleName().toString().equals(n.getName()) && (n.getParameters() == null ? 0 : n.getParameters().size()) - (element.getParameters() == null ? 0 : element.getParameters().size()) == 0) { if (n.getBody() == null) { this.methodBody = null; } else { this.methodBody = n.getBody().toString(); } } }
/** * Adds the given statement to the specified block. The list of statements * will be initialized if it is <code>null</code>. * * @param block * @param stmt */ public static void addStmt(BlockStmt block, Statement stmt) { List<Statement> stmts = block.getStmts(); if (stmts == null) { stmts = new ArrayList<Statement>(); block.setStmts(stmts); } stmts.add(stmt); }
@Override public void visit(final BlockStmt n, final A arg) { visitComment(n.getComment(), arg); if (n.getStmts() != null) { for (final Statement s : n.getStmts()) { s.accept(this, arg); } } }
final public BlockStmt Block() throws ParseException { List stmts; int beginLine; int beginColumn; jj_consume_token(LBRACE); beginLine=token.beginLine; beginColumn=token.beginColumn; stmts = Statements(); jj_consume_token(RBRACE); {if (true) return new BlockStmt(beginLine, beginColumn, token.endLine, token.endColumn, stmts);} throw new Error("Missing return statement in function"); }
final public InitializerDeclaration InitializerDeclaration() throws ParseException { BlockStmt block; int line = -1; int column = 0; boolean isStatic = false; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STATIC: jj_consume_token(STATIC); isStatic = true; line=token.beginLine; column=token.beginColumn; break; default: jj_la1[49] = jj_gen; ; } block = Block(); if(line==-1){line=block.getBeginLine(); column=block.getBeginColumn();} InitializerDeclaration tmp = new InitializerDeclaration(line, column, token.endLine, token.endColumn, isStatic, block); {if (true) return tmp;} throw new Error("Missing return statement in function"); }
final public BlockStmt Block() throws ParseException { List stmts; int beginLine; int beginColumn; jj_consume_token(LBRACE); beginLine=token.beginLine; beginColumn=token.beginColumn; stmts = Statements(); jj_consume_token(RBRACE); BlockStmt tmp = new BlockStmt(beginLine, beginColumn, token.endLine, token.endColumn, stmts); {if (true) return tmp;} throw new Error("Missing return statement in function"); }
final public InitializerDeclaration InitializerDeclaration() throws ParseException { BlockStmt block; int line = -1; int column = 0; boolean isStatic = false; switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case STATIC: jj_consume_token(STATIC); isStatic = true; line=token.beginLine; column=token.beginColumn; break; default: jj_la1[49] = jj_gen; ; } block = Block(); if(line==-1){line=block.getBeginLine(); column=block.getBeginColumn();} {if (true) return new InitializerDeclaration(line, column, token.endLine, token.endColumn,popJavadoc(), isStatic, block);} throw new Error("Missing return statement in function"); }
@Override public void visit(final BlockStmt n, final Object arg) { printOrphanCommentsBeforeThisChildNode(n); printJavaComment(n.getComment(), arg); printer.printLn("{"); if (n.getStmts() != null) { printer.indent(); for (final Statement s : n.getStmts()) { s.accept(this, arg); printer.printLn(); } printer.unindent(); } printer.print("}"); }
private NodeAndImports<MethodDeclaration> createPrimaryKeyHashCode(Collection<FieldDescriptor> primaryKeyDescriptors) { final MethodDeclaration hashCode = new MethodDeclaration(ModifierSet.PUBLIC, new PrimitiveType(PrimitiveType.Primitive.Int), "hashCode"); hashCode.setAnnotations(Collections.<AnnotationExpr>singletonList(new MarkerAnnotationExpr(new NameExpr("Override")))); final List<Expression> ctorArgs = new ArrayList<Expression>(); ctorArgs.add(new IntegerLiteralExpr("17")); ctorArgs.add(new IntegerLiteralExpr("37")); Expression hashCodeExpr = new ObjectCreationExpr(null, new ClassOrInterfaceType("HashCodeBuilder"), ctorArgs); for (FieldDescriptor f : primaryKeyDescriptors) { final List<Expression> args = new ArrayList<Expression>(); args.add(new FieldAccessExpr(new ThisExpr(), f.getAttributeName())); hashCodeExpr = new MethodCallExpr(hashCodeExpr, "append", args); } hashCodeExpr = new MethodCallExpr(hashCodeExpr, "toHashCode"); final BlockStmt equalsBody = new BlockStmt(Collections.<Statement>singletonList(new ReturnStmt(hashCodeExpr))); hashCode.setBody(equalsBody); return new NodeAndImports<MethodDeclaration>(hashCode, Collections.singleton(new ImportDeclaration(new QualifiedNameExpr(new NameExpr("org.apache.commons.lang.builder"), "HashCodeBuilder"), false, false))); }
@Override public R visit(final CatchClause n, final A arg) { { R result = n.getExcept().accept(this, arg); if (result != null) { return result; } } { R result = n.getCatchBlock().accept(this, arg); if (result != null) { return result; } } return null; }
@Override public Node visit(final BlockStmt n, final A arg) { final List<Statement> stmts = n.getStmts(); if (stmts != null) { for (int i = 0; i < stmts.size(); i++) { stmts.set(i, (Statement) stmts.get(i).accept(this, arg)); } removeNulls(stmts); } return n; }
@Override public void visit(MethodDeclaration method, A result) { if (CollectionUtils.isEmpty(method.getAnnotations())) { return; } for (AnnotationExpr annotation : method.getAnnotations()) { if (!annotation.getClass().equals(NormalAnnotationExpr.class)) { continue; } NormalAnnotationExpr annot = (NormalAnnotationExpr) annotation; if (annot.getName().toString().equals(SampleCode.class.getSimpleName()) && !CollectionUtils.isEmpty(annot.getPairs())) { for (MemberValuePair pair : annot.getPairs()) { // get the 'api' parameter from the annotation to let us know which api this function belongs to if (StringUtils.equals(pair.getName(), "api") && !StringUtils.isBlank(pair.getValue().toString())) { result.put(getCacheRowKey(type, pair.getValue().toString().replace("\"", "")), stripTestPrefix(method.getName()), stripCurlyBrackets(method.getBody().toString())); return; } } } } } }
private NodeAndImports<MethodDeclaration> createPrimaryKeyToString(Collection<FieldDescriptor> primaryKeyDescriptors) { final MethodDeclaration toString = new MethodDeclaration(ModifierSet.PUBLIC, new ClassOrInterfaceType("String"), "toString"); toString.setAnnotations(Collections.<AnnotationExpr>singletonList(new MarkerAnnotationExpr(new NameExpr("Override")))); Expression toStringBuilderExpr = new ObjectCreationExpr(null, new ClassOrInterfaceType("ToStringBuilder"), Collections.<Expression>singletonList(new ThisExpr())); for (FieldDescriptor f : primaryKeyDescriptors) { final List<Expression> args = new ArrayList<Expression>(); args.add(new StringLiteralExpr(f.getAttributeName())); args.add(new FieldAccessExpr(new ThisExpr(), f.getAttributeName())); toStringBuilderExpr = new MethodCallExpr(toStringBuilderExpr, "append", args); } toStringBuilderExpr = new MethodCallExpr(toStringBuilderExpr, "toString"); final BlockStmt toStringBody = new BlockStmt(Collections.<Statement>singletonList(new ReturnStmt(toStringBuilderExpr))); toString.setBody(toStringBody); return new NodeAndImports<MethodDeclaration>(toString, Collections.singleton(new ImportDeclaration(new QualifiedNameExpr(new NameExpr("org.apache.commons.lang.builder"), "ToStringBuilder"), false, false))); }
@Override public void visit(final TryStmt n, final A arg) { visitComment(n.getComment(), arg); n.getTryBlock().accept(this, arg); if (n.getCatchs() != null) { for (final CatchClause c : n.getCatchs()) { c.accept(this, arg); } } if (n.getFinallyBlock() != null) { n.getFinallyBlock().accept(this, arg); } }
private NodeAndImports<MethodDeclaration> createPrimaryKeyCompareTo(Collection<FieldDescriptor> primaryKeyDescriptors, String enclosingClassName) { final MethodDeclaration compareTo = new MethodDeclaration(ModifierSet.PUBLIC, new PrimitiveType(PrimitiveType.Primitive.Int), "compareTo", Collections.singletonList(new Parameter(new ClassOrInterfaceType(enclosingClassName), new VariableDeclaratorId("other")))); compareTo.setAnnotations(Collections.<AnnotationExpr>singletonList(new MarkerAnnotationExpr(new NameExpr("Override")))); Expression compareToBuilderExpr = new ObjectCreationExpr(null, new ClassOrInterfaceType("CompareToBuilder"), Collections.<Expression>emptyList()); for (FieldDescriptor f : primaryKeyDescriptors) { final List<Expression> args = new ArrayList<Expression>(); args.add(new FieldAccessExpr(new ThisExpr(), f.getAttributeName())); args.add(new FieldAccessExpr(new NameExpr("other"), f.getAttributeName())); compareToBuilderExpr = new MethodCallExpr(compareToBuilderExpr, "append", args); } compareToBuilderExpr = new MethodCallExpr(compareToBuilderExpr, "toComparison"); final List<Statement> statements = new ArrayList<Statement>(); statements.add(new ReturnStmt(compareToBuilderExpr)); final BlockStmt equalsBody = new BlockStmt(statements); compareTo.setBody(equalsBody); return new NodeAndImports<MethodDeclaration>(compareTo, Collections.singleton(new ImportDeclaration(new QualifiedNameExpr(new NameExpr("org.apache.commons.lang.builder"), "CompareToBuilder"), false, false))); }