diff --git a/src/org/jetbrains/jet/j2k/Converter.java b/src/org/jetbrains/jet/j2k/Converter.java index 20cb5ae68cb..84531d4877e 100644 --- a/src/org/jetbrains/jet/j2k/Converter.java +++ b/src/org/jetbrains/jet/j2k/Converter.java @@ -196,7 +196,7 @@ public class Converter { private static List createParametersFromFields(@NotNull List fields) { List result = new LinkedList(); for (Field f : fields) - result.add(new Parameter(new IdentifierImpl("_" + f.getIdentifier().getName()), f.getType())); + result.add(new Parameter(new IdentifierImpl("_" + f.getIdentifier().getName()), f.getType(), false)); return result; } @@ -669,7 +669,8 @@ public class Converter { public Parameter parameterToParameter(@NotNull PsiParameter parameter) { return new Parameter( new IdentifierImpl(parameter.getName()), - typeToType(parameter.getType(), ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())) + typeToType(parameter.getType(), ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())), + false ); } diff --git a/src/org/jetbrains/jet/j2k/ast/BreakStatement.java b/src/org/jetbrains/jet/j2k/ast/BreakStatement.java deleted file mode 100644 index c07b2fc6db8..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/BreakStatement.java +++ /dev/null @@ -1,48 +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; - -/** - * @author ignatov - */ -public class BreakStatement extends Statement { - private Identifier myLabel = Identifier.EMPTY_IDENTIFIER; - - public BreakStatement(Identifier label) { - myLabel = label; - } - - public BreakStatement() { - } - - @NotNull - @Override - public Kind getKind() { - return Kind.BREAK; - } - - @NotNull - @Override - public String toKotlin() { - if (myLabel.isEmpty()) { - return "break"; - } - return "break" + AT + myLabel.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/BreakStatement.kt b/src/org/jetbrains/jet/j2k/ast/BreakStatement.kt new file mode 100644 index 00000000000..45995d8ac78 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/BreakStatement.kt @@ -0,0 +1,10 @@ +package org.jetbrains.jet.j2k.ast + + +public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() { + public override fun getKind() : INode.Kind = INode.Kind.BREAK + + public override fun toKotlin() : String { + return if (label.isEmpty()) "break" else "break@" + label.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/CallChainExpression.java b/src/org/jetbrains/jet/j2k/ast/CallChainExpression.java deleted file mode 100644 index bd9fca6e9ba..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/CallChainExpression.java +++ /dev/null @@ -1,61 +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; - -/** - * @author ignatov - */ -public class CallChainExpression extends Expression { - private final Expression myExpression; - private final Expression myIdentifier; - - public Expression getIdentifier() { - return myIdentifier; - } - - @NotNull - @Override - public Kind getKind() { - return Kind.CALL_CHAIN; - } - - public CallChainExpression(Expression expression, Expression identifier) { - myExpression = expression; - myIdentifier = identifier; - } - - @Override - public boolean isNullable() { - return myIdentifier.isNullable(); - } - - @NotNull - @Override - public String toKotlin() { - if (!myExpression.isEmpty()) { - if (myExpression.isNullable()) { - return myExpression.toKotlin() + QUESTDOT + myIdentifier.toKotlin(); - } - else { - return myExpression.toKotlin() + DOT + myIdentifier.toKotlin(); - } - } - return myIdentifier.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/CallChainExpression.kt b/src/org/jetbrains/jet/j2k/ast/CallChainExpression.kt new file mode 100644 index 00000000000..69464a42327 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/CallChainExpression.kt @@ -0,0 +1,20 @@ +package org.jetbrains.jet.j2k.ast + +import a.h.id + + +public open class CallChainExpression(val expression : Expression, val identifier : Expression) : Expression() { + public override fun getKind() : INode.Kind { + return INode.Kind.CALL_CHAIN + } + + public override fun isNullable() : Boolean = identifier.isNullable() + + public override fun toKotlin() : String { + if (!expression.isEmpty()) { + return expression.toKotlin() + (if (expression.isNullable()) "?." else ".") + identifier.toKotlin() + } + + return identifier.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/Parameter.java b/src/org/jetbrains/jet/j2k/ast/Parameter.java deleted file mode 100644 index 39a522c8072..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/Parameter.java +++ /dev/null @@ -1,48 +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 Parameter extends Expression { - private final Identifier myIdentifier; - private final Type myType; - private boolean myReadOnly; - - public Parameter(Identifier identifier, Type type) { - myIdentifier = identifier; - myType = type; - myReadOnly = true; - } - - public Parameter(IdentifierImpl identifier, Type type, boolean readOnly) { - this(identifier, type); - myReadOnly = readOnly; - } - - @NotNull - @Override - public String toKotlin() { - String vararg = myType.getKind() == Kind.VARARG ? "vararg" + SPACE : EMPTY; - String var = myReadOnly ? EMPTY : "var" + SPACE; - return vararg + var + myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/Parameter.kt b/src/org/jetbrains/jet/j2k/ast/Parameter.kt new file mode 100644 index 00000000000..71a96be0c30 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/Parameter.kt @@ -0,0 +1,17 @@ +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class Parameter(val identifier : Identifier, val `type` : Type, val readOnly: Boolean = false) : Expression() { + public override fun toKotlin() : String { + val vararg : String = (if (`type`.getKind() == INode.Kind.VARARG) + "vararg" + " " + else + "") + val `var` : String? = (if (readOnly) + "" + else + "var" + " ") + return vararg + `var` + identifier.toKotlin() + " : " + `type`.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/ParameterList.java b/src/org/jetbrains/jet/j2k/ast/ParameterList.java deleted file mode 100644 index 7f26c4414eb..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ParameterList.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 org.jetbrains.jet.j2k.util.AstUtil; - -import java.util.List; - -/** - * @author ignatov - */ -public class ParameterList extends Expression { - private final List myParameters; - - public ParameterList(List parameters) { - myParameters = parameters; - } - - @NotNull - @Override - public String toKotlin() { - return AstUtil.joinNodes(myParameters, COMMA_WITH_SPACE); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/ParameterList.kt b/src/org/jetbrains/jet/j2k/ast/ParameterList.kt new file mode 100644 index 00000000000..1fd1a982fbe --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/ParameterList.kt @@ -0,0 +1,8 @@ +package org.jetbrains.jet.j2k.ast + +import java.util.List + +public open class ParameterList(val parameters : List) : Expression() { + public override fun toKotlin() = parameters.map { it.toKotlin() }.makeString(", ") +} + diff --git a/src/org/jetbrains/jet/j2k/ast/ParenthesizedExpression.java b/src/org/jetbrains/jet/j2k/ast/ParenthesizedExpression.java deleted file mode 100644 index 4f73f4ee719..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ParenthesizedExpression.java +++ /dev/null @@ -1,36 +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; - -/** - * @author ignatov - */ -public class ParenthesizedExpression extends Expression { - private final Expression myExpression; - - public ParenthesizedExpression(Expression expression) { - myExpression = expression; - } - - @NotNull - @Override - public String toKotlin() { - return "(" + myExpression.toKotlin() + ")"; - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/ParenthesizedExpression.kt b/src/org/jetbrains/jet/j2k/ast/ParenthesizedExpression.kt new file mode 100644 index 00000000000..5dd40be1a53 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/ParenthesizedExpression.kt @@ -0,0 +1,6 @@ +package org.jetbrains.jet.j2k.ast + + +public open class ParenthesizedExpression(val expression : Expression) : Expression() { + public override fun toKotlin() = "(" + expression.toKotlin() + ")" +} diff --git a/src/org/jetbrains/jet/j2k/ast/ThisExpression.java b/src/org/jetbrains/jet/j2k/ast/ThisExpression.java deleted file mode 100644 index b7bb054a91f..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/ThisExpression.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; - -/** - * @author ignatov - */ -public class ThisExpression extends Expression { - private final Identifier myIdentifier; - - public ThisExpression(Identifier identifier) { - myIdentifier = identifier; - } - - @NotNull - @Override - public String toKotlin() { - if (myIdentifier.isEmpty()) { - return "this"; - } - return "this" + AT + myIdentifier.toKotlin(); - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/ThisExpression.kt b/src/org/jetbrains/jet/j2k/ast/ThisExpression.kt new file mode 100644 index 00000000000..84928f4dceb --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/ThisExpression.kt @@ -0,0 +1,10 @@ +package org.jetbrains.jet.j2k.ast + +import a.h.id + + +public open class ThisExpression(val identifier: Identifier) : Expression() { + public override fun toKotlin() : String { + return if (identifier.isEmpty()) "this" else "this@" + identifier.toKotlin() + } +} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeCastExpression.java b/src/org/jetbrains/jet/j2k/ast/TypeCastExpression.java deleted file mode 100644 index 6f30b02f15a..00000000000 --- a/src/org/jetbrains/jet/j2k/ast/TypeCastExpression.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 org.jetbrains.jet.j2k.ast.types.Type; - -/** - * @author ignatov - */ -public class TypeCastExpression extends Expression { - private final Type myType; - private final Expression myExpression; - - public TypeCastExpression(Type type, Expression expression) { - myType = type; - myExpression = expression; - } - - @NotNull - @Override - public String toKotlin() { - return "(" + myExpression.toKotlin() + SPACE + "as" + SPACE + myType.toKotlin() + ")"; - } -} diff --git a/src/org/jetbrains/jet/j2k/ast/TypeCastExpression.kt b/src/org/jetbrains/jet/j2k/ast/TypeCastExpression.kt new file mode 100644 index 00000000000..65672003293 --- /dev/null +++ b/src/org/jetbrains/jet/j2k/ast/TypeCastExpression.kt @@ -0,0 +1,7 @@ +package org.jetbrains.jet.j2k.ast + +import org.jetbrains.jet.j2k.ast.types.Type + +public open class TypeCastExpression(val `type` : Type, val expression : Expression) : Expression() { + public override fun toKotlin() = "(" + expression.toKotlin() + " as " + `type`.toKotlin() + ")" +} diff --git a/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt b/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt index 312290e2811..c1e9dd926dc 100644 --- a/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt +++ b/src/org/jetbrains/jet/j2k/visitors/ElementVisitor.kt @@ -61,6 +61,6 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit } public override fun visitParameterList(list : PsiParameterList?) : Unit { - myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters())) + myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters()).requireNoNulls()) } } diff --git a/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.java b/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.java index 1cb4d33093b..88866b32932 100644 --- a/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.java +++ b/src/org/jetbrains/jet/j2k/visitors/StatementVisitor.java @@ -69,7 +69,7 @@ public class StatementVisitor extends ElementVisitor { public void visitBreakStatement(@NotNull PsiBreakStatement statement) { super.visitBreakStatement(statement); if (statement.getLabelIdentifier() == null) { - myResult = new BreakStatement(); + myResult = new BreakStatement(Identifier.EMPTY_IDENTIFIER); } else { myResult = new BreakStatement(