to kotlin
This commit is contained in:
committed by
Pavel V. Talanov
parent
10a0f55026
commit
2a679f9968
@@ -196,7 +196,7 @@ public class Converter {
|
|||||||
private static List<Parameter> createParametersFromFields(@NotNull List<? extends Field> fields) {
|
private static List<Parameter> createParametersFromFields(@NotNull List<? extends Field> fields) {
|
||||||
List<Parameter> result = new LinkedList<Parameter>();
|
List<Parameter> result = new LinkedList<Parameter>();
|
||||||
for (Field f : fields)
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,7 +669,8 @@ public class Converter {
|
|||||||
public Parameter parameterToParameter(@NotNull PsiParameter parameter) {
|
public Parameter parameterToParameter(@NotNull PsiParameter parameter) {
|
||||||
return new Parameter(
|
return new Parameter(
|
||||||
new IdentifierImpl(parameter.getName()),
|
new IdentifierImpl(parameter.getName()),
|
||||||
typeToType(parameter.getType(), ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList()))
|
typeToType(parameter.getType(), ConverterUtil.isAnnotatedAsNotNull(parameter.getModifierList())),
|
||||||
|
false
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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<Parameter> myParameters;
|
|
||||||
|
|
||||||
public ParameterList(List<Parameter> parameters) {
|
|
||||||
myParameters = parameters;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return AstUtil.joinNodes(myParameters, COMMA_WITH_SPACE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
|
import java.util.List
|
||||||
|
|
||||||
|
public open class ParameterList(val parameters : List<Parameter>) : Expression() {
|
||||||
|
public override fun toKotlin() = parameters.map { it.toKotlin() }.makeString(", ")
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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() + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package org.jetbrains.jet.j2k.ast
|
||||||
|
|
||||||
|
|
||||||
|
public open class ParenthesizedExpression(val expression : Expression) : Expression() {
|
||||||
|
public override fun toKotlin() = "(" + expression.toKotlin() + ")"
|
||||||
|
}
|
||||||
@@ -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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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() + ")";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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() + ")"
|
||||||
|
}
|
||||||
@@ -61,6 +61,6 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
|||||||
}
|
}
|
||||||
|
|
||||||
public override fun visitParameterList(list : PsiParameterList?) : Unit {
|
public override fun visitParameterList(list : PsiParameterList?) : Unit {
|
||||||
myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters()))
|
myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters()).requireNoNulls())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class StatementVisitor extends ElementVisitor {
|
|||||||
public void visitBreakStatement(@NotNull PsiBreakStatement statement) {
|
public void visitBreakStatement(@NotNull PsiBreakStatement statement) {
|
||||||
super.visitBreakStatement(statement);
|
super.visitBreakStatement(statement);
|
||||||
if (statement.getLabelIdentifier() == null) {
|
if (statement.getLabelIdentifier() == null) {
|
||||||
myResult = new BreakStatement();
|
myResult = new BreakStatement(Identifier.EMPTY_IDENTIFIER);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
myResult = new BreakStatement(
|
myResult = new BreakStatement(
|
||||||
|
|||||||
Reference in New Issue
Block a user