@Override public Node visit(VariableDeclarator _n, Object _arg) { VariableDeclaratorId id = cloneNodes(_n.getId(), _arg); Expression init = cloneNodes(_n.getInit(), _arg); Comment comment = cloneNodes(_n.getComment(), _arg); VariableDeclarator r = new VariableDeclarator( _n.getBeginLine(), _n.getBeginColumn(), _n.getEndLine(), _n.getEndColumn(), id, init ); r.setComment(comment); return r; }
@Override public void visit(final VariableDeclarator n, final A arg) { visitComment(n.getComment(), arg); n.getId().accept(this, arg); if (n.getInit() != null) { n.getInit().accept(this, arg); } }
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); }
@Override public Node visit(final VariableDeclarationExpr 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.setType((Type) n.getType().accept(this, arg)); final List<VariableDeclarator> vars = n.getVars(); for (int i = 0; i < vars.size(); i++) { vars.set(i, (VariableDeclarator) vars.get(i).accept(this, arg)); } removeNulls(vars); return n; }
@Override public void visit(final VariableDeclarator n, final Object arg) { printJavaComment(n.getComment(), arg); n.getId().accept(this, arg); if (n.getInit() != null) { printer.print(" = "); n.getInit().accept(this, arg); } }
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; }
/** * 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); }
public void visit(VariableDeclarationExpr n, Object arg) { printAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); n.getType().accept(this, arg); printer.print(" "); for (Iterator<VariableDeclarator> i = n.getVars().iterator(); i.hasNext();) { VariableDeclarator v = i.next(); v.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } }
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; }
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"); }
@Override public void visit(final VariableDeclarationExpr n, final Object arg) { printJavaComment(n.getComment(), arg); printAnnotations(n.getAnnotations(), arg); printModifiers(n.getModifiers()); n.getType().accept(this, arg); printer.print(" "); for (final Iterator<VariableDeclarator> i = n.getVars().iterator(); i.hasNext();) { final VariableDeclarator v = i.next(); v.accept(this, arg); if (i.hasNext()) { printer.print(", "); } } }
@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 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"); }
@Override public Node visit(final FieldDeclaration n, final A arg) { if (n.getJavaDoc() != null) { n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, 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.setType((Type) n.getType().accept(this, arg)); final List<VariableDeclarator> variables = n.getVariables(); for (int i = 0; i < variables.size(); i++) { variables.set(i, (VariableDeclarator) variables.get(i).accept(this, arg)); } removeNulls(variables); return n; }
@Override public void visit(FieldDeclaration n, Object arg) { for (VariableDeclarator var : n.getVariables()) { CGEntry currentVariable = new CGEntry(TYPE.VARIABLE, currentClass, currentMethod, var.getId().getName()); if (isDebug()) System.out.println("V:" + currentVariable); list.add(currentVariable); List<AnnotationExpr> annos = n.getAnnotations(); if (annos != null) { for (AnnotationExpr anno : annos) { if (isDebug()) System.out.println("A:" + anno.getName()); currentVariable.addAnnotation(new CGEntry(TYPE.ANNOTATION, currentClass, currentMethod, anno.getName().getName())); } } } super.visit(n, arg); }