mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suppress for parameter: make it possible to suppress one parameter (IDEA-69021)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+76
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Suppress for parameter" "true"
|
||||
public class Test {
|
||||
private void run(@SuppressWarnings("UnusedParameters") String s<caret>ss) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Test().run(null);
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Suppress for parameter" "true"
|
||||
public class Test {
|
||||
private void run(String s<caret>ss) {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Test().run(null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user