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); 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 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/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/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/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/testData/templates/interface.exp.kt b/idea/testData/templates/interface.exp.kt new file mode 100644 index 00000000000..9363c7e4379 --- /dev/null +++ b/idea/testData/templates/interface.exp.kt @@ -0,0 +1,3 @@ +trait SomeTrait { + +} \ No newline at end of file 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/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/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/testData/templates/main.exp.kt b/idea/testData/templates/main.exp.kt new file mode 100644 index 00000000000..0876a3bf7d2 --- /dev/null +++ b/idea/testData/templates/main.exp.kt @@ -0,0 +1,3 @@ +fun main(args : Array) { + +} \ No newline at end of file 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/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/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/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/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/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/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 2c65045b33c..dc2d66dfda3 100644 --- a/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java +++ b/idea/tests/org/jetbrains/jet/plugin/codeInsight/LiveTemplatesTest.java @@ -5,12 +5,16 @@ 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.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; @@ -25,12 +29,213 @@ import java.util.Arrays; * @since 2/10/12 */ public class LiveTemplatesTest extends LightCodeInsightFixtureTestCase { + public void testSout() { + paremeterless(); + } + + public void testSerr() { + paremeterless(); + } + + public void testMain() { + paremeterless(); + } + + public void testSoutv() { + start(); + + assertStringItems("args", "x", "y"); + typeAndNextTab("y"); + + checkAfter(); + } + + public void testSoutp() { + 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 testExfun() { + start(); + + typeAndNextTab("Int"); + typeAndNextTab("foo"); + typeAndNextTab("arg : Int"); + nextTab(); + + checkAfter(); + } + + public void testExval() { + start(); + + typeAndNextTab("Int"); + nextTab(); + typeAndNextTab("Int"); + + checkAfter(); + } + + public void testExvar() { + start(); + + typeAndNextTab("Int"); + nextTab(); + typeAndNextTab("Int"); + + checkAfter(); + } + + public void testClosure() { + start(); + + typeAndNextTab("param"); + nextTab(); + + checkAfter(); + } + + public void testInterface() { + start(); + + typeAndNextTab("SomeTrait"); + + checkAfter(); + } + + public void testSingleton() { + start(); + + typeAndNextTab("MySingleton"); + + checkAfter(); + } + + public void testVoid() { + start(); + + typeAndNextTab("foo"); + typeAndNextTab("x : Int"); + + checkAfter(); + } + public void testIter() { - myFixture.configureByFile(getTestName(false) + ".kt"); - myFixture.type("iter"); + start(); + + assertStringItems("args", "collection", "myList", "str", "stream"); + type("args"); + nextTab(2); + + checkAfter(); + } + + public void testAnonymous_1() { + start(); + + typeAndNextTab("Runnable"); + + checkAfter(); + } + + public void testAnonymous_2() { + start(); + + typeAndNextTab("Thread"); + + checkAfter(); + } + + + + private void paremeterless() { + start(); + + checkAfter(); + } + + private void start() { + myFixture.configureByFile(getTestName(true) + ".kt"); + myFixture.type(getTemplateName()); doAction("ExpandLiveTemplateByTab"); - assertStringItems("args", "collection", "myList", "str", "stream"); + } + + 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", true); + } + + private void typeAndNextTab(String s) { + type(s); + 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) { + myFixture.type(s); + } + + private void nextTab() { + getTemplateState().nextTab(); + } + + private void nextTab(int times) { + for (int i = 0; i < times; i++) { + nextTab(); + } + } + + private TemplateState getTemplateState() { + return TemplateManagerImpl.getTemplateState(myFixture.getEditor()); } @NotNull @@ -59,10 +264,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); }