mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
[java] IJ-CR-162106 IDEA-360079 live templates for instance main methods in implicitly declared classes
- introduce psvma and maina instead of template GitOrigin-RevId: baf47b932895fbf11a920509c51e8cb30c84c4ce
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7f2652b15b
commit
ef450d5df0
@@ -1242,7 +1242,6 @@
|
|||||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CurrentPackageMacro"/>
|
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CurrentPackageMacro"/>
|
||||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.RightSideTypeMacro"/>
|
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.RightSideTypeMacro"/>
|
||||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CastToLeftSideTypeMacro"/>
|
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.CastToLeftSideTypeMacro"/>
|
||||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.StringArgsMacro"/>
|
|
||||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.IterableVariableMacro"/>
|
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.IterableVariableMacro"/>
|
||||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.IterableComponentTypeMacro"/>
|
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.IterableComponentTypeMacro"/>
|
||||||
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.TypeParameterOfMacro"/>
|
<liveTemplateMacro implementation="com.intellij.codeInsight.template.macro.TypeParameterOfMacro"/>
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
|
||||||
package com.intellij.codeInsight.template.macro;
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
|
||||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
|
||||||
import com.intellij.codeInsight.lookup.LookupFocusDegree;
|
|
||||||
import com.intellij.codeInsight.template.*;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public final class StringArgsMacro extends Macro {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "stringArgs";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull String getDefaultValue() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Result calculateResult(Expression @NotNull [] params, ExpressionContext context) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LookupElement[] calculateLookupItems(Expression @NotNull [] params, final ExpressionContext context) {
|
|
||||||
return new LookupElement[]{LookupElementBuilder.create("String[] args")};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isAcceptableInContext(TemplateContextType context) {
|
|
||||||
return context instanceof JavaCodeContextType.NormalClassDeclarationAfterShortMainMethod ||
|
|
||||||
context instanceof JavaCodeContextType.ImplicitClassDeclaration;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NotNull LookupFocusDegree getLookupFocusDegree() {
|
|
||||||
return LookupFocusDegree.UNFOCUSED;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -821,12 +821,8 @@ public class JavaLiveTemplateTest extends LiveTemplateTestCase {
|
|||||||
<caret>
|
<caret>
|
||||||
""");
|
""");
|
||||||
final TemplateImpl template =
|
final TemplateImpl template =
|
||||||
TemplateSettings.getInstance().getTemplate("psvm", "Java//Instance 'main' methods for implicitly declared classes");
|
TemplateSettings.getInstance().getTemplate("psvma", "Java//Instance 'main' methods for implicitly declared classes");
|
||||||
startTemplate(template);
|
startTemplate(template);
|
||||||
LookupElement[] elements = myFixture.getLookupElements();
|
|
||||||
LookupElement last = elements[elements.length - 1];
|
|
||||||
myFixture.getLookup().setCurrentItem(last);
|
|
||||||
myFixture.finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
|
||||||
myFixture.checkResult(
|
myFixture.checkResult(
|
||||||
"""
|
"""
|
||||||
void main(String[] args) {
|
void main(String[] args) {
|
||||||
@@ -851,7 +847,6 @@ public class JavaLiveTemplateTest extends LiveTemplateTestCase {
|
|||||||
""");
|
""");
|
||||||
final TemplateImpl template = TemplateSettings.getInstance().getTemplate("main", "Java//Instance 'main' methods for normal classes");
|
final TemplateImpl template = TemplateSettings.getInstance().getTemplate("main", "Java//Instance 'main' methods for normal classes");
|
||||||
startTemplate(template);
|
startTemplate(template);
|
||||||
myFixture.type("\n");
|
|
||||||
myFixture.checkResult(
|
myFixture.checkResult(
|
||||||
"""
|
"""
|
||||||
class A{
|
class A{
|
||||||
|
|||||||
@@ -193,7 +193,10 @@ livetemplate.description.lst=Fetches last element of an array
|
|||||||
livetemplate.description.mn=Sets lesser value to a variable
|
livetemplate.description.mn=Sets lesser value to a variable
|
||||||
livetemplate.description.mx=Sets greater value to a variable
|
livetemplate.description.mx=Sets greater value to a variable
|
||||||
livetemplate.description.psvm=main() method declaration
|
livetemplate.description.psvm=main() method declaration
|
||||||
livetemplate.description.short.psvm=Instance main() method declaration
|
livetemplate.description.short.static.psvm=static void main()
|
||||||
|
livetemplate.description.short.static.psvma=static void main(String[] args)
|
||||||
|
livetemplate.description.short.psvm=void main()
|
||||||
|
livetemplate.description.short.psvma=void main(String[] args)
|
||||||
livetemplate.description.toar=Stores elements of java.util.Collection into array
|
livetemplate.description.toar=Stores elements of java.util.Collection into array
|
||||||
livetemplate.description.lazy=Performs lazy initialization
|
livetemplate.description.lazy=Performs lazy initialization
|
||||||
livetemplate.description.if.not.null=Inserts 'if not null' statement
|
livetemplate.description.if.not.null=Inserts 'if not null' statement
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<templateSet group="Java//Instance 'main' methods for implicitly declared classes">
|
<templateSet group="Java//Instance 'main' methods for implicitly declared classes">
|
||||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
||||||
name="psvm" toReformat="true" toShortenFQNames="true" value="void main($STRING_ARGS$){ $END$ }">
|
name="psvm" toReformat="true" toShortenFQNames="true" value="void main(){ $END$ }">
|
||||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
|
||||||
<context>
|
<context>
|
||||||
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
||||||
</context>
|
</context>
|
||||||
</template>
|
</template>
|
||||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
||||||
name="main" toReformat="true" toShortenFQNames="true" value="void main($STRING_ARGS$){ $END$ }">
|
name="main" toReformat="true" toShortenFQNames="true" value="void main(){ $END$ }">
|
||||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
<context>
|
||||||
|
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
||||||
|
</context>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvma"
|
||||||
|
name="psvma" toReformat="true" toShortenFQNames="true" value="void main(String[] args){ $END$ }">
|
||||||
|
<context>
|
||||||
|
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
||||||
|
</context>
|
||||||
|
</template>
|
||||||
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvma"
|
||||||
|
name="maina" toReformat="true" toShortenFQNames="true" value="void main(String[] args){ $END$ }">
|
||||||
<context>
|
<context>
|
||||||
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
||||||
</context>
|
</context>
|
||||||
|
|||||||
@@ -1,15 +1,26 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<templateSet group="Java//Instance 'main' methods for normal classes">
|
<templateSet group="Java//Instance 'main' methods for normal classes">
|
||||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.static.psvm"
|
||||||
name="psvm" toReformat="true" toShortenFQNames="true" value="static void main($STRING_ARGS$){ $END$ }">
|
name="psvm" toReformat="true" toShortenFQNames="true" value="static void main(){ $END$ }">
|
||||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
|
||||||
<context>
|
<context>
|
||||||
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
||||||
</context>
|
</context>
|
||||||
</template>
|
</template>
|
||||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.static.psvm"
|
||||||
name="main" toReformat="true" toShortenFQNames="true" value="static void main($STRING_ARGS$){ $END$ }">
|
name="main" toReformat="true" toShortenFQNames="true" value="static void main(){ $END$ }">
|
||||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
<context>
|
||||||
|
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
||||||
|
</context>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.static.psvma"
|
||||||
|
name="psvma" toReformat="true" toShortenFQNames="true" value="static void main(String[] args){ $END$ }">
|
||||||
|
<context>
|
||||||
|
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
||||||
|
</context>
|
||||||
|
</template>
|
||||||
|
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.static.psvma"
|
||||||
|
name="maina" toReformat="true" toShortenFQNames="true" value="static void main(String[] args){ $END$ }">
|
||||||
<context>
|
<context>
|
||||||
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
||||||
</context>
|
</context>
|
||||||
|
|||||||
Reference in New Issue
Block a user