Refactor Converter:
Minor: change naming convention of EMPTY_* constants to Empty
This commit is contained in:
committed by
Pavel V. Talanov
parent
8577d3ca55
commit
5dc790246a
@@ -167,7 +167,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
}
|
||||
}
|
||||
}
|
||||
members.add(Constructor(this, Identifier.EMPTY_IDENTIFIER, null, Collections.emptySet<Modifier>(),
|
||||
members.add(Constructor(this, Identifier.Empty, null, Collections.emptySet<Modifier>(),
|
||||
ClassType(name, Collections.emptyList<Element>(), false, this),
|
||||
TypeParameterList.Empty,
|
||||
ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||
@@ -270,7 +270,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
|
||||
public fun convertBlock(block: PsiCodeBlock?, notEmpty: Boolean): Block {
|
||||
if (block == null)
|
||||
return Block.EMPTY_BLOCK
|
||||
return Block.Empty
|
||||
|
||||
return Block(convertStatements(block.getChildren().toList()), notEmpty)
|
||||
}
|
||||
@@ -285,7 +285,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
|
||||
public fun convertStatement(s: PsiStatement?): Statement {
|
||||
if (s == null)
|
||||
return Statement.EMPTY_STATEMENT
|
||||
return Statement.Empty
|
||||
|
||||
val statementVisitor: StatementVisitor = StatementVisitor(this)
|
||||
s.accept(statementVisitor)
|
||||
@@ -301,7 +301,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
|
||||
public fun convertExpression(e: PsiExpression?): Expression {
|
||||
if (e == null)
|
||||
return Expression.EMPTY_EXPRESSION
|
||||
return Expression.Empty
|
||||
|
||||
val expressionVisitor: ExpressionVisitor = dispatcher.expressionVisitor
|
||||
e.accept(expressionVisitor)
|
||||
@@ -310,7 +310,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
|
||||
public fun convertElement(e: PsiElement?): Element {
|
||||
if (e == null)
|
||||
return Element.EMPTY_ELEMENT
|
||||
return Element.Empty
|
||||
|
||||
val elementVisitor: ElementVisitor = ElementVisitor(this)
|
||||
e.accept(elementVisitor)
|
||||
@@ -399,7 +399,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
|
||||
public fun convertExpression(argument: PsiExpression?, expectedType: PsiType?): Expression {
|
||||
if (argument == null)
|
||||
return Identifier.EMPTY_IDENTIFIER
|
||||
return Identifier.Empty
|
||||
|
||||
var expression: Expression = convertExpression(argument)
|
||||
val actualType: PsiType? = argument.getType()
|
||||
@@ -458,17 +458,9 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return s + "(" + fields.map { initializers[it.identifier.toKotlin()] }.makeString(", ") + ")"
|
||||
}
|
||||
|
||||
private fun removeEmpty(statements: List<Element>): List<Element> {
|
||||
return statements.filterNot {
|
||||
it == Statement.EMPTY_STATEMENT ||
|
||||
it == Expression.EMPTY_EXPRESSION ||
|
||||
it == Element.EMPTY_ELEMENT
|
||||
}
|
||||
}
|
||||
|
||||
public fun convertIdentifier(identifier: PsiIdentifier?): Identifier {
|
||||
if (identifier == null)
|
||||
return Identifier.EMPTY_IDENTIFIER
|
||||
return Identifier.Empty
|
||||
|
||||
return Identifier(identifier.getText()!!)
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public class AssertStatement(val condition: Expression, val detail: Expression) : Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
val lazyStringMessage = if (detail != Expression.EMPTY_EXPRESSION)
|
||||
val lazyStringMessage = if (detail != Expression.Empty)
|
||||
" {" + detail.toKotlin() + "}"
|
||||
else
|
||||
""
|
||||
|
||||
@@ -43,6 +43,6 @@ public class Block(val statementList: StatementList, val notEmpty: Boolean = fal
|
||||
}
|
||||
|
||||
class object {
|
||||
public val EMPTY_BLOCK: Block = Block(StatementList(ArrayList()))
|
||||
public val Empty: Block = Block(StatementList(ArrayList()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public trait Element : Node {
|
||||
public fun isEmpty(): Boolean = false
|
||||
|
||||
class object {
|
||||
public val EMPTY_ELEMENT: Element = object : Element {
|
||||
public val Empty: Element = object : Element {
|
||||
override fun toKotlin() = ""
|
||||
override fun isEmpty() = true
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public abstract class Expression() : Statement() {
|
||||
}
|
||||
|
||||
class object {
|
||||
public val EMPTY_EXPRESSION: Expression = object: Expression() {
|
||||
public val Empty: Expression = object: Expression() {
|
||||
public override fun toKotlin() = ""
|
||||
public override fun isEmpty() = true
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public open class Identifier(val name: String,
|
||||
public override fun isNullable(): Boolean = myNullable
|
||||
|
||||
class object {
|
||||
public val EMPTY_IDENTIFIER: Identifier = Identifier("")
|
||||
public val Empty: Identifier = Identifier("")
|
||||
private open fun quote(str: String): String {
|
||||
return "`" + str + "`"
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public open class NewClassExpression(val name: Element,
|
||||
val arguments: List<Expression>,
|
||||
val qualifier: Expression = Expression.EMPTY_EXPRESSION,
|
||||
val qualifier: Expression = Expression.Empty,
|
||||
val anonymousClass: AnonymousClass? = null) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
val callOperator: String? = (if (qualifier.isNullable())
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public abstract class Statement() : Element {
|
||||
class object {
|
||||
public val EMPTY_STATEMENT: Statement = object : Statement() {
|
||||
public val Empty: Statement = object : Statement() {
|
||||
override fun toKotlin() = ""
|
||||
override fun isEmpty() = true
|
||||
}
|
||||
@@ -57,7 +57,7 @@ public open class IfStatement(val condition: Expression,
|
||||
val elseStatement: Element) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin()
|
||||
if (elseStatement != Statement.EMPTY_STATEMENT) {
|
||||
if (elseStatement != Statement.Empty) {
|
||||
return result + "\nelse\n" + elseStatement.toKotlin()
|
||||
}
|
||||
|
||||
@@ -90,11 +90,11 @@ public open class ForeachWithRangeStatement(val identifier: Identifier,
|
||||
start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() {
|
||||
public open class BreakStatement(val label: Identifier = Identifier.Empty) : Statement() {
|
||||
public override fun toKotlin() = "break" + label.withPrefix("@")
|
||||
}
|
||||
|
||||
public open class ContinueStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() {
|
||||
public open class ContinueStatement(val label: Identifier = Identifier.Empty) : Statement() {
|
||||
public override fun toKotlin() = "continue" + label.withPrefix("@")
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.jet.j2k.ast.*
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class ElementVisitor(val myConverter: Converter) : JavaElementVisitor() {
|
||||
protected var myResult: Element = Element.EMPTY_ELEMENT
|
||||
protected var myResult: Element = Element.Empty
|
||||
|
||||
public fun getConverter(): Converter {
|
||||
return myConverter
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.jet.j2k.ast.types.ArrayType
|
||||
|
||||
public open class ExpressionVisitor(converter: Converter) : StatementVisitor(converter) {
|
||||
{
|
||||
myResult = Expression.EMPTY_EXPRESSION
|
||||
myResult = Expression.Empty
|
||||
}
|
||||
|
||||
public override fun getResult(): Expression {
|
||||
@@ -296,7 +296,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
myResult = SuperExpression((if (qualifier != null)
|
||||
Identifier(qualifier.getQualifiedName()!!)
|
||||
else
|
||||
Identifier.EMPTY_IDENTIFIER))
|
||||
Identifier.Empty))
|
||||
}
|
||||
|
||||
public override fun visitThisExpression(expression: PsiThisExpression?) {
|
||||
@@ -304,7 +304,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
myResult = ThisExpression((if (qualifier != null)
|
||||
Identifier(qualifier.getQualifiedName()!!)
|
||||
else
|
||||
Identifier.EMPTY_IDENTIFIER))
|
||||
Identifier.Empty))
|
||||
}
|
||||
|
||||
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
|
||||
public override fun visitBreakStatement(statement: PsiBreakStatement?) {
|
||||
if (statement?.getLabelIdentifier() == null) {
|
||||
myResult = BreakStatement(Identifier.EMPTY_IDENTIFIER)
|
||||
myResult = BreakStatement(Identifier.Empty)
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -45,7 +45,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
public override fun visitContinueStatement(statement: PsiContinueStatement?) {
|
||||
if (statement?.getLabelIdentifier() == null)
|
||||
{
|
||||
myResult = ContinueStatement(Identifier.EMPTY_IDENTIFIER)
|
||||
myResult = ContinueStatement(Identifier.Empty)
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -294,6 +294,6 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
}
|
||||
|
||||
override fun visitEmptyStatement(statement: PsiEmptyStatement?) {
|
||||
myResult = Statement.EMPTY_STATEMENT
|
||||
myResult = Statement.Empty
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user