diff --git a/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java b/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java index 838ec39aae02..e06a3b8182d7 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInspection/JavaSuppressionUtil.java @@ -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 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; } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advFixture/SuppressedInGenerated.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advFixture/SuppressedInGenerated.java new file mode 100644 index 000000000000..b717b9dc894f --- /dev/null +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advFixture/SuppressedInGenerated.java @@ -0,0 +1,9 @@ + + +class Test { + + static { + @javax.annotation.Generated + String noRedundantCastForGeneratedCode = (String) ""; + } +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingFixtureTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingFixtureTest.java index cae71202d460..bc9a989a32de 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingFixtureTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LightAdvHighlightingFixtureTest.java @@ -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";