mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
replace constructor with factory: insert class type parameters for default constructor(IDEA-104858)
This commit is contained in:
+3
-3
@@ -116,9 +116,9 @@ public class ReplaceConstructorWithFactoryHandler
|
||||
CommonRefactoringUtil.showErrorHint(myProject, editor, message, REFACTORING_NAME, HelpID.REPLACE_CONSTRUCTOR_WITH_FACTORY);
|
||||
return;
|
||||
}
|
||||
final int answer = Messages.showYesNoCancelDialog(myProject,
|
||||
RefactoringBundle.message("would.you.like.to.replace.default.constructor.of.0.with.factory.method", aClass.getQualifiedName()),
|
||||
REFACTORING_NAME, Messages.getQuestionIcon()
|
||||
final int answer = Messages.showYesNoDialog(myProject,
|
||||
RefactoringBundle.message("would.you.like.to.replace.default.constructor.of.0.with.factory.method", aClass.getQualifiedName()),
|
||||
REFACTORING_NAME, Messages.getQuestionIcon()
|
||||
);
|
||||
if (answer != 0) return;
|
||||
if (!CommonRefactoringUtil.checkReadOnlyStatus(myProject, aClass)) return;
|
||||
|
||||
+7
-6
@@ -250,15 +250,16 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce
|
||||
if (myConstructor != null) {
|
||||
factoryMethod.getParameterList().replace(myConstructor.getParameterList());
|
||||
factoryMethod.getThrowsList().replace(myConstructor.getThrowsList());
|
||||
}
|
||||
|
||||
Collection<String> names = new HashSet<String>();
|
||||
for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(myConstructor)) {
|
||||
if (!names.contains(typeParameter.getName())) { //Otherwise type parameter is hidden in the constructor
|
||||
names.add(typeParameter.getName());
|
||||
factoryMethod.getTypeParameterList().addAfter(typeParameter, null);
|
||||
}
|
||||
Collection<String> names = new HashSet<String>();
|
||||
for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(myConstructor != null ? myConstructor : containingClass)) {
|
||||
if (!names.contains(typeParameter.getName())) { //Otherwise type parameter is hidden in the constructor
|
||||
names.add(typeParameter.getName());
|
||||
factoryMethod.getTypeParameterList().addAfter(typeParameter, null);
|
||||
}
|
||||
}
|
||||
|
||||
PsiReturnStatement returnStatement =
|
||||
(PsiReturnStatement)myFactory.createStatementFromText("return new A();", null);
|
||||
PsiNewExpression newExpression = (PsiNewExpression)returnStatement.getReturnValue();
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
class Test<A,B,C> {
|
||||
private Test() {
|
||||
}
|
||||
|
||||
static <A, B, C> Test<A, B, C> newTest() {
|
||||
return new Test<A, B, C>();
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
class Te<caret>st<A,B,C> {
|
||||
}
|
||||
+1
@@ -22,6 +22,7 @@ public class ReplaceConstructorWithFactoryTest extends LightRefactoringTestCase
|
||||
public void testSubclass() throws Exception { runTest("02", null); }
|
||||
|
||||
public void testDefaultConstructor() throws Exception { runTest("03", null); }
|
||||
public void testDefaultConstructorWithTypeParams() throws Exception { runTest("TypeParams", null); }
|
||||
|
||||
public void testInnerClass() throws Exception { runTest("04", "OuterClass"); }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user