diff --git a/src/org/jetbrains/jet/j2k/ast/Class.java b/src/org/jetbrains/jet/j2k/ast/Class.java index 90255375311..e36156529a3 100644 --- a/src/org/jetbrains/jet/j2k/ast/Class.java +++ b/src/org/jetbrains/jet/j2k/ast/Class.java @@ -29,6 +29,24 @@ public class Class extends Node { myFields = fields; } + private boolean hasWhere() { + for (Element t : myTypeParameters) + if (t instanceof TypeParameter && ((TypeParameter)t).hasWhere()) + return true; + return false; + } + + String typeParameterWhereToKotlin() { + if (hasWhere()) { + List wheres = new LinkedList(); + for (Element t : myTypeParameters) + if (t instanceof TypeParameter) + wheres.add(((TypeParameter)t).getWhereToKotlin()); + return SPACE + "where" + SPACE + AstUtil.join(wheres, COMMA_WITH_SPACE) + SPACE; + } + return EMPTY; + } + @NotNull List methodsExceptConstructors() { final LinkedList result = new LinkedList(); @@ -55,7 +73,10 @@ public class Class extends Node { @NotNull @Override public String toKotlin() { - return TYPE + SPACE + myName.toKotlin() + typeParametersToKotlin() + implementTypesToKotlin() + SPACE + "{" + N + + return TYPE + SPACE + myName.toKotlin() + typeParametersToKotlin() + + implementTypesToKotlin() + + typeParameterWhereToKotlin() + + SPACE + "{" + N + AstUtil.joinNodes(myFields, N) + N + AstUtil.joinNodes(methodsExceptConstructors(), N) + N + AstUtil.joinNodes(myInnerClasses, N) + N + diff --git a/test/org/jetbrains/jet/j2k/ast/TypeParametersTest.java b/test/org/jetbrains/jet/j2k/ast/TypeParametersTest.java index 56576185a51..1473dd6213e 100644 --- a/test/org/jetbrains/jet/j2k/ast/TypeParametersTest.java +++ b/test/org/jetbrains/jet/j2k/ast/TypeParametersTest.java @@ -36,4 +36,56 @@ public class TypeParametersTest extends JetTestCaseBase { "fun max(coll : Collection?) : T? where T : Comparable?, K : Collection? { }" ); } + + public void testClassDoubleParametrizationWithTwoBoundsWithExtending() throws Exception { + Assert.assertEquals( + classToSingleLineKotlin("final class CC , K extends Node & Collection> extends A {}"), + "class CC : A where T : Comparable?, K : Collection? { }" + ); + } + + public void testTraitDoubleParametrizationWithTwoBoundsWithExtending() throws Exception { + Assert.assertEquals( + classToSingleLineKotlin( + "interface I , K extends Node & Collection> extends II {}"), + "trait I : II where T : Comparable?, K : Collection? { }" + ); + } + + public void testGenericClass() throws Exception { + Assert.assertEquals( + classToSingleLineKotlin("final class Comparable {}"), + "class Comparable { }" + ); + } + + public void testComplexExampleWithClassExtending() throws Exception { + Assert.assertEquals( + classToSingleLineKotlin( + "interface CommandHandler {}"), + "trait CommandHandler { }" + ); + } + + public void testClassParametrizationWithTwoBounds() throws Exception { + Assert.assertEquals( + classToSingleLineKotlin("final class C> {}"), + "class C where T : Comparable? { }" + ); + } + + public void testClassParametrizationWithTwoBoundsWithExtending() throws Exception { + Assert.assertEquals( + classToSingleLineKotlin("final class C> extends A {}"), + "class C : A where T : Comparable? { }" + ); + } + + public void testComplexExampleWithClassMultiplyExtending() throws Exception { + Assert.assertEquals( + classToSingleLineKotlin( + "interface CommandHandler {}"), + "trait CommandHandler { }" + ); + } }