"everything's broken" state of kj2k
This commit is contained in:
committed by
Pavel V. Talanov
parent
ef22c61ee6
commit
600629ed6e
@@ -529,7 +529,7 @@ public open class Converter() {
|
||||
return false
|
||||
}
|
||||
private fun removeEmpty(statements: List<Statement>): List<Statement> {
|
||||
return statements.filterNot { it == Statement.EMPTY_STATEMENT || it == Expression.EMPTY_EXPRESSION }
|
||||
return statements.filterNot { it is EmptyStatement || it == Expression.EMPTY_EXPRESSION }
|
||||
}
|
||||
|
||||
private fun isNotOpenMethod(method: PsiMethod): Boolean {
|
||||
|
||||
@@ -1,77 +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 Identifier extends Expression {
|
||||
@NotNull
|
||||
public static Identifier EMPTY_IDENTIFIER = new Identifier("");
|
||||
|
||||
private final String myName;
|
||||
private boolean myIsNullable = true;
|
||||
private boolean myQuotingNeeded = true;
|
||||
|
||||
public Identifier(String name) {
|
||||
myName = name;
|
||||
}
|
||||
|
||||
public Identifier(String name, boolean isNullable) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
}
|
||||
|
||||
public Identifier(String name, boolean isNullable, boolean quotingNeeded) {
|
||||
myName = name;
|
||||
myIsNullable = isNullable;
|
||||
myQuotingNeeded = quotingNeeded;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return myName.length() == 0;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String quote(String str) {
|
||||
return BACKTICK + str + BACKTICK;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNullable() {
|
||||
return myIsNullable;
|
||||
}
|
||||
|
||||
private String ifNeedQuote() {
|
||||
if (myQuotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(myName) || myName.contains("$"))) {
|
||||
return quote(myName);
|
||||
}
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return ifNeedQuote();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class Identifier(val name: String,
|
||||
val nullable: Boolean = true,
|
||||
val quotingNeeded: Boolean = true): Expression() {
|
||||
public override fun isEmpty(): Boolean {
|
||||
return name.length() == 0
|
||||
}
|
||||
private open fun ifNeedQuote(): String {
|
||||
if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS?.contains(name)) || name.contains("$"))) {
|
||||
return quote(name)
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
public override fun toKotlin(): String = ifNeedQuote()
|
||||
|
||||
class object {
|
||||
public val EMPTY_IDENTIFIER: Identifier = Identifier("")
|
||||
private open fun quote(str: String): String {
|
||||
return "`" + str + "`"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +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 abstract class Statement extends Element {
|
||||
@NotNull
|
||||
public static final Statement EMPTY_STATEMENT = new EmptyStatement();
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
private static class EmptyStatement extends Statement {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,14 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import java.util.List
|
||||
|
||||
public abstract class Statement(): Element() {
|
||||
class object {
|
||||
public val EMPTY_STATEMENT = object : Statement {
|
||||
public override fun toKotlin() = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public open class DeclarationStatement(val elements: List<Element>): Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
return elements.filter { it is LocalVariable }.map { convertDeclaration(it as LocalVariable) }.makeString("\n")
|
||||
@@ -31,7 +39,7 @@ public open class ReturnStatement(val expression: Expression): Statement() {
|
||||
public open class IfStatement(val condition: Expression, val thenStatement: Statement, val elseStatement: Statement): Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n"
|
||||
if (elseStatement != Statement.EMPTY_STATEMENT) {
|
||||
if (elseStatement !is EmptyStatement) {
|
||||
return result + "else\n" + elseStatement.toKotlin()
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.List
|
||||
import org.jetbrains.jet.j2k.ConverterUtil.countWritingAccesses
|
||||
|
||||
public open class StatementVisitor(converter: Converter): ElementVisitor(converter) {
|
||||
private var myResult: Statement = Statement.EMPTY_STATEMENT
|
||||
private var myResult: Statement =
|
||||
public override fun getResult(): Statement {
|
||||
return myResult
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user