diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java index 11cd6b45302f..fd11d3e49540 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovyToJavaGenerator.java @@ -589,17 +589,7 @@ public class GroovyToJavaGenerator { /************* parameters **********/ GrParameter[] parameterList = constructor.getParameters(); - text.append("("); - - for (int i = 0; i < parameterList.length; i++) { - if (i > 0) text.append(", "); - - GrParameter parameter = parameterList[i]; - - text.append(getTypeText(parameter.getTypeElementGroovy())).append(" ").append(parameter.getName()); - } - - text.append(") "); + writeParameterList(text, parameterList); final Set throwsTypes = collectThrowsTypes(constructor, new THashSet()); if (!throwsTypes.isEmpty()) { @@ -684,7 +674,8 @@ public class GroovyToJavaGenerator { } private static void writeVariableDeclarations(StringBuffer text, GrVariableDeclaration variableDeclaration) { - final String type = getTypeText(variableDeclaration.getTypeElementGroovy()); + GrTypeElement typeElement = variableDeclaration.getTypeElementGroovy(); + final String type = typeElement == null ? CommonClassNames.JAVA_LANG_OBJECT : getTypeText(typeElement.getType(), typeElement, false); final String initializer = getDefaultValueText(type); final GrModifierList modifierList = variableDeclaration.getModifierList(); @@ -728,11 +719,27 @@ public class GroovyToJavaGenerator { text.append(getTypeText(retType, method, false)); text.append(" "); - //append method name text.append(name); - /************* parameters **********/ + writeParameterList(text, parameters); + if (!isAbstract) { + /************* body **********/ + text.append("{\n"); + text.append(" return "); + + text.append(getDefaultValueText(getTypeText(retType, method, false))); + + text.append(";"); + + text.append("\n }"); + } else { + text.append(";"); + } + text.append("\n"); + } + + private static void writeParameterList(StringBuffer text, PsiParameter[] parameters) { text.append("("); //writes myParameters @@ -751,21 +758,6 @@ public class GroovyToJavaGenerator { } text.append(")"); text.append(" "); - - if (!isAbstract) { - /************* body **********/ - text.append("{\n"); - text.append(" return "); - - text.append(getDefaultValueText(getTypeText(retType, method, false))); - - text.append(";"); - - text.append("\n }"); - } else { - text.append(";"); - } - text.append("\n"); } private static boolean writeMethodModifiers(StringBuffer text, PsiModifierList modifierList, String[] modifiers) { @@ -813,14 +805,6 @@ public class GroovyToJavaGenerator { } } - private static String getTypeText(GrTypeElement typeElement) { - if (typeElement == null) { - return CommonClassNames.JAVA_LANG_OBJECT; - } - - return getTypeText(typeElement.getType(), typeElement, false); - } - private static String getTypeText(@Nullable PsiType type, @Nullable PsiElement context, boolean allowVarargs) { if (context != null && type instanceof PsiClassType) { final String accessible = findAccessibleSuperClass(context, ((PsiClassType)type).resolve()); diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java index 466ae8733a0e..c89ce67f8bce 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/compiler/GeneratorTest.java @@ -61,6 +61,7 @@ public void testArrayType1() throws Throwable { doTest(); } public void testVararg1() throws Throwable { doTest(); } public void testInaccessibleConstructor() throws Throwable { doTest(); } public void testSynchronizedProperty() throws Throwable { doTest(); } + public void testVarargs() throws Throwable { doTest(); } public void testCheckedExceptionInConstructorDelegate() throws Throwable { myFixture.addClass("package foo;" + diff --git a/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test b/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test index e74375fc8805..c7b8c01f988c 100644 --- a/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test +++ b/plugins/groovy/testdata/groovy/stubGenerator/grvy1376.test @@ -5,7 +5,7 @@ class PerformanceLine extends HashMap { } ----- public class PerformanceLine extends java.util.HashMap implements groovy.lang.GroovyObject { - public PerformanceLine(java.lang.String data) { + public PerformanceLine(java.lang.String... data) { super((java.util.Map)null); } diff --git a/plugins/groovy/testdata/groovy/stubGenerator/varargs.test b/plugins/groovy/testdata/groovy/stubGenerator/varargs.test new file mode 100644 index 000000000000..bbd2895ee32c --- /dev/null +++ b/plugins/groovy/testdata/groovy/stubGenerator/varargs.test @@ -0,0 +1,67 @@ +class Foo { + def Foo(String... s) {} + def foo(String... s) {} +} + +class Derived { + def Derived(String... s) { + super(s) + } +} +----- +public class Foo implements groovy.lang.GroovyObject { + public Foo(java.lang.String... s) { + + } + + public java.lang.Object foo(java.lang.String... s) { + return null; + } + + public groovy.lang.MetaClass getMetaClass() { + return null; + } + + public void setMetaClass(groovy.lang.MetaClass mc) { + return ; + } + + public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { + return null; + } + + public java.lang.Object getProperty(java.lang.String propertyName) { + return null; + } + + public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { + return ; + } +} +--- +public class Derived implements groovy.lang.GroovyObject { + public Derived(java.lang.String... s) { + super(); + } + + public groovy.lang.MetaClass getMetaClass() { + return null; + } + + public void setMetaClass(groovy.lang.MetaClass mc) { + return ; + } + + public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object args) { + return null; + } + + public java.lang.Object getProperty(java.lang.String propertyName) { + return null; + } + + public void setProperty(java.lang.String propertyName, java.lang.Object newValue) { + return ; + } +} +--- \ No newline at end of file