diff options
author | Tor Norbye <tnorbye@google.com> | 2013-05-07 20:09:46 -0700 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-05-07 20:09:46 -0700 |
commit | 934b9431b0b827a132df794e307fe5a2b70de00b (patch) | |
tree | dadfd1ccaeb2ce0403d306a59b35711531481e2b /plugins/InspectionGadgets | |
parent | f56a0fff1a336635c966bffc25e16af9a4e6e988 (diff) | |
download | idea-934b9431b0b827a132df794e307fe5a2b70de00b.tar.gz |
Snapshot 5220ac5242aadc343c995ec9a49d09765db4a0c7 from master branch of git://git.jetbrains.org/idea/community.git
Change-Id: I2494d92b34f89102885b2f39d7552747fafdafec
Diffstat (limited to 'plugins/InspectionGadgets')
-rw-r--r-- | plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java b/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java index dcd264d51d52..e0396ee6d402 100644 --- a/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java +++ b/plugins/InspectionGadgets/src/com/intellij/codeInspection/booleanIsAlwaysInverted/BooleanMethodIsAlwaysInvertedInspection.java @@ -26,27 +26,32 @@ import java.util.Collection; public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaInspectionTool { private static final Key<Boolean> ALWAYS_INVERTED = Key.create("ALWAYS_INVERTED_METHOD"); + @Override @NotNull public String getDisplayName() { return InspectionsBundle.message("boolean.method.is.always.inverted.display.name"); } + @Override @NotNull public String getGroupDisplayName() { return GroupNames.DATA_FLOW_ISSUES; } + @Override @NotNull @NonNls public String getShortName() { return "BooleanMethodIsAlwaysInverted"; } + @Override @Nullable public RefGraphAnnotator getAnnotator(final RefManager refManager) { return new BooleanInvertedAnnotator(); } + @Override public CommonProblemDescriptor[] checkElement(RefEntity refEntity, AnalysisScope scope, final InspectionManager manager, @@ -81,6 +86,7 @@ public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaInspectio return false; } + @Override protected boolean queryExternalUsagesRequests(final RefManager manager, final GlobalJavaInspectionContext context, final ProblemDescriptionsProcessor descriptionsProcessor) { manager.iterate(new RefJavaVisitor() { @@ -88,6 +94,7 @@ public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaInspectio public void visitMethod(@NotNull final RefMethod refMethod) { if (descriptionsProcessor.getDescriptions(refMethod) != null) { //suspicious method -> need to check external usages final GlobalJavaInspectionContext.UsagesProcessor usagesProcessor = new GlobalJavaInspectionContext.UsagesProcessor() { + @Override public boolean process(PsiReference psiReference) { final PsiElement psiReferenceExpression = psiReference.getElement(); if (psiReferenceExpression instanceof PsiReferenceExpression && @@ -147,6 +154,7 @@ public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaInspectio } private static class BooleanInvertedAnnotator extends RefGraphAnnotator { + @Override public void onInitialize(RefElement refElement) { if (refElement instanceof RefMethod) { final PsiElement element = refElement.getElement(); @@ -156,6 +164,7 @@ public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaInspectio } } + @Override public void onMarkReferenced(RefElement refWhat, RefElement refFrom, boolean referencedFromClassInitializer) { checkMethodCall(refWhat, refFrom.getElement()); } @@ -168,22 +177,26 @@ public class BooleanMethodIsAlwaysInvertedInspection extends GlobalJavaInspectio private static class InvertMethodFix implements LocalQuickFix { + @Override @NotNull public String getName() { return "Invert method"; } + @Override @NotNull public String getFamilyName() { return getName(); } + @Override public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) { final PsiElement element = descriptor.getPsiElement(); final PsiMethod psiMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class); assert psiMethod != null; final RefactoringActionHandler invertBooleanHandler = JavaRefactoringActionHandlerFactory.getInstance().createInvertBooleanHandler(); final Runnable runnable = new Runnable() { + @Override public void run() { invertBooleanHandler.invoke(project, new PsiElement[]{psiMethod}, DataManager.getInstance().getDataContext()); } |