since api: check annotation pairs (IDEA-177856)

This commit is contained in:
Anna.Kozlova
2017-08-21 19:08:01 +02:00
parent c74250434d
commit 18c13320a2
3 changed files with 34 additions and 3 deletions

View File

@@ -40,6 +40,7 @@ import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.reference.SoftReference;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.hash.HashSet;
import gnu.trove.THashSet;
@@ -226,6 +227,25 @@ public class Java15APIUsageInspectionBase extends BaseJavaBatchLocalInspectionTo
visitReferenceElement(expression);
}
@Override
public void visitNameValuePair(PsiNameValuePair pair) {
super.visitNameValuePair(pair);
PsiReference reference = pair.getReference();
if (reference != null) {
PsiElement resolve = reference.resolve();
if (resolve instanceof PsiCompiledElement && resolve instanceof PsiAnnotationMethod) {
final Module module = ModuleUtilCore.findModuleForPsiElement(pair);
if (module != null) {
final LanguageLevel languageLevel = getEffectiveLanguageLevel(module);
LanguageLevel sinceLanguageLevel = getLastIncompatibleLanguageLevel((PsiMember)resolve, languageLevel);
if (sinceLanguageLevel != null) {
registerError(ObjectUtils.notNull(pair.getNameIdentifier(), pair), sinceLanguageLevel);
}
}
}
}
}
@Override public void visitReferenceElement(PsiJavaCodeReferenceElement reference) {
super.visitReferenceElement(reference);
final PsiElement resolved = reference.resolve();
@@ -339,7 +359,7 @@ public class Java15APIUsageInspectionBase extends BaseJavaBatchLocalInspectionTo
return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module);
}
private void registerError(PsiJavaCodeReferenceElement reference, LanguageLevel api) {
private void registerError(PsiElement reference, LanguageLevel api) {
if (reference != null && isInProject(reference)) {
//noinspection DialogTitleCapitalization
myHolder.registerProblem(reference,

View File

@@ -0,0 +1,2 @@
@Deprecated(<error descr="Usage of API documented as @since 1.9+">forRemoval</error> = true)
class MyTest {}

View File

@@ -17,6 +17,7 @@ package com.intellij.java.codeInsight.daemon;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
import com.intellij.codeInspection.java15api.Java15APIUsageInspection;
import com.intellij.codeInspection.javaDoc.JavaDocReferenceInspection;
import com.intellij.codeInspection.redundantCast.RedundantCastInspection;
import com.intellij.codeInspection.uncheckedWarnings.UncheckedWarningLocalInspection;
@@ -31,7 +32,11 @@ public class LightAdvHighlightingJdk9Test extends LightDaemonAnalyzerTestCase {
@Override
protected void setUp() throws Exception {
super.setUp();
enableInspectionTools(new UnusedDeclarationInspection(), new UncheckedWarningLocalInspection(), new RedundantCastInspection(), new JavaDocReferenceInspection());
enableInspectionTools(new UnusedDeclarationInspection(),
new UncheckedWarningLocalInspection(),
new RedundantCastInspection(),
new JavaDocReferenceInspection(),
new Java15APIUsageInspection());
setLanguageLevel(LanguageLevel.JDK_1_9);
IdeaTestUtil.setTestVersion(JavaSdkVersion.JDK_1_9, getModule(), getTestRootDisposable());
}
@@ -52,7 +57,11 @@ public class LightAdvHighlightingJdk9Test extends LightDaemonAnalyzerTestCase {
public void testDiamondsWithAnonymousRejectIntersectionType() { doTest(false, false);}
public void testDiamondsWithAnonymousInsideCallToInfer() { doTest(false, false);}
public void testDiamondsWithAnonymousDiamond() { doTest(false, false);}
public void testHighlightApiUsages() {
setLanguageLevel(LanguageLevel.JDK_1_8);
doTest(false, false);}
public void testValueTypes() { setLanguageLevel(LanguageLevel.JDK_X); doTest(false, false); }
public void testModuleInfoSuppression() {