mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
idiomatic groovy constructors don't start with def (IDEA-27066)
This commit is contained in:
+19
-16
@@ -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) {
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -4,6 +4,6 @@ class ConstructorAtEnd {
|
||||
|
||||
}
|
||||
|
||||
<caret>def ConstructorAtEnd() {
|
||||
<caret>ConstructorAtEnd() {
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ class ConstructorAtOffset {
|
||||
|
||||
}
|
||||
|
||||
<caret>def ConstructorAtOffset() {
|
||||
<caret>ConstructorAtOffset() {
|
||||
}
|
||||
|
||||
def bar() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class LonelyConstructor {
|
||||
|
||||
<caret>def LonelyConstructor() {
|
||||
<caret>LonelyConstructor() {
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
class B extends A {
|
||||
def B() {
|
||||
B() {
|
||||
super(27)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user