Java: small "inst" live template improvement

GitOrigin-RevId: 4aff8d17660d18524a768317b1796dfc09597496
This commit is contained in:
Bas Leijdekkers
2023-02-24 12:22:56 +01:00
committed by intellij-monorepo-bot
parent d0657697d6
commit 294a698154
4 changed files with 35 additions and 11 deletions

View File

@@ -0,0 +1,9 @@
class X {
void x(Number n) {
if (n instanceof Number) {
Number number = (Number) n;
<caret>
}
}
}

View File

@@ -0,0 +1,6 @@
class X {
void x(Number n) {
<caret>
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.java.codeInsight.template
import com.intellij.JavaTestUtil
@@ -151,35 +151,35 @@ class Outer {
'''
}
void testToar() throws Throwable {
void testToar() {
configure()
startTemplate("toar", "Java")
state.gotoEnd(false)
checkResult()
}
void testElseIf() throws Throwable {
void testElseIf() {
configure()
startTemplate("else-if", "Java")
WriteCommandAction.runWriteCommandAction(project) { state.gotoEnd(false) }
checkResult()
}
void testElseIf2() throws Throwable {
void testElseIf2() {
configure()
startTemplate("else-if", "Java")
WriteCommandAction.runWriteCommandAction(project) { state.gotoEnd(false) }
checkResult()
}
void testElseIf3() throws Throwable {
void testElseIf3() {
configure()
startTemplate("else-if", "Java")
WriteCommandAction.runWriteCommandAction(project) { state.gotoEnd(false) }
checkResult()
}
void testIter() throws Throwable {
void testIter() {
configure()
startTemplate("iter", "Java")
WriteCommandAction.runWriteCommandAction(project) { state.nextTab() }
@@ -187,7 +187,7 @@ class Outer {
checkResult()
}
void testIter1() throws Throwable {
void testIter1() {
configure()
startTemplate("iter", "Java")
myFixture.performEditorAction("NextTemplateVariable")
@@ -247,6 +247,15 @@ class Outer {
WriteCommandAction.runWriteCommandAction(project) { state.gotoEnd(false) }
checkResult()
}
void testInst() {
configure()
startTemplate("inst", "Java")
myFixture.type('\n')
myFixture.type('\n')
myFixture.type('\n')
checkResult()
}
void testSoutConsumerApplicability() {
for (String name : ["soutc", "serrc"]) {
@@ -269,7 +278,7 @@ class Outer {
checkResult()
}
private boolean isApplicable(String text, TemplateImpl inst) throws IOException {
private boolean isApplicable(String text, TemplateImpl inst) {
myFixture.configureByText("a.java", text)
return TemplateManagerImpl.isApplicable(myFixture.getFile(), getEditor().getCaretModel().getOffset(), inst)
}

View File

@@ -116,10 +116,10 @@
</context>
</template>
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.inst"
name="inst" toReformat="true" toShortenFQNames="true" value="if ($EXPR$ instanceof $TYPE$) {&#13;&#10; $TYPE$ $VAR1$ = ($TYPE$)$EXPR$;&#13;&#10; $END$&#13;&#10;}">
name="inst" toReformat="true" toShortenFQNames="true" value="if ($EXPR$ instanceof $TYPE$) {&#13;&#10; $TYPE$ $VAR$ = ($TYPE$)$EXPR$;&#13;&#10; $END$&#13;&#10;}">
<variable alwaysStopAt="true" defaultValue="expr" expression="variableOfType(&quot;Object&quot;)" name="EXPR" />
<variable alwaysStopAt="true" defaultValue="" expression="&quot;Object&quot;" name="TYPE" />
<variable alwaysStopAt="true" defaultValue="" expression="suggestVariableName()" name="VAR1" />
<variable alwaysStopAt="true" defaultValue="" expression="subtypes(typeOfVariable(EXPR))" name="TYPE" />
<variable alwaysStopAt="true" defaultValue="" expression="suggestVariableName()" name="VAR" />
<context>
<option name="JAVA_CODE" value="false" />
<option name="JAVA_STATEMENT" value="true" />