Search in sources :

Example 46 with IExtendedModifier

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

the class ObsoleteStaticInnerClassThanNonStaticCleanUp method makeStatic.

private void makeStatic(final TypeDeclaration node) {
    ASTRewrite rewrite = cuRewrite.getASTRewrite();
    ASTNodeFactory ast = cuRewrite.getASTBuilder();
    TextEditGroup group = new TextEditGroup(MultiFixMessages.ObsoleteStaticInnerClassThanNonStaticCleanUp_description);
    List<IExtendedModifier> modifiers = node.modifiers();
    Modifier static0 = ast.static0();
    if (modifiers.isEmpty()) {
        rewrite.insertBefore(static0, node, group);
    } else {
        IExtendedModifier lastModifier = modifiers.get(modifiers.size() - 1);
        if (!lastModifier.isModifier()) {
            rewrite.insertAfter(static0, (Annotation) lastModifier, group);
        } else if (((Modifier) lastModifier).isFinal()) {
            rewrite.insertBefore(static0, (Modifier) lastModifier, group);
        } else {
            rewrite.insertAfter(static0, (Modifier) lastModifier, group);
        }
    }
}
Also used : ASTNodeFactory(org.autorefactor.jdt.internal.corext.dom.ASTNodeFactory) ASTRewrite(org.autorefactor.jdt.core.dom.ASTRewrite) TextEditGroup(org.eclipse.text.edits.TextEditGroup) Modifier(org.eclipse.jdt.core.dom.Modifier) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) 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