add suppress with comment for local variables (IDEA-90851)

This commit is contained in:
Anna Kozlova
2012-09-12 21:40:08 +04:00
parent 73c8ca17fe
commit ae06f67cd2
3 changed files with 73 additions and 7 deletions
@@ -45,7 +45,20 @@ public class SuppressByJavaCommentFix extends SuppressByCommentFix {
final Editor editor,
final PsiElement element,
final PsiElement container) throws IncorrectOperationException {
boolean added = false;
PsiElement declaredElement = getElementToAnnotate(element, container);
if (declaredElement != null) {
SuppressFix.addSuppressAnnotation(project, editor, container, (PsiLocalVariable)declaredElement, myID);
} else {
suppressWithComment(project, editor, element, container);
}
}
protected void suppressWithComment(Project project, Editor editor, PsiElement element, PsiElement container) {
super.createSuppression(project, editor, element, container);
}
@Nullable
protected static PsiElement getElementToAnnotate(PsiElement element, PsiElement container) {
if (container instanceof PsiDeclarationStatement && SuppressManager.getInstance().canHave15Suppressions(element)) {
final PsiDeclarationStatement declarationStatement = (PsiDeclarationStatement)container;
final PsiElement[] declaredElements = declarationStatement.getDeclaredElements();
@@ -53,15 +66,11 @@ public class SuppressByJavaCommentFix extends SuppressByCommentFix {
if (declaredElement instanceof PsiLocalVariable) {
final PsiModifierList modifierList = ((PsiLocalVariable)declaredElement).getModifierList();
if (modifierList != null) {
SuppressFix.addSuppressAnnotation(project, editor, container, (PsiLocalVariable)declaredElement, myID);
added = true;
break;
return declaredElement;
}
}
}
}
if (!added) {
super.createSuppression(project, editor, element, container);
}
return null;
}
}
@@ -0,0 +1,56 @@
/*
* Copyright 2000-2012 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.daemon.HighlightDisplayKey;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
* User: anna
*/
public class SuppressLocalWithCommentFix extends SuppressByJavaCommentFix {
public SuppressLocalWithCommentFix(HighlightDisplayKey key) {
super(key);
}
@Nullable
@Override
protected PsiElement getContainer(PsiElement context) {
final PsiElement container = super.getContainer(context);
if (container != null) {
final PsiElement elementToAnnotate = getElementToAnnotate(context, container);
if (elementToAnnotate == null) return null;
}
return container;
}
@Override
protected void createSuppression(Project project, Editor editor, PsiElement element, PsiElement container)
throws IncorrectOperationException {
suppressWithComment(project, editor, element, container);
}
@NotNull
@Override
public String getText() {
return "Suppress for statement with comment";
}
}
@@ -55,6 +55,7 @@ public class SuppressManagerImpl extends SuppressManager {
public SuppressIntentionAction[] createSuppressActions(@NotNull final HighlightDisplayKey displayKey) {
return new SuppressIntentionAction[]{
new SuppressByJavaCommentFix(displayKey),
new SuppressLocalWithCommentFix(displayKey),
new SuppressParameterFix(displayKey),
new SuppressFix(displayKey),
new SuppressForClassFix(displayKey),