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

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

Introduction

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

Prototype

public final void delete() 

Source Link

Document

Removes this node from its parent.

Usage

From source file:ch.acanda.eclipse.pmd.java.resolution.design.SingularFieldQuickFix.java

License:Open Source License

/**
 * Updates the field declaration. If the replaced field was the only fragment, the entire field declaration is
 * removed. Otherwise the field declaration stays and only the respective fragment is removed.
 *///from   w ww . j  a  v  a2  s  .co  m
private void updateFieldDeclaration(final VariableDeclarationFragment node) {
    final FieldDeclaration fieldDeclaration = (FieldDeclaration) node.getParent();
    @SuppressWarnings("unchecked")
    final List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
    if (fragments.size() > 1) {
        for (final VariableDeclarationFragment fragment : fragments) {
            if (fragment.getName().getIdentifier().equals(node.getName().getIdentifier())) {
                fragment.delete();
            }
        }
    } else {
        fieldDeclaration.delete();
    }
}

From source file:org.jboss.forge.roaster.model.impl.statements.ForStatementImpl.java

License:Open Source License

@Override
public org.eclipse.jdt.core.dom.ForStatement materialize(AST ast) {
    if (iter != null) {
        return iter;
    }/*w ww  .ja v  a2s .  co m*/

    iter = ast.newForStatement();

    for (DeclareExpression declaration : declarations) {
        VariableDeclarationExpression declare = (VariableDeclarationExpression) wireAndGetExpression(
                declaration, this, ast);
        if (iter.initializers().isEmpty()) {
            iter.initializers().add(declare);
        } else {
            VariableDeclarationExpression existing = (VariableDeclarationExpression) iter.initializers().get(0);
            VariableDeclarationFragment frag = (VariableDeclarationFragment) declare.fragments().get(0);
            frag.delete();
            existing.fragments().add(frag);
        }
    }

    if (condition != null) {
        iter.setExpression(wireAndGetExpression(condition, this, ast));
    }

    for (ExpressionSource<O, ForStatement<O, P>, ?> updater : updaters) {
        iter.updaters().add(wireAndGetExpression(updater, this, ast));
    }

    if (body != null) {
        iter.setBody(wireAndGetStatement(body, this, ast));
    }

    return iter;
}