IDEA-140043 Predefined Variables in Code Template "Catch Statement Body" not available

This commit is contained in:
Dmitry Avdeev
2015-05-13 16:01:02 +03:00
parent 6275084617
commit 632af5206e
4 changed files with 50 additions and 1 deletions
@@ -269,7 +269,7 @@ public class JavaPsiImplementationHelperImpl extends JavaPsiImplementationHelper
final FileTemplate catchBodyTemplate = FileTemplateManager.getInstance(catchSection.getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
LOG.assertTrue(catchBodyTemplate != null);
final Properties props = new Properties();
Properties props = FileTemplateManager.getInstance(myProject).getDefaultProperties();
props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION, exceptionName);
props.setProperty(FileTemplate.ATTRIBUTE_EXCEPTION_TYPE, exceptionType.getCanonicalText());
if (context != null && context.isPhysical()) {
@@ -0,0 +1,14 @@
class Test {
public static void main(String[] args){
<selection>I i = ExceptionTest::foo;</selection>
}
class Ex extends Exception {}
static void foo() throws Ex {}
interface I {
void f();
}
}
@@ -0,0 +1,19 @@
class Test {
public static void main(String[] args){
try {
I i = ExceptionTest::foo;
} catch (Exception e) {
// $
e.printStackTrace();
}
}
class Ex extends Exception {}
static void foo() throws Ex {}
interface I {
void f();
}
}
@@ -17,6 +17,9 @@ package com.intellij.codeInsight.generation.surroundWith;
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
import com.intellij.codeInsight.template.impl.TemplateState;
import com.intellij.ide.fileTemplates.FileTemplate;
import com.intellij.ide.fileTemplates.FileTemplateManager;
import com.intellij.ide.fileTemplates.JavaTemplateUtil;
import com.intellij.ide.highlighter.JavaFileType;
import com.intellij.lang.LanguageSurrounders;
import com.intellij.lang.java.JavaLanguage;
@@ -174,6 +177,19 @@ public class JavaSurroundWithTest extends LightCodeInsightTestCase {
doTest(new JavaWithTryCatchSurrounder());
}
public void testSurroundWithTryCatchProperties() {
FileTemplate template = FileTemplateManager.getInstance(getProject()).getCodeTemplate(JavaTemplateUtil.TEMPLATE_CATCH_BODY);
String old = template.getText();
template.setText("// ${DS} \n" +
"${EXCEPTION}.printStackTrace();");
try {
doTest(new JavaWithTryCatchSurrounder());
}
finally {
template.setText(old);
}
}
public void testSurroundIfBranchWithNoBracesAndComment() {
doTest(new JavaWithBlockSurrounder());
}