diff --git a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryHandler.java b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryHandler.java index dd722308c4d9..c9480d3d40d6 100644 --- a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryHandler.java +++ b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryHandler.java @@ -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; diff --git a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryProcessor.java b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryProcessor.java index 019529402fdb..2f7af4714a5c 100644 --- a/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryProcessor.java +++ b/java/java-impl/src/com/intellij/refactoring/replaceConstructorWithFactory/ReplaceConstructorWithFactoryProcessor.java @@ -250,15 +250,16 @@ public class ReplaceConstructorWithFactoryProcessor extends BaseRefactoringProce if (myConstructor != null) { factoryMethod.getParameterList().replace(myConstructor.getParameterList()); factoryMethod.getThrowsList().replace(myConstructor.getThrowsList()); + } - Collection names = new HashSet(); - 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 names = new HashSet(); + 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(); diff --git a/java/java-tests/testData/refactoring/replaceConstructorWithFactory/afterTypeParams.java b/java/java-tests/testData/refactoring/replaceConstructorWithFactory/afterTypeParams.java new file mode 100644 index 000000000000..8426e26d8190 --- /dev/null +++ b/java/java-tests/testData/refactoring/replaceConstructorWithFactory/afterTypeParams.java @@ -0,0 +1,8 @@ +class Test { + private Test() { + } + + static Test newTest() { + return new Test(); + } +} \ No newline at end of file diff --git a/java/java-tests/testData/refactoring/replaceConstructorWithFactory/beforeTypeParams.java b/java/java-tests/testData/refactoring/replaceConstructorWithFactory/beforeTypeParams.java new file mode 100644 index 000000000000..c718d892b51d --- /dev/null +++ b/java/java-tests/testData/refactoring/replaceConstructorWithFactory/beforeTypeParams.java @@ -0,0 +1,2 @@ +class Test { +} \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithFactoryTest.java b/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithFactoryTest.java index d760625812e4..f000a1938c53 100644 --- a/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithFactoryTest.java +++ b/java/java-tests/testSrc/com/intellij/refactoring/ReplaceConstructorWithFactoryTest.java @@ -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"); }