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

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

Introduction

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

Prototype

public final AST getAST() 

Source Link

Document

Returns this node's AST.

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());
    }/*from   w w w  .  j ava  2 s  . c o m*/
    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:ch.acanda.eclipse.pmd.java.resolution.optimization.LocalVariableCouldBeFinalQuickFix.java

License:Open Source License

/**
 * Adds the final modifier to the variable declaration.
 *///  w  w  w . j  a v  a  2 s. c o  m
@Override
@SuppressWarnings("unchecked")
protected boolean apply(final VariableDeclarationStatement 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(VariableDeclarationStatement node) {
    printIndent();/*  w  w  w. j av a 2s .c  o  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:lang.java.jdt.internal.JdtAstToRascalAstConverter.java

License:Open Source License

public boolean visit(VariableDeclarationStatement node) {
    java.util.Map.Entry<IValueList, IValueList> extendedModifiers;
    if (node.getAST().apiLevel() == AST.JLS2) {
        extendedModifiers = new java.util.AbstractMap.SimpleEntry<IValueList, IValueList>(
                parseModifiers(node.getModifiers()), new IValueList(values));
    } else {//from  www .j  a v a 2 s  .  c om
        extendedModifiers = parseExtendedModifiers(node.modifiers());
    }

    IValue type = visitChild(node.getType());

    IValueList fragments = new IValueList(values);
    for (Iterator it = node.fragments().iterator(); it.hasNext();) {
        VariableDeclarationFragment f = (VariableDeclarationFragment) it.next();
        fragments.add(visitChild(f));
    }

    ownValue = constructRascalNode(node, extendedModifiers.getKey().asList(),
            extendedModifiers.getValue().asList(), type, fragments.asList());
    return false;
}

From source file:lombok.eclipse.agent.PatchValEclipse.java

License:Open Source License

public static void addFinalAndValAnnotationToVariableDeclarationStatement(Object converter,
        VariableDeclarationStatement out, LocalDeclaration in) {
    @SuppressWarnings("unchecked")
    List<IExtendedModifier> modifiers = out.modifiers();
    addFinalAndValAnnotationToModifierList(converter, modifiers, out.getAST(), in);
}

From source file:net.sf.eclipsecs.ui.quickfixes.misc.ArrayTypeStyleQuickfix.java

License:Open Source License

/**
 * {@inheritDoc}//from  w  w  w .j a va2s. c  o m
 */
protected ASTVisitor handleGetCorrectingASTVisitor(final IRegion lineInfo, final int markerStartOffset) {

    return new ASTVisitor() {

        public boolean visit(VariableDeclarationStatement node) {

            if (containsPosition(node, markerStartOffset)) {

                if (isCStyle(node.fragments())) {

                    int dimensions = 0;

                    List fragments = node.fragments();
                    for (int i = 0, size = fragments.size(); i < size; i++) {
                        VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
                        if (decl.getExtraDimensions() > dimensions) {
                            dimensions = decl.getExtraDimensions();

                        }
                        decl.setExtraDimensions(0);
                    }

                    // wrap current type into ArrayType
                    ArrayType arrayType = createArrayType(node.getType(), dimensions);
                    node.setType(arrayType);

                } else if (isJavaStyle(node.getType())) {

                    int dimensions = ((ArrayType) node.getType()).getDimensions();

                    List fragments = node.fragments();
                    for (int i = 0, size = fragments.size(); i < size; i++) {
                        VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
                        decl.setExtraDimensions(dimensions);
                    }

                    Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
                            ((ArrayType) node.getType()).getElementType());
                    node.setType(elementType);
                }
            }
            return true;
        }

        public boolean visit(SingleVariableDeclaration node) {

            if (containsPosition(node, markerStartOffset)) {
                if (isCStyle(node)) {
                    // wrap the existing type into an array type
                    node.setType(createArrayType(node.getType(), node.getExtraDimensions()));
                    node.setExtraDimensions(0);
                } else if (isJavaStyle(node.getType())) {

                    ArrayType arrayType = (ArrayType) node.getType();
                    Type elementType = (Type) ASTNode.copySubtree(node.getAST(), arrayType.getElementType());

                    node.setType(elementType);
                    node.setExtraDimensions(arrayType.getDimensions());
                }
            }

            return true;
        }

        public boolean visit(FieldDeclaration node) {

            if (containsPosition(node, markerStartOffset)) {

                if (isCStyle(node.fragments())) {

                    int dimensions = 0;

                    List fragments = node.fragments();
                    for (int i = 0, size = fragments.size(); i < size; i++) {
                        VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
                        if (decl.getExtraDimensions() > dimensions) {
                            dimensions = decl.getExtraDimensions();

                        }
                        decl.setExtraDimensions(0);
                    }

                    // wrap current type into ArrayType
                    ArrayType arrayType = createArrayType(node.getType(), dimensions);
                    node.setType(arrayType);
                } else if (isJavaStyle(node.getType())) {

                    int dimensions = ((ArrayType) node.getType()).getDimensions();

                    List fragments = node.fragments();
                    for (int i = 0, size = fragments.size(); i < size; i++) {
                        VariableDeclaration decl = (VariableDeclaration) fragments.get(i);
                        decl.setExtraDimensions(dimensions);
                    }

                    Type elementType = (Type) ASTNode.copySubtree(node.getAST(),
                            ((ArrayType) node.getType()).getElementType());
                    node.setType(elementType);
                }
            }
            return true;
        }

        private boolean isJavaStyle(Type type) {
            return type instanceof ArrayType;
        }

        private boolean isCStyle(VariableDeclaration decl) {
            return decl.getExtraDimensions() > 0;
        }

        private boolean isCStyle(List fragments) {

            Iterator it = fragments.iterator();
            while (it.hasNext()) {
                VariableDeclaration decl = (VariableDeclaration) it.next();
                if (isCStyle(decl)) {
                    return true;
                }
            }
            return false;
        }

        private ArrayType createArrayType(Type componentType, int dimensions) {
            Type type = (Type) ASTNode.copySubtree(componentType.getAST(), componentType);
            ArrayType arrayType = componentType.getAST().newArrayType(type, dimensions);

            return arrayType;
        }
    };
}

From source file:org.codemucker.jmutate.ast.JAstFlattener.java

License:Open Source License

public boolean visit(VariableDeclarationStatement node) {
    printIndent();/*from ww w  .j  a  v  a 2 s  .c  o  m*/
    if (node.getAST().apiLevel() == JLS2) {
        printModifiers(node.getModifiers());
    }
    if (node.getAST().apiLevel() >= 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:parser.AnnotationType.java

License:Open Source License

public boolean visit(VariableDeclarationStatement node) {
    printIndent();//  ww  w. j av  a 2  s .c  om
    if (node.getAST().apiLevel() == JLS2) {
        printModifiers(node.getModifiers());
    }
    if (node.getAST().apiLevel() >= JLS3) {
        printModifiers(node.modifiers());
    }
    node.getType().accept(this);
    this.buffer.append(AnnotationType.Type);
    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:refactorer.Refactorer.java

License:Apache License

@SuppressWarnings("unchecked")
protected void processVariableDeclarationStatement(VariableDeclarationStatement variableDeclarationStatement) {
    ITypeBinding binding = variableDeclarationStatement.getType().resolveBinding();

    for (VariableDeclarationFragment fragment : (List<VariableDeclarationFragment>) variableDeclarationStatement
            .fragments()) {//from  w ww. j a v a  2 s.  c  o m
        processExpression(fragment.getInitializer());

        if (binding != null) {
            variables.add(binding, fragment.getName().getFullyQualifiedName());
        }
    }

    if (binding != null) {
        String typeName = binding.getQualifiedName();
        if ("javax.media.opengl.GL".equals(typeName)) {
            AST ast = variableDeclarationStatement.getAST();
            Name name = ast.newName("GL2");
            Type type = ast.newSimpleType(name);
            variableDeclarationStatement.setType(type);
            addImportIfRequired("javax.media.opengl.GL2");
        } else if ("javax.media.opengl.GLCanvas".equals(typeName)) {
            addImportIfRequired("javax.media.opengl.awt.GLCanvas");
        }
    }
}