List of usage examples for org.eclipse.jdt.core.dom SingleVariableDeclaration getType
public Type getType()
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()); }/*from w w w. ja va 2s . c o m*/ 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// w w w . j ava 2s.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/*w w w.j ava 2 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()); 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 ww w . ja v a2s .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()); 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// w w w . j av a 2s. c om 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:boa.datagen.util.Java8Visitor.java
License:Apache License
@Override public boolean visit(LambdaExpression node) { Method.Builder b = Method.newBuilder(); b.setName(""); boa.types.Ast.Type.Builder rt = boa.types.Ast.Type.newBuilder(); rt.setName(getIndex("")); rt.setKind(boa.types.Ast.TypeKind.OTHER); b.setReturnType(rt.build());// www. j av a 2 s. c o m for (Object o : node.parameters()) { VariableDeclaration ex = (VariableDeclaration) o; Variable.Builder vb = Variable.newBuilder(); vb.setName(ex.getName().getFullyQualifiedName()); if (o instanceof SingleVariableDeclaration) { SingleVariableDeclaration svd = (SingleVariableDeclaration) o; boa.types.Ast.Type.Builder tp = boa.types.Ast.Type.newBuilder(); String name = typeName(svd.getType()); // FIXME JLS8: Deprecated getExtraDimensions() and added extraDimensions() for (int i = 0; i < svd.getExtraDimensions(); i++) name += "[]"; if (svd.isVarargs()) name += "..."; tp.setName(getIndex(name)); tp.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tp.build()); } else { VariableDeclarationFragment vdf = (VariableDeclarationFragment) o; boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder(); tb.setName(getIndex("")); tb.setKind(boa.types.Ast.TypeKind.OTHER); vb.setVariableType(tb.build()); } b.addArguments(vb.build()); } if (node.getBody() != null) { statements.push(new ArrayList<boa.types.Ast.Statement>()); node.getBody().accept(this); if (node.getBody() instanceof org.eclipse.jdt.core.dom.Expression) { boa.types.Ast.Expression e = expressions.pop(); boa.types.Ast.Statement.Builder sb = boa.types.Ast.Statement.newBuilder(); sb.setKind(boa.types.Ast.Statement.StatementKind.EXPRESSION); sb.setExpression(e); statements.peek().add(sb.build()); } for (boa.types.Ast.Statement s : statements.pop()) b.addStatements(s); } boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder(); eb.setKind(boa.types.Ast.Expression.ExpressionKind.LAMBDA); eb.setLambda(b.build()); expressions.push(eb.build()); return false; }
From source file:ch.acanda.eclipse.pmd.java.resolution.design.UseVarargsQuickFix.java
License:Open Source License
@Override protected boolean apply(final SingleVariableDeclaration node) { node.setType(copy(((ArrayType) node.getType()).getComponentType())); node.setVarargs(true);/*from w ww . ja va 2 s.c o m*/ return true; // final SingleVariableDeclaration varargsDeclaration = copy(node); // varargsDeclaration.setVarargs(true); // final Type type = copy(((ArrayType) node.getType()).getComponentType()); // varargsDeclaration.setType(type); // return replace(node, varargsDeclaration); }
From source file:changetypes.ASTVisitorAtomicChange.java
License:Open Source License
public boolean visit(MethodDeclaration node) { IMethodBinding mtb = node.resolveBinding(); this.mtbStack.push(mtb); String nodeStr = node.toString(); String modifier = "protected"; int dex = nodeStr.indexOf(' '); if (dex >= 0) { String temp = nodeStr.substring(0, dex); if (temp.equals("public")) { modifier = "public"; } else if (temp.equals("private")) { modifier = "private"; }//from w w w. j ava 2s. c o m } try { String visibility = getModifier(mtb); this.facts.add(Fact.makeMethodFact(getQualifiedName(mtb), getSimpleName(mtb), getQualifiedName(mtb.getDeclaringClass()), visibility)); } catch (Exception localException1) { System.err.println("Cannot resolve return method bindings for method " + node.getName().toString()); } try { String returntype = getQualifiedName(mtb.getReturnType()); this.facts.add(Fact.makeReturnsFact(getQualifiedName(mtb), returntype)); } catch (Exception localException2) { System.err.println("Cannot resolve return type bindings for method " + node.getName().toString()); } try { this.facts.add(Fact.makeModifierMethodFact(getQualifiedName(mtb), modifier)); } catch (Exception localException3) { System.err.println( "Cannot resolve return type bindings for method modifier " + node.getName().toString()); } try { String bodystring = node.getBody() != null ? node.getBody().toString() : ""; bodystring = bodystring.replace('\n', ' '); bodystring = bodystring.replace('"', ' '); bodystring = bodystring.replace('"', ' '); bodystring = bodystring.replace('\\', ' '); this.facts.add(Fact.makeMethodBodyFact(getQualifiedName(mtb), bodystring)); } catch (Exception localException4) { System.err.println("Cannot resolve bindings for body"); } SingleVariableDeclaration param; try { List<SingleVariableDeclaration> parameters = node.parameters(); StringBuilder sb = new StringBuilder(); for (Iterator localIterator = parameters.iterator(); localIterator.hasNext();) { param = (SingleVariableDeclaration) localIterator.next(); if (sb.length() != 0) { sb.append(", "); } sb.append(param.getType().toString()); sb.append(":"); sb.append(param.getName().toString()); } this.facts.add(Fact.makeParameterFact(getQualifiedName(mtb), sb.toString(), "")); } catch (Exception localException5) { System.err.println("Cannot resolve bindings for parameters"); } try { List<Name> thrownTypes = node.thrownExceptions(); for (Name n : thrownTypes) { this.facts.add(Fact.makeThrownExceptionFact(getQualifiedName(mtb), getQualifiedName(n.resolveTypeBinding()))); } } catch (Exception localException6) { System.err.println("Cannot resolve bindings for exceptions"); } return true; }
From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java
License:Open Source License
@Override public boolean visit(SingleVariableDeclaration node) { boolean isNotParam = getCurrentParent().getLabel() != EntityType.PARAMETERS.toString();// @inria pushNode(node, node.getName().getIdentifier()); node.getType().accept(this); return false; }
From source file:coloredide.utils.CopiedNaiveASTFlattener.java
License:Open Source License
public boolean visit(SingleVariableDeclaration node) { printIndent();/*from w w w. j a va 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; }