mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-14 18:05:27 +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.RightSideTypeMacro"/>
|
||||
<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.IterableComponentTypeMacro"/>
|
||||
<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>
|
||||
""");
|
||||
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);
|
||||
LookupElement[] elements = myFixture.getLookupElements();
|
||||
LookupElement last = elements[elements.length - 1];
|
||||
myFixture.getLookup().setCurrentItem(last);
|
||||
myFixture.finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
myFixture.checkResult(
|
||||
"""
|
||||
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");
|
||||
startTemplate(template);
|
||||
myFixture.type("\n");
|
||||
myFixture.checkResult(
|
||||
"""
|
||||
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.mx=Sets greater value to a variable
|
||||
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.lazy=Performs lazy initialization
|
||||
livetemplate.description.if.not.null=Inserts 'if not null' statement
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templateSet group="Java//Instance 'main' methods for implicitly declared classes">
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
||||
name="psvm" toReformat="true" toShortenFQNames="true" value="void main($STRING_ARGS$){ $END$ }">
|
||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
||||
name="psvm" toReformat="true" toShortenFQNames="true" value="void main(){ $END$ }">
|
||||
<context>
|
||||
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
||||
</context>
|
||||
</template>
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
||||
name="main" toReformat="true" toShortenFQNames="true" value="void main($STRING_ARGS$){ $END$ }">
|
||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
||||
name="main" toReformat="true" toShortenFQNames="true" value="void main(){ $END$ }">
|
||||
<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>
|
||||
<option name="JAVA_IMPLICIT_CLASS_DECLARATION" value="true" />
|
||||
</context>
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templateSet group="Java//Instance 'main' methods for normal classes">
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
||||
name="psvm" toReformat="true" toShortenFQNames="true" value="static void main($STRING_ARGS$){ $END$ }">
|
||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.static.psvm"
|
||||
name="psvm" toReformat="true" toShortenFQNames="true" value="static void main(){ $END$ }">
|
||||
<context>
|
||||
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
||||
</context>
|
||||
</template>
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.psvm"
|
||||
name="main" toReformat="true" toShortenFQNames="true" value="static void main($STRING_ARGS$){ $END$ }">
|
||||
<variable name="STRING_ARGS" expression="stringArgs()" defaultValue="" alwaysStopAt="false" />
|
||||
<template resource-bundle="messages.CodeInsightBundle" key="livetemplate.description.short.static.psvm"
|
||||
name="main" toReformat="true" toShortenFQNames="true" value="static void main(){ $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="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>
|
||||
<option name="JAVA_NORMAL_CLASS_DECLARATION_WITH_INSTANCE_MAIN" value="true" />
|
||||
</context>
|
||||
|
||||
Reference in New Issue
Block a user