diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java index 4d0c71967bcc..d2ddf3d11bf8 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressFix.java @@ -188,15 +188,21 @@ public class SuppressFix extends SuppressIntentionAction { } private String getID(PsiElement place) { - if (myAlternativeID != null) { + String id = getID(place, myAlternativeID); + return id != null ? id : myID; + } + + @Nullable + static String getID(PsiElement place, String alternativeID) { + if (alternativeID != null) { final Module module = ModuleUtil.findModuleForPsiElement(place); if (module != null) { if (!ClasspathStorage.getStorageType(module).equals(ClasspathStorage.DEFAULT_STORAGE)) { - return myAlternativeID; + return alternativeID; } } } - return myID; + return null; } } diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressParameterFix.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressParameterFix.java new file mode 100644 index 000000000000..bab75fd786dd --- /dev/null +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/actions/SuppressParameterFix.java @@ -0,0 +1,76 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon.impl.actions; + +import com.intellij.codeInsight.CodeInsightUtilBase; +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer; +import com.intellij.codeInsight.daemon.HighlightDisplayKey; +import com.intellij.codeInspection.InspectionsBundle; +import com.intellij.codeInspection.SuppressIntentionAction; +import com.intellij.codeInspection.SuppressManager; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleUtil; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.roots.impl.storage.ClasspathStorage; +import com.intellij.psi.*; +import com.intellij.psi.util.PsiTreeUtil; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; + +/** + * @author ven + */ +public class SuppressParameterFix extends SuppressIntentionAction { + private String myID; + private String myAlternativeID; + + public SuppressParameterFix(HighlightDisplayKey key) { + this(key.getID()); + myAlternativeID = HighlightDisplayKey.getAlternativeID(key); + } + + public SuppressParameterFix(String ID) { + myID = ID; + } + + @NotNull + public String getText() { + return "Suppress for parameter"; + } + + @NotNull + public String getFamilyName() { + return InspectionsBundle.message("suppress.inspection.family"); + } + + public boolean isAvailable(@NotNull final Project project, final Editor editor, @NotNull final PsiElement context) { + PsiParameter psiParameter = PsiTreeUtil.getParentOfType(context, PsiParameter.class, false); + return psiParameter != null && SuppressManager.getInstance().canHave15Suppressions(psiParameter); + } + + public void invoke(final Project project, final Editor editor, final PsiElement element) throws IncorrectOperationException { + PsiParameter container = PsiTreeUtil.getParentOfType(element, PsiParameter.class, false); + assert container != null; + if (!CodeInsightUtilBase.preparePsiElementForWrite(container)) return; + final PsiModifierList modifierList = container.getModifierList(); + if (modifierList != null) { + final String id = SuppressFix.getID(container, myAlternativeID); + SuppressFix.addSuppressAnnotation(project, editor, container, container, id != null ? id : myID); + } + DaemonCodeAnalyzer.getInstance(project).restart(); + } +} diff --git a/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java b/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java index 8f879a679306..c0c3b5daf24d 100644 --- a/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java +++ b/java/java-impl/src/com/intellij/codeInspection/SuppressManagerImpl.java @@ -23,10 +23,7 @@ package com.intellij.codeInspection; import com.intellij.codeInsight.AnnotationUtil; import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings; import com.intellij.codeInsight.daemon.HighlightDisplayKey; -import com.intellij.codeInsight.daemon.impl.actions.SuppressAllForClassFix; -import com.intellij.codeInsight.daemon.impl.actions.SuppressByJavaCommentFix; -import com.intellij.codeInsight.daemon.impl.actions.SuppressFix; -import com.intellij.codeInsight.daemon.impl.actions.SuppressForClassFix; +import com.intellij.codeInsight.daemon.impl.actions.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleUtil; @@ -58,6 +55,7 @@ public class SuppressManagerImpl extends SuppressManager { public SuppressIntentionAction[] createSuppressActions(@NotNull final HighlightDisplayKey displayKey) { return new SuppressIntentionAction[]{ new SuppressByJavaCommentFix(displayKey), + new SuppressParameterFix(displayKey), new SuppressFix(displayKey), new SuppressForClassFix(displayKey), new SuppressAllForClassFix() @@ -171,7 +169,7 @@ public class SuppressManagerImpl extends SuppressManager { return statement; } - PsiLocalVariable local = PsiTreeUtil.getParentOfType(place, PsiLocalVariable.class); + PsiVariable local = PsiTreeUtil.getParentOfType(place, PsiVariable.class); if (local != null && getAnnotationMemberSuppressedIn(local, toolId) != null) { PsiModifierList modifierList = local.getModifierList(); return modifierList != null ? modifierList.findAnnotation(SUPPRESS_INSPECTIONS_ANNOTATION_NAME) : null; diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/afterSuppressUnusedParameter.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/afterSuppressUnusedParameter.java new file mode 100644 index 000000000000..27ec49d1a6f5 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/afterSuppressUnusedParameter.java @@ -0,0 +1,9 @@ +// "Suppress for parameter" "true" +public class Test { + private void run(@SuppressWarnings("UnusedParameters") String sss) { + } + + public static void main(String[] args) { + new Test().run(null); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/beforeSuppressUnusedParameter.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/beforeSuppressUnusedParameter.java new file mode 100644 index 000000000000..31739ff49868 --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/quickFix/suppress15Inspections/beforeSuppressUnusedParameter.java @@ -0,0 +1,9 @@ +// "Suppress for parameter" "true" +public class Test { + private void run(String sss) { + } + + public static void main(String[] args) { + new Test().run(null); + } +} \ No newline at end of file