Example usage for org.eclipse.jdt.core.dom VariableDeclarationStatement getType

List of usage examples for org.eclipse.jdt.core.dom VariableDeclarationStatement getType

Introduction

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

Prototype

public Type getType() 

Source Link

Document

Returns the base type declared in this variable declaration statement.

Usage

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

License:Open Source License

@Override
public boolean visit(VariableDeclarationStatement node) {
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
    }// w ww . j  a  v a 2 s.  com
    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$
        }
    }
    this.fBuffer.append(";");//$NON-NLS-1$
    return false;
}

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

License:Apache License

@Override
public boolean visit(VariableDeclarationStatement 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.EXPRESSION);
    boa.types.Ast.Expression.Builder eb = boa.types.Ast.Expression.newBuilder();
    //      eb.setPosition(pos.build());//FIXME
    eb.setKind(boa.types.Ast.Expression.ExpressionKind.VARDECL);
    for (Object o : node.fragments()) {
        VariableDeclarationFragment f = (VariableDeclarationFragment) o;
        Variable.Builder vb = Variable.newBuilder();
        //         vb.setPosition(pos.build());//FIXME
        vb.setName(f.getName().getFullyQualifiedName());
        for (Object m : node.modifiers()) {
            if (((IExtendedModifier) m).isAnnotation())
                ((Annotation) m).accept(this);
            else// w w  w . j  a v  a 2s .  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(node.getType());
        for (int i = 0; i < f.getExtraDimensions(); i++)
            name += "[]";
        tb.setName(getIndex(name));
        tb.setKind(boa.types.Ast.TypeKind.OTHER);
        vb.setVariableType(tb.build());
        if (f.getInitializer() != null) {
            f.getInitializer().accept(this);
            vb.setInitializer(expressions.pop());
        }
        eb.addVariableDecls(vb.build());
    }
    b.setExpression(eb.build());
    list.add(b.build());
    return false;
}

From source file:br.uff.ic.mergeguider.languageConstructs.MyVariableDeclaration.java

public ITypeBinding resolveTypeBinding() {

    Type type = null;//from www  . jav a2 s.  co m

    if (this.singleVariableDeclaration != null) {
        type = this.singleVariableDeclaration.getType();
    } else if (this.variableDeclaration != null) {
        ASTNode parent = this.variableDeclaration.getParent();

        if (parent instanceof VariableDeclarationStatement) {
            VariableDeclarationStatement variable = (VariableDeclarationStatement) parent;
            type = variable.getType();
        } else if (parent instanceof VariableDeclarationExpression) {
            VariableDeclarationExpression variable = (VariableDeclarationExpression) parent;
            type = variable.getType();
        }
    }

    if (type != null) {
        return type.resolveBinding();
    } else {
        return null;
    }
}

From source file:changetypes.ASTVisitorAtomicChange.java

License:Open Source License

public boolean visit(VariableDeclarationStatement vds) {
    if (this.mtbStack.isEmpty()) {
        return true;
    }/*from w w w. j  a  va2s . com*/
    for (Object ovdf : vds.fragments()) {
        VariableDeclarationFragment vdf = (VariableDeclarationFragment) ovdf;
        try {
            this.facts.add(Fact.makeLocalVarFact(getQualifiedName((IMethodBinding) this.mtbStack.peek()),
                    getQualifiedName(vds.getType().resolveBinding()), vdf.getName().getIdentifier(),
                    vdf.getInitializer().toString()));
        } catch (Exception localException) {
            System.err.println("Cannot resolve variable declaration \"" + vdf.getName().toString() + "\"");
        }
    }
    return true;
}

From source file:coloredide.utils.CopiedNaiveASTFlattener.java

License:Open Source License

public boolean visit(VariableDeclarationStatement node) {
    printIndent();/*w  ww .ja v  a  2s.co  m*/
    if (node.getAST().apiLevel() >= AST.JLS3) {
        printModifiers(node.modifiers());
    }
    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$
        }
    }
    this.buffer.append(";\n");//$NON-NLS-1$
    return false;
}

