Search in sources :

Example 1 with IExtendedModifier

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

the class ModifierRewrite method copyAllModifiers.

public void copyAllModifiers(ASTNode otherDecl, TextEditGroup editGroup, boolean copyIndividually) {
    ListRewrite modifierList = evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl);
    List<IExtendedModifier> originalList = modifierList.getOriginalList();
    if (originalList.isEmpty()) {
        return;
    }
    if (copyIndividually) {
        for (Iterator<IExtendedModifier> iterator = originalList.iterator(); iterator.hasNext(); ) {
            ASTNode modifier = (ASTNode) iterator.next();
            ASTNode copy = fModifierRewrite.getASTRewrite().createCopyTarget(modifier);
            if (copy != null) {
                //paranoia check (only left here because we're in RC1)
                fModifierRewrite.insertLast(copy, editGroup);
            }
        }
    } else {
        ASTNode copy = modifierList.createCopyTarget((ASTNode) originalList.get(0), (ASTNode) originalList.get(originalList.size() - 1));
        if (copy != null) {
            //paranoia check (only left here because we're in RC1)
            fModifierRewrite.insertLast(copy, editGroup);
        }
    }
}
Also used : ASTNode(org.eclipse.jdt.core.dom.ASTNode) ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 2 with IExtendedModifier

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

the class ModifierRewrite method copyAllAnnotations.

public void copyAllAnnotations(ASTNode otherDecl, TextEditGroup editGroup) {
    ListRewrite modifierList = evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl);
    List<IExtendedModifier> originalList = modifierList.getOriginalList();
    for (Iterator<IExtendedModifier> iterator = originalList.iterator(); iterator.hasNext(); ) {
        IExtendedModifier modifier = iterator.next();
        if (modifier.isAnnotation()) {
            fModifierRewrite.insertLast(fModifierRewrite.getASTRewrite().createCopyTarget((Annotation) modifier), editGroup);
        }
    }
}
Also used : ListRewrite(org.eclipse.jdt.core.dom.rewrite.ListRewrite) Annotation(org.eclipse.jdt.core.dom.Annotation) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 3 with IExtendedModifier

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

the class ModifierCorrectionSubProcessor method findAnnotation.

private static Annotation findAnnotation(String qualifiedTypeName, List<IExtendedModifier> modifiers) {
    for (int i = 0; i < modifiers.size(); i++) {
        IExtendedModifier curr = modifiers.get(i);
        if (curr instanceof Annotation) {
            Annotation annot = (Annotation) curr;
            ITypeBinding binding = annot.getTypeName().resolveTypeBinding();
            if (binding != null && qualifiedTypeName.equals(binding.getQualifiedName())) {
                return annot;
            }
        }
    }
    return null;
}
Also used : ITypeBinding(org.eclipse.jdt.core.dom.ITypeBinding) Annotation(org.eclipse.jdt.core.dom.Annotation) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 4 with IExtendedModifier

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

the class ModifierCorrectionSubProcessor method findVisibilityModifier.

private static Modifier findVisibilityModifier(List<IExtendedModifier> modifiers) {
    for (int i = 0; i < modifiers.size(); i++) {
        IExtendedModifier curr = modifiers.get(i);
        if (curr instanceof Modifier) {
            Modifier modifier = (Modifier) curr;
            ModifierKeyword keyword = modifier.getKeyword();
            if (keyword == ModifierKeyword.PUBLIC_KEYWORD || keyword == ModifierKeyword.PROTECTED_KEYWORD || keyword == ModifierKeyword.PRIVATE_KEYWORD) {
                return modifier;
            }
        }
    }
    return null;
}
Also used : ModifierKeyword(org.eclipse.jdt.core.dom.Modifier.ModifierKeyword) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) Modifier(org.eclipse.jdt.core.dom.Modifier) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier)

Example 5 with IExtendedModifier

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

the class NullAnnotationsRewriteOperations method hasNullAnnotation.

private static boolean hasNullAnnotation(MethodDeclaration decl) {
    List<IExtendedModifier> modifiers = decl.modifiers();
    String nonnull = NullAnnotationsFix.getNonNullAnnotationName(decl.resolveBinding().getJavaElement(), false);
    String nullable = NullAnnotationsFix.getNullableAnnotationName(decl.resolveBinding().getJavaElement(), false);
    for (Object mod : modifiers) {
        if (mod instanceof Annotation) {
            Name annotationName = ((Annotation) mod).getTypeName();
            String fullyQualifiedName = annotationName.getFullyQualifiedName();
            if (annotationName.isSimpleName() ? nonnull.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nonnull))
                return true;
            if (annotationName.isSimpleName() ? nullable.endsWith(fullyQualifiedName) : fullyQualifiedName.equals(nullable))
                return true;
        }
    }
    return false;
}
Also used : MarkerAnnotation(org.eclipse.jdt.core.dom.MarkerAnnotation) Annotation(org.eclipse.jdt.core.dom.Annotation) IExtendedModifier(org.eclipse.jdt.core.dom.IExtendedModifier) SimpleName(org.eclipse.jdt.core.dom.SimpleName) Name(org.eclipse.jdt.core.dom.Name)

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