[java] "Surround with try-with-resources" template ditched in favor of intention action (IDEA-149130, IDEA-152348)

This commit is contained in:
Roman Shevchenko
2016-03-03 10:28:22 +01:00
parent ca28f9a0d5
commit 1f6af9e047
11 changed files with 202 additions and 106 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
* Copyright 2000-2016 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.
@@ -27,14 +27,17 @@ public class SurroundAutoCloseableActionTest extends LightCodeInsightFixtureTest
}
public void testSimple() { doTest(); }
public void testSimplePast() { doTest(); }
public void testUsage() { doTest(); }
public void testMixedUsages() { doTest(); }
public void testLastDeclaration() { doTest(); }
public void testSplitVar() { doTest(); }
public void testExpression() { doTest(); }
public void testExpressionIncomplete() { doTest(); }
private void doTest() {
String name = getTestName(false);
String intention = CodeInsightBundle.message("intention.surround.resource.with.ARM.block");
CodeInsightTestUtil.doIntentionTest(myFixture, intention, name + ".java", name + "_after.java");
}
}
}
@@ -1,56 +0,0 @@
/*
* Copyright 2000-2015 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
*
* 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.
*/
package com.intellij.codeInsight.template
import com.intellij.codeInsight.template.impl.InvokeTemplateAction
import com.intellij.codeInsight.template.impl.SurroundWithTemplateHandler
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
class SurroundWithTemplateTest extends LightCodeInsightFixtureTestCase {
public void testSurroundWithTryWithResources() {
myFixture.configureByText "C.java", """\
import java.io.*;
class C {
void m() {
new FileReader("/dev/null")<caret>
}
}""".stripIndent()
invokeTemplate("TR")
myFixture.checkResult """\
import java.io.*;
class C {
void m() {
try (FileReader fileReader = new FileReader("/dev/null")) {
<caret>
}
}
}""".stripIndent()
}
private void invokeTemplate(String template) {
DefaultActionGroup group = SurroundWithTemplateHandler.createActionGroup(project, editor, file)
assertNotNull(group)
InvokeTemplateAction action = group.childActionsOrStubs.find {
it instanceof InvokeTemplateAction && (it as InvokeTemplateAction).template.key == template
} as InvokeTemplateAction
assertNotNull(action)
action.perform()
}
}