get rid of INode.Kind
This commit is contained in:
committed by
Pavel V. Talanov
parent
ae4404cdc4
commit
f88f07a6f5
@@ -134,10 +134,11 @@ public open class Converter() {
|
||||
for (s : Statement? in m.block!!.statements) {
|
||||
var isRemoved: Boolean = false
|
||||
if (s is AssignmentExpression) {
|
||||
if (s.left.getKind() == INode.Kind.CALL_CHAIN) {
|
||||
val assignee = s.left
|
||||
if (assignee is CallChainExpression) {
|
||||
for (fo : Field in finalOrWithEmptyInitializer) {
|
||||
val id: String = fo.identifier.toKotlin()
|
||||
if ((s.left as CallChainExpression).identifier.toKotlin().endsWith("." + id)) {
|
||||
if (assignee.identifier.toKotlin().endsWith("." + id)) {
|
||||
initializers.put(id, s.right.toKotlin())
|
||||
isRemoved = true
|
||||
}
|
||||
|
||||
@@ -33,10 +33,8 @@ public open class ArrayInitializerExpression(val `type` : Type, val initializers
|
||||
val afterReplace : String = innerTypeStr().replace(">", "").replace("<", "").replace("?", "")
|
||||
if (doubleOrFloatTypes.contains(afterReplace))
|
||||
{
|
||||
if (i.getKind() == INode.Kind.LITERAL)
|
||||
{
|
||||
if (i.toKotlin().contains("."))
|
||||
{
|
||||
if (i is LiteralExpression) {
|
||||
if (i.toKotlin().contains(".")) {
|
||||
return i.toKotlin()
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,8 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class ArrayWithoutInitializationExpression(val `type` : Type, val expressions : List<Expression>) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
if (`type`.getKind() == INode.Kind.ARRAY_TYPE)
|
||||
{
|
||||
return constructInnerType(`type` as ArrayType, expressions)
|
||||
if (`type` is ArrayType) {
|
||||
return constructInnerType(`type`, expressions)
|
||||
}
|
||||
|
||||
return getConstructorName(`type`)
|
||||
@@ -22,9 +21,9 @@ public open class ArrayWithoutInitializationExpression(val `type` : Type, val ex
|
||||
}
|
||||
|
||||
val innerType = hostType.elementType
|
||||
if (expressions.size() > 1 && innerType.getKind() == INode.Kind.ARRAY_TYPE)
|
||||
if (expressions.size() > 1 && innerType is ArrayType)
|
||||
{
|
||||
return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType as ArrayType, expressions.subList(1, expressions.size())) + "}")
|
||||
return oneDim(hostType, expressions[0], "{" + constructInnerType(innerType, expressions.subList(1, expressions.size())) + "}")
|
||||
}
|
||||
|
||||
return getConstructorName(hostType)
|
||||
|
||||
@@ -5,8 +5,4 @@ public open class AssignmentExpression(val left : Expression, val right : Expres
|
||||
public override fun toKotlin() : String {
|
||||
return left.toKotlin() + " "+ op + " "+ right.toKotlin()
|
||||
}
|
||||
|
||||
public override fun getKind() : INode.Kind {
|
||||
return INode.Kind.ASSIGNMENT_EXPRESSION
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,6 @@ 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()
|
||||
}
|
||||
|
||||
@@ -4,10 +4,6 @@ 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 {
|
||||
if (!expression.isEmpty() && expression.isNullable()) return true
|
||||
return identifier.isNullable()
|
||||
|
||||
@@ -1,47 +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.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class CaseContainer extends Statement {
|
||||
private final List<Statement> myCaseStatement;
|
||||
private final Block myBlock;
|
||||
|
||||
public CaseContainer(final List<Statement> caseStatement, @NotNull final List<Statement> statements) {
|
||||
myCaseStatement = caseStatement;
|
||||
List<Statement> newStatements = new LinkedList<Statement>();
|
||||
for (Statement s : statements)
|
||||
if (s.getKind() != Kind.BREAK && s.getKind() != Kind.CONTINUE) {
|
||||
newStatements.add(s);
|
||||
}
|
||||
myBlock = new Block(newStatements, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AstUtil.joinNodes(myCaseStatement, COMMA_WITH_SPACE) + SPACE + "->" + SPACE + myBlock.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.util.AstUtil
|
||||
import java.util.LinkedList
|
||||
import java.util.List
|
||||
|
||||
public open class CaseContainer(val caseStatement: List<Statement>, statements: List<Statement>): Statement() {
|
||||
private val myBlock: Block
|
||||
|
||||
{
|
||||
val newStatements: List<Statement> = statements.filterNot { it is BreakStatement || it is ContinueStatement }
|
||||
myBlock = Block(newStatements, false)
|
||||
}
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
return AstUtil.joinNodes(caseStatement, ", ") + " -> " + myBlock.toKotlin()
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import java.util.List
|
||||
import java.util.Set
|
||||
import org.jetbrains.jet.j2k.ast.INode.Kind
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class Constructor(identifier : Identifier,
|
||||
@@ -20,8 +19,4 @@ public open class Constructor(identifier : Identifier,
|
||||
public open fun primaryBodyToKotlin() : String {
|
||||
return block!!.toKotlin()
|
||||
}
|
||||
|
||||
public override fun getKind() : INode.Kind {
|
||||
return INode.Kind.CONSTRUCTOR
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ContinueStatement extends Statement {
|
||||
private Identifier myLabel = Identifier.EMPTY_IDENTIFIER;
|
||||
|
||||
public ContinueStatement(Identifier label) {
|
||||
myLabel = label;
|
||||
}
|
||||
|
||||
public ContinueStatement() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CONTINUE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myLabel.isEmpty()) {
|
||||
return "continue";
|
||||
}
|
||||
return "continue" + AT + myLabel.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class ContinueStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER): Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
if (label.isEmpty()) {
|
||||
return "continue"
|
||||
}
|
||||
|
||||
return "continue@" + label.toKotlin()
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,4 @@ import org.jetbrains.annotations.NotNull;
|
||||
public interface INode {
|
||||
@NotNull
|
||||
String toKotlin();
|
||||
|
||||
@NotNull
|
||||
Kind getKind();
|
||||
|
||||
enum Kind {
|
||||
UNDEFINED, TYPE, CONSTRUCTOR, BREAK, CONTINUE, VARARG, TRAIT, ASSIGNMENT_EXPRESSION, CALL_CHAIN, LITERAL, ARRAY_TYPE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +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 LiteralExpression extends Expression {
|
||||
private final Identifier myIdentifier;
|
||||
|
||||
public LiteralExpression(Identifier identifier) {
|
||||
myIdentifier = identifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.LITERAL;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myIdentifier.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class LiteralExpression(val identifier: Identifier): Expression() {
|
||||
public override fun toKotlin() = identifier.toKotlin()
|
||||
}
|
||||
@@ -26,12 +26,6 @@ import java.util.Set;
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Node implements INode {
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.UNDEFINED;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
final static Set<String> ONLY_KOTLIN_KEYWORDS = new HashSet<String>(Arrays.asList(
|
||||
"package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This"
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.ast.types.VarArg
|
||||
|
||||
public open class Parameter(val identifier : Identifier, val `type` : Type, val readOnly: Boolean = true) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
val vararg : String = (if (`type`.getKind() == INode.Kind.VARARG)
|
||||
"vararg" + " "
|
||||
val vararg : String = (if (`type` is VarArg)
|
||||
"vararg "
|
||||
else
|
||||
"")
|
||||
val `var` : String? = (if (readOnly)
|
||||
|
||||
@@ -3,8 +3,6 @@ package org.jetbrains.jet.j2k.ast.types
|
||||
import org.jetbrains.jet.j2k.ast.INode
|
||||
|
||||
public open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nullable) {
|
||||
public override fun getKind() : INode.Kind = INode.Kind.ARRAY_TYPE
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
if (elementType is PrimitiveType) {
|
||||
return elementType.toKotlin() + "Array" + isNullableStr()
|
||||
|
||||
@@ -4,8 +4,6 @@ import org.jetbrains.jet.j2k.ast.Element
|
||||
import org.jetbrains.jet.j2k.ast.INode
|
||||
|
||||
public abstract class Type(val nullable: Boolean) : Element() {
|
||||
public override fun getKind() : INode.Kind = INode.Kind.TYPE
|
||||
|
||||
public open fun convertedToNotNull() : Type {
|
||||
if (nullable) throw UnsupportedOperationException("convertedToNotNull must be defined")
|
||||
return this
|
||||
|
||||
@@ -4,6 +4,5 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.ast.INode
|
||||
|
||||
public open class VarArg(val `type` : Type) : Type(false) {
|
||||
public override fun getKind() : INode.Kind = INode.Kind.VARARG
|
||||
public override fun toKotlin() : String = `type`.toKotlin()
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class StatementVisitor extends ElementVisitor {
|
||||
public void visitContinueStatement(@NotNull PsiContinueStatement statement) {
|
||||
super.visitContinueStatement(statement);
|
||||
if (statement.getLabelIdentifier() == null) {
|
||||
myResult = new ContinueStatement();
|
||||
myResult = new ContinueStatement(Identifier.EMPTY_IDENTIFIER);
|
||||
}
|
||||
else {
|
||||
myResult = new ContinueStatement(
|
||||
|
||||
Reference in New Issue
Block a user