mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-05 01:50:56 +07:00
Update Override annotation support for Java 15 records (part of IDEA-239088)
GitOrigin-RevId: 16744c263f812eeaf19151fb2f46d95d0f994838
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0fcaf4e04e
commit
93dafadf4a
@@ -1000,6 +1000,9 @@ public class GenericsHighlightUtil {
|
||||
}
|
||||
}
|
||||
if (superMethod == null) {
|
||||
if (languageLevel != LanguageLevel.JDK_14_PREVIEW && JavaPsiRecordUtil.getRecordComponentForAccessor(method) != null) {
|
||||
return null;
|
||||
}
|
||||
String description = JavaErrorBundle.message("method.does.not.override.super");
|
||||
HighlightInfo highlightInfo =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(overrideAnnotation).descriptionAndTooltip(description).create();
|
||||
|
||||
@@ -17,4 +17,8 @@ record RecNonPublic(int x, int y, int z) {
|
||||
record RecThrows(int x) {
|
||||
public int x() <error descr="Record component accessor cannot declare thrown exceptions">throws Exception</error> {return x;}
|
||||
public int y() throws Exception {return x;}
|
||||
}
|
||||
record CheckOverride(int x) {
|
||||
<error descr="Method does not override method from its superclass">@Override</error> public int x() { return x; }
|
||||
<error descr="Method does not override method from its superclass">@Override</error> public int y() { return x; }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
record CheckOverride(int x) {
|
||||
@Override public int x() { return x; }
|
||||
<error descr="Method does not override method from its superclass">@Override</error> public int y() { return x; }
|
||||
}
|
||||
@@ -2,6 +2,8 @@
|
||||
package com.intellij.java.codeInsight.daemon;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -24,6 +26,9 @@ public class LightRecordsHighlightingTest extends LightJavaCodeInsightFixtureTes
|
||||
public void testRecordAccessors() {
|
||||
doTest();
|
||||
}
|
||||
public void testRecordAccessorsJava15() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_15_PREVIEW, this::doTest);
|
||||
}
|
||||
public void testRecordConstructors() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -14,10 +14,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.ThreeState;
|
||||
import com.intellij.util.containers.ConcurrentFactoryMap;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
@@ -174,7 +171,12 @@ public class MissingOverrideAnnotationInspection extends AbstractBaseJavaLocalIn
|
||||
if (hasOverrideAnnotation(method)) {
|
||||
return;
|
||||
}
|
||||
final boolean useJdk6Rules = PsiUtil.isLanguageLevel6OrHigher(method);
|
||||
LanguageLevel level = PsiUtil.getLanguageLevel(method);
|
||||
if (level != LanguageLevel.JDK_14_PREVIEW && JavaPsiRecordUtil.getRecordComponentForAccessor(method) != null) {
|
||||
result.requireAnnotation = true;
|
||||
return;
|
||||
}
|
||||
final boolean useJdk6Rules = level.isAtLeast(LanguageLevel.JDK_1_6);
|
||||
if (useJdk6Rules) {
|
||||
if (!isJdk6Override(method, methodClass)) {
|
||||
return;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
record R(int x) {
|
||||
public int x() {return x;}
|
||||
public int y() {return x;}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
record R(int x) {
|
||||
public int <warning descr="Missing '@Override' annotation on 'x()'">x</warning>() {return x;}
|
||||
public int y() {return x;}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class A implements Runnable {
|
||||
public void run() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
package com.siyeh.ig.inheritance;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
@@ -42,19 +41,26 @@ public class MissingOverrideAnnotationInspectionTest extends LightJavaInspection
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSimpleJava5() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_5, this::doTest);
|
||||
}
|
||||
|
||||
public void testNotAvailableMethodInLanguageLevel7() {
|
||||
doTest();
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_1_7, this::doTest);
|
||||
}
|
||||
|
||||
public void testRecordAccessorJava14() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_14_PREVIEW, this::doTest);
|
||||
}
|
||||
|
||||
public void testRecordAccessorJava15() {
|
||||
IdeaTestUtil.withLevel(getModule(), LanguageLevel.JDK_15_PREVIEW, this::doTest);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return new ProjectDescriptor(LanguageLevel.JDK_1_7) {
|
||||
@Override
|
||||
public Sdk getSdk() {
|
||||
return IdeaTestUtil.getMockJdk18();
|
||||
}
|
||||
};
|
||||
return JAVA_8;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user