mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
Java: small "inst" live template improvement
GitOrigin-RevId: 4aff8d17660d18524a768317b1796dfc09597496
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d0657697d6
commit
294a698154
@@ -0,0 +1,9 @@
|
||||
class X {
|
||||
|
||||
void x(Number n) {
|
||||
if (n instanceof Number) {
|
||||
Number number = (Number) n;
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
6
java/java-tests/testData/codeInsight/template/Inst.java
Normal file
6
java/java-tests/testData/codeInsight/template/Inst.java
Normal file
@@ -0,0 +1,6 @@
|
||||
class X {
|
||||
|
||||
void x(Number n) {
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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$) { $TYPE$ $VAR1$ = ($TYPE$)$EXPR$; $END$ }">
|
||||
name="inst" toReformat="true" toShortenFQNames="true" value="if ($EXPR$ instanceof $TYPE$) { $TYPE$ $VAR$ = ($TYPE$)$EXPR$; $END$ }">
|
||||
<variable alwaysStopAt="true" defaultValue="expr" expression="variableOfType("Object")" name="EXPR" />
|
||||
<variable alwaysStopAt="true" defaultValue="" expression=""Object"" 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" />
|
||||
|
||||
Reference in New Issue
Block a user