Example usage for org.eclipse.jdt.core.dom VariableDeclarationExpression fragments

List of usage examples for org.eclipse.jdt.core.dom VariableDeclarationExpression fragments

Introduction

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

Prototype

public List fragments() 

Source Link

Document

Returns the live list of variable declaration fragments in this expression.

Usage

From source file:at.bestsolution.fxide.jdt.corext.dom.ASTFlattener.java

License:Open Source License

@Override
public boolean visit(VariableDeclarationExpression node) {
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
    }//from w  ww. jav  a  2s .  c om
    node.getType().accept(this);
    this.fBuffer.append(" ");//$NON-NLS-1$
    for (Iterator<VariableDeclarationFragment> it = node.fragments().iterator(); it.hasNext();) {
        VariableDeclarationFragment f = it.next();
        f.accept(this);
        if (it.hasNext()) {
            this.fBuffer.append(", ");//$NON-NLS-1$
        }
    }
    return false;
}

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

@Override
public boolean visit(VariableDeclarationExpression node) {
    boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder();
    //      eb.setPosition(pos.build());
    eb.setKind(boa.types.Ast.Expression.ExpressionKind.VARDECL);
    for (Object o : node.fragments()) {
        VariableDeclarationFragment f = (VariableDeclarationFragment) o;
        Variable.Builder b = Variable.newBuilder();
        //         b.setPosition(pos.build());//FIXME
        b.setName(f.getName().getFullyQualifiedName());
        for (Object m : node.modifiers()) {
            if (((IExtendedModifier) m).isAnnotation())
                ((Annotation) m).accept(this);
            else/*from   w  w w . ja  v a  2 s.  c om*/
                ((org.eclipse.jdt.core.dom.Modifier) m).accept(this);
            b.addModifiers(modifiers.pop());
        }
        boa.types.Ast.Type.Builder tb = boa.types.Ast.Type.newBuilder();
        String name = typeName(node.getType());
        for (int i = 0; i < f.getExtraDimensions(); i++)
            name += "[]";
        tb.setName(getIndex(name));
        tb.setKind(boa.types.Ast.TypeKind.OTHER);
        b.setVariableType(tb.build());
        if (f.getInitializer() != null) {
            f.getInitializer().accept(this);
            b.setInitializer(expressions.pop());
        }
        eb.addVariableDecls(b.build());
    }
    expressions.push(eb.build());
    return false;
}

From source file:br.uff.ic.gems.resources.ast.Visitor.java

@Override
public boolean visit(VariableDeclarationExpression node) {

    List<VariableDeclarationFragment> fragments = node.fragments();
    for (VariableDeclarationFragment fragment : fragments) {
        int beginLine = cu.getLineNumber(fragment.getStartPosition());
        int endLine = cu.getLineNumber(fragment.getStartPosition() + fragment.getLength());
        int beginColumn = cu.getColumnNumber(node.getStartPosition());
        int endColumn = cu.getColumnNumber(node.getStartPosition() + node.getLength());

        SimpleName name = fragment.getName();

        if (name != null) {
            endLine = cu.getLineNumber(name.getStartPosition() + name.getLength());
            endColumn = cu.getColumnNumber(name.getStartPosition() + name.getLength());
        }// w w  w  .  j  a v  a  2 s.c om

        languageConstructs.add(new LanguageConstruct(node.getClass().getSimpleName(), beginLine, endLine,
                beginColumn, endColumn, fragment.getName().getIdentifier()));
    }

    return true;
}

From source file:br.uff.ic.mergeguider.javaparser.DepVisitor.java

@Override
public boolean visit(VariableDeclarationExpression node) {

    Location location;//from ww  w .  j ava2 s. com

    List<VariableDeclarationFragment> fragments = node.fragments();

    for (VariableDeclarationFragment fragment : fragments) {

        int elementLineBegin = cu.getLineNumber(fragment.getStartPosition());
        int elementLineEnd = cu.getLineNumber(fragment.getStartPosition() + node.getLength());
        int elementColumnBegin = cu.getColumnNumber(fragment.getStartPosition());
        int elementColumnEnd = cu.getColumnNumber(fragment.getStartPosition() + node.getLength());

        location = new Location(elementLineBegin, elementLineEnd, elementColumnBegin, elementColumnEnd);

        MyVariableDeclaration myVariableDeclaration = new MyVariableDeclaration(fragment, location);

        if (!classLanguageConstructsList.isEmpty()) {
            classLanguageConstructsList.get(classLanguageConstructsList.size() - 1).getVariableDeclarations()
                    .add(myVariableDeclaration);
        }

    }

    return true;

}

From source file:cc.kave.eclipse.namefactory.NodeFactory.java

License:Apache License

