mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 03:21:12 +07:00
[java-intentions] ReplaceConstructorWithFactoryAction: fix reference when outer class is selected (IDEA-324475)
GitOrigin-RevId: be488adf9bf28eccb3f8a91f9527c23c7c120578
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9d63ecb44c
commit
4e73b61fc5
@@ -105,7 +105,7 @@ public class ReplaceConstructorWithFactoryAction implements ModCommandAction {
|
||||
PsiElementFactory factory = JavaPsiFacade.getElementFactory(project);
|
||||
PsiClass wrContainingClass = updater.getWritable(
|
||||
constructorOrClass instanceof PsiClass cls ? cls : Objects.requireNonNull(constructorOrClass.getContainingClass()));
|
||||
PsiReferenceExpression classReferenceExpression = factory.createReferenceExpression(wrContainingClass);
|
||||
PsiReferenceExpression classReferenceExpression = factory.createReferenceExpression(targetClass);
|
||||
String factoryName = suggestName(wrContainingClass);
|
||||
PsiReferenceExpression qualifiedMethodReference = (PsiReferenceExpression)factory.createExpressionFromText("A." + factoryName, null);
|
||||
PsiMethod constructor = ObjectUtils.tryCast(constructorOrClass, PsiMethod.class);
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
class SimpleClass {
|
||||
|
||||
public SimpleClass() {
|
||||
}
|
||||
|
||||
public static SimpleInnerClass createSimpleInnerClass() {
|
||||
return new SimpleInnerClass();
|
||||
}
|
||||
|
||||
public static class SimpleInnerClass {
|
||||
private SimpleInnerClass() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SimpleClass.SimpleInnerClass s2 = SimpleClass.createSimpleInnerClass();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
class SimpleClass {
|
||||
|
||||
public SimpleClass() {
|
||||
}
|
||||
|
||||
public static class SimpleInnerClass {
|
||||
public <caret>SimpleInnerClass() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SimpleClass.SimpleInnerClass s2 = new SimpleClass.SimpleInnerClass();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -37,6 +37,8 @@ public class ReplaceConstructorWithFactoryTest extends LightRefactoringTestCase
|
||||
public void testImplicitConstructorCreation() { runTest("07", null); }
|
||||
|
||||
public void testConstructorTypeParameters() { runTest("08", null); }
|
||||
|
||||
public void testInnerClass2() { runTest("InnerClass2", "SimpleClass"); }
|
||||
|
||||
private void runTest(final String testIndex, @NonNls String targetClassName) {
|
||||
configureByFile("/refactoring/replaceConstructorWithFactory/before" + testIndex + ".java");
|
||||
|
||||
Reference in New Issue
Block a user