[codeInsight] IDEA-238740 Support the jdk.internal.PreviewFeature annotation

This patch fixes the problems according to the code review, it includes:

- moving extractHighlightingFeature to HighlightingFeature and renaming it to fromPreviewFeatureAnnotation
- assuring the PreviewFeature annotation name by calling PsiAnnotation#hasQualifiedName instead of comparing the name by equals
- moving JDK_INTERNAL_PREVIEW_FEATURE to HighlightingFeature
- extracting repeating part of checking the language level to HighlightUtil#checkPreviewFeatureElement
- adding a new case "SEALED_CLASSES" to HighlightFeature#fromPreviewAnnotationName

In addition to that there is also more robust solution to detect invalid contexts in references and static imports. The test data updated accordingly.

Signed-off-by: Nikita Eshkeev <nikita.eshkeev@jetbrains.com>

GitOrigin-RevId: 999d43ec5d9315d0881d08ce9341433707de96a0
This commit is contained in:
Nikita Eshkeev
2020-06-18 23:18:40 +03:00
committed by intellij-monorepo-bot
parent e1e85554b4
commit ef90c9f857
22 changed files with 216 additions and 121 deletions
@@ -11,9 +11,9 @@ class Main {
Main(int i){}
static {
<error descr="Patterns in 'instanceof' are not supported at language level '8'">new Main()</error>;
<error descr="Records are not supported at language level '8'">new Main(42l)</error>;
<error descr="Text block literals are not supported at language level '8'">new Main("42")</error>;
<error descr="Patterns in 'instanceof' are not supported at language level '9'">new Main()</error>;
<error descr="Records are not supported at language level '9'">new Main(42l)</error>;
<error descr="Text block literals are not supported at language level '9'">new Main("42")</error>;
new Main(42);
}
@@ -3,9 +3,9 @@ import jdk.internal.PreviewFeature.Feature;
class Main {
static {
<error descr="Patterns in 'instanceof' are not supported at language level '8'">requirePatternMatching()</error>;
<error descr="Text block literals are not supported at language level '8'">Main.requireTextBlocks()</error>;
<error descr="Records are not supported at language level '8'">new Main().requireRecords()</error>;
<error descr="Patterns in 'instanceof' are not supported at language level '9'">requirePatternMatching()</error>;
<error descr="Text block literals are not supported at language level '9'">Main.requireTextBlocks()</error>;
<error descr="Records are not supported at language level '9'">new Main().requireRecords()</error>;
}
@PreviewFeature(feature=Feature.PATTERN_MATCHING_IN_INSTANCEOF)
@@ -9,14 +9,14 @@ class Main {
@PreviewFeature(feature=Feature.TEXT_BLOCKS)
String textBlocks;
int i;
<error descr="Patterns in 'instanceof' are not supported at language level '8'">org.myorg.preview.FromPreview</error> preview;
<error descr="Patterns in 'instanceof' are not supported at language level '9'">org.myorg.preview.FromPreview</error> preview;
static {
String s = <error descr="Text block literals are not supported at language level '8'">new Main().textBlocks</error>;
String o = <error descr="Patterns in 'instanceof' are not supported at language level '8'">Main.instanceOf</error>;
long l = <error descr="Records are not supported at language level '8'">records</error>;
String s = <error descr="Text block literals are not supported at language level '9'">new Main().textBlocks</error>;
String o = <error descr="Patterns in 'instanceof' are not supported at language level '9'">Main.instanceOf</error>;
long l = <error descr="Records are not supported at language level '9'">records</error>;
int k = new Main().i;
<error descr="Patterns in 'instanceof' are not supported at language level '8'">org.myorg.preview.FromPreview</error> local = null;
<error descr="Patterns in 'instanceof' are not supported at language level '9'">org.myorg.preview.FromPreview</error> local = null;
}
}
@@ -1,3 +1,9 @@
<error descr="Patterns in 'instanceof' are not supported at language level '8'">import org.myorg.preview.FromPreview;</error>
<error descr="Patterns in 'instanceof' are not supported at language level '9'">import org.myorg.preview.FromPreview;</error>
<error descr="Patterns in 'instanceof' are not supported at language level '9'">import static org.myorg.preview.FromPreview.f;</error>
class Main { }
class Main {
static {
<error descr="Patterns in 'instanceof' are not supported at language level '9'">org.myorg.preview.FromPreview</error>.f();
<error descr="Patterns in 'instanceof' are not supported at language level '9'">f()</error>;
}
}
@@ -21,6 +21,7 @@ public @interface PreviewFeature {
PATTERN_MATCHING_IN_INSTANCEOF,
TEXT_BLOCKS,
RECORDS,
SEALED_CLASSES
;
}
}
@@ -0,0 +1,27 @@
import jdk.internal.PreviewFeature;
import jdk.internal.PreviewFeature.Feature;
class Main {
@PreviewFeature(feature=Feature.PATTERN_MATCHING_IN_INSTANCEOF)
static class InstanceOf{
static void f(){}
}
@PreviewFeature(feature=Feature.RECORDS)
static class Records{
static void f(){}
}
@PreviewFeature(feature=Feature.TEXT_BLOCKS)
static class TextBlocks{
static void f(){}
}
static class Empty{
static void f(){}
}
static {
<error descr="Patterns in 'instanceof' are not supported at language level '9'">InstanceOf</error>.f();
<error descr="Records are not supported at language level '9'">Records</error>.f();
<error descr="Text block literals are not supported at language level '9'">TextBlocks</error>.f();
Empty.f();
}
}
@@ -0,0 +1,5 @@
module consumer {
<error descr="Text block literals are not supported at language level '9'">requires producer;</error>
<error descr="Patterns in 'instanceof' are not supported at language level '9'">provides org.myorg.preview.FromPreview with org.myorg.preview.impl.FromPreviewImpl;</error>
}
@@ -10,8 +10,8 @@ class Main {
class TextBlocks{}
class Empty{}
private void f(<error descr="Patterns in 'instanceof' are not supported at language level '8'">InstanceOf</error> o, Empty e) {}
private void f(Empty e, <error descr="Records are not supported at language level '8'">Records</error> r) {}
private void f(<error descr="Text block literals are not supported at language level '8'">TextBlocks</error> e, <error descr="Records are not supported at language level '8'">Records</error> r) {}
private void f(<error descr="Patterns in 'instanceof' are not supported at language level '8'">org.myorg.preview.FromPreview</error> p) {}
private void f(<error descr="Patterns in 'instanceof' are not supported at language level '9'">InstanceOf</error> o, Empty e) {}
private void f(Empty e, <error descr="Records are not supported at language level '9'">Records</error> r) {}
private void f(<error descr="Text block literals are not supported at language level '9'">TextBlocks</error> e, <error descr="Records are not supported at language level '9'">Records</error> r) {}
private void f(<error descr="Patterns in 'instanceof' are not supported at language level '9'">org.myorg.preview.FromPreview</error> p) {}
}
@@ -0,0 +1,5 @@
package org.myorg.preview.impl;
public class FromPreviewImpl implements FromPreview {
void g() {}
}
@@ -0,0 +1,2 @@
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.PATTERN_MATCHING_IN_INSTANCEOF)
package org.myorg.preview.impl;
@@ -1,3 +1,6 @@
package org.myorg.preview;
public interface FromPreview {}
public interface FromPreview {
static void f();
void g();
}
@@ -0,0 +1,4 @@
@jdk.internal.PreviewFeature(feature = jdk.internal.PreviewFeature.Feature.TEXT_BLOCKS)
module producer {
exports org.myorg.preview;
}