From 9b372fae29ff0223c80c81223bb3a7832b1aa07e Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Tue, 17 Apr 2012 14:10:03 +0200 Subject: [PATCH] improve quickfix text --- .../siyeh/InspectionGadgetsBundle.properties | 3 +- .../AddToIgnoreIfAnnotatedByListQuickFix.java | 30 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties index 013f1a273a15..ed07c640c0c5 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties +++ b/plugins/InspectionGadgets/src/com/siyeh/InspectionGadgetsBundle.properties @@ -1970,4 +1970,5 @@ ambiguous.field.access.hides.parameter.problem.descriptor=Field #ref#ref from super class ''{0}'' accessed, while field access from surrounding class might be expected #loc ambiguous.field.access.quickfix=Qualify field access with 'super.' string.builder.replaceable.by.string.quickfix=Replace 'StringBuilder' with 'String' -string.buffer.replaceable.by.string.quickfix=Replace 'StringBuffer' with 'String' \ No newline at end of file +string.buffer.replaceable.by.string.quickfix=Replace 'StringBuffer' with 'String' +add.0.to.ignore.if.annotated.by.list.quickfix=Add ''{0}'' to ''Ignore if annotated by'' list \ No newline at end of file diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/AddToIgnoreIfAnnotatedByListQuickFix.java b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/AddToIgnoreIfAnnotatedByListQuickFix.java index 594f6f23b42a..0f8757324903 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/AddToIgnoreIfAnnotatedByListQuickFix.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/fixes/AddToIgnoreIfAnnotatedByListQuickFix.java @@ -17,10 +17,14 @@ package com.siyeh.ig.fixes; import com.intellij.codeInsight.daemon.QuickFixBundle; import com.intellij.codeInspection.util.SpecialAnnotationsUtil; +import com.intellij.psi.PsiAnnotation; +import com.intellij.psi.PsiModifierList; import com.intellij.psi.PsiModifierListOwner; import com.intellij.util.Processor; +import com.siyeh.InspectionGadgetsBundle; import com.siyeh.ig.DelegatingFix; import com.siyeh.ig.InspectionGadgetsFix; +import org.jetbrains.annotations.NonNls; import java.util.ArrayList; import java.util.List; @@ -32,7 +36,6 @@ public class AddToIgnoreIfAnnotatedByListQuickFix { private AddToIgnoreIfAnnotatedByListQuickFix() {} - public static InspectionGadgetsFix[] build(PsiModifierListOwner modifierListOwner, List configurationList) { final List fixes = build(modifierListOwner, configurationList, new ArrayList()); return fixes.isEmpty() ? InspectionGadgetsFix.EMPTY_ARRAY : fixes.toArray(new InspectionGadgetsFix[fixes.size()]); @@ -41,16 +44,33 @@ public class AddToIgnoreIfAnnotatedByListQuickFix { public static List build(final PsiModifierListOwner modifierListOwner, final List configurationList, final List fixes) { - SpecialAnnotationsUtil.createAddToSpecialAnnotationFixes(modifierListOwner, new Processor() { + processAnnotationTexts(modifierListOwner, new Processor() { @Override - public boolean process(String qualifiedName) { + public boolean process(String annotationText) { fixes.add(new DelegatingFix(SpecialAnnotationsUtil.createAddToSpecialAnnotationsListQuickFix( - "Add '" + qualifiedName + "' to 'ignore if annotated by' list", // add '@asdf' to 'ignore if annotated by' list + InspectionGadgetsBundle.message("add.0.to.ignore.if.annotated.by.list.quickfix", annotationText), QuickFixBundle.message("fix.add.special.annotation.family"), - configurationList, qualifiedName, modifierListOwner))); + configurationList, annotationText, modifierListOwner))); return true; } }); return fixes; } + + private static void processAnnotationTexts(final PsiModifierListOwner owner, final Processor processor) { + final PsiModifierList modifierList = owner.getModifierList(); + if (modifierList == null) { + return; + } + final PsiAnnotation[] annotations = modifierList.getAnnotations(); + for (PsiAnnotation annotation : annotations) { + @NonNls final String text = annotation.getText(); + if (text.startsWith("java.") || text.startsWith("javax.") || text.startsWith("org.jetbrains.")) { + continue; + } + if (!processor.process(text)) { + break; + } + } + } }