List of usage examples for org.eclipse.jdt.core.dom SingleVariableDeclaration modifiers
ASTNode.NodeList modifiers
To view the source code for org.eclipse.jdt.core.dom SingleVariableDeclaration modifiers.
Click Source Link
From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java
License:Open Source License
@Override public boolean visit(SingleVariableDeclaration node) { if (node.getAST().apiLevel() >= JLS3) { printModifiers(node.modifiers()); }//w ww .j a v a2s .c om node.getType().accept(this); if (node.getAST().apiLevel() >= JLS3) { if (node.isVarargs()) { if (node.getAST().apiLevel() >= AST.JLS8) { this.fBuffer.append(' '); List<Annotation> annotations = node.varargsAnnotations(); printAnnotationsList(annotations); } this.fBuffer.append("...");//$NON-NLS-1$ } } this.fBuffer.append(" ");//$NON-NLS-1$ node.getName().accept(this); if (node.getAST().apiLevel() >= AST.JLS8) { List<Dimension> dimensions = node.extraDimensions(); for (Iterator<Dimension> it = dimensions.iterator(); it.hasNext();) { Dimension e = it.next(); e.accept(this); } } else { for (int i = 0; i < node.getExtraDimensions(); i++) { this.fBuffer.append("[]"); //$NON-NLS-1$ } } if (node.getInitializer() != null) { this.fBuffer.append("=");//$NON-NLS-1$ node.getInitializer().accept(this); } return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(MethodDeclaration node) { List<boa.types.Ast.Method> list = methods.peek(); Method.Builder b = Method.newBuilder(); // b.setPosition(pos.build()); if (node.isConstructor()) b.setName("<init>"); else/*from w ww .ja v a2s .c o m*/ b.setName(node.getName().getFullyQualifiedName()); for (Object m : node.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); b.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); if (node.getReturnType2() != null) { String name = typeName(node.getReturnType2()); for (int i = 0; i < node.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } else { tb.setName(getIndex("void")); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } for (Object t : node.typeParameters()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = ((TypeParameter) t).getName().getFullyQualifiedName(); String bounds = ""; for (Object o : ((TypeParameter) t).typeBounds()) { if (bounds.length() > 0) bounds += " & "; bounds += typeName((org.eclipse.jdt.core.dom.Type) o); } if (bounds.length() > 0) name = name + " extends " + bounds; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.GENERIC); b.addGenericParameters(tp.build()); } for (Object o : node.parameters()) { SingleVariableDeclaration ex = (SingleVariableDeclaration) o; Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build()); // FIXME vb.setName(ex.getName().getFullyQualifiedName()); for (Object m : ex.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); vb.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(ex.getType()); for (int i = 0; i < ex.getExtraDimensions(); i++) name += "[]"; if (ex.isVarargs()) name += "..."; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tp.build()); if (ex.getInitializer() != null) { ex.getInitializer().accept(this); vb.setInitializer(expressions.pop()); } b.addArguments(vb.build()); } for (Object o : node.thrownExceptions()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); tp.setName(getIndex(((Name) o).getFullyQualifiedName())); tp.setKind(boa.types.Ast.TypeKind.CLASS); b.addExceptionTypes(tp.build()); } if (node.getBody() != null) { statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); } list.add(b.build()); return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(CatchClause node) { boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder(); // b.setPosition(pos.build()); List<boa.types.Ast.Statement> list = statements.peek(); b.setKind(boa.types.Ast.Statement.StatementKind.CATCH); SingleVariableDeclaration ex = node.getException(); Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build());// FIXME vb.setName(ex.getName().getFullyQualifiedName()); for (Object m : ex.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else/*from w w w. j a va2s.c o m*/ ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); vb.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); String name = typeName(ex.getType()); for (int i = 0; i < ex.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tb.build()); if (ex.getInitializer() != null) { ex.getInitializer().accept(this); vb.setInitializer(expressions.pop()); } b.setVariableDeclaration(vb.build()); statements.push(new ArrayList<boa.types.Ast.Statement>()); for (Object s : node.getBody().statements()) ((org.eclipse.jdt.core.dom.Statement) s).accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); list.add(b.build()); return false; }
From source file:boa.datagen.util.Java7Visitor.java
License:Apache License
@Override public boolean visit(EnhancedForStatement node) { boa.types.Ast.Statement.Builder b = boa.types.Ast.Statement.newBuilder(); // b.setPosition(pos.build()); List<boa.types.Ast.Statement> list = statements.peek(); b.setKind(boa.types.Ast.Statement.StatementKind.FOR); SingleVariableDeclaration ex = node.getParameter(); Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build());//FIXME vb.setName(ex.getName().getFullyQualifiedName()); for (Object m : ex.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else//from w ww. ja va2 s . co m ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); vb.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); String name = typeName(ex.getType()); for (int i = 0; i < ex.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tb.build()); if (ex.getInitializer() != null) { ex.getInitializer().accept(this); vb.setInitializer(expressions.pop()); } b.setVariableDeclaration(vb.build()); node.getExpression().accept(this); b.setExpression(expressions.pop()); statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); list.add(b.build()); return false; }
From source file:boa.datagen.util.Java8Visitor.java
License:Apache License
@Override public boolean visit(MethodDeclaration node) { List<boa.types.Ast.Method> list = methods.peek(); Method.Builder b = Method.newBuilder(); // b.setPosition(pos.build()); if (node.isConstructor()) b.setName("<init>"); else//from w w w.j a va2s.c o m b.setName(node.getName().getFullyQualifiedName()); for (Object m : node.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); b.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); if (node.getReturnType2() != null) { String name = typeName(node.getReturnType2()); // FIXME JLS8: Deprecated getExtraDimensions() and added extraDimensions() for (int i = 0; i < node.getExtraDimensions(); i++) name += "[]"; tb.setName(getIndex(name)); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } else { tb.setName(getIndex("void")); tb.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(tb.build()); } for (Object t : node.typeParameters()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = ((TypeParameter) t).getName().getFullyQualifiedName(); String bounds = ""; for (Object o : ((TypeParameter) t).typeBounds()) { if (bounds.length() > 0) bounds += " & "; bounds += typeName((org.eclipse.jdt.core.dom.Type) o); } if (bounds.length() > 0) name = name + " extends " + bounds; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.GENERIC); b.addGenericParameters(tp.build()); } if (node.getReceiverType() != null) { Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build()); // FIXME vb.setName("this"); boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(node.getReceiverType()); if (node.getReceiverQualifier() != null) name = node.getReceiverQualifier().getFullyQualifiedName() + "." + name; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); // FIXME change to receiver? or something? vb.setVariableType(tp.build()); b.addArguments(vb.build()); } for (Object o : node.parameters()) { SingleVariableDeclaration ex = (SingleVariableDeclaration) o; Variable.Builder vb = Variable.newBuilder(); // vb.setPosition(pos.build()); // FIXME vb.setName(ex.getName().getFullyQualifiedName()); for (Object m : ex.modifiers()) { if (((IExtendedModifier) m).isAnnotation()) ((Annotation) m).accept(this); else ((org.eclipse.jdt.core.dom.Modifier) m).accept(this); vb.addModifiers(modifiers.pop()); } boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(ex.getType()); // FIXME JLS8: Deprecated getExtraDimensions() and added extraDimensions() for (int i = 0; i < ex.getExtraDimensions(); i++) name += "[]"; if (ex.isVarargs()) name += "..."; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tp.build()); if (ex.getInitializer() != null) { ex.getInitializer().accept(this); vb.setInitializer(expressions.pop()); } b.addArguments(vb.build()); } for (Object o : node.thrownExceptionTypes()) { boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex(typeName((org.eclipse.jdt.core.dom.Type) o))); tp.setKind(boa.types.Ast.TypeKind.CLASS); b.addExceptionTypes(tp.build()); } if (node.getBody() != null) { statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); } list.add(b.build()); return false; }
From source file:ch.acanda.eclipse.pmd.java.resolution.optimization.MethodArgumentCouldBeFinalQuickFix.java
License:Open Source License
/** * Adds the final modifier to the variable declaration. *//*w w w . j av a 2 s.c o m*/ @Override @SuppressWarnings("unchecked") protected boolean apply(final SingleVariableDeclaration node) { final Modifier modifier = (Modifier) node.getAST().createInstance(Modifier.class); modifier.setKeyword(ModifierKeyword.FINAL_KEYWORD); node.modifiers().add(modifier); return true; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(SingleVariableDeclaration node) { printIndent();//from w w w.jav a 2s. c o m if (node.getAST().apiLevel() >= AST.JLS3) { printModifiers(node.modifiers()); } node.getType().accept(this); if (node.getAST().apiLevel() >= AST.JLS3) { if (node.isVarargs()) { this.buffer.append("...");//$NON-NLS-1$ } } this.buffer.append(" ");//$NON-NLS-1$ node.getName().accept(this); for (int i = 0; i < node.getExtraDimensions(); i++) { this.buffer.append("[]"); //$NON-NLS-1$ } if (node.getInitializer() != null) { this.buffer.append("=");//$NON-NLS-1$ node.getInitializer().accept(this); } return false; }
From source file:com.google.devtools.j2cpp.translate.ClassConverter.java
License:Open Source License
@SuppressWarnings("unchecked") protected List<SingleVariableDeclaration> createConstructorArguments(List<IVariableBinding> innerFields, IMethodBinding constructor, AST ast, String prefix) { int nameOffset = constructor.getParameterTypes().length; List<SingleVariableDeclaration> args = Lists.newArrayList(); for (int i = 0; i < innerFields.size(); i++) { IVariableBinding field = innerFields.get(i); String argName = prefix + (i + nameOffset); SimpleName name = ast.newSimpleName(argName); GeneratedVariableBinding binding = new GeneratedVariableBinding(argName, Modifier.FINAL, field.getType(), false, true, constructor.getDeclaringClass(), constructor); Types.addBinding(name, binding); SingleVariableDeclaration newArg = ast.newSingleVariableDeclaration(); newArg.setName(name);//from www . j a v a 2s.c o m newArg.setType(Types.makeType(field.getType())); newArg.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD)); Types.addBinding(newArg, binding); args.add(newArg); } return args; }
From source file:com.google.devtools.j2objc.util.ASTUtil.java
License:Apache License
@SuppressWarnings("unchecked") public static List<IExtendedModifier> getModifiers(SingleVariableDeclaration node) { return node.modifiers(); }
From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java
License:Apache License
/** * Helper method for {@link EnhancedForStatement}s, {@link MethodDeclaration}s, and * {@link SingleVariableDeclaration}s./* w w w .java2s . c o m*/ */ private void visitToDeclare(Direction annotationsDirection, SingleVariableDeclaration node, Optional<Expression> initializer, String equals) { sync(node); declareOne(node, annotationsDirection, node.modifiers(), node.getType(), VarArgsOrNot.valueOf(node.isVarargs()), node.varargsAnnotations(), node.getName(), "", node.extraDimensions(), equals, initializer, Optional.<String>absent(), ReceiverParameter.NO); }