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),
|
ClassType(name, Collections.emptyList<Element>(), false, this),
|
||||||
TypeParameterList.Empty,
|
TypeParameterList.Empty,
|
||||||
ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||||
@@ -270,7 +270,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
|||||||
|
|
||||||
public fun convertBlock(block: PsiCodeBlock?, notEmpty: Boolean): Block {
|
public fun convertBlock(block: PsiCodeBlock?, notEmpty: Boolean): Block {
|
||||||
if (block == null)
|
if (block == null)
|
||||||
return Block.EMPTY_BLOCK
|
return Block.Empty
|
||||||
|
|
||||||
return Block(convertStatements(block.getChildren().toList()), notEmpty)
|
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 {
|
public fun convertStatement(s: PsiStatement?): Statement {
|
||||||
if (s == null)
|
if (s == null)
|
||||||
return Statement.EMPTY_STATEMENT
|
return Statement.Empty
|
||||||
|
|
||||||
val statementVisitor: StatementVisitor = StatementVisitor(this)
|
val statementVisitor: StatementVisitor = StatementVisitor(this)
|
||||||
s.accept(statementVisitor)
|
s.accept(statementVisitor)
|
||||||
@@ -301,7 +301,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
|||||||
|
|
||||||
public fun convertExpression(e: PsiExpression?): Expression {
|
public fun convertExpression(e: PsiExpression?): Expression {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return Expression.EMPTY_EXPRESSION
|
return Expression.Empty
|
||||||
|
|
||||||
val expressionVisitor: ExpressionVisitor = dispatcher.expressionVisitor
|
val expressionVisitor: ExpressionVisitor = dispatcher.expressionVisitor
|
||||||
e.accept(expressionVisitor)
|
e.accept(expressionVisitor)
|
||||||
@@ -310,7 +310,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
|||||||
|
|
||||||
public fun convertElement(e: PsiElement?): Element {
|
public fun convertElement(e: PsiElement?): Element {
|
||||||
if (e == null)
|
if (e == null)
|
||||||
return Element.EMPTY_ELEMENT
|
return Element.Empty
|
||||||
|
|
||||||
val elementVisitor: ElementVisitor = ElementVisitor(this)
|
val elementVisitor: ElementVisitor = ElementVisitor(this)
|
||||||
e.accept(elementVisitor)
|
e.accept(elementVisitor)
|
||||||
@@ -399,7 +399,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
|||||||
|
|
||||||
public fun convertExpression(argument: PsiExpression?, expectedType: PsiType?): Expression {
|
public fun convertExpression(argument: PsiExpression?, expectedType: PsiType?): Expression {
|
||||||
if (argument == null)
|
if (argument == null)
|
||||||
return Identifier.EMPTY_IDENTIFIER
|
return Identifier.Empty
|
||||||
|
|
||||||
var expression: Expression = convertExpression(argument)
|
var expression: Expression = convertExpression(argument)
|
||||||
val actualType: PsiType? = argument.getType()
|
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(", ") + ")"
|
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 {
|
public fun convertIdentifier(identifier: PsiIdentifier?): Identifier {
|
||||||
if (identifier == null)
|
if (identifier == null)
|
||||||
return Identifier.EMPTY_IDENTIFIER
|
return Identifier.Empty
|
||||||
|
|
||||||
return Identifier(identifier.getText()!!)
|
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 class AssertStatement(val condition: Expression, val detail: Expression) : Statement() {
|
||||||
public override fun toKotlin(): String {
|
public override fun toKotlin(): String {
|
||||||
val lazyStringMessage = if (detail != Expression.EMPTY_EXPRESSION)
|
val lazyStringMessage = if (detail != Expression.Empty)
|
||||||
" {" + detail.toKotlin() + "}"
|
" {" + detail.toKotlin() + "}"
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
|
|||||||
@@ -43,6 +43,6 @@ public class Block(val statementList: StatementList, val notEmpty: Boolean = fal
|
|||||||
}
|
}
|
||||||
|
|
||||||
class object {
|
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
|
public fun isEmpty(): Boolean = false
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
public val EMPTY_ELEMENT: Element = object : Element {
|
public val Empty: Element = object : Element {
|
||||||
override fun toKotlin() = ""
|
override fun toKotlin() = ""
|
||||||
override fun isEmpty() = true
|
override fun isEmpty() = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public abstract class Expression() : Statement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
public val EMPTY_EXPRESSION: Expression = object: Expression() {
|
public val Empty: Expression = object: Expression() {
|
||||||
public override fun toKotlin() = ""
|
public override fun toKotlin() = ""
|
||||||
public override fun isEmpty() = true
|
public override fun isEmpty() = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public open class Identifier(val name: String,
|
|||||||
public override fun isNullable(): Boolean = myNullable
|
public override fun isNullable(): Boolean = myNullable
|
||||||
|
|
||||||
class object {
|
class object {
|
||||||
public val EMPTY_IDENTIFIER: Identifier = Identifier("")
|
public val Empty: Identifier = Identifier("")
|
||||||
private open fun quote(str: String): String {
|
private open fun quote(str: String): String {
|
||||||
return "`" + str + "`"
|
return "`" + str + "`"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.ast
|
|||||||
|
|
||||||
public open class NewClassExpression(val name: Element,
|
public open class NewClassExpression(val name: Element,
|
||||||
val arguments: List<Expression>,
|
val arguments: List<Expression>,
|
||||||
val qualifier: Expression = Expression.EMPTY_EXPRESSION,
|
val qualifier: Expression = Expression.Empty,
|
||||||
val anonymousClass: AnonymousClass? = null) : Expression() {
|
val anonymousClass: AnonymousClass? = null) : Expression() {
|
||||||
public override fun toKotlin(): String {
|
public override fun toKotlin(): String {
|
||||||
val callOperator: String? = (if (qualifier.isNullable())
|
val callOperator: String? = (if (qualifier.isNullable())
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ package org.jetbrains.jet.j2k.ast
|
|||||||
|
|
||||||
public abstract class Statement() : Element {
|
public abstract class Statement() : Element {
|
||||||
class object {
|
class object {
|
||||||
public val EMPTY_STATEMENT: Statement = object : Statement() {
|
public val Empty: Statement = object : Statement() {
|
||||||
override fun toKotlin() = ""
|
override fun toKotlin() = ""
|
||||||
override fun isEmpty() = true
|
override fun isEmpty() = true
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ public open class IfStatement(val condition: Expression,
|
|||||||
val elseStatement: Element) : Expression() {
|
val elseStatement: Element) : Expression() {
|
||||||
public override fun toKotlin(): String {
|
public override fun toKotlin(): String {
|
||||||
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin()
|
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin()
|
||||||
if (elseStatement != Statement.EMPTY_STATEMENT) {
|
if (elseStatement != Statement.Empty) {
|
||||||
return result + "\nelse\n" + elseStatement.toKotlin()
|
return result + "\nelse\n" + elseStatement.toKotlin()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,11 +90,11 @@ public open class ForeachWithRangeStatement(val identifier: Identifier,
|
|||||||
start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin()
|
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 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("@")
|
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
|
import org.jetbrains.jet.j2k.ast.types.Type
|
||||||
|
|
||||||
public open class ElementVisitor(val myConverter: Converter) : JavaElementVisitor() {
|
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 {
|
public fun getConverter(): Converter {
|
||||||
return myConverter
|
return myConverter
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import org.jetbrains.jet.j2k.ast.types.ArrayType
|
|||||||
|
|
||||||
public open class ExpressionVisitor(converter: Converter) : StatementVisitor(converter) {
|
public open class ExpressionVisitor(converter: Converter) : StatementVisitor(converter) {
|
||||||
{
|
{
|
||||||
myResult = Expression.EMPTY_EXPRESSION
|
myResult = Expression.Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun getResult(): Expression {
|
public override fun getResult(): Expression {
|
||||||
@@ -296,7 +296,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
|||||||
myResult = SuperExpression((if (qualifier != null)
|
myResult = SuperExpression((if (qualifier != null)
|
||||||
Identifier(qualifier.getQualifiedName()!!)
|
Identifier(qualifier.getQualifiedName()!!)
|
||||||
else
|
else
|
||||||
Identifier.EMPTY_IDENTIFIER))
|
Identifier.Empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun visitThisExpression(expression: PsiThisExpression?) {
|
public override fun visitThisExpression(expression: PsiThisExpression?) {
|
||||||
@@ -304,7 +304,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
|||||||
myResult = ThisExpression((if (qualifier != null)
|
myResult = ThisExpression((if (qualifier != null)
|
||||||
Identifier(qualifier.getQualifiedName()!!)
|
Identifier(qualifier.getQualifiedName()!!)
|
||||||
else
|
else
|
||||||
Identifier.EMPTY_IDENTIFIER))
|
Identifier.Empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?) {
|
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
|||||||
|
|
||||||
public override fun visitBreakStatement(statement: PsiBreakStatement?) {
|
public override fun visitBreakStatement(statement: PsiBreakStatement?) {
|
||||||
if (statement?.getLabelIdentifier() == null) {
|
if (statement?.getLabelIdentifier() == null) {
|
||||||
myResult = BreakStatement(Identifier.EMPTY_IDENTIFIER)
|
myResult = BreakStatement(Identifier.Empty)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
|||||||
public override fun visitContinueStatement(statement: PsiContinueStatement?) {
|
public override fun visitContinueStatement(statement: PsiContinueStatement?) {
|
||||||
if (statement?.getLabelIdentifier() == null)
|
if (statement?.getLabelIdentifier() == null)
|
||||||
{
|
{
|
||||||
myResult = ContinueStatement(Identifier.EMPTY_IDENTIFIER)
|
myResult = ContinueStatement(Identifier.Empty)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -294,6 +294,6 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitEmptyStatement(statement: PsiEmptyStatement?) {
|
override fun visitEmptyStatement(statement: PsiEmptyStatement?) {
|
||||||
myResult = Statement.EMPTY_STATEMENT
|
myResult = Statement.Empty
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user