mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
[java, fix] support creating static methods for inner classes IDEA-310703
GitOrigin-RevId: bcb0a09fd5d3e92957b4543880c5ef4640eb4d8f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bf8bfd5990
commit
eb3bf098b3
@@ -135,10 +135,12 @@ class JavaElementActionsFactory : JvmElementActionsFactory() {
|
||||
val staticMethodRequested = JvmModifier.STATIC in requestedModifiers
|
||||
|
||||
if (staticMethodRequested) {
|
||||
// static method in interfaces are allowed starting with Java 8
|
||||
// static methods in interfaces are allowed starting with Java 8
|
||||
if (javaClass.isInterface && !PsiUtil.isLanguageLevel8OrHigher(javaClass)) return emptyList()
|
||||
// static methods in inner classes are disallowed: see JLS 8.1.3
|
||||
if (javaClass.containingClass != null && !javaClass.hasModifierProperty(PsiModifier.STATIC)) return emptyList()
|
||||
// static methods in inner classes are disallowed before Java 16: see JLS 8.1.3
|
||||
if (javaClass.containingClass != null &&
|
||||
!javaClass.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
!PsiUtil.isLanguageLevel16OrHigher(javaClass)) return emptyList()
|
||||
}
|
||||
|
||||
val result = ArrayList<IntentionAction>()
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Create property 'next' in 'InnerClass in MainClass'" "true-preview"
|
||||
public class MainClass {
|
||||
void foo() {
|
||||
int counter = InnerClass.getNext();
|
||||
}
|
||||
|
||||
private class InnerClass {
|
||||
|
||||
private static int next;
|
||||
|
||||
public static int getNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
public static void setNext(int next) {
|
||||
InnerClass.next = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Create read-only property 'next' in 'InnerClass in MainClass'" "true-preview"
|
||||
public class MainClass {
|
||||
void foo() {
|
||||
int counter = InnerClass.getNext();
|
||||
}
|
||||
|
||||
private class InnerClass {
|
||||
|
||||
private static int next;
|
||||
|
||||
public static int getNext() {
|
||||
return next;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// "Create method 'getNext' in 'InnerClass in MainClass'" "true-preview"
|
||||
public class MainClass {
|
||||
void foo() {
|
||||
int counter = InnerClass.getNext();
|
||||
}
|
||||
|
||||
private class InnerClass {
|
||||
|
||||
public static int getNext() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Create property 'next' in 'InnerClass in MainClass'" "true-preview"
|
||||
public class MainClass {
|
||||
void foo() {
|
||||
int counter = InnerClass.<caret>getNext();
|
||||
}
|
||||
|
||||
private class InnerClass {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Create read-only property 'next' in 'InnerClass in MainClass'" "true-preview"
|
||||
public class MainClass {
|
||||
void foo() {
|
||||
int counter = InnerClass.<caret>getNext();
|
||||
}
|
||||
|
||||
private class InnerClass {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Create method 'getNext' in 'InnerClass in MainClass'" "true-preview"
|
||||
public class MainClass {
|
||||
void foo() {
|
||||
int counter = InnerClass.<caret>getNext();
|
||||
}
|
||||
|
||||
private class InnerClass {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,10 @@ import com.intellij.codeInsight.daemon.quickFix.ActionHint;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.impl.preview.IntentionPreviewPopupUpdateProcessor;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -16,6 +19,16 @@ public class CreateMethodFromUsageTest extends LightQuickFixParameterizedTestCas
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/createMethodFromUsage";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LanguageLevel getLanguageLevel() {
|
||||
return LanguageLevel.JDK_21_PREVIEW;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return IdeaTestUtil.getMockJdk21();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ActionHint parseActionHintImpl(@NotNull PsiFile file, @NotNull String contents) {
|
||||
return ActionHint.parse(file, contents, false);
|
||||
|
||||
Reference in New Issue
Block a user