diff --git a/src/org/jetbrains/jet/j2k/ast/EnumConstant.java b/src/org/jetbrains/jet/j2k/ast/EnumConstant.java deleted file mode 100644 index 014165d33fb..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/EnumConstant.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.j2k.ast.types.Type; - -import java.util.Set; - -/** - * @author ignatov - */ -public class EnumConstant extends Field { - public EnumConstant(Identifier identifier, Set modifiers, @NotNull Type type, Element params) { - super(identifier, modifiers, type.convertedToNotNull(), params, 0); - } - - @NotNull - @Override - public String toKotlin() { - if (myInitializer.toKotlin().isEmpty()) { - return myIdentifier.toKotlin(); - } - return myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin() + "(" + myInitializer.toKotlin() + ")"; - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/EnumConstant.kt b/src/org/jetbrains/jet/j2k/ast/EnumConstant.kt new file mode 100644 index 00000000000..c88c6809112 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/EnumConstant.kt @@ -0,0 +1,20 @@ +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type +import java.util.Set + +public open class EnumConstant(identifier : Identifier, + modifiers : Set, + `type` : Type, + params : Element) : Field(identifier, modifiers, `type`.convertedToNotNull(), params, 0) { + + public override fun toKotlin() : String { + if (initializer.toKotlin().isEmpty()) { + return identifier.toKotlin() + } + + return identifier.toKotlin() + " : " + `type`.toKotlin() + "(" + initializer.toKotlin() + ")" + } + + +} diff --git a/src/org/jetbrains/jet/j2k/ast/Field.java b/src/org/jetbrains/jet/j2k/ast/Field.java deleted file mode 100644 index 91482dd8990..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/Field.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.j2k.ast.types.Type; -import org.jetbrains.jet.j2k.util.AstUtil; - -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - -import static org.jetbrains.jet.j2k.Converter.getDefaultInitializer; - -/** - * @author ignatov - */ -public class Field extends Member { - final Identifier myIdentifier; - private final int myWritingAccesses; - final Type myType; - final Element myInitializer; - - public Field(Identifier identifier, Set modifiers, Type type, Element initializer, int writingAccesses) { - super(modifiers); - myIdentifier = identifier; - myWritingAccesses = writingAccesses; - myType = type; - myInitializer = initializer; - } - - public Element getInitializer() { - return myInitializer; - } - - public Identifier getIdentifier() { - return myIdentifier; - } - - public Type getType() { - return myType; - } - - @NotNull - String modifiersToKotlin() { - List modifierList = new LinkedList(); - - if (isAbstract()) { - modifierList.add(Modifier.ABSTRACT); - } - - modifierList.add(accessModifier()); - - modifierList.add(isVal() ? "val" : "var"); - - if (modifierList.size() > 0) { - return AstUtil.join(modifierList, SPACE) + SPACE; - } - - return EMPTY; - } - - public boolean isVal() { - return myModifiers.contains(Modifier.FINAL); - } - - @Override - public boolean isStatic() { - return myModifiers.contains(Modifier.STATIC); - } - - @NotNull - @Override - public String toKotlin() { - final String declaration = modifiersToKotlin() + myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin(); - - if (myInitializer.isEmpty()) { - return declaration + (isVal() && !isStatic() && myWritingAccesses == 1 - ? EMPTY - : SPACE + EQUAL + SPACE + getDefaultInitializer(this)); - } - - return declaration + SPACE + EQUAL + SPACE + myInitializer.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/Field.kt b/src/org/jetbrains/jet/j2k/ast/Field.kt new file mode 100644 index 00000000000..9464f67ca28 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/Field.kt @@ -0,0 +1,51 @@ +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type +import org.jetbrains.jet.j2k.util.AstUtil +import java.util.LinkedList +import java.util.List +import java.util.Set +import org.jetbrains.jet.j2k.Converter.getDefaultInitializer + +public open class Field(val identifier : Identifier, + modifiers : Set, + val `type` : Type, + val initializer : Element, + val writingAccesses : Int) : Member(modifiers) { + + open fun modifiersToKotlin() : String { + val modifierList : List = arrayList() + if (isAbstract()) { + modifierList.add(Modifier.ABSTRACT) + } + + modifierList.add(accessModifier()) + modifierList.add(if (isVal()) "val" else "var") + if (modifierList.size() > 0) + { + return modifierList.makeString(" ") + " " + } + + return "" + } + + public open fun isVal() : Boolean { + return myModifiers.contains(Modifier.FINAL) + } + + public override fun isStatic() : Boolean { + return myModifiers.contains(Modifier.STATIC) + } + + public override fun toKotlin() : String { + val declaration : String? = modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin() + if (initializer.isEmpty()) { + return declaration + ((if (isVal() && !isStatic() && writingAccesses == 1) + "" + else + " = " + getDefaultInitializer(this))) + } + + return declaration + " = " + initializer.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Initializer.java b/src/org/jetbrains/jet/j2k/ast/Initializer.java deleted file mode 100644 index 80b86abb8e0..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/Initializer.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; - -import java.util.Set; - -/** - * @author ignatov - */ -public class Initializer extends Member { - private final Block myBlock; - - public Initializer(Block block, Set modifiers) { - super(modifiers); - myBlock = block; - } - - @NotNull - @Override - public String toKotlin() { - return myBlock.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/Initializer.kt b/src/org/jetbrains/jet/j2k/ast/Initializer.kt new file mode 100644 index 00000000000..5aa73e0c338 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/Initializer.kt @@ -0,0 +1,9 @@ +package org.jetbrains.jet.j2k.ast + +import java.util.Set + +public open class Initializer(val block : Block, modifiers : Set) : Member(modifiers) { + public override fun toKotlin() : String { + return block.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeElement.java b/src/org/jetbrains/jet/j2k/ast/TypeElement.java deleted file mode 100644 index eafbdc62b2d..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/TypeElement.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.j2k.ast.types.Type; - -/** - * @author ignatov - */ -public class TypeElement extends Element { - private final Type myType; - - public TypeElement(Type type) { - myType = type; - } - - @NotNull - @Override - public String toKotlin() { - return myType.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeElement.kt b/src/org/jetbrains/jet/j2k/ast/TypeElement.kt new file mode 100644 index 00000000000..7a3ce4871e2 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/TypeElement.kt @@ -0,0 +1,9 @@ +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class TypeElement(val `type` : Type) : Element() { + public override fun toKotlin() : String { + return `type`.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeParameter.java b/src/org/jetbrains/jet/j2k/ast/TypeParameter.java deleted file mode 100644 index f72d97f2e53..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/TypeParameter.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2010-2012 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.jet.j2k.ast; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.jet.j2k.ast.types.Type; - -import java.util.List; - -/** - * @author ignatov - */ -public class TypeParameter extends Element { - private final Identifier myName; - private final List myExtendsTypes; - - public TypeParameter(Identifier name, List extendsTypes) { - myName = name; - myExtendsTypes = extendsTypes; - } - - public boolean hasWhere() { - return myExtendsTypes.size() > 1; - } - - @NotNull - public String getWhereToKotlin() { - if (hasWhere()) { - return myName.toKotlin() + SPACE + COLON + SPACE + myExtendsTypes.get(1).toKotlin(); - } - return EMPTY; - } - - @NotNull - @Override - public String toKotlin() { - if (myExtendsTypes.size() > 0) { - return myName.toKotlin() + SPACE + COLON + SPACE + myExtendsTypes.get(0).toKotlin(); - } - return myName.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeParameter.kt b/src/org/jetbrains/jet/j2k/ast/TypeParameter.kt new file mode 100644 index 00000000000..9c2932f2312 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/TypeParameter.kt @@ -0,0 +1,23 @@ +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type +import java.util.List + +public open class TypeParameter(val name : Identifier, val extendsTypes : List) : Element() { + public open fun hasWhere() : Boolean = extendsTypes.size() > 1 + public open fun getWhereToKotlin() : String { + if (hasWhere()) { + return name.toKotlin() + " : " + extendsTypes.get(1).toKotlin() + } + + return "" + } + + public override fun toKotlin() : String { + if (extendsTypes.size() > 0) { + return name.toKotlin() + " : " + extendsTypes [0].toKotlin() + } + + return name.toKotlin() + } +}