diff --git a/idea/resources/liveTemplates/Kotlin.xml b/idea/resources/liveTemplates/Kotlin.xml
index 2c35f8e6d00..53c46e1b935 100644
--- a/idea/resources/liveTemplates/Kotlin.xml
+++ b/idea/resources/liveTemplates/Kotlin.xml
@@ -48,7 +48,22 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties
index 26f81e9529c..94215905798 100644
--- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties
+++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties
@@ -89,6 +89,8 @@ goto.super.class.chooser.title=Choose super class or interface
livetemplate.description.main=main() function
livetemplate.description.soutp=Prints function parameter names and values to System.out
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.fun0=Function with no parameters
livetemplate.description.fun1=Function with one parameter
diff --git a/idea/src/org/jetbrains/jet/plugin/liveTemplates/macro/JetSuggestVariableNameMacro.java b/idea/src/org/jetbrains/jet/plugin/liveTemplates/macro/JetSuggestVariableNameMacro.java
index ca995766145..92a47c72d82 100644
--- a/idea/src/org/jetbrains/jet/plugin/liveTemplates/macro/JetSuggestVariableNameMacro.java
+++ b/idea/src/org/jetbrains/jet/plugin/liveTemplates/macro/JetSuggestVariableNameMacro.java
@@ -16,14 +16,14 @@
package org.jetbrains.jet.plugin.liveTemplates.macro;
-import com.intellij.codeInsight.template.Expression;
-import com.intellij.codeInsight.template.ExpressionContext;
-import com.intellij.codeInsight.template.Macro;
-import com.intellij.codeInsight.template.Result;
+import com.intellij.openapi.project.Project;
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;
-public class JetSuggestVariableNameMacro extends Macro {
+public class JetSuggestVariableNameMacro extends BaseJetVariableMacro {
@Override
public String getName() {
return "kotlinSuggestVariableName";
@@ -35,7 +35,12 @@ public class JetSuggestVariableNameMacro extends Macro {
}
@Override
- public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
- return null; //TODO
+ protected boolean isSuitable(
+ @NotNull VariableDescriptor variableDescriptor,
+ @NotNull JetScope scope,
+ @NotNull Project project,
+ ExpressionTypingServices callResolverContext
+ ) {
+ return variableDescriptor.getType().isNullable();
}
}
diff --git a/idea/testData/templates/ifn.exp.kt b/idea/testData/templates/ifn.exp.kt
new file mode 100644
index 00000000000..97941bf89b2
--- /dev/null
+++ b/idea/testData/templates/ifn.exp.kt
@@ -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) {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/templates/ifn.kt b/idea/testData/templates/ifn.kt
new file mode 100644
index 00000000000..de2f86ef50a
--- /dev/null
+++ b/idea/testData/templates/ifn.kt
@@ -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? = ""
+
+
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/templates/inn.exp.kt b/idea/testData/templates/inn.exp.kt
new file mode 100644
index 00000000000..6e8638c2cf8
--- /dev/null
+++ b/idea/testData/templates/inn.exp.kt
@@ -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) {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/idea/testData/templates/inn.kt b/idea/testData/templates/inn.kt
new file mode 100644
index 00000000000..de2f86ef50a
--- /dev/null
+++ b/idea/testData/templates/inn.kt
@@ -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? = ""
+
+
+ }
+}
\ No newline at end of file
diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java
index 3ebe3730a6f..cd13a9ec0de 100644
--- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java
+++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java
@@ -198,7 +198,22 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase {
checkAfter();
}
+ private void doTestIfnInn() {
+ start();
+ assertStringItems("b", "t", "y");
+ typeAndNextTab("b");
+
+ checkAfter();
+ }
+
+ public void testIfn() {
+ doTestIfnInn();
+ }
+
+ public void testInn() {
+ doTestIfnInn();
+ }
private void paremeterless() {
start();