mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
correctly generate stubs for varargs in groovy constructors
This commit is contained in:
+21
-37
@@ -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<String> throwsTypes = collectThrowsTypes(constructor, new THashSet<PsiMethod>());
|
||||
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());
|
||||
|
||||
@@ -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;" +
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ;
|
||||
}
|
||||
}
|
||||
---
|
||||
Reference in New Issue
Block a user