private static Name createVariableName(ASTNode node) {
    StringBuilder sb = new StringBuilder();

    switch (node.getNodeType()) {

    case ASTNode.FIELD_DECLARATION:
        FieldDeclaration fieldNode = (FieldDeclaration) node;

        Object field = fieldNode.fragments().get(0);
        if (field instanceof VariableDeclarationFragment) {
            sb.append(modifierHelper(((VariableDeclarationFragment) field).resolveBinding()));
            sb.append("[");
            sb.append(BindingFactory//from  w  ww. j  a v a2 s  .  c  o m
                    .getBindingName(((VariableDeclarationFragment) field).resolveBinding().getType()));
            sb.append("] [");
            sb.append(getDeclaringType(fieldNode));
            sb.append("].");
            sb.append(((VariableDeclarationFragment) field).getName().getIdentifier());

            return CsFieldName.newFieldName(sb.toString());
        }
        break;

    case ASTNode.VARIABLE_DECLARATION_STATEMENT:
        VariableDeclarationStatement variableStatementNode = (VariableDeclarationStatement) node;

        Object variableStatement = variableStatementNode.fragments().get(0);
        if (variableStatement instanceof VariableDeclarationFragment) {
            sb.append("[");
            sb.append(BindingFactory.getBindingName(
                    ((VariableDeclarationFragment) variableStatement).resolveBinding().getType()));
            sb.append("] ");
            sb.append(((VariableDeclarationFragment) variableStatement).getName().getIdentifier());
            return CsLocalVariableName.newLocalVariableName(sb.toString());
        }
        break;

    case ASTNode.VARIABLE_DECLARATION_EXPRESSION:
        VariableDeclarationExpression variableExpressionNode = (VariableDeclarationExpression) node;

        Object variableExpression = variableExpressionNode.fragments().get(0);
        if (variableExpression instanceof VariableDeclarationFragment) {
            sb.append("[");
            sb.append(BindingFactory.getBindingName(
                    ((VariableDeclarationFragment) variableExpression).resolveBinding().getType()));
            sb.append("] ");
            sb.append(((VariableDeclarationFragment) variableExpression).getName().getIdentifier());
            return CsLocalVariableName.newLocalVariableName(sb.toString());
        }
        break;
    }
    throw new RuntimeException("should not happen");
}

From source file:chibi.gumtreediff.gen.jdt.cd.CdJdtVisitor.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*  w  ww  . j a  v  a 2s . com*/
public boolean visit(VariableDeclarationExpression node) {
    pushNode(node, "");
    visitListAsNode(EntityType.MODIFIERS, node.modifiers());
    node.getType().accept(this);
    visitListAsNode(EntityType.FRAGMENTS, node.fragments());
    return false;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(VariableDeclarationExpression node) {
    if (node.getAST().apiLevel() >= AST.JLS3) {
        printModifiers(node.modifiers());
    }/*  ww w  .j  ava2 s  . co m*/
    node.getType().accept(this);
    this.buffer.append(" ");//$NON-NLS-1$
    for (Iterator it = node.fragments().iterator(); it.hasNext();) {
        VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
        f.accept(this);
        if (it.hasNext()) {
            this.buffer.append(", ");//$NON-NLS-1$
        }
    }
    return false;
}

From source file:com.bsiag.eclipse.jdt.java.formatter.SpacePreparator.java

License:Open Source License

@Override
public boolean visit(VariableDeclarationExpression node) {
    ASTNode parent = node.getParent();/* w  ww  .j  av  a  2s  . c o  m*/
    if (parent instanceof ForStatement) {
        handleCommas(node.fragments(), this.options.insert_space_before_comma_in_for_inits,
                this.options.insert_space_after_comma_in_for_inits);
    } else if (parent instanceof ExpressionStatement) {
        handleCommas(node.fragments(), this.options.insert_space_before_comma_in_multiple_local_declarations,
                this.options.insert_space_after_comma_in_multiple_local_declarations);
    }
    this.tm.firstTokenAfter(node.getType(), -1).spaceBefore();
    return true;
}

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

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.ForStatement node) {
    Expression condition = translateExpression(node.getExpression());
    List<Expression> updaters = translateExpressionList(node.updaters());
    Statement body = (Statement) translate(node.getBody());
    Object javaInitializer = !node.initializers().isEmpty() ? node.initializers().get(0) : null;
    if (javaInitializer instanceof org.eclipse.jdt.core.dom.VariableDeclarationExpression) {
        org.eclipse.jdt.core.dom.VariableDeclarationExpression javaVDE = (org.eclipse.jdt.core.dom.VariableDeclarationExpression) javaInitializer;
        List<VariableDeclaration> variables = Lists.newArrayList();
        for (Iterator<?> I = javaVDE.fragments().iterator(); I.hasNext();) {
            org.eclipse.jdt.core.dom.VariableDeclarationFragment fragment = (org.eclipse.jdt.core.dom.VariableDeclarationFragment) I
                    .next();//ww  w  .j a  v  a2  s. co  m
            variables.add((VariableDeclaration) translate(fragment));
        }
        VariableDeclarationList variableList = variableDeclarationList(null,
                (TypeName) translate(javaVDE.getType()), variables);
        return done(forStatement(variableList, condition, updaters, body));
    } else {
        Expression initializer = translate((org.eclipse.jdt.core.dom.ASTNode) javaInitializer);
        return done(forStatement(initializer, condition, updaters, body));
    }
}

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

License:Open Source License

@Override
public boolean visit(VariableDeclarationExpression node) {
    buffer.append(NameTable.javaRefToCpp(node.getType()));
    buffer.append(" ");
    for (Iterator<?> it = node.fragments().iterator(); it.hasNext();) {
        VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
        f.accept(this);
        if (it.hasNext()) {
            buffer.append(", ");
        }/* w w w .  j  a  v  a  2s  .  c  o  m*/
    }
    return false;
}