From source file:com.crispico.flower.mp.codesync.code.java.adapter.JavaAbstractAstNodeModelAdapter.java

License:Open Source License

/**
 * Creates a {@link Type} from the given name, owned by the given AST.
 *//*from  w  w  w  .  j a va  2 s .  co m*/
protected Type getTypeFromString(AST ast, String name) {
    if (name == null) {
        return ast.newPrimitiveType(PrimitiveType.VOID);
    }
    PrimitiveType.Code primitiveTypeCode = PrimitiveType.toCode(name);
    if (primitiveTypeCode != null) {
        return ast.newPrimitiveType(primitiveTypeCode);
    }

    ASTParser parser = ASTParser.newParser(AST.JLS4);
    parser.setKind(ASTParser.K_STATEMENTS);
    parser.setSource((name + " a;").toCharArray());

    Block block = (Block) parser.createAST(null);
    VariableDeclarationStatement declaration = (VariableDeclarationStatement) block.statements().get(0);
    return (Type) ASTNode.copySubtree(ast, declaration.getType());
}

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

License:Open Source License

/**
 * Creates a new appropriate {@link Type} from the given <code>value</code>.
 * <p>//from   ww w  .  j a va 2s.  c om
 * Note that if <code>value</code> is <code>null</code> returns
 * {@link PrimitiveType#VOID}.
 * 
 * @param ast
 *            {@link AST} of the {@link ASTNode ASTElement} needing a new
 *            Type
 * @param value
 *            the name of the {@link Type} to be created.
 * @param canBePrimitiveType
 *            if <code>true</code> try to create a primitive from the
 *            given <code>value</code> if possible, otherwise create a new
 *            Type without checking primitives
 * @author Luiza
 * 
 * @flowerModelElementId _zVs8hZiOEd6aNMdNFvR5WQ
 */
public static Type getJavaTypeFromString(AST ast, String value, boolean canBePrimitiveType) {
    if (canBePrimitiveType) {
        PrimitiveType.Code primitiveTypeCode = null;
        if (value == null)
            primitiveTypeCode = PrimitiveType.VOID;
        else {
            primitiveTypeCode = PrimitiveType.toCode(value);
        }
        if (primitiveTypeCode != null)
            return ast.newPrimitiveType(primitiveTypeCode);
    }

    // not a primitive
    ASTParser statementParser = ASTParser.newParser(AST.JLS3);
    statementParser.setKind(ASTParser.K_STATEMENTS);
    statementParser.setSource((value + " a;").toCharArray()); // try to parse a variable declaration

    Block block = (Block) statementParser.createAST(null);
    VariableDeclarationStatement declaration = (VariableDeclarationStatement) block.statements().get(0);
    return (Type) ASTNode.copySubtree(ast, declaration.getType()); // detach the type from the parent node
}

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

License:Open Source License

@Override
public boolean visit(org.eclipse.jdt.core.dom.VariableDeclarationStatement node) {
    return done(variableDeclarationStatement(
            translateVariableDeclarationList(false, node.getType(), node.fragments())));
}

From source file:com.google.devtools.j2cpp.types.ImplementationImportCollector.java

License:Open Source License

@Override
public boolean visit(VariableDeclarationStatement node) {
    addReference(node.getType());
    return super.visit(node);
}

From source file:com.google.devtools.j2objc.ast.DebugASTPrinter.java

License:Apache License

@Override
public boolean visit(VariableDeclarationStatement node) {
    sb.printIndent();/*from   ww  w  .  j a  va  2s  .  c o m*/
    printModifiers(node.getType().getTypeBinding().getModifiers());
    node.getType().accept(this);
    sb.print(' ');
    for (Iterator<VariableDeclarationFragment> it = node.getFragments().iterator(); it.hasNext();) {
        it.next().accept(this);
        if (it.hasNext()) {
            sb.print(", ");
        }
    }
    sb.println(';');
    return false;
}