Local records support (IDEA-228460)

GitOrigin-RevId: 6bd11c1161f4773570573910d88c7a395f972e3c
This commit is contained in:
Tagir Valeev
2019-12-24 10:05:47 +00:00
committed by intellij-monorepo-bot
parent bc5e69a390
commit ee428f70e6
3 changed files with 34 additions and 2 deletions
@@ -904,9 +904,11 @@ public class HighlightUtil extends HighlightUtilBase {
else {
//noinspection DuplicateExpressions
if (PsiModifier.STATIC.equals(modifier) || privateOrProtected || PsiModifier.PACKAGE_LOCAL.equals(modifier)) {
isAllowed = modifierOwnerParent instanceof PsiClass &&
isAllowed = modifierOwnerParent instanceof PsiClass && ((PsiClass)modifierOwnerParent).getQualifiedName() != null ||
modifierOwnerParent instanceof PsiDeclarationStatement && aClass.isRecord() ||
FileTypeUtils.isInServerPageFile(modifierOwnerParent) ||
// non-physical dummy holder might not have FQN
((PsiClass)modifierOwnerParent).getQualifiedName() != null || FileTypeUtils.isInServerPageFile(modifierOwnerParent) || !modifierOwnerParent.isPhysical();
!modifierOwnerParent.isPhysical();
}
if (privateOrProtected && !isAllowed) {
fix = QUICK_FIX_FACTORY.createChangeModifierFix();
@@ -0,0 +1,27 @@
class Foo {
void test() {
record NoComponent() {}
static record DeclaredStatic() {}
}
static int STATIC_VAR = 3;
int instanceVar;
void capture() {
int outerLocal = 2;
final int compileTimeConstant = 3;
record Local() {
static int X = 2;
void test() {
System.out.println(STATIC_VAR);
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);
}
}
}
}
@@ -30,6 +30,9 @@ public class LightRecordsHighlightingTest extends LightJavaCodeInsightFixtureTes
public void testRecordCompactConstructors() {
doTest();
}
public void testLocalRecords() {
doTest();
}
private void doTest() {
myFixture.addClass("package java.lang; public abstract class Record {" +