Example usage for org.eclipse.jdt.core.dom FieldDeclaration setJavadoc

List of usage examples for org.eclipse.jdt.core.dom FieldDeclaration setJavadoc

Introduction

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

Prototype

public void setJavadoc(Javadoc docComment) 

Source Link

Document

Sets or clears the doc comment node.

Usage

From source file:org.autorefactor.refactoring.rules.SingleDeclarationsRatherThanMultiDeclarationRefactoring.java

License:Open Source License

@SuppressWarnings("rawtypes")
private void refactorMultiDeclaration(final ASTNode node, final List modifiers, final Type type,
        final List fragments, final Javadoc docComment) {
    final ASTBuilder b = this.ctx.getASTBuilder();

    for (int i = fragments.size() - 1; 0 <= i; i--) {
        final VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(i);

        final SimpleName copyOfFragment = b.copy(fragment.getName());
        final Type copyOfType = b.copy(type);
        final Expression copyOfInitializer;
        if (fragment.getInitializer() != null) {
            copyOfInitializer = b.copy(fragment.getInitializer());
        } else {/*from  w w  w .  ja va 2  s  .  c om*/
            copyOfInitializer = null;
        }

        final VariableDeclarationFragment newFragment = b.declareFragment(copyOfFragment, copyOfInitializer);
        final ASTNode newNode;
        if (node instanceof VariableDeclarationStatement) {
            final VariableDeclarationStatement newStmt = b.declareStmt(copyOfType, newFragment);
            updateModifiers(b, modifiers, newStmt.modifiers());
            newNode = newStmt;
        } else {
            final FieldDeclaration newField = b.declareField(copyOfType, newFragment);
            if (docComment != null) {
                newField.setJavadoc(b.copy(docComment));
            }
            updateModifiers(b, modifiers, newField.modifiers());
            newNode = newField;
        }

        if (i > 0) {
            ctx.getRefactorings().insertAfter(newNode, node);
        } else {
            ctx.getRefactorings().replace(node, newNode);
        }
    }
}

From source file:org.whole.lang.java.util.JDTTransformerVisitor.java

License:Open Source License

public boolean visit(FieldDeclaration node) {
    org.whole.lang.java.model.FieldDeclaration fieldDecl = lf.create(JavaEntityDescriptorEnum.FieldDeclaration);
    appendBodyDeclaration(fieldDecl);//w  ww .  jav  a2s.  c  om

    if (acceptChild(node.getJavadoc()))
        fieldDecl.setJavadoc(this.javadoc);

    acceptChild(node.getType());
    fieldDecl.setType(type);

    List<?> modifiers = node.modifiers();
    if (!modifiers.isEmpty()) {
        fieldDecl.setModifiers(lf.create(JavaEntityDescriptorEnum.ExtendedModifiers));
        setExtendedModifiers(fieldDecl.getModifiers(), modifiers);
    }

    Iterator<?> i = node.fragments().iterator();
    while (i.hasNext()) {
        ((ASTNode) i.next()).accept(this);
        fieldDecl.getFragments().wAdd(varFrag);
    }

    return false;
}