diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java index bf538c0048d1..2ba1c96e7463 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/GroovyPsiElementFactoryImpl.java @@ -354,13 +354,13 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { String[] paramNames, String body, PsiElement context) { - final GrMethod method = createMethodFromText(null, constructorName, null, paramTypes, paramNames, body, context); + final String text = generateMethodText(null, constructorName, null, paramTypes, paramNames, body, true); - GroovyFileImpl file = createDummyFile("class " + constructorName + "{" + method.getText() + "}"); + GroovyFileImpl file = createDummyFile("class " + constructorName + "{" + text + "}"); file.setContext(context); - GrTopLevelDefintion defintion = file.getTopLevelDefinitions()[0]; - assert defintion != null && defintion instanceof GrClassDefinition; - final PsiMethod constructor = ((GrClassDefinition) defintion).getMethods()[0]; + GrTopLevelDefintion definition = file.getTopLevelDefinitions()[0]; + assert definition != null && definition instanceof GrClassDefinition; + final PsiMethod constructor = ((GrClassDefinition) definition).getMethods()[0]; assert constructor instanceof GrConstructorImpl; return ((GrConstructorImpl) constructor); } @@ -502,13 +502,13 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { } - private GrMethod createMethodFromText(String modifier, - String name, - String type, - @Nullable String[] paramTypes, - @NotNull String[] paramNames, - String body, - PsiElement context) { + private static String generateMethodText(String modifier, + String name, + String type, + String[] paramTypes, + String[] paramNames, + String body, + boolean isConstructor) { StringBuilder builder = new StringBuilder(); if (modifier != null){ @@ -516,7 +516,9 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { builder.append(" "); } - builder.append("def "); + if (!isConstructor) { + builder.append("def "); + } //This is for constructor creation if (type != null) { @@ -547,7 +549,7 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { builder.append("}"); } - return createMethodFromText(builder.toString(), context); + return builder.toString(); } public GrMethod createMethodFromText(String modifier, String name, @Nullable String type, String[] paramTypes, PsiElement context) { @@ -565,8 +567,9 @@ public class GroovyPsiElementFactoryImpl extends GroovyPsiElementFactory { res.add(psiType); } - return createMethodFromText(modifier, name, type, paramTypes, - QuickfixUtil.getMethodArgumentsNames(myProject, res.toArray(new PsiType[res.size()])), null, context); + String[] paramNames = QuickfixUtil.getMethodArgumentsNames(myProject, res.toArray(new PsiType[res.size()])); + final String text = generateMethodText(modifier, name, type, paramTypes, paramNames, null, false); + return createMethodFromText(text, context); } public GrDocComment createDocCommentFromText(String text) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy index a0d9cac99121..25a2bab0634c 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/actions/generate/GroovyGenerateMembersTest.groovy @@ -59,7 +59,7 @@ class Foo extends Super { Object d final e - def Foo(a, int b, int c, Object d, e) { + Foo(a, int b, int c, Object d, e) { super(a, b) this.c = c this.d = d diff --git a/plugins/groovy/testdata/generate/ConstructorAtEnd_after.groovy b/plugins/groovy/testdata/generate/ConstructorAtEnd_after.groovy index e66f9654f021..ef24405d6fd0 100644 --- a/plugins/groovy/testdata/generate/ConstructorAtEnd_after.groovy +++ b/plugins/groovy/testdata/generate/ConstructorAtEnd_after.groovy @@ -4,6 +4,6 @@ class ConstructorAtEnd { } - def ConstructorAtEnd() { + ConstructorAtEnd() { } } \ No newline at end of file diff --git a/plugins/groovy/testdata/generate/ConstructorAtOffset_after.groovy b/plugins/groovy/testdata/generate/ConstructorAtOffset_after.groovy index 799b0208cb76..cb313720239f 100644 --- a/plugins/groovy/testdata/generate/ConstructorAtOffset_after.groovy +++ b/plugins/groovy/testdata/generate/ConstructorAtOffset_after.groovy @@ -4,7 +4,7 @@ class ConstructorAtOffset { } - def ConstructorAtOffset() { + ConstructorAtOffset() { } def bar() { diff --git a/plugins/groovy/testdata/generate/LonelyConstructor_after.groovy b/plugins/groovy/testdata/generate/LonelyConstructor_after.groovy index 97b761702aa6..ec1c72136e52 100644 --- a/plugins/groovy/testdata/generate/LonelyConstructor_after.groovy +++ b/plugins/groovy/testdata/generate/LonelyConstructor_after.groovy @@ -1,5 +1,5 @@ class LonelyConstructor { - def LonelyConstructor() { + LonelyConstructor() { } } \ No newline at end of file diff --git a/plugins/groovy/testdata/refactoring/introduceParameter/implicitDefaultConstructor/ImplicitDefaultConstructorAfter.groovy b/plugins/groovy/testdata/refactoring/introduceParameter/implicitDefaultConstructor/ImplicitDefaultConstructorAfter.groovy index 71c2f34d1813..42d1bbcf8451 100644 --- a/plugins/groovy/testdata/refactoring/introduceParameter/implicitDefaultConstructor/ImplicitDefaultConstructorAfter.groovy +++ b/plugins/groovy/testdata/refactoring/introduceParameter/implicitDefaultConstructor/ImplicitDefaultConstructorAfter.groovy @@ -1,5 +1,5 @@ class B extends A { - def B() { + B() { super(27) } }