@Override public Node visit(IfStmt _n, Object _arg) { Expression condition = cloneNodes(_n.getCondition(), _arg); Statement thenStmt = cloneNodes(_n.getThenStmt(), _arg); Statement elseStmt = cloneNodes(_n.getElseStmt(), _arg); Comment comment = cloneNodes(_n.getComment(), _arg); IfStmt r = new IfStmt( _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), condition, thenStmt, elseStmt ); r.setComment(comment); return r; }
@Override public Node visit(final IfStmt n, final A arg) { n.setCondition((Expression) n.getCondition().accept(this, arg)); n.setThenStmt((Statement) n.getThenStmt().accept(this, arg)); if (n.getElseStmt() != null) { n.setElseStmt((Statement) n.getElseStmt().accept(this, arg)); } return n; }
@Override public Boolean visit(final IfStmt n1, final Node arg) { final IfStmt n2 = (IfStmt) arg; if (!nodeEquals(n1.getCondition(), n2.getCondition())) { return Boolean.FALSE; } if (!nodeEquals(n1.getThenStmt(), n2.getThenStmt())) { return Boolean.FALSE; } if (!nodeEquals(n1.getElseStmt(), n2.getElseStmt())) { return Boolean.FALSE; } return Boolean.TRUE; }
@Override public void visit(final IfStmt n, final A arg) { visitComment(n.getComment(), arg); n.getCondition().accept(this, arg); n.getThenStmt().accept(this, arg); if (n.getElseStmt() != null) { n.getElseStmt().accept(this, arg); } }
final public IfStmt IfStatement() throws ParseException { Expression condition; Statement thenStmt; Statement elseStmt = null; int line; int column; jj_consume_token(IF); line=token.beginLine; column=token.beginColumn; jj_consume_token(LPAREN); condition = Expression(); jj_consume_token(RPAREN); thenStmt = Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ELSE: jj_consume_token(ELSE); elseStmt = Statement(); break; default: jj_la1[111] = jj_gen; ; } {if (true) return new IfStmt(line, column, token.endLine, token.endColumn,condition, thenStmt, elseStmt);} throw new Error("Missing return statement in function"); }
public void visit(IfStmt n, Object arg) { printer.print("if ("); n.getCondition().accept(this, arg); printer.print(") "); n.getThenStmt().accept(this, arg); if (n.getElseStmt() != null) { printer.print(" else "); n.getElseStmt().accept(this, arg); } }
@Override public void visit(final IfStmt n, final Object arg) { printJavaComment(n.getComment(), arg); printer.print("if ("); n.getCondition().accept(this, arg); final boolean thenBlock = n.getThenStmt() instanceof BlockStmt; if (thenBlock) // block statement should start on the same line printer.print(") "); printer.indent(); n.getThenStmt().accept(this, arg); if (!thenBlock) printer.unindent(); if (n.getElseStmt() != null) { if (thenBlock) printer.print(" "); else printer.printLn(); final boolean elseIf = n.getElseStmt() instanceof IfStmt; final boolean elseBlock = n.getElseStmt() instanceof BlockStmt; if (elseIf || elseBlock) // put chained if and start of block statement on a same level printer.print("else "); printer.indent(); n.getElseStmt().accept(this, arg); if (!(elseIf || elseBlock)) printer.unindent();
final public IfStmt IfStatement() throws ParseException { Expression condition; Statement thenStmt; Statement elseStmt = null; int line; int column; Comment thenCmmt = null; Comment elseCmmt = null; jj_consume_token(IF); line=token.beginLine; column=token.beginColumn; jj_consume_token(LPAREN); condition = Expression(); jj_consume_token(RPAREN); thenStmt = Statement(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ELSE: jj_consume_token(ELSE); elseStmt = Statement(); break; default: jj_la1[112] = jj_gen; ; } IfStmt tmp = new IfStmt(line, column, token.endLine, token.endColumn,condition, thenStmt, elseStmt); thenStmt.setComment(thenCmmt); if (elseStmt != null) elseStmt.setComment(elseCmmt); {if (true) return tmp;} throw new Error("Missing return statement in function"); }
@Override public R visit(final IfStmt n, final A arg) { { R result = n.getCondition().accept(this, arg); if (result != null) { return result; } } { R result = n.getThenStmt().accept(this, arg); if (result != null) { return result; } } if (n.getElseStmt() != null) { { R result = n.getElseStmt().accept(this, arg); if (result != null) { return result; } } } return null; }
private NodeAndImports<MethodDeclaration> createPrimaryKeyEquals(Collection<FieldDescriptor> primaryKeyDescriptors, String enclosingClassName) { final MethodDeclaration equals = new MethodDeclaration(ModifierSet.PUBLIC, new PrimitiveType(PrimitiveType.Primitive.Boolean), "equals", Collections.singletonList(new Parameter(new ClassOrInterfaceType("Object"), new VariableDeclaratorId("other")))); equals.setAnnotations(Collections.<AnnotationExpr>singletonList(new MarkerAnnotationExpr(new NameExpr("Override")))); final Statement ifEqualNullStmt = new IfStmt(new BinaryExpr(new NameExpr("other"), new NullLiteralExpr(), BinaryExpr.Operator.equals), new ReturnStmt(new BooleanLiteralExpr(false)), null); final Statement ifEqualThisStmt = new IfStmt(new BinaryExpr(new NameExpr("other"), new ThisExpr(), BinaryExpr.Operator.equals), new ReturnStmt(new BooleanLiteralExpr(true)), null); final Statement ifEqualClassStmt = new IfStmt(new BinaryExpr(new MethodCallExpr(new NameExpr("other"), "getClass"), new MethodCallExpr(new ThisExpr(), "getClass"), BinaryExpr.Operator.notEquals), new ReturnStmt(new BooleanLiteralExpr(false)), null); final Statement rhsStmt = new ExpressionStmt(new VariableDeclarationExpr(ModifierSet.FINAL, new ClassOrInterfaceType(enclosingClassName), Collections.singletonList(new VariableDeclarator( new VariableDeclaratorId("rhs"), new CastExpr(new ClassOrInterfaceType(enclosingClassName), new NameExpr("other")))))); Expression equalsBuilderExpr = new ObjectCreationExpr(null, new ClassOrInterfaceType("EqualsBuilder"), 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("rhs"), f.getAttributeName())); equalsBuilderExpr = new MethodCallExpr(equalsBuilderExpr, "append", args); } equalsBuilderExpr = new MethodCallExpr(equalsBuilderExpr, "isEquals"); final List<Statement> statements = new ArrayList<Statement>(); statements.add(ifEqualNullStmt); statements.add(ifEqualThisStmt); statements.add(ifEqualClassStmt); statements.add(rhsStmt); statements.add(new ReturnStmt(equalsBuilderExpr)); final BlockStmt equalsBody = new BlockStmt(statements); equals.setBody(equalsBody); return new NodeAndImports<MethodDeclaration>(equals, Collections.singleton(new ImportDeclaration(new QualifiedNameExpr(new NameExpr("org.apache.commons.lang.builder"), "EqualsBuilder"), false, false))); }