Search in sources :

Example 41 with IExtendedModifier

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

the class ObsoleteRedundantModifiersCleanUp method removePrivateModifier.

private boolean removePrivateModifier(final BodyDeclaration visited) {
    List<IExtendedModifier> modifiers = visited.modifiers();
    for (Modifier modifier : getModifiersOnly(modifiers)) {
        if (modifier.isPrivate()) {
            TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteRedundantModifiersCleanUp_description);
            ASTRewrite rewrite = cuRewrite.getASTRewrite();
            rewrite.remove(modifier, group);
            return false;
        }
    }
    return true;
}
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 IExtendedModifier

use of org.eclipse.jdt.core.dom.IExtendedModifier 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 43 with IExtendedModifier

use of org.eclipse.jdt.core.dom.IExtendedModifier 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 44 with IExtendedModifier

use of org.eclipse.jdt.core.dom.IExtendedModifier 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 45 with IExtendedModifier

use of org.eclipse.jdt.core.dom.IExtendedModifier 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)

Aggregations

IExtendedModifier (org.eclipse.jdt.core.dom.IExtendedModifier)46 Modifier (org.eclipse.jdt.core.dom.Modifier)27 ASTNode (org.eclipse.jdt.core.dom.ASTNode)15 Annotation (org.eclipse.jdt.core.dom.Annotation)14 ASTRewrite (org.autorefactor.jdt.core.dom.ASTRewrite)11 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)11 TextEditGroup (org.eclipse.text.edits.TextEditGroup)11 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)9 VariableDeclarationFragment (org.eclipse.jdt.core.dom.VariableDeclarationFragment)9 ArrayList (java.util.ArrayList)8 AST (org.eclipse.jdt.core.dom.AST)6 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)5 AbstractTypeDeclaration (org.eclipse.jdt.core.dom.AbstractTypeDeclaration)5 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)5 ModifierKeyword (org.eclipse.jdt.core.dom.Modifier.ModifierKeyword)5 Statement (org.eclipse.jdt.core.dom.Statement)5 Type (org.eclipse.jdt.core.dom.Type)5 VariableDeclarationStatement (org.eclipse.jdt.core.dom.VariableDeclarationStatement)5 Expression (org.eclipse.jdt.core.dom.Expression)4 SimpleName (org.eclipse.jdt.core.dom.SimpleName)4