@Override public Node visit(VariableDeclaratorId _n, Object _arg) { Comment comment = cloneNodes(_n.getComment(), _arg); VariableDeclaratorId r = new VariableDeclaratorId( _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), _n.getName(), _n.getArrayCount() ); r.setComment(comment); return r; }
protected Node visit(final BaseParameter n, final A arg) { final List<AnnotationExpr> annotations = n.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.size(); i++) { annotations.set(i, (AnnotationExpr) annotations.get(i).accept(this, arg)); } removeNulls(annotations); } n.setId((VariableDeclaratorId) n.getId().accept(this, arg)); return n; }
@Override public Boolean visit(final VariableDeclaratorId n1, final Node arg) { final VariableDeclaratorId n2 = (VariableDeclaratorId) arg; if (n1.getArrayCount() != n2.getArrayCount()) { return Boolean.FALSE; } if (!objEquals(n1.getName(), n2.getName())) { return Boolean.FALSE; } return Boolean.TRUE; }
@Override public void visit(final VariableDeclaratorId n, final Object arg) { printJavaComment(n.getComment(), arg); printer.print(n.getName()); for (int i = 0; i < n.getArrayCount(); i++) { printer.print("[]"); } }
public String getName() { return parameter.getId().getName(); }
/** * Creates a new {@link Parameter}. * * @param type * type of the parameter * @param name * name of the parameter * @return instance of {@link Parameter} */ public static Parameter createParameter(Type type, String name) { return new Parameter(type, new VariableDeclaratorId(name)); }
final public VariableDeclarator VariableDeclarator() throws ParseException { VariableDeclaratorId id; Expression init = null; id = VariableDeclaratorId(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: jj_consume_token(ASSIGN); init = VariableInitializer(); break; default: jj_la1[31] = jj_gen; ; } {if (true) return new VariableDeclarator(id.getBeginLine(), id.getBeginColumn(), token.endLine, token.endColumn, id, init);} throw new Error("Missing return statement in function"); }
public static String getFieldName(FieldDeclaration field) { if (field.getVariables().size() > 1) { throw new IllegalArgumentException("cannot handle multiple variable declarations on a single line. This should have been cleaned up earlier."); } return field.getVariables().get(0).getId().getName(); }
/** * Creates a {@link VariableDeclarationExpr}. * * @param type * type * @param name * name * @return instance of {@link VariableDeclarationExpr} */ public static VariableDeclarationExpr createVariableDeclarationExpr(Type type, String name) { List<VariableDeclarator> vars = new ArrayList<VariableDeclarator>(); vars.add(new VariableDeclarator(new VariableDeclaratorId(name))); return new VariableDeclarationExpr(type, vars); }
public void visit(VariableDeclaratorId n, Object arg) { printer.print(n.getName()); for (int i = 0; i < n.getArrayCount(); i++) { printer.print("[]"); } }
final public VariableDeclarator VariableDeclarator() throws ParseException { VariableDeclaratorId id; Expression init = null; id = VariableDeclaratorId(); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case ASSIGN: jj_consume_token(ASSIGN); init = VariableInitializer(); break; default: jj_la1[31] = jj_gen; ; } VariableDeclarator tmp = new VariableDeclarator(id.getBeginLine(), id.getBeginColumn(), token.endLine, token.endColumn, id, init); {if (true) return tmp;} throw new Error("Missing return statement in function"); }
private String getTypeOrFieldNameForMsg(final BodyDeclaration n) { if (n instanceof TypeDeclaration) { return ((TypeDeclaration) n).getName(); } else if (n instanceof FieldDeclaration) { final FieldDeclaration fd = (FieldDeclaration) n; //this wont work for nested classes but we should be in nexted classes at this point final CompilationUnit unit = getCompilationUnit(n); final TypeDeclaration parent = unit.getTypes().get(0); Collection<String> variableNames = new ArrayList<String>(); if (fd.getVariables() != null) { for (VariableDeclarator vd : fd.getVariables()) { variableNames.add(vd.getId().getName()); } } return variableNames.size() == 1 ? parent.getName() + "." + variableNames.iterator().next() : parent.getName() + "." + variableNames.toString(); } return null; }
public class ClassCreator { public static void main(String[] args) throws Exception { // creates the compilation unit CompilationUnit cu = createCU(); // prints the created compilation unit System.out.println(cu.toString()); } /** * creates the compilation unit */ private static CompilationUnit createCU() { CompilationUnit cu = new CompilationUnit(); // set the package cu.setPackage(new PackageDeclaration(ASTHelper.createNameExpr("java.parser.test"))); // create the type declaration ClassOrInterfaceDeclaration type = new ClassOrInterfaceDeclaration(ModifierSet.PUBLIC, false, "GeneratedClass"); ASTHelper.addTypeDeclaration(cu, type); // create a field FieldDeclaration field = new FieldDeclaration(ModifierSet.PUBLIC, new ClassOrInterface(String.class.getName()), new VariableDeclarator(new VariableDeclaratorId("variableName"))) ASTHelper.addMember(type, field); return cu; } }
public void visit(MultiTypeParameter n, Object arg) { printAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); Iterator<Type> types = n.getTypes().iterator(); types.next().accept(this, arg); while (types.hasNext()) { printer.print(" | "); types.next().accept(this, arg); } printer.print(" "); n.getId().accept(this, arg); }
private boolean nodeContainsPkFields(TypeDeclaration dclr, Collection<FieldDescriptor> pks) { for (FieldDescriptor pk : pks) { boolean contains = false; for (FieldDeclaration field : ParserUtil.getFieldMembers(dclr.getMembers())) { if (field.getVariables().get(0).getId().getName().equals(pk.getAttributeName())) { contains = true; break; } } if (!contains) { return false; } } return true; }
/** * Creates a {@link FieldDeclaration}. * * @param modifiers * modifiers * @param type * type * @param name * field name * @return instance of {@link FieldDeclaration} */ public static FieldDeclaration createFieldDeclaration(int modifiers, Type type, String name) { VariableDeclaratorId id = new VariableDeclaratorId(name); VariableDeclarator variable = new VariableDeclarator(id); return createFieldDeclaration(modifiers, type, variable); }
@Override public R visit(final VariableDeclarator n, final A arg) { { R result = n.getId().accept(this, arg); if (result != null) { return result; } } if (n.getInit() != null) { { R result = n.getInit().accept(this, arg); if (result != null) { return result; } } } return null; }
@Override public Void visit(FieldDeclaration n, Visit v) { if (n.getVariables().size() == 1) { VariableDeclarator declarator = n.getVariables().get(0); VariableDeclaratorId id = declarator.getId(); NamedMemberSource fieldSource = new NamedMemberSource( id.getName(), clip(n), v.javaDoc(n)); ((Visit.TD)v).stack.getLast().addLast(fieldSource); } else { throw new UnsupportedOperationException("todo"); } return super.visit(n, v); }
final public VariableDeclaratorId VariableDeclaratorId() throws ParseException { String name; int arrayCount = 0; int line; int column; jj_consume_token(IDENTIFIER); name = token.image; line=token.beginLine; column=token.beginColumn; label_14: while (true) { switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case LBRACKET: ; break; default: jj_la1[32] = jj_gen; break label_14; } jj_consume_token(LBRACKET); jj_consume_token(RBRACKET); arrayCount++; } VariableDeclaratorId tmp = new VariableDeclaratorId(line, column, token.endLine, token.endColumn,name, arrayCount); {if (true) return tmp;} throw new Error("Missing return statement in function"); }
public void visit(VariableDeclarator n, Object arg) { n.getId().accept(this, arg); if (n.getInit() != null) { printer.print(" = "); n.getInit().accept(this, arg); } }