From 7fb880e585e242ab8d74d0027c697065b7e9969c Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Mon, 13 Feb 2012 21:30:14 +0400 Subject: [PATCH 01/16] fix constructor signature write fix after ace34b01bc941db4bff14413dc83a5597f0ba4ed --- .../org/jetbrains/jet/codegen/ImplementationBodyCodegen.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index a75901720c5..a7ce5d6ae09 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -460,9 +460,9 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { consArgTypes.add(insert++, new JvmMethodParameterSignature(t, "", JvmMethodParameterKind.SHARED_VAR)); } } - } - constructorMethod = JvmMethodSignature.simple("", Type.VOID_TYPE, consArgTypes); + constructorMethod = JvmMethodSignature.simple("", Type.VOID_TYPE, consArgTypes); + } int flags = ACC_PUBLIC; // TODO final MethodVisitor mv = v.newMethod(myClass, flags, constructorMethod.getName(), constructorMethod.getAsmMethod().getDescriptor(), constructorMethod.getGenericsSignature(), null); From 53e643ca33795394c8ae13b00767813aea1c1f26 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 20:49:11 +0400 Subject: [PATCH 02/16] Added checking of result in LiveTemplatesTest. --- idea/testData/templates/Iter.exp.kt | 18 ++++++++++++++++++ .../plugin/codeInsight/LiveTemplatesTest.java | 12 ++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 idea/testData/templates/Iter.exp.kt diff --git a/idea/testData/templates/Iter.exp.kt b/idea/testData/templates/Iter.exp.kt new file mode 100644 index 00000000000..2e6d275892f --- /dev/null +++ b/idea/testData/templates/Iter.exp.kt @@ -0,0 +1,18 @@ +import java.io.InputStream +import java.util.ArrayList +import java.io.FileInputStream +import java.util.HashSet + +class MyClass { + public var collection : HashSet? = null + private var isAlive : Boolean = false + + fun main(args : Array, v : Int) { + var str = "" + val myList = ArrayList() + val stream = FileInputStream(".") + for (i in args) { + + } + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index 2c65045b33c..ef7232bc45e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -5,6 +5,7 @@ import com.intellij.codeInsight.lookup.LookupEx; import com.intellij.codeInsight.lookup.LookupManager; import com.intellij.codeInsight.template.TemplateManager; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; +import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.ide.DataManager; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.editor.actionSystem.EditorActionManager; @@ -31,6 +32,17 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { doAction("ExpandLiveTemplateByTab"); assertStringItems("args", "collection", "myList", "str", "stream"); + + myFixture.type("args"); + + getTemplateState().nextTab(); + getTemplateState().nextTab(); + assertNull(getTemplateState()); + myFixture.checkResultByFile(getTestName(false) + ".exp.kt"); + } + + private TemplateState getTemplateState() { + return TemplateManagerImpl.getTemplateState(myFixture.getEditor()); } @NotNull From 468d31b5e86ae04547c1f47985a2ef27e81b870e Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 20:57:05 +0400 Subject: [PATCH 03/16] Refactored LiveTemplatesTest to make adding new tests simpler. --- .../plugin/codeInsight/LiveTemplatesTest.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index ef7232bc45e..ad87cb5faf8 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -27,20 +27,36 @@ import java.util.Arrays; */ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { public void testIter() { + start(); + + assertStringItems("args", "collection", "myList", "str", "stream"); + type("args"); + nextTab(); + nextTab(); + + checkAfter(); + } + + private void start() { myFixture.configureByFile(getTestName(false) + ".kt"); - myFixture.type("iter"); + myFixture.type(getTestName(true)); doAction("ExpandLiveTemplateByTab"); - assertStringItems("args", "collection", "myList", "str", "stream"); + } - myFixture.type("args"); - - getTemplateState().nextTab(); - getTemplateState().nextTab(); + private void checkAfter() { assertNull(getTemplateState()); myFixture.checkResultByFile(getTestName(false) + ".exp.kt"); } + private void type(String s) { + myFixture.type(s); + } + + private void nextTab() { + getTemplateState().nextTab(); + } + private TemplateState getTemplateState() { return TemplateManagerImpl.getTemplateState(myFixture.getEditor()); } @@ -71,10 +87,8 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { @Override protected void setUp() throws Exception { super.setUp(); - myFixture.setTestDataPath(new File(PluginTestCaseBase.getTestDataPathBase(), "/templates").getPath() + File.separator); - ((TemplateManagerImpl) TemplateManager.getInstance(getProject())).setTemplateTesting(true); } From 404921eb372e70b4526339a4f90a824fdba8b83b Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 20:59:54 +0400 Subject: [PATCH 04/16] Test file names to lower case. --- idea/testData/templates/{Iter.exp.kt => iter.exp.kt} | 0 idea/testData/templates/{Iter.kt => iter.kt} | 0 .../jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java | 4 ++-- 3 files changed, 2 insertions(+), 2 deletions(-) rename idea/testData/templates/{Iter.exp.kt => iter.exp.kt} (100%) rename idea/testData/templates/{Iter.kt => iter.kt} (100%) diff --git a/idea/testData/templates/Iter.exp.kt b/idea/testData/templates/iter.exp.kt similarity index 100% rename from idea/testData/templates/Iter.exp.kt rename to idea/testData/templates/iter.exp.kt diff --git a/idea/testData/templates/Iter.kt b/idea/testData/templates/iter.kt similarity index 100% rename from idea/testData/templates/Iter.kt rename to idea/testData/templates/iter.kt diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index ad87cb5faf8..c9d0281f18e 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -38,7 +38,7 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { } private void start() { - myFixture.configureByFile(getTestName(false) + ".kt"); + myFixture.configureByFile(getTestName(true) + ".kt"); myFixture.type(getTestName(true)); doAction("ExpandLiveTemplateByTab"); @@ -46,7 +46,7 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { private void checkAfter() { assertNull(getTemplateState()); - myFixture.checkResultByFile(getTestName(false) + ".exp.kt"); + myFixture.checkResultByFile(getTestName(true) + ".exp.kt"); } private void type(String s) { From 5e408f13f55aa94ff98bad401bf62901840fd0ee Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:03:22 +0400 Subject: [PATCH 05/16] Added test four sout/serr. --- idea/testData/templates/serr.exp.kt | 3 +++ idea/testData/templates/serr.kt | 3 +++ idea/testData/templates/sout.exp.kt | 3 +++ idea/testData/templates/sout.kt | 3 +++ .../jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java | 6 ++++++ 5 files changed, 18 insertions(+) create mode 100644 idea/testData/templates/serr.exp.kt create mode 100644 idea/testData/templates/serr.kt create mode 100644 idea/testData/templates/sout.exp.kt create mode 100644 idea/testData/templates/sout.kt diff --git a/idea/testData/templates/serr.exp.kt b/idea/testData/templates/serr.exp.kt new file mode 100644 index 00000000000..94baca416ae --- /dev/null +++ b/idea/testData/templates/serr.exp.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + System.err?.println() +} diff --git a/idea/testData/templates/serr.kt b/idea/testData/templates/serr.kt new file mode 100644 index 00000000000..27e64de1f8e --- /dev/null +++ b/idea/testData/templates/serr.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + +} diff --git a/idea/testData/templates/sout.exp.kt b/idea/testData/templates/sout.exp.kt new file mode 100644 index 00000000000..7634ec98167 --- /dev/null +++ b/idea/testData/templates/sout.exp.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + println() +} diff --git a/idea/testData/templates/sout.kt b/idea/testData/templates/sout.kt new file mode 100644 index 00000000000..27e64de1f8e --- /dev/null +++ b/idea/testData/templates/sout.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + +} diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index c9d0281f18e..aac4be2549f 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -26,6 +26,12 @@ import java.util.Arrays; * @since 2/10/12 */ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { + public void testSout() { + start(); + + checkAfter(); + } + public void testIter() { start(); From 98db9c741f1c1f01d8eb8bd9262974a791dfe840 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:07:09 +0400 Subject: [PATCH 06/16] Added test for main. --- idea/testData/templates/main.exp.kt | 3 +++ idea/testData/templates/main.kt | 0 .../plugin/codeInsight/LiveTemplatesTest.java | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 idea/testData/templates/main.exp.kt create mode 100644 idea/testData/templates/main.kt diff --git a/idea/testData/templates/main.exp.kt b/idea/testData/templates/main.exp.kt new file mode 100644 index 00000000000..27e64de1f8e --- /dev/null +++ b/idea/testData/templates/main.exp.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + +} diff --git a/idea/testData/templates/main.kt b/idea/testData/templates/main.kt new file mode 100644 index 00000000000..e69de29bb2d diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index aac4be2549f..39213b0a0fd 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -27,9 +27,15 @@ import java.util.Arrays; */ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { public void testSout() { - start(); + paremeterless(); + } - checkAfter(); + public void testSerr() { + paremeterless(); + } + + public void testMain() { + paremeterless(); } public void testIter() { @@ -43,6 +49,14 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { checkAfter(); } + + + private void paremeterless() { + start(); + + checkAfter(); + } + private void start() { myFixture.configureByFile(getTestName(true) + ".kt"); myFixture.type(getTestName(true)); From 1060e441373877df46b37e7deda4ee7ce40c86d7 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:11:13 +0400 Subject: [PATCH 07/16] Added test for soutv. --- idea/testData/templates/soutv.exp.kt | 5 +++++ idea/testData/templates/soutv.kt | 5 +++++ .../jet/plugin/codeInsight/LiveTemplatesTest.java | 10 ++++++++++ 3 files changed, 20 insertions(+) create mode 100644 idea/testData/templates/soutv.exp.kt create mode 100644 idea/testData/templates/soutv.kt diff --git a/idea/testData/templates/soutv.exp.kt b/idea/testData/templates/soutv.exp.kt new file mode 100644 index 00000000000..48cc752b70f --- /dev/null +++ b/idea/testData/templates/soutv.exp.kt @@ -0,0 +1,5 @@ +fun main(args : Array) { + val x = 5 + val y = "str" + println("y = ${y}") +} diff --git a/idea/testData/templates/soutv.kt b/idea/testData/templates/soutv.kt new file mode 100644 index 00000000000..613ecf17295 --- /dev/null +++ b/idea/testData/templates/soutv.kt @@ -0,0 +1,5 @@ +fun main(args : Array) { + val x = 5 + val y = "str" + +} diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index 39213b0a0fd..1cec8a29a6c 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -38,6 +38,16 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { paremeterless(); } + public void testSoutv() { + start(); + + assertStringItems("args", "x", "y"); + type("y"); + nextTab(); + + checkAfter(); + } + public void testIter() { start(); From db8fa0dd0a551541b062fb62f9b8553d4c7884ab Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:18:12 +0400 Subject: [PATCH 08/16] Added test for soutp. --- idea/testData/templates/soutp.exp.kt | 5 +++++ idea/testData/templates/soutp.kt | 5 +++++ .../jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java | 4 ++++ 3 files changed, 14 insertions(+) create mode 100644 idea/testData/templates/soutp.exp.kt create mode 100644 idea/testData/templates/soutp.kt diff --git a/idea/testData/templates/soutp.exp.kt b/idea/testData/templates/soutp.exp.kt new file mode 100644 index 00000000000..f2ea1f6b927 --- /dev/null +++ b/idea/testData/templates/soutp.exp.kt @@ -0,0 +1,5 @@ +fun main(args : Array) { + fun secondary(x : Int, y : Int) { + println("x = [${x}], y = [${y}]") + } +} diff --git a/idea/testData/templates/soutp.kt b/idea/testData/templates/soutp.kt new file mode 100644 index 00000000000..b76b88f16f9 --- /dev/null +++ b/idea/testData/templates/soutp.kt @@ -0,0 +1,5 @@ +fun main(args : Array) { + fun secondary(x : Int, y : Int) { + + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index 1cec8a29a6c..53d0f32b79c 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -48,6 +48,10 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { checkAfter(); } + public void testSoutp() { + paremeterless(); + } + public void testIter() { start(); From bb06bcab6cb9866da63043b4aeeb65be7b8eaab5 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:26:35 +0400 Subject: [PATCH 09/16] Added tests for fun0, fun1, fun2. --- idea/testData/templates/fun0.exp.kt | 3 ++ idea/testData/templates/fun0.kt | 1 + idea/testData/templates/fun1.exp.kt | 3 ++ idea/testData/templates/fun1.kt | 1 + idea/testData/templates/fun2.exp.kt | 3 ++ idea/testData/templates/fun2.kt | 1 + .../plugin/codeInsight/LiveTemplatesTest.java | 36 +++++++++++++++++-- 7 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 idea/testData/templates/fun0.exp.kt create mode 100644 idea/testData/templates/fun0.kt create mode 100644 idea/testData/templates/fun1.exp.kt create mode 100644 idea/testData/templates/fun1.kt create mode 100644 idea/testData/templates/fun2.exp.kt create mode 100644 idea/testData/templates/fun2.kt diff --git a/idea/testData/templates/fun0.exp.kt b/idea/testData/templates/fun0.exp.kt new file mode 100644 index 00000000000..9f0021f25c9 --- /dev/null +++ b/idea/testData/templates/fun0.exp.kt @@ -0,0 +1,3 @@ +fun foo() : Unit { + +} \ No newline at end of file diff --git a/idea/testData/templates/fun0.kt b/idea/testData/templates/fun0.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/fun0.kt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/idea/testData/templates/fun1.exp.kt b/idea/testData/templates/fun1.exp.kt new file mode 100644 index 00000000000..a6845e8fe7d --- /dev/null +++ b/idea/testData/templates/fun1.exp.kt @@ -0,0 +1,3 @@ +fun foo(x : Any) : Unit { + +} \ No newline at end of file diff --git a/idea/testData/templates/fun1.kt b/idea/testData/templates/fun1.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/fun1.kt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/idea/testData/templates/fun2.exp.kt b/idea/testData/templates/fun2.exp.kt new file mode 100644 index 00000000000..4a49344a3e4 --- /dev/null +++ b/idea/testData/templates/fun2.exp.kt @@ -0,0 +1,3 @@ +fun foo(x : Any, y : Any) : Unit { + +} \ No newline at end of file diff --git a/idea/testData/templates/fun2.kt b/idea/testData/templates/fun2.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/fun2.kt @@ -0,0 +1 @@ + \ 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 53d0f32b79c..879d56a5935 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -52,13 +52,39 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { paremeterless(); } + public void testFun0() { + start(); + + type("foo"); + nextTab(2); + + checkAfter(); + } + + public void testFun1() { + start(); + + type("foo"); + nextTab(4); + + checkAfter(); + } + + public void testFun2() { + start(); + + type("foo"); + nextTab(6); + + checkAfter(); + } + public void testIter() { start(); assertStringItems("args", "collection", "myList", "str", "stream"); type("args"); - nextTab(); - nextTab(); + nextTab(2); checkAfter(); } @@ -91,6 +117,12 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { getTemplateState().nextTab(); } + private void nextTab(int times) { + for (int i = 0; i < times; i++) { + nextTab(); + } + } + private TemplateState getTemplateState() { return TemplateManagerImpl.getTemplateState(myFixture.getEditor()); } From 1bd56b7121b30cde0b51c8ec472bd385681bb70e Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:35:30 +0400 Subject: [PATCH 10/16] Added tests for exfun/exval/exvar. --- idea/testData/templates/exfun.exp.kt | 3 ++ idea/testData/templates/exfun.kt | 1 + idea/testData/templates/exval.exp.kt | 4 ++ idea/testData/templates/exval.kt | 1 + idea/testData/templates/exvar.exp.kt | 7 ++++ idea/testData/templates/exvar.kt | 1 + .../plugin/codeInsight/LiveTemplatesTest.java | 39 ++++++++++++++++++- 7 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 idea/testData/templates/exfun.exp.kt create mode 100644 idea/testData/templates/exfun.kt create mode 100644 idea/testData/templates/exval.exp.kt create mode 100644 idea/testData/templates/exval.kt create mode 100644 idea/testData/templates/exvar.exp.kt create mode 100644 idea/testData/templates/exvar.kt diff --git a/idea/testData/templates/exfun.exp.kt b/idea/testData/templates/exfun.exp.kt new file mode 100644 index 00000000000..62b7baae450 --- /dev/null +++ b/idea/testData/templates/exfun.exp.kt @@ -0,0 +1,3 @@ +fun Int.foo(arg : Int) : Unit { + +} \ No newline at end of file diff --git a/idea/testData/templates/exfun.kt b/idea/testData/templates/exfun.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/exfun.kt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/idea/testData/templates/exval.exp.kt b/idea/testData/templates/exval.exp.kt new file mode 100644 index 00000000000..f3e8ea4ec7a --- /dev/null +++ b/idea/testData/templates/exval.exp.kt @@ -0,0 +1,4 @@ +val Int.v : Int +get() { + +} \ No newline at end of file diff --git a/idea/testData/templates/exval.kt b/idea/testData/templates/exval.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/exval.kt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/idea/testData/templates/exvar.exp.kt b/idea/testData/templates/exvar.exp.kt new file mode 100644 index 00000000000..bf56eeac055 --- /dev/null +++ b/idea/testData/templates/exvar.exp.kt @@ -0,0 +1,7 @@ +var Int.v : Int +get() { + +} +set(value) { + +} \ No newline at end of file diff --git a/idea/testData/templates/exvar.kt b/idea/testData/templates/exvar.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/exvar.kt @@ -0,0 +1 @@ + \ 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 879d56a5935..cd97e7680bb 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -42,8 +42,7 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { start(); assertStringItems("args", "x", "y"); - type("y"); - nextTab(); + typeAndNext("y"); checkAfter(); } @@ -79,6 +78,42 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { checkAfter(); } + public void testExfun() { + start(); + + typeAndNext("Int"); + typeAndNext("foo"); + typeAndNext("arg : Int"); + nextTab(); + + checkAfter(); + } + + public void testExval() { + start(); + + typeAndNext("Int"); + nextTab(); + typeAndNext("Int"); + + checkAfter(); + } + + public void testExvar() { + start(); + + typeAndNext("Int"); + nextTab(); + typeAndNext("Int"); + + checkAfter(); + } + + private void typeAndNext(String s) { + type(s); + nextTab(); + } + public void testIter() { start(); From c895f502f93b05f52495f41764e01ff6e438d110 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:38:33 +0400 Subject: [PATCH 11/16] Added test for closure template. --- idea/testData/templates/closure.exp.kt | 3 +++ idea/testData/templates/closure.kt | 3 +++ .../jet/plugin/codeInsight/LiveTemplatesTest.java | 13 +++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 idea/testData/templates/closure.exp.kt create mode 100644 idea/testData/templates/closure.kt diff --git a/idea/testData/templates/closure.exp.kt b/idea/testData/templates/closure.exp.kt new file mode 100644 index 00000000000..bf00def3787 --- /dev/null +++ b/idea/testData/templates/closure.exp.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + val someFun = {param -> param} +} diff --git a/idea/testData/templates/closure.kt b/idea/testData/templates/closure.kt new file mode 100644 index 00000000000..83464539e04 --- /dev/null +++ b/idea/testData/templates/closure.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + val someFun = +} diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index cd97e7680bb..3379270176c 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -109,9 +109,13 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { checkAfter(); } - private void typeAndNext(String s) { - type(s); + public void testClosure() { + start(); + + typeAndNext("param"); nextTab(); + + checkAfter(); } public void testIter() { @@ -144,6 +148,11 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { myFixture.checkResultByFile(getTestName(true) + ".exp.kt"); } + private void typeAndNext(String s) { + type(s); + nextTab(); + } + private void type(String s) { myFixture.type(s); } From 1c8ca38380ebfee820547bd510c4864adc821a49 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:39:48 +0400 Subject: [PATCH 12/16] Added tests for interface and singleton. --- idea/testData/templates/interface.exp.kt | 3 ++ idea/testData/templates/interface.kt | 1 + idea/testData/templates/singleton.exp.kt | 3 ++ idea/testData/templates/singleton.kt | 1 + .../plugin/codeInsight/LiveTemplatesTest.java | 36 +++++++++++++------ 5 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 idea/testData/templates/interface.exp.kt create mode 100644 idea/testData/templates/interface.kt create mode 100644 idea/testData/templates/singleton.exp.kt create mode 100644 idea/testData/templates/singleton.kt diff --git a/idea/testData/templates/interface.exp.kt b/idea/testData/templates/interface.exp.kt new file mode 100644 index 00000000000..581d785ebb6 --- /dev/null +++ b/idea/testData/templates/interface.exp.kt @@ -0,0 +1,3 @@ +trait SomeTrait { + +} diff --git a/idea/testData/templates/interface.kt b/idea/testData/templates/interface.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/interface.kt @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/idea/testData/templates/singleton.exp.kt b/idea/testData/templates/singleton.exp.kt new file mode 100644 index 00000000000..05d8d27dd25 --- /dev/null +++ b/idea/testData/templates/singleton.exp.kt @@ -0,0 +1,3 @@ +object MySingleton { + +} \ No newline at end of file diff --git a/idea/testData/templates/singleton.kt b/idea/testData/templates/singleton.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/singleton.kt @@ -0,0 +1 @@ + \ 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 3379270176c..d0f3a4b3f9b 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -42,7 +42,7 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { start(); assertStringItems("args", "x", "y"); - typeAndNext("y"); + typeAndNextTab("y"); checkAfter(); } @@ -81,9 +81,9 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { public void testExfun() { start(); - typeAndNext("Int"); - typeAndNext("foo"); - typeAndNext("arg : Int"); + typeAndNextTab("Int"); + typeAndNextTab("foo"); + typeAndNextTab("arg : Int"); nextTab(); checkAfter(); @@ -92,9 +92,9 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { public void testExval() { start(); - typeAndNext("Int"); + typeAndNextTab("Int"); nextTab(); - typeAndNext("Int"); + typeAndNextTab("Int"); checkAfter(); } @@ -102,9 +102,9 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { public void testExvar() { start(); - typeAndNext("Int"); + typeAndNextTab("Int"); nextTab(); - typeAndNext("Int"); + typeAndNextTab("Int"); checkAfter(); } @@ -112,12 +112,28 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { public void testClosure() { start(); - typeAndNext("param"); + typeAndNextTab("param"); nextTab(); checkAfter(); } + public void testInterface() { + start(); + + typeAndNextTab("SomeTrait"); + + checkAfter(); + } + + public void testSingleton() { + start(); + + typeAndNextTab("MySingleton"); + + checkAfter(); + } + public void testIter() { start(); @@ -148,7 +164,7 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { myFixture.checkResultByFile(getTestName(true) + ".exp.kt"); } - private void typeAndNext(String s) { + private void typeAndNextTab(String s) { type(s); nextTab(); } From a790616eef80b2b3a3f2b2e063554404c05576ec Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 21:42:39 +0400 Subject: [PATCH 13/16] Added test for 'void' live template. --- idea/testData/templates/void.exp.kt | 3 +++ idea/testData/templates/void.kt | 1 + .../jet/plugin/codeInsight/LiveTemplatesTest.java | 9 +++++++++ 3 files changed, 13 insertions(+) create mode 100644 idea/testData/templates/void.exp.kt create mode 100644 idea/testData/templates/void.kt diff --git a/idea/testData/templates/void.exp.kt b/idea/testData/templates/void.exp.kt new file mode 100644 index 00000000000..50da812f4df --- /dev/null +++ b/idea/testData/templates/void.exp.kt @@ -0,0 +1,3 @@ +fun foo(x : Int) { + +} \ No newline at end of file diff --git a/idea/testData/templates/void.kt b/idea/testData/templates/void.kt new file mode 100644 index 00000000000..81389d50841 --- /dev/null +++ b/idea/testData/templates/void.kt @@ -0,0 +1 @@ + \ 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 d0f3a4b3f9b..b1ec7e915c9 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -134,6 +134,15 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { checkAfter(); } + public void testVoid() { + start(); + + typeAndNextTab("foo"); + typeAndNextTab("x : Int"); + + checkAfter(); + } + public void testIter() { start(); From 8c75c408c16fdd09cd6699b34056a6ba5862a3d6 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 22:04:41 +0400 Subject: [PATCH 14/16] Added tests for anonymous template --- idea/testData/templates/anonymous_1.exp.kt | 10 ++++ idea/testData/templates/anonymous_1.kt | 5 ++ idea/testData/templates/anonymous_2.exp.kt | 7 +++ idea/testData/templates/anonymous_2.kt | 5 ++ .../plugin/codeInsight/LiveTemplatesTest.java | 48 +++++++++++++++++-- 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 idea/testData/templates/anonymous_1.exp.kt create mode 100644 idea/testData/templates/anonymous_1.kt create mode 100644 idea/testData/templates/anonymous_2.exp.kt create mode 100644 idea/testData/templates/anonymous_2.kt diff --git a/idea/testData/templates/anonymous_1.exp.kt b/idea/testData/templates/anonymous_1.exp.kt new file mode 100644 index 00000000000..e319b8a07f9 --- /dev/null +++ b/idea/testData/templates/anonymous_1.exp.kt @@ -0,0 +1,10 @@ +import javax.swing.SwingUtilities + +fun main(args : Array) { + SwingUtilities.invokeLater(object : Runnable { + + override fun run() { + throw UnsupportedOperationException() + } + }) +} diff --git a/idea/testData/templates/anonymous_1.kt b/idea/testData/templates/anonymous_1.kt new file mode 100644 index 00000000000..9a31e402c33 --- /dev/null +++ b/idea/testData/templates/anonymous_1.kt @@ -0,0 +1,5 @@ +import javax.swing.SwingUtilities + +fun main(args : Array) { + SwingUtilities.invokeLater() +} diff --git a/idea/testData/templates/anonymous_2.exp.kt b/idea/testData/templates/anonymous_2.exp.kt new file mode 100644 index 00000000000..cdc6ddbf363 --- /dev/null +++ b/idea/testData/templates/anonymous_2.exp.kt @@ -0,0 +1,7 @@ +import javax.swing.SwingUtilities + +fun main(args : Array) { + SwingUtilities.invokeLater(object : Thread() { + + }) +} diff --git a/idea/testData/templates/anonymous_2.kt b/idea/testData/templates/anonymous_2.kt new file mode 100644 index 00000000000..9a31e402c33 --- /dev/null +++ b/idea/testData/templates/anonymous_2.kt @@ -0,0 +1,5 @@ +import javax.swing.SwingUtilities + +fun main(args : Array) { + SwingUtilities.invokeLater() +} diff --git a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java index b1ec7e915c9..dc2d66dfda3 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -7,11 +7,14 @@ import com.intellij.codeInsight.template.TemplateManager; import com.intellij.codeInsight.template.impl.TemplateManagerImpl; import com.intellij.codeInsight.template.impl.TemplateState; import com.intellij.ide.DataManager; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.command.CommandProcessor; import com.intellij.openapi.editor.actionSystem.EditorActionHandler; import com.intellij.openapi.editor.actionSystem.EditorActionManager; import com.intellij.testFramework.LightProjectDescriptor; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; import com.intellij.util.ArrayUtil; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor; @@ -153,6 +156,22 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { checkAfter(); } + public void testAnonymous_1() { + start(); + + typeAndNextTab("Runnable"); + + checkAfter(); + } + + public void testAnonymous_2() { + start(); + + typeAndNextTab("Thread"); + + checkAfter(); + } + private void paremeterless() { @@ -163,19 +182,42 @@ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { private void start() { myFixture.configureByFile(getTestName(true) + ".kt"); - myFixture.type(getTestName(true)); + myFixture.type(getTemplateName()); doAction("ExpandLiveTemplateByTab"); } + private String getTemplateName() { + String testName = getTestName(true); + if (testName.contains("_")) { + return testName.substring(0, testName.indexOf("_")); + } + return testName; + } + private void checkAfter() { assertNull(getTemplateState()); - myFixture.checkResultByFile(getTestName(true) + ".exp.kt"); + myFixture.checkResultByFile(getTestName(true) + ".exp.kt", true); } private void typeAndNextTab(String s) { type(s); - nextTab(); + UIUtil.invokeAndWaitIfNeeded(new Runnable() { + @Override + public void run() { + CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() { + @Override + public void run() { + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + nextTab(); + } + }); + } + }, "nextTab", null); + } + }); } private void type(String s) { From 37eb7d7e632d444737ad5003aee163ea6ca9d227 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Mon, 13 Feb 2012 22:28:51 +0400 Subject: [PATCH 15/16] Removed trailing newline characters in test cases for 'interface' and 'main' live templates. --- idea/testData/templates/interface.exp.kt | 2 +- idea/testData/templates/main.exp.kt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/idea/testData/templates/interface.exp.kt b/idea/testData/templates/interface.exp.kt index 581d785ebb6..9363c7e4379 100644 --- a/idea/testData/templates/interface.exp.kt +++ b/idea/testData/templates/interface.exp.kt @@ -1,3 +1,3 @@ trait SomeTrait { -} +} \ No newline at end of file diff --git a/idea/testData/templates/main.exp.kt b/idea/testData/templates/main.exp.kt index 27e64de1f8e..0876a3bf7d2 100644 --- a/idea/testData/templates/main.exp.kt +++ b/idea/testData/templates/main.exp.kt @@ -1,3 +1,3 @@ fun main(args : Array) { -} +} \ No newline at end of file From e3fdc5d595247d80c3485bec50470f3f71a34ad1 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Mon, 13 Feb 2012 23:34:01 +0400 Subject: [PATCH 16/16] fix a case of fake override of abstract and non-abstract function === open class Ccc() { fun foo() = 1 } trait Ttt { fun foo(): Int } class Zzz() : Ccc(), Ttt // there must not be an error here === Reported by Andrey Breslav as a bug of Comparator implementation: === fun comparator(f: (T, T) -> Int): Comparator = object : Comparator, Object() { override fun compare(o1: T, o2: T): Int = f(o1, o2) } === --- .../jetbrains/jet/lang/resolve/OverrideResolver.java | 10 +++++++++- .../override/FakeOverrideAbstractAndNonAbstractFun.jet | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.jet diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java index b51f51a91af..673239d71c4 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/OverrideResolver.java @@ -357,7 +357,15 @@ public class OverrideResolver { abstractNoImpl.add(single); } } else { - manyImpl.addAll(overridenDeclarations); + List nonAbstractManyImpl = Lists.newArrayList(); + for (CallableMemberDescriptor overriden : overridenDeclarations) { + if (overriden.getModality() != Modality.ABSTRACT) { + nonAbstractManyImpl.add(overriden); + } + } + if (nonAbstractManyImpl.size() > 1) { + manyImpl.addAll(nonAbstractManyImpl); + } } } } diff --git a/compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.jet b/compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.jet new file mode 100644 index 00000000000..4ba1095f8fb --- /dev/null +++ b/compiler/testData/diagnostics/tests/override/FakeOverrideAbstractAndNonAbstractFun.jet @@ -0,0 +1,9 @@ +open class Ccc() { + fun foo() = 1 +} + +trait Ttt { + fun foo(): Int +} + +class Zzz() : Ccc(), Ttt