mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Add itm "Iterate keys and values of java.util.Map" default Java Live Template
also to demonstrate typeParameterOf() macro GitOrigin-RevId: ba5fede72fc9391bfa4e97426b0cd706c429fa1d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2786f8bf0d
commit
67dbbe7dce
@@ -0,0 +1,14 @@
|
||||
import java.util.*;
|
||||
|
||||
class BarGoo {}
|
||||
|
||||
class Foo {
|
||||
{
|
||||
Map<String, BarGoo> goos;
|
||||
for (Map.Entry<String, BarGoo> stringBarGooEntry : goos.entrySet()) {
|
||||
String key = stringBarGooEntry.getKey();
|
||||
BarGoo value = stringBarGooEntry.getValue();
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import java.util.*;
|
||||
|
||||
class BarGoo {}
|
||||
|
||||
class Foo {
|
||||
{
|
||||
Map<String, BarGoo> goos;
|
||||
<caret>
|
||||
}
|
||||
}
|
||||
+9
-2
@@ -221,7 +221,7 @@ class Outer {
|
||||
private void stripTrailingSpaces() {
|
||||
DocumentImpl document = (DocumentImpl)getEditor().getDocument()
|
||||
document.setStripTrailingSpacesEnabled(true)
|
||||
document.stripTrailingSpaces(getProject())
|
||||
document.stripTrailingSpaces(getProject())
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments()
|
||||
}
|
||||
|
||||
@@ -243,6 +243,13 @@ class Outer {
|
||||
startTemplate("soutp", "Java")
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testItm() {
|
||||
configure()
|
||||
startTemplate("itm", "Java")
|
||||
WriteCommandAction.runWriteCommandAction(project) { state.gotoEnd(false) }
|
||||
checkResult()
|
||||
}
|
||||
|
||||
void testSoutConsumerApplicability() {
|
||||
for (String name : ["soutc", "serrc"]) {
|
||||
@@ -507,7 +514,7 @@ class Foo {
|
||||
'''
|
||||
}
|
||||
|
||||
void "test ritar template in expression lambda"() {
|
||||
void "test itar template in expression lambda"() {
|
||||
myFixture.configureByText 'a.java', '''class Foo {
|
||||
void test(int[] arr) {
|
||||
Runnable r = () -> itar<caret>
|
||||
|
||||
@@ -179,6 +179,7 @@ livetemplate.description.itco=Iterate elements of java.util.Collection
|
||||
livetemplate.description.iten=Iterate java.util.Enumeration
|
||||
livetemplate.description.itit=Iterate java.util.Iterator
|
||||
livetemplate.description.itli=Iterate elements of java.util.List
|
||||
livetemplate.description.itm=Iterate keys and values of java.util.Map
|
||||
livetemplate.description.ittok=Iterate tokens from String
|
||||
livetemplate.description.ritar=Iterate elements of array in reverse order
|
||||
livetemplate.description.iter=Iterate Iterable or array
|
||||
|
||||
@@ -71,6 +71,18 @@
|
||||
<option name="JAVA_STATEMENT" value="true" />
|
||||
</context>
|
||||
</template>
|
||||
<template name="itm" value="for (java.util.Map.Entry<$KEY_TYPE$, $VALUE_TYPE$> $ENTRY$: $MAP$.entrySet()) { $KEY_TYPE$ $KEY$ = $ENTRY$.getKey(); $VALUE_TYPE$ $VALUE$ = $ENTRY$.getValue(); $END$ }"
|
||||
resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.itm" toReformat="true" toShortenFQNames="true">
|
||||
<variable name="MAP" expression="variableOfType("java.util.Map")" defaultValue=""map"" alwaysStopAt="true" />
|
||||
<variable name="KEY_TYPE" expression="typeParameterOf(MAP,"0")" defaultValue="" alwaysStopAt="false" />
|
||||
<variable name="VALUE_TYPE" expression="typeParameterOf(MAP,"1")" defaultValue="" alwaysStopAt="false" />
|
||||
<variable name="ENTRY" expression="suggestVariableName()" defaultValue=""entry"" alwaysStopAt="true" />
|
||||
<variable name="KEY" expression="suggestVariableName()" defaultValue=""key"" alwaysStopAt="true" />
|
||||
<variable name="VALUE" expression="suggestVariableName()" defaultValue=""value"" alwaysStopAt="true" />
|
||||
<context>
|
||||
<option name="JAVA_STATEMENT" value="true" />
|
||||
</context>
|
||||
</template>
|
||||
<template name="ittok" value="for (java.util.StringTokenizer $TOKENIZER$ = new java.util.StringTokenizer($STRING$); $TOKENIZER$.hasMoreTokens(); ) { String $VAR$ = $TOKENIZER_COPY$.nextToken(); $END$ } "
|
||||
resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.ittok" toReformat="true" toShortenFQNames="true">
|
||||
<variable name="TOKENIZER" expression="suggestVariableName()" defaultValue=""tokenizer"" alwaysStopAt="true" />
|
||||
|
||||
Reference in New Issue
Block a user