mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
api usage: warn about @Override on 'non-existing' method
This commit is contained in:
+27
@@ -17,6 +17,7 @@ package com.intellij.codeInspection.java15api;
|
||||
|
||||
import com.intellij.ToolExtensionPoints;
|
||||
import com.intellij.codeHighlighting.HighlightDisplayLevel;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.daemon.GroupNames;
|
||||
import com.intellij.codeInsight.intention.QuickFixFactory;
|
||||
import com.intellij.codeInspection.*;
|
||||
@@ -296,6 +297,32 @@ public class Java15APIUsageInspectionBase extends BaseJavaBatchLocalInspectionTo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethod(PsiMethod method) {
|
||||
super.visitMethod(method);
|
||||
PsiAnnotation annotation = AnnotationUtil.findAnnotation(method, CommonClassNames.JAVA_LANG_OVERRIDE);
|
||||
if (annotation != null) {
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(annotation);
|
||||
if (module != null) {
|
||||
final LanguageLevel languageLevel = getEffectiveLanguageLevel(module);
|
||||
final PsiMethod[] methods = method.findSuperMethods();
|
||||
for (PsiMethod superMethod : methods) {
|
||||
if (superMethod instanceof PsiCompiledElement) {
|
||||
if (!isForbiddenApiUsage(superMethod, languageLevel)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (methods.length > 0) {
|
||||
registerError(annotation.getNameReferenceElement(), languageLevel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private LanguageLevel getEffectiveLanguageLevel(Module module) {
|
||||
if (myEffectiveLanguageLevel != null) return myEffectiveLanguageLevel;
|
||||
return EffectiveLanguageLevelUtil.getEffectiveLanguageLevel(module);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>Test.java</file>
|
||||
<line>4</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Usages of API documented as @since 1.5 (1.6|1.7)</problem_class>
|
||||
<description>Usage of API documented as @since 1.7+</description>
|
||||
</problem>
|
||||
|
||||
</problems>
|
||||
@@ -0,0 +1,9 @@
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class Test implements Map<String, String> {
|
||||
@Override
|
||||
public String getOrDefault(Object key, String defaultValue) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,15 @@ public class JavaAPIUsagesInspectionTest extends InspectionTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
public void testOverrideAnnotation() throws Exception {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_6, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
doTest();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getTestProjectSdk() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
|
||||
Reference in New Issue
Block a user