mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
Java: disallow inlining record to anonymous class (IDEA-359857)
GitOrigin-RevId: f477736ff39ea95cf9c9c5088c2dd0af9399f605
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1c4ecd3c3c
commit
7be0072137
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||||
package com.intellij.refactoring.inline;
|
package com.intellij.refactoring.inline;
|
||||||
|
|
||||||
import com.intellij.codeInsight.TargetElementUtil;
|
import com.intellij.codeInsight.TargetElementUtil;
|
||||||
@@ -192,6 +192,9 @@ public final class InlineToAnonymousClassHandler extends JavaInlineActionHandler
|
|||||||
if (psiClass.isEnum()) {
|
if (psiClass.isEnum()) {
|
||||||
return JavaBundle.message("enums.cannot.be.inlined");
|
return JavaBundle.message("enums.cannot.be.inlined");
|
||||||
}
|
}
|
||||||
|
if (psiClass.isRecord()) {
|
||||||
|
return JavaBundle.message("records.cannot.be.inlined");
|
||||||
|
}
|
||||||
if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
if (psiClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||||
return JavaRefactoringBundle.message("inline.to.anonymous.no.abstract");
|
return JavaRefactoringBundle.message("inline.to.anonymous.no.abstract");
|
||||||
}
|
}
|
||||||
@@ -373,7 +376,6 @@ public final class InlineToAnonymousClassHandler extends JavaInlineActionHandler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public String getActionName(PsiElement element) {
|
public String getActionName(PsiElement element) {
|
||||||
return JavaRefactoringBundle.message("inline.to.anonymous.refactoring");
|
return JavaRefactoringBundle.message("inline.to.anonymous.refactoring");
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
class A {
|
||||||
|
private R r = new R<caret>();
|
||||||
|
}
|
||||||
|
record R() {
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "A";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -283,6 +283,10 @@ public class InlineToAnonymousClassTest extends LightRefactoringTestCase {
|
|||||||
public void testNoInlineAnnotationType() {
|
public void testNoInlineAnnotationType() {
|
||||||
doTestNoInline("Annotation types cannot be inlined");
|
doTestNoInline("Annotation types cannot be inlined");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNoInlineRecordJava21() {
|
||||||
|
doTestNoInline("Record classes cannot be inlined");
|
||||||
|
}
|
||||||
|
|
||||||
public void testNoInlineMultipleInterfaces() {
|
public void testNoInlineMultipleInterfaces() {
|
||||||
doTestNoInline("Classes which implement multiple interfaces cannot be inlined");
|
doTestNoInline("Classes which implement multiple interfaces cannot be inlined");
|
||||||
@@ -437,7 +441,7 @@ public class InlineToAnonymousClassTest extends LightRefactoringTestCase {
|
|||||||
TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
|
TargetElementUtil.REFERENCED_ELEMENT_ACCEPTED);
|
||||||
assertInstanceOf(element, PsiClass.class);
|
assertInstanceOf(element, PsiClass.class);
|
||||||
|
|
||||||
assertEquals(null, InlineToAnonymousClassHandler.getCannotInlineMessage((PsiClass) element));
|
assertNull(InlineToAnonymousClassHandler.getCannotInlineMessage((PsiClass)element));
|
||||||
return new InlineToAnonymousClassProcessor(getProject(), (PsiClass) element, null, false, false, false);
|
return new InlineToAnonymousClassProcessor(getProject(), (PsiClass) element, null, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1666,6 +1666,7 @@ class.cannot.be.inlined.because.its.superclass.cannot.be.resolved=Class cannot b
|
|||||||
library.classes.cannot.be.inlined=Library classes cannot be inlined
|
library.classes.cannot.be.inlined=Library classes cannot be inlined
|
||||||
enums.cannot.be.inlined=Enums cannot be inlined
|
enums.cannot.be.inlined=Enums cannot be inlined
|
||||||
interfaces.cannot.be.inlined=Interfaces cannot be inlined
|
interfaces.cannot.be.inlined=Interfaces cannot be inlined
|
||||||
|
records.cannot.be.inlined=Record classes cannot be inlined
|
||||||
annotation.types.cannot.be.inlined=Annotation types cannot be inlined
|
annotation.types.cannot.be.inlined=Annotation types cannot be inlined
|
||||||
type.parameters.cannot.be.inlined=Type parameters cannot be inlined
|
type.parameters.cannot.be.inlined=Type parameters cannot be inlined
|
||||||
postfix.template.editor.choose.class.title=Choose Class
|
postfix.template.editor.choose.class.title=Choose Class
|
||||||
|
|||||||
Reference in New Issue
Block a user