IDEA-58055 Groovy: ArrayIndexOutOfBoundsException at GroovyPsiElementFactoryImpl...
authorMaxim Medvedev <maxim.medvedev@jetbrains.com>
Mon, 13 Sep 2010 12:16:29 +0000 (16:16 +0400)
committerMaxim Medvedev <maxim.medvedev@jetbrains.com>
Mon, 13 Sep 2010 13:16:59 +0000 (17:16 +0400)
plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/conversions/ConvertClosureToMethodIntention.java
plugins/groovy/test/org/jetbrains/plugins/groovy/intentions/ConvertMethodToClosureTest.java
plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithImplicitParameterToMethod_after.groovy
plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod.groovy [new file with mode: 0644]
plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy [new file with mode: 0644]

index c3ed59c7c0619329196087514b4a34ab58a76821..750cdea930c17e12c4e031140fdb6d61bcdf1010 100644 (file)
@@ -24,6 +24,8 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.plugins.groovy.intentions.base.Intention;
 import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate;
 import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElementFactory;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifier;
+import org.jetbrains.plugins.groovy.lang.psi.api.auxiliary.modifiers.GrModifierList;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
 import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrClosableBlock;
@@ -48,14 +50,21 @@ public class ConvertClosureToMethodIntention extends Intention {
     final GrField field = (GrField)element;
     final GrClosableBlock block = (GrClosableBlock)field.getInitializerGroovy();
 
-    builder.append(field.getModifierList().getText()).append(' ').append(field.getName());
+    final GrModifierList modifierList = field.getModifierList();
+    if (modifierList.getModifiers().length > 0 || modifierList.getAnnotations().length > 0) {
+      builder.append(modifierList.getText());
+    }
+    else {
+      builder.append(GrModifier.DEF);
+    }
+    builder.append(' ').append(field.getName());
 
     builder.append('(');
     if (block.hasParametersSection()) {
       builder.append(block.getParameterList().getText());
     }
     else {
-      builder.append("def it");
+      builder.append("def it = null");
     }
     builder.append(") {");
     block.getParameterList().delete();
index b1f1850304cb3d18ef7087a616cf681f37830e37..c43028ad0df7b25888e13dc1ccecf3132edf6303 100644 (file)
@@ -38,8 +38,12 @@ public class ConvertMethodToClosureTest extends GrIntentionTestCase {
   public void testClosureToMethod() throws Exception {
     doTest(GroovyIntentionsBundle.message("convert.closure.to.method.intention.name"), true);
   }
-  
+
   public void testClosureWithImplicitParameterToMethod() throws Exception {
     doTest(GroovyIntentionsBundle.message("convert.closure.to.method.intention.name"), true);
   }
+
+  public void testClosureWithoutModifiersToMethod() {
+    doTest(GroovyIntentionsBundle.message("convert.closure.to.method.intention.name"), true);
+  }
 }
index bf6db6d56436773284bf59d620955ccbccf431bc..013f7ca14badd982d57cf5e689caad0ae8285a2e 100644 (file)
@@ -1,7 +1,7 @@
 class X{
   def a;
 
-  static private final def foo(def it) {
+  static private final def foo(def it = null) {
     print it + a;
   }
 }
\ No newline at end of file
diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod.groovy
new file mode 100644 (file)
index 0000000..7dcc7b5
--- /dev/null
@@ -0,0 +1,3 @@
+class C {
+ Closure clo<caret>s = {/* do smth */}
+}
\ No newline at end of file
diff --git a/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy b/plugins/groovy/testdata/intentions/convertMethodToClosure/ClosureWithoutModifiersToMethod_after.groovy
new file mode 100644 (file)
index 0000000..d5708f7
--- /dev/null
@@ -0,0 +1,3 @@
+class C {
+  def clos(def it = null) {/* do smth */}
+}
\ No newline at end of file