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

This patch adds support of the jdk.internal.PreviewFeature annotation

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

GitOrigin-RevId: b2f56d62c3b12475690f667628811e5345b1d1cf
This commit is contained in:
Nikita Eshkeev
2020-06-18 01:19:37 +03:00
committed by intellij-monorepo-bot
parent 98d35a58ad
commit 6cdf8f6eef
17 changed files with 323 additions and 1 deletions
@@ -0,0 +1,20 @@
import jdk.internal.PreviewFeature;
import jdk.internal.PreviewFeature.Feature;
class Main {
@PreviewFeature(feature=Feature.PATTERN_MATCHING_IN_INSTANCEOF)
Main(){}
@PreviewFeature(feature=Feature.RECORDS)
Main(long i){}
@PreviewFeature(feature=Feature.TEXT_BLOCKS)
Main(String s){}
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>;
new Main(42);
}
}
@@ -0,0 +1,20 @@
import jdk.internal.PreviewFeature;
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>;
}
@PreviewFeature(feature=Feature.PATTERN_MATCHING_IN_INSTANCEOF)
static void requirePatternMatching(){}
@PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.TEXT_BLOCKS)
static void requireTextBlocks(){}
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.RECORDS)
void requireRecords(){}
}
@@ -0,0 +1,22 @@
import jdk.internal.PreviewFeature;
import jdk.internal.PreviewFeature.Feature;
class Main {
@PreviewFeature(feature=Feature.PATTERN_MATCHING_IN_INSTANCEOF)
static String instanceOf;
@PreviewFeature(feature=Feature.RECORDS)
static long records;
@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;
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>;
int k = new Main().i;
<error descr="Patterns in 'instanceof' are not supported at language level '8'">org.myorg.preview.FromPreview</error> local = null;
}
}
@@ -0,0 +1,3 @@
<error descr="Patterns in 'instanceof' are not supported at language level '8'">import org.myorg.preview.FromPreview;</error>
class Main { }
@@ -0,0 +1,26 @@
package jdk.internal;
import java.lang.annotation.*;
@Target({ElementType.METHOD,
ElementType.CONSTRUCTOR,
ElementType.FIELD,
ElementType.PACKAGE,
ElementType.TYPE})
@Retention(RetentionPolicy.CLASS)
public @interface PreviewFeature {
/**
* Name of the preview feature the annotated API is associated
* with.
*/
public Feature feature();
public boolean essentialAPI() default false;
public enum Feature {
PATTERN_MATCHING_IN_INSTANCEOF,
TEXT_BLOCKS,
RECORDS,
;
}
}
@@ -0,0 +1,17 @@
import jdk.internal.PreviewFeature;
import jdk.internal.PreviewFeature.Feature;
class Main {
@PreviewFeature(feature=Feature.PATTERN_MATCHING_IN_INSTANCEOF)
class InstanceOf{}
@PreviewFeature(feature=Feature.RECORDS)
class Records{}
@PreviewFeature(feature=Feature.TEXT_BLOCKS)
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) {}
}
@@ -0,0 +1,3 @@
package org.myorg.preview;
public interface FromPreview {}
@@ -0,0 +1,2 @@
@jdk.internal.PreviewFeature(feature=jdk.internal.PreviewFeature.Feature.PATTERN_MATCHING_IN_INSTANCEOF)
package org.myorg.preview;