Example usage for org.eclipse.jdt.core.dom SingleVariableDeclaration isVarargs

List of usage examples for org.eclipse.jdt.core.dom SingleVariableDeclaration isVarargs

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom SingleVariableDeclaration isVarargs.

Prototype

public boolean isVarargs() 

Source Link

Document

Returns whether this declaration declares the last parameter of a variable arity method (added in JLS3 API).

Usage

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 va 2  s.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/*ww w .  j av  a  2s  .  co 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.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 av  a2 s  .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: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());/*w  w  w .  j a  va2  s . com*/
    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:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(SingleVariableDeclaration node) {
    printIndent();/*  www  .j  ava  2 s.  c om*/
    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.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public void endVisit(SingleVariableDeclaration node) {
    // this must be endVisit in case a space added by a visit on a child node needs to be cleared
    if (node.isVarargs()) {
        handleTokenBefore(node.getName(), TokenNameELLIPSIS, this.options.insert_space_before_ellipsis,
                this.options.insert_space_after_ellipsis);
        List<Annotation> varargsAnnotations = node.varargsAnnotations();
        if (!varargsAnnotations.isEmpty()) {
            this.tm.firstTokenIn(varargsAnnotations.get(0), TokenNameAT).spaceBefore();
            this.tm.lastTokenIn(varargsAnnotations.get(varargsAnnotations.size() - 1), -1).clearSpaceAfter();
        }//from  w w w.jav  a  2 s .  c  o m
    } else {
        handleToken(node.getName(), TokenNameIdentifier, true, false);
    }
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java

License:Open Source License

/**
 * @author Mariana - added support for array dimensions (e.g. int[][]) and variable arguments (e.g. int...)
 * /*from  w  w  w.j a va 2  s. com*/
 * @throws CodeSyncException 
 * @flowerModelElementId _zVs8fpiOEd6aNMdNFvR5WQ
 */
@SuppressWarnings("unchecked")
public static Object getJavaLookupKeyForMethod(MethodDeclaration md, ReversePackage_Type reversePackage_Type)
        throws CodeSyncException {
    String result = getSimpleNameString(md) + "(";
    List<SingleVariableDeclaration> params = md.parameters();
    for (Iterator<SingleVariableDeclaration> it = params.iterator(); it.hasNext();) {
        SingleVariableDeclaration p = it.next();
        result += SyncUtils.getFullyQualifiedNameForAstType(p.getType().toString(), reversePackage_Type);
        // support for extra dimensions
        // e.g. int x[][] will return int[][]
        for (int i = 0; i < p.getExtraDimensions(); i++) {
            result += "[]";
        }
        // support for variable arguments
        if (p.isVarargs()) {
            result += "...";
        }
        result += ",";
    }
    result += ")";
    return result;
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaMethod.java

License:Open Source License

/**
 * @author Mariana - added support for array dimensions (e.g. int[][]) and variable arguments (e.g. int...)
 *//*from   w w w. ja v  a  2s. c om*/
@SuppressWarnings("unchecked")
@Override
protected Object getFeatureValueFromAST(EStructuralFeature feature, MethodDeclaration astElement) {
    if (astElement == null)
        throw new IllegalArgumentException("astElement is null");
    String typeName = null;
    ReversePackage_JavaTypes reversePackage_JavaTypes = parentReverse.parentReverse.parentReverse;

    switch (feature.getFeatureID()) {
    case UMLPackage.OPERATION__TYPE:
        typeName = JavaSyncUtils.getReturnTypeAsString(astElement);
        return SyncUtils.getTypeOrCreateInUnknownTypes(typeName,
                new JavaTypeCreation(JavaTypeCreation.CLASS_OR_INTERFACE), reversePackage_JavaTypes,
                currentElement);
    case UMLPackage.BEHAVIORAL_FEATURE__OWNED_PARAMETER:
        List<Parameter> result = new ArrayList<Parameter>();
        for (SingleVariableDeclaration javaPar : (List<SingleVariableDeclaration>) astElement.parameters()) {
            typeName = javaPar.getType().toString();
            // support for extra dimensions
            // e.g. int x[][] will return int[][]
            for (int i = 0; i < javaPar.getExtraDimensions(); i++) {
                typeName += "[]";
            }
            // support for variable arguments
            if (javaPar.isVarargs()) {
                typeName += "...";
            }
            Type selectedType = SyncUtils.getTypeOrCreateInUnknownTypes(typeName,
                    new JavaTypeCreation(JavaTypeCreation.CLASS_OR_INTERFACE), reversePackage_JavaTypes,
                    currentElement);

            Parameter par = CodeSyncFactory.eINSTANCE.createSyncParameter();
            par.setName(javaPar.getName().toString());
            par.setType(selectedType);
            result.add(par);
        }
        return result;
    case UMLPackage.BEHAVIORAL_FEATURE__IS_ABSTRACT:
        return JavaSyncUtils.getFeatureValueFromJavaModifier(astElement, JavaSyncUtils.MODIFIER_ABSTRACT);
    default:
        return super.getFeatureValueFromAST(feature, astElement);
    }
}

From source file:com.google.dart.java2dart.SyntaxTranslator.java

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.SingleVariableDeclaration node) {
    TypeName type = (TypeName) translate(node.getType());
    type = listType(type, node.getExtraDimensions());
    if (node.isVarargs()) {
        type = listType(type, 1);/* w w  w  .j  a v  a  2 s. c o m*/
    }
    return done(simpleFormalParameter(type, translateSimpleName(node.getName())));
}

From source file:com.google.devtools.j2cpp.gen.CppStatementGenerator.java

License:Open Source License

@Override
public boolean visit(SingleVariableDeclaration node) {
    buffer.append(NameTable.javaRefToCpp(node.getType()));
    if (node.isVarargs()) {
        buffer.append("...");
    }//  w  ww .  jav  a  2s  . co  m
    if (buffer.charAt(buffer.length() - 1) != '*') {
        buffer.append(" ");
    }
    node.getName().accept(this);
    for (int i = 0; i < node.getExtraDimensions(); i++) {
        buffer.append("[]");
    }
    if (node.getInitializer() != null) {
        buffer.append(" = ");
        node.getInitializer().accept(this);
    }
    return false;
}