Search in sources :

Example 41 with Modifier

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

the class ObsoleteRedundantModifiersCleanUp method maybeRemovePublicStaticFinalModifiers.

private boolean maybeRemovePublicStaticFinalModifiers(final FieldDeclaration visited) {
    // Remove modifiers implied by the context
    boolean result = true;
    List<IExtendedModifier> modifiers = visited.modifiers();
    for (Modifier modifier : getModifiersOnly(modifiers)) {
        if (modifier.isPublic() || modifier.isStatic() || modifier.isFinal()) {
            TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
            ASTRewrite rewrite = cuRewrite.getASTRewrite();
            rewrite.remove(modifier, group);
            result = false;
        }
    }
    return result;
}
Also used : ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) Modifier(org.eclipse.jdt.core.dom.Modifier) TextEditGroup(org.eclipse.text.edits.TextEditGroup) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 42 with Modifier

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

the class ObsoleteRedundantModifiersCleanUp method removeStaticAbstractModifier.

private boolean removeStaticAbstractModifier(final List<IExtendedModifier> modifiers) {
    boolean result = true;
    for (Modifier modifier : getModifiersOnly(modifiers)) {
        if (modifier.isStatic() || modifier.isAbstract()) {
            TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
            ASTRewrite rewrite = cuRewrite.getASTRewrite();
            rewrite.remove(modifier, group);
            result = false;
        }
    }
    return result;
}
Also used : ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) Modifier(org.eclipse.jdt.core.dom.Modifier) TextEditGroup(org.eclipse.text.edits.TextEditGroup)

Example 43 with Modifier

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

the class ObsoleteRedundantModifiersCleanUp method reorderModifiers.

private void reorderModifiers(final List<IExtendedModifier> reorderedModifiers) {
    ASTRewrite rewrite = cuRewrite.getASTRewrite();
    TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
    for (int i = 0; i < reorderedModifiers.size(); i++) {
        IExtendedModifier extendedModifier = reorderedModifiers.get(i);
        if (extendedModifier.isModifier()) {
            rewrite.moveToIndex((Modifier) extendedModifier, i, ASTNodes.createMoveTarget(rewrite, (Modifier) extendedModifier), group);
        } else {
            rewrite.moveToIndex((Annotation) extendedModifier, i, ASTNodes.createMoveTarget(rewrite, (Annotation) extendedModifier), group);
        }
    }
}
Also used : ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) Modifier(org.eclipse.jdt.core.dom.Modifier) Annotation(org.eclipse.jdt.core.dom.Annotation) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 44 with Modifier

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

the class ObsoleteRedundantModifiersCleanUp method removePublicAbstractModifiers.

private boolean removePublicAbstractModifiers(final BodyDeclaration visited) {
    List<IExtendedModifier> modifiers = visited.modifiers();
    boolean result = true;
    for (Modifier modifier : getModifiersOnly(modifiers)) {
        if (modifier.isPublic() || modifier.isAbstract()) {
            TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
            ASTRewrite rewrite = cuRewrite.getASTRewrite();
            rewrite.remove(modifier, group);
            result = false;
        }
    }
    return result;
}
Also used : ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) Modifier(org.eclipse.jdt.core.dom.Modifier) TextEditGroup(org.eclipse.text.edits.TextEditGroup) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 45 with Modifier

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

the class JavaASTFlattener method visit.

@Override
public boolean visit(final FieldDeclaration it) {
    Javadoc _javadoc = it.getJavadoc();
    boolean _tripleNotEquals = (_javadoc != null);
    if (_tripleNotEquals) {
        it.getJavadoc().accept(this);
    }
    final Consumer<VariableDeclarationFragment> _function = (VariableDeclarationFragment frag) -> {
        this.appendModifiers(it, it.modifiers());
        boolean _isPackageVisibility = this._aSTFlattenerUtils.isPackageVisibility(Iterables.<Modifier>filter(it.modifiers(), Modifier.class));
        if (_isPackageVisibility) {
            ASTNode _parent = it.getParent();
            if ((_parent instanceof TypeDeclaration)) {
                ASTNode _parent_1 = it.getParent();
                boolean _isInterface = ((TypeDeclaration) _parent_1).isInterface();
                boolean _not = (!_isInterface);
                if (_not) {
                    this.appendToBuffer("package ");
                }
            }
        }
        it.getType().accept(this);
        this.appendExtraDimensions(frag.getExtraDimensions());
        this.appendSpaceToBuffer();
        frag.accept(this);
    };
    it.fragments().forEach(_function);
    return false;
}
Also used : VariableDeclarationFragment(org.eclipse.jdt.core.dom.VariableDeclarationFragment) ASTNode(org.eclipse.jdt.core.dom.ASTNode) Javadoc(org.eclipse.jdt.core.dom.Javadoc) Modifier(org.eclipse.jdt.core.dom.Modifier) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) TypeDeclaration(org.eclipse.jdt.core.dom.TypeDeclaration) AbstractTypeDeclaration(org.eclipse.jdt.core.dom.AbstractTypeDeclaration) AnnotationTypeDeclaration(org.eclipse.jdt.core.dom.AnnotationTypeDeclaration)

Aggregations

Modifier (org.eclipse.jdt.core.dom.Modifier)49 IExtendedModifier (org.eclipse.jdt.core.dom.IExtendedModifier)39 ASTNode (org.eclipse.jdt.core.dom.ASTNode)16 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)12 ASTRewrite (org.autorefactor.jdt.core.dom.ASTRewrite)11 TextEditGroup (org.eclipse.text.edits.TextEditGroup)11 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)9 AST (org.eclipse.jdt.core.dom.AST)7 ArrayList (java.util.ArrayList)6 Block (org.eclipse.jdt.core.dom.Block)6 ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)6 SimpleType (org.eclipse.jdt.core.dom.SimpleType)6 Type (org.eclipse.jdt.core.dom.Type)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)5 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)5 Expression (org.eclipse.jdt.core.dom.Expression)5 SimpleName (org.eclipse.jdt.core.dom.SimpleName)5 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)5 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)5 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)4