mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-17 04:35:13 +07:00
IDEA-243546 Allow local interfaces and enums on language level 15-preview (part of JEP 384)
Also: fix non-static access checks for local interfaces/enums/records (JEP 384) Also: i18n of error messages GitOrigin-RevId: 40448f089229d77e32eb200b4011e1aea09391b0
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1a1a2b05a6
commit
2072855222
+3
-3
@@ -89,16 +89,16 @@ public class a {
|
||||
// local interface
|
||||
class cc {
|
||||
void f() {
|
||||
<error descr="Interface not allowed here">interface i</error> {}
|
||||
<error descr="Local interfaces are not supported at language level '1.4'">interface</error> i {}
|
||||
}
|
||||
void ff() {
|
||||
class inn {
|
||||
<error descr="Interface not allowed here">interface i</error> {}
|
||||
<error descr="Inner classes cannot have static declarations">interface i</error> {}
|
||||
}
|
||||
}
|
||||
|
||||
Object o = new Runnable() {
|
||||
<error descr="Interface not allowed here">interface i</error> {}
|
||||
<error descr="Inner classes cannot have static declarations">interface i</error> {}
|
||||
public void run() {}
|
||||
};
|
||||
}
|
||||
|
||||
+13
-2
@@ -2,7 +2,7 @@ class Foo {
|
||||
void test() {
|
||||
record NoComponent() {}
|
||||
|
||||
static record DeclaredStatic() {}
|
||||
<error descr="Modifier 'static' not allowed here">static</error> record DeclaredStatic() {}
|
||||
|
||||
<error descr="Modifier 'private' not allowed here">private</error> record Private() {}
|
||||
}
|
||||
@@ -22,8 +22,19 @@ class Foo {
|
||||
System.out.println(<error descr="Non-static field 'instanceVar' cannot be referenced from a static context">instanceVar</error>);
|
||||
System.out.println(<error descr="Non-static variable 'outerLocal' cannot be referenced from a static context">outerLocal</error>);
|
||||
System.out.println(X);
|
||||
System.out.println(compileTimeConstant);
|
||||
System.out.println(<error descr="Non-static variable 'compileTimeConstant' cannot be referenced from a static context">compileTimeConstant</error>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
<T> void typeParameter() {
|
||||
record R(<error descr="'T' cannot be referenced from a static context">T</error> t) {}
|
||||
}
|
||||
|
||||
static class Box<T> {
|
||||
void test() {
|
||||
T t;
|
||||
record R(<error descr="'Foo.Box.this' cannot be referenced from a static context">T</error> t) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -145,7 +145,7 @@ interface Barz {
|
||||
///////////////////////
|
||||
class sss {
|
||||
void f() {
|
||||
<error descr="Enum must not be local">enum EEEE</error> { EE, YY };
|
||||
<error descr="Local enums are not supported at language level '5'">enum</error> EEEE { EE, YY };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ interface Barz {
|
||||
///////////////////////
|
||||
class sss {
|
||||
void f() {
|
||||
<error descr="Enum must not be local">enum EEEE</error> { EE, YY };
|
||||
<error descr="Local enums are not supported at language level '8'">enum</error> EEEE { EE, YY };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
class X {
|
||||
void ok() {
|
||||
enum Foo {
|
||||
A, B, C;
|
||||
void m() {
|
||||
|
||||
}
|
||||
}
|
||||
Foo.A.m();
|
||||
}
|
||||
|
||||
void modifiers() {
|
||||
<error descr="Modifier 'static' not allowed here">static</error> enum E1 {}
|
||||
<error descr="Modifier 'private' not allowed here">private</error> enum E2 {}
|
||||
<error descr="Modifier 'public' not allowed here">public</error> enum E3 {}
|
||||
<error descr="Modifier 'protected' not allowed here">protected</error> enum E4 {}
|
||||
<error descr="Modifier 'abstract' not allowed here">abstract</error> enum E5 {}
|
||||
strictfp enum E6 {}
|
||||
<error descr="Modifier 'final' not allowed here">final</error> enum E7 {}
|
||||
}
|
||||
|
||||
static int sf = 0;
|
||||
|
||||
int f = 2;
|
||||
|
||||
void capture() {
|
||||
int l = 5;
|
||||
final int cst = 2;
|
||||
|
||||
enum Foo {
|
||||
A, B, C {
|
||||
void m() {
|
||||
System.out.println(x);
|
||||
System.out.println(<error descr="Non-static variable 'l' cannot be referenced from a static context">l</error>);
|
||||
System.out.println(<error descr="Non-static field 'f' cannot be referenced from a static context">f</error>);
|
||||
System.out.println(sf);
|
||||
System.out.println(<error descr="Non-static variable 'cst' cannot be referenced from a static context">cst</error>);
|
||||
}
|
||||
};
|
||||
|
||||
int x = 2;
|
||||
void m() {}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
<U> U getAndSet(U u) {
|
||||
enum Xyz {
|
||||
A;
|
||||
<error descr="'U' cannot be referenced from a static context">U</error> u;
|
||||
}
|
||||
U old = Xyz.A.u;
|
||||
Xyz.A.u = u;
|
||||
return old;
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
class X {
|
||||
void ok() {
|
||||
interface Foo {
|
||||
void m();
|
||||
default void m2() {}
|
||||
static void m3() {}
|
||||
}
|
||||
Foo foo = () -> {};
|
||||
}
|
||||
|
||||
void modifiers() {
|
||||
<error descr="Modifier 'static' not allowed here">static</error> interface Intf1 {}
|
||||
<error descr="Modifier 'private' not allowed here">private</error> interface Intf2 {}
|
||||
<error descr="Modifier 'public' not allowed here">public</error> interface Intf3 {}
|
||||
<error descr="Modifier 'protected' not allowed here">protected</error> interface Intf3 {}
|
||||
abstract interface Intf4 {}
|
||||
strictfp interface Intf5 {}
|
||||
<error descr="Modifier 'final' not allowed here">final</error> interface Intf6 {}
|
||||
}
|
||||
|
||||
static int sf = 0;
|
||||
|
||||
int f = 2;
|
||||
|
||||
void capture() {
|
||||
int l = 5;
|
||||
final int cst = 2;
|
||||
|
||||
interface Foo {
|
||||
int x = 2;
|
||||
void m();
|
||||
default void m2() {
|
||||
System.out.println(<error descr="Non-static variable 'l' cannot be referenced from a static context">l</error>);
|
||||
System.out.println(<error descr="Non-static field 'f' cannot be referenced from a static context">f</error>);
|
||||
System.out.println(sf);
|
||||
System.out.println(x);
|
||||
System.out.println(<error descr="Non-static variable 'cst' cannot be referenced from a static context">cst</error>);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static <T> void typeParameter() {
|
||||
interface Foo extends I<String> {
|
||||
<error descr="'T' cannot be referenced from a static context">T</error> t = null;
|
||||
}
|
||||
interface Foo1 extends I<<error descr="'T' cannot be referenced from a static context">T</error>> {}
|
||||
}
|
||||
|
||||
interface I<Y> {}
|
||||
|
||||
class Box<PARAM> {
|
||||
void test() {
|
||||
interface LocalI {
|
||||
<error descr="'X.Box.this' cannot be referenced from a static context">PARAM</error> getParam();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user