Example usage for org.eclipse.jdt.core.dom VariableDeclarationFragment extraDimensions

List of usage examples for org.eclipse.jdt.core.dom VariableDeclarationFragment extraDimensions

Introduction

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

Prototype

public List extraDimensions() 

Source Link

Document

Returns the live ordered list of extra dimensions with optional annotations (added in JLS8 API).

Usage

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

License:Open Source License

@Override
public boolean visit(VariableDeclarationFragment node) {
    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);
        }//from w ww.  j a v a2  s . c  o m
    } 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:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/** Visitor method for {@link VariableDeclarationFragment}s. */
@Override//from ww w .  jav  a  2s .  c o  m
public boolean visit(VariableDeclarationFragment node) {
    sync(node);
    // TODO(jdd): Why no open-close?
    visit(node.getName());
    extraDimensions(plusFour, node.extraDimensions());
    if (node.getInitializer() != null) {
        builder.space();
        token("=");
        builder.breakToFill(" ");
        // TODO(jdd): Why this way.
        builder.open(ZERO);
        node.getInitializer().accept(this);
        builder.close();
    }
    return false;
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/**
 * Declare multiple variables or variable-like things.
 * @param annotationsDirection {@link Direction#VERTICAL} or {@link Direction#HORIZONTAL}
 * @param modifiers the {@link IExtendedModifier}s, including annotations
 * @param type the {@link Type}s/*from  www .  j a v  a  2 s . com*/
 * @param fragments the {@link VariableDeclarationFragment}s
 */
private void declareMany(Direction annotationsDirection, List<IExtendedModifier> modifiers, Type type,
        List<VariableDeclarationFragment> fragments) {
    builder.open(ZERO);
    visitAndBreakModifiers(modifiers, annotationsDirection, Optional.<BreakTag>absent());
    builder.open(plusFour);
    type.accept(this);
    // TODO(jdd): Open another time?
    boolean first = true;
    for (VariableDeclarationFragment fragment : fragments) {
        if (!first) {
            token(",");
        }
        builder.breakOp(" ");
        builder.open(ZERO);
        visit(fragment.getName());
        Expression initializer = fragment.getInitializer();
        extraDimensions(initializer != null ? plusEight : plusFour, fragment.extraDimensions());
        if (initializer != null) {
            builder.space();
            token("=");
            if (initializer.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
                // TODO(jdd): Check on this.
                builder.close();
                builder.open(ZERO);
                builder.space();
                initializer.accept(this);
            } else {
                builder.open(plusFour);
                builder.breakOp(" ");
                initializer.accept(this);
                builder.close();
            }
        }
        builder.close();
        first = false;
    }
    builder.close();
    token(";");
    builder.close();
}

From source file:com.google.googlejavaformat.java.JavaInputAstVisitor.java

License:Apache License

/**
 * Add a declaration.//from w w w .  ja  v a2 s  . c  o m
 * @param modifiers the {@link IExtendedModifier}s, including annotations
 * @param type the {@link Type}s
 * @param fragments the {@link VariableDeclarationFragment}s
 * @param annotationsDirection {@link Direction#VERTICAL} or {@link Direction#HORIZONTAL}
 */
void addDeclaration(ASTNode node, List<IExtendedModifier> modifiers, Type type,
        List<VariableDeclarationFragment> fragments, Direction annotationsDirection) {
    if (fragments.size() == 1) {
        VariableDeclarationFragment fragment = fragments.get(0);
        declareOne(node, annotationsDirection, modifiers, type, VarArgsOrNot.NO, ImmutableList.<Annotation>of(),
                fragment.getName(), "", fragment.extraDimensions(), "=",
                Optional.fromNullable(fragment.getInitializer()), Optional.of(";"), ReceiverParameter.NO);
    } else {
        declareMany(annotationsDirection, modifiers, type, fragments);
    }
}

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

License:Open Source License

public boolean visit(VariableDeclarationFragment node) {
    node.getName().accept(this);
    int size = node.getExtraDimensions();
    if (node.getAST().apiLevel() >= AST.JLS8) {
        List dimensions = node.extraDimensions();
        for (int i = 0; i < size; i++) {
            visit((Dimension) dimensions.get(i));
        }//www  .j  av a  2  s .c o m
    } else {
        for (int i = 0; i < size; 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:parser.AnnotationType.java

License:Open Source License

public boolean visit(VariableDeclarationFragment node) {
    node.getName().accept(this);
    this.buffer.append(AnnotationType.Variable);
    int size = node.getExtraDimensions();
    if (node.getAST().apiLevel() >= AST.JLS8) {
        List dimensions = node.extraDimensions();
        for (int i = 0; i < size; i++) {
            visit((Dimension) dimensions.get(i));
        }//from  ww w .  j  a v a2  s .  c  o m
    } else {
        for (int i = 0; i < size; i++) {
            this.buffer.append("[]");//$NON-NLS-1$
        }
    }
    if (node.getInitializer() != null) {
        this.buffer.append(" = ");//$NON-NLS-1$
        node.getInitializer().accept(this);
    }
    return false;
}