[groovy] don't allow to convert constructor to closure (IDEA-175428)

This commit is contained in:
Daniil Ovchinnikov
2017-07-07 13:42:29 +03:00
parent a1fefa9eb0
commit 24e6769632
3 changed files with 20 additions and 12 deletions
@@ -151,7 +151,7 @@ public class ConvertMethodToClosureIntention extends Intention {
if (((GrMethod)parent).getNameIdentifierGroovy() != element) return false;
method = (GrMethod)parent;
}
return method.getBlock() != null && method.getParent() instanceof GrTypeDefinitionBody;
return !method.isConstructor() && method.getBlock() != null && method.getParent() instanceof GrTypeDefinitionBody;
// return element instanceof GrMethod && ((GrMethod)element).getBlock() != null && element.getParent() instanceof GrTypeDefinitionBody;
}
}
@@ -1,17 +1,17 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.intentions;
@@ -63,12 +63,17 @@ public class ConvertMethodToClosureTest extends GrIntentionTestCase {
doClosureToMethodTest();
}
public void testConstructorToClosure() { doMethodToClosureTest(false); }
private void doClosureToMethodTest() {
doTest(GroovyIntentionsBundle.message("convert.closure.to.method.intention.name"), true);
}
private void doMethodToClosureTest() {
doTest(GroovyIntentionsBundle.message("convert.method.to.closure.intention.name"), true);
doMethodToClosureTest(true);
}
private void doMethodToClosureTest(boolean available) {
doTest(GroovyIntentionsBundle.message("convert.method.to.closure.intention.name"), available);
}
}
@@ -0,0 +1,3 @@
class Aa {
A<caret>a(a) {}
}