suppressions: if @Generated found, mark as suppressed even if no @SuppressWarning is present (IDEA-158300)

This commit is contained in:
Anna.Kozlova
2016-07-11 18:05:00 +02:00
parent 750afb8497
commit 8eab2c79a4
3 changed files with 28 additions and 6 deletions
@@ -129,8 +129,6 @@ public class JavaSuppressionUtil {
}
static PsiElement getAnnotationMemberSuppressedIn(@NotNull PsiModifierListOwner owner, @NotNull String inspectionToolID) {
final PsiAnnotation generatedAnnotation = AnnotationUtil.findAnnotation(owner, Generated.class.getName());
if (generatedAnnotation != null) return generatedAnnotation;
PsiModifierList modifierList = owner.getModifierList();
Collection<String> suppressedIds = getInspectionIdsSuppressedInAnnotation(modifierList);
for (String ids : suppressedIds) {
@@ -138,7 +136,7 @@ public class JavaSuppressionUtil {
return modifierList != null ? AnnotationUtil.findAnnotation(owner, SUPPRESS_INSPECTIONS_ANNOTATION_NAME) : null;
}
}
return null;
return AnnotationUtil.findAnnotation(owner, Generated.class.getName());
}
static PsiElement getDocCommentToolSuppressedIn(@NotNull PsiDocCommentOwner owner, @NotNull String inspectionToolID) {
@@ -215,9 +213,9 @@ public class JavaSuppressionUtil {
}
if (up instanceof PsiVariable) {
PsiVariable local = (PsiVariable)up;
if (getAnnotationMemberSuppressedIn(local, toolId) != null) {
PsiModifierList modifierList = local.getModifierList();
return modifierList != null ? modifierList.findAnnotation(SUPPRESS_INSPECTIONS_ANNOTATION_NAME) : null;
final PsiElement annotation = getAnnotationMemberSuppressedIn(local, toolId);
if (annotation != null) {
return annotation;
}
}
@@ -0,0 +1,9 @@
class Test {
static {
@javax.annotation.Generated
String noRedundantCastForGeneratedCode = (String) "";
}
}
@@ -16,6 +16,7 @@
package com.intellij.codeInsight.daemon;
import com.intellij.JavaTestUtil;
import com.intellij.codeInspection.redundantCast.RedundantCastInspection;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.testFramework.LightProjectDescriptor;
@@ -55,6 +56,20 @@ public class LightAdvHighlightingFixtureTest extends LightCodeInsightFixtureTest
myFixture.checkHighlighting();
}
public void testSuppressedInGenerated() throws Exception {
myFixture.addClass("package javax.annotation; public @interface Generated {}");
final RedundantCastInspection inspection = new RedundantCastInspection();
try {
myFixture.enableInspections(inspection);
myFixture.configureByFile(getTestName(false) + ".java");
myFixture.checkHighlighting();
}
finally {
myFixture.disableInspections(inspection);
}
}
@Override
protected String getBasePath() {
return JavaTestUtil.getRelativeJavaTestDataPath() + "/codeInsight/daemonCodeAnalyzer/advFixture";