Implement "if null" / "if not null" live templates
This commit is contained in:
@@ -48,7 +48,22 @@
|
|||||||
<option name="KOTLIN_STATEMENT" value="true" />
|
<option name="KOTLIN_STATEMENT" value="true" />
|
||||||
</context>
|
</context>
|
||||||
</template>
|
</template>
|
||||||
|
<template resource-bundle="org.jetbrains.jet.plugin.JetBundle" key="livetemplate.description.ifn"
|
||||||
|
name="ifn" toReformat="true" toShortenFQNames="true"
|
||||||
|
value="if ($VAR$ == null) { $END$ }">
|
||||||
|
<variable alwaysStopAt="true" defaultValue=""i"" expression="kotlinSuggestVariableName()" name="VAR" />
|
||||||
|
<context>
|
||||||
|
<option name="KOTLIN_EXPRESSION" value="true" />
|
||||||
|
</context>
|
||||||
|
</template>
|
||||||
|
<template resource-bundle="org.jetbrains.jet.plugin.JetBundle" key="livetemplate.description.inn"
|
||||||
|
name="inn" toReformat="true" toShortenFQNames="true"
|
||||||
|
value="if ($VAR$ != null) { $END$ }">
|
||||||
|
<variable alwaysStopAt="true" defaultValue=""i"" expression="kotlinSuggestVariableName()" name="VAR" />
|
||||||
|
<context>
|
||||||
|
<option name="KOTLIN_EXPRESSION" value="true" />
|
||||||
|
</context>
|
||||||
|
</template>
|
||||||
<template resource-bundle="org.jetbrains.jet.plugin.JetBundle" key="livetemplate.description.void"
|
<template resource-bundle="org.jetbrains.jet.plugin.JetBundle" key="livetemplate.description.void"
|
||||||
name="void" toReformat="true" toShortenFQNames="true" value="fun $NAME$($PARAMS$) { $END$ }">
|
name="void" toReformat="true" toShortenFQNames="true" value="fun $NAME$($PARAMS$) { $END$ }">
|
||||||
<variable alwaysStopAt="true" defaultValue="" expression="" name="NAME" />
|
<variable alwaysStopAt="true" defaultValue="" expression="" name="NAME" />
|
||||||
|
|||||||
@@ -89,6 +89,8 @@ goto.super.class.chooser.title=Choose super class or interface
|
|||||||
livetemplate.description.main=main() function
|
livetemplate.description.main=main() function
|
||||||
livetemplate.description.soutp=Prints function parameter names and values to System.out
|
livetemplate.description.soutp=Prints function parameter names and values to System.out
|
||||||
livetemplate.description.iter=Iterate over elements of iterable
|
livetemplate.description.iter=Iterate over elements of iterable
|
||||||
|
livetemplate.description.ifn=Inserts ''if null'' expression
|
||||||
|
livetemplate.description.inn=Inserts ''if not null'' expression
|
||||||
livetemplate.description.void=Function returning nothing
|
livetemplate.description.void=Function returning nothing
|
||||||
livetemplate.description.fun0=Function with no parameters
|
livetemplate.description.fun0=Function with no parameters
|
||||||
livetemplate.description.fun1=Function with one parameter
|
livetemplate.description.fun1=Function with one parameter
|
||||||
|
|||||||
+12
-7
@@ -16,14 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.jet.plugin.liveTemplates.macro;
|
package org.jetbrains.jet.plugin.liveTemplates.macro;
|
||||||
|
|
||||||
import com.intellij.codeInsight.template.Expression;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.codeInsight.template.ExpressionContext;
|
|
||||||
import com.intellij.codeInsight.template.Macro;
|
|
||||||
import com.intellij.codeInsight.template.Result;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||||
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||||
import org.jetbrains.jet.plugin.JetBundle;
|
import org.jetbrains.jet.plugin.JetBundle;
|
||||||
|
|
||||||
public class JetSuggestVariableNameMacro extends Macro {
|
public class JetSuggestVariableNameMacro extends BaseJetVariableMacro {
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "kotlinSuggestVariableName";
|
return "kotlinSuggestVariableName";
|
||||||
@@ -35,7 +35,12 @@ public class JetSuggestVariableNameMacro extends Macro {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
|
protected boolean isSuitable(
|
||||||
return null; //TODO
|
@NotNull VariableDescriptor variableDescriptor,
|
||||||
|
@NotNull JetScope scope,
|
||||||
|
@NotNull Project project,
|
||||||
|
ExpressionTypingServices callResolverContext
|
||||||
|
) {
|
||||||
|
return variableDescriptor.getType().isNullable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
val a: String = ""
|
||||||
|
val b: String? = ""
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
val x: String = ""
|
||||||
|
val y: String? = ""
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val s: String = ""
|
||||||
|
val t: String? = ""
|
||||||
|
|
||||||
|
if (b == null) {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
val a: String = ""
|
||||||
|
val b: String? = ""
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
val x: String = ""
|
||||||
|
val y: String? = ""
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val s: String = ""
|
||||||
|
val t: String? = ""
|
||||||
|
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
val a: String = ""
|
||||||
|
val b: String? = ""
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
val x: String = ""
|
||||||
|
val y: String? = ""
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val s: String = ""
|
||||||
|
val t: String? = ""
|
||||||
|
|
||||||
|
if (b != null) {
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
val a: String = ""
|
||||||
|
val b: String? = ""
|
||||||
|
|
||||||
|
class MyClass {
|
||||||
|
val x: String = ""
|
||||||
|
val y: String? = ""
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val s: String = ""
|
||||||
|
val t: String? = ""
|
||||||
|
|
||||||
|
<caret>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -198,7 +198,22 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase {
|
|||||||
checkAfter();
|
checkAfter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void doTestIfnInn() {
|
||||||
|
start();
|
||||||
|
|
||||||
|
assertStringItems("b", "t", "y");
|
||||||
|
typeAndNextTab("b");
|
||||||
|
|
||||||
|
checkAfter();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIfn() {
|
||||||
|
doTestIfnInn();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testInn() {
|
||||||
|
doTestIfnInn();
|
||||||
|
}
|
||||||
|
|
||||||
private void paremeterless() {
|
private void paremeterless() {
|
||||||
start();
|
start();
|
||||||
|
|||||||
Reference in New Issue
Block a user