Search in sources :

Example 46 with FieldDeclaration

use of org.eclipse.jdt.core.dom.FieldDeclaration in project xtext-xtend by eclipse.

the class JavaASTFlattener method visit.

@Override
public boolean visit(final Initializer it) {
    Javadoc _javadoc = it.getJavadoc();
    boolean _tripleNotEquals = (_javadoc != null);
    if (_tripleNotEquals) {
        it.getJavadoc().accept(this);
    }
    this.appendModifiers(it, it.modifiers());
    boolean _isStatic = this._aSTFlattenerUtils.isStatic(it.modifiers());
    if (_isStatic) {
        if (((it.getParent() instanceof TypeDeclaration) && IterableExtensions.<FieldDeclaration>forall(IterableExtensions.<FieldDeclaration>filter(((Iterable<FieldDeclaration>) Conversions.doWrapArray(((TypeDeclaration) it.getParent()).getFields())), ((Function1<FieldDeclaration, Boolean>) (FieldDeclaration it_1) -> {
            return Boolean.valueOf((this._aSTFlattenerUtils.isStatic(it_1.modifiers()) && this._aSTFlattenerUtils.isFinal(it_1.modifiers())));
        })), ((Function1<FieldDeclaration, Boolean>) (FieldDeclaration f) -> {
            final Function1<VariableDeclarationFragment, Boolean> _function = (VariableDeclarationFragment fragment) -> {
                Boolean _isAssignedInBody = this._aSTFlattenerUtils.isAssignedInBody(it.getBody(), fragment);
                return Boolean.valueOf((!(_isAssignedInBody).booleanValue()));
            };
            return Boolean.valueOf(IterableExtensions.<VariableDeclarationFragment>forall(f.fragments(), _function));
        })))) {
            this.appendToBuffer(" final Void static_initializer = {");
            this.appendLineWrapToBuffer();
            it.getBody().accept(this);
            this.appendToBuffer("null }");
            this.appendLineWrapToBuffer();
        } else {
            this.addProblem(it, "Static initializer is not fully supported");
            this.appendToBuffer("{/*FIXME ");
            it.getBody().accept(this);
            this.appendToBuffer("*/}");
        }
    } else {
        ASTNode _parent = it.getParent();
        if ((_parent instanceof AnonymousClassDeclaration)) {
            StringConcatenation _builder = new StringConcatenation();
            _builder.append("Initializer is not supported in ");
            String _simpleName = ASTNode.nodeClassForType(it.getParent().getNodeType()).getSimpleName();
            _builder.append(_simpleName);
            this.addProblem(it, _builder.toString());
        }
        it.getBody().accept(this);
    }
    return false;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) Function1(org.eclipse.xtext.xbase.lib.Functions.Function1) ASTNode(org.eclipse.jdt.core.dom.ASTNode) AnonymousClassDeclaration(org.eclipse.jdt.core.dom.AnonymousClassDeclaration) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Javadoc(org.eclipse.jdt.core.dom.Javadoc) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) AnnotationTypeDeclaration(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 47 with FieldDeclaration

use of org.eclipse.jdt.core.dom.FieldDeclaration in project AutoRefactor by JnRouvignac.

the class ASTBuilder method declareField.

/**
 * Builds a new {@link FieldDeclaration} instance.
 *
 * @param type
 *            the declared variable type
 * @param fragment
 *            the variable declaration fragment
 * @return a new field declaration
 */
public FieldDeclaration declareField(Type type, VariableDeclarationFragment fragment) {
    final FieldDeclaration fd = ast.newFieldDeclaration(fragment);
    fd.setType(type);
    return fd;
}
Also used : FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Example 48 with FieldDeclaration

use of org.eclipse.jdt.core.dom.FieldDeclaration in project eclipse-pmd by acanda.

the class SingularFieldQuickFix method updateFieldDeclaration.

/**
 * 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.
 */
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();
    }
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) FieldDeclaration(org.eclipse.jdt.core.dom.FieldDeclaration)

Aggregations

FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)48 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)28 ASTNode (org.eclipse.jdt.core.dom.ASTNode)26 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)18 AST (org.eclipse.jdt.core.dom.AST)15 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)15 BodyDeclaration (org.eclipse.jdt.core.dom.BodyDeclaration)13 Type (org.eclipse.jdt.core.dom.Type)13 TypeDeclaration (org.eclipse.jdt.core.dom.TypeDeclaration)11 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)11 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)10 VariableDeclarationExpression (org.eclipse.jdt.core.dom.VariableDeclarationExpression)9 Expression (org.eclipse.jdt.core.dom.Expression)8 SingleVariableDeclaration (org.eclipse.jdt.core.dom.SingleVariableDeclaration)8 Block (org.eclipse.jdt.core.dom.Block)7 Initializer (org.eclipse.jdt.core.dom.Initializer)7 Javadoc (org.eclipse.jdt.core.dom.Javadoc)7 SimpleName (org.eclipse.jdt.core.dom.SimpleName)7 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)7 ArrayList (java.util.ArrayList)6