Apply reformat code and optimize imports to kotlin code in j2k
Minor: remove Unit return types
This commit is contained in:
@@ -66,7 +66,7 @@ public open class Converter(val project: Project) {
|
||||
return Collections.unmodifiableSet(classIdentifiersSet)
|
||||
}
|
||||
|
||||
public open fun clearClassIdentifiers(): Unit {
|
||||
public open fun clearClassIdentifiers() {
|
||||
classIdentifiersSet.clear()
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public open class Converter(val project: Project) {
|
||||
imports.add(Import(i))
|
||||
|
||||
val body: ArrayList<Node> = arrayListOf()
|
||||
for(element in javaFile.getChildren()) {
|
||||
for (element in javaFile.getChildren()) {
|
||||
if (element !is PsiImportStatementBase) {
|
||||
val node = topElementToElement(element)
|
||||
if (node != null) {
|
||||
@@ -167,7 +167,7 @@ public open class Converter(val project: Project) {
|
||||
val implementsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getImplementsListTypes())
|
||||
val extendsTypes: List<Type> = typesToNotNullableTypeList(psiClass.getExtendsListTypes())
|
||||
val name: Identifier = Identifier(psiClass.getName()!!)
|
||||
val baseClassParams= ArrayList<Expression>()
|
||||
val baseClassParams = ArrayList<Expression>()
|
||||
val members = getMembers(psiClass)
|
||||
val docComments = getDocComments(psiClass)
|
||||
val visitor: SuperVisitor = SuperVisitor()
|
||||
@@ -218,11 +218,11 @@ public open class Converter(val project: Project) {
|
||||
}
|
||||
}
|
||||
members.add(Constructor(Identifier.EMPTY_IDENTIFIER, arrayListOf(), Collections.emptySet<Modifier>(),
|
||||
ClassType(name, Collections.emptyList<Element>(), false),
|
||||
Collections.emptyList<Element>(),
|
||||
ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||
Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)),
|
||||
true))
|
||||
ClassType(name, Collections.emptyList<Element>(), false),
|
||||
Collections.emptyList<Element>(),
|
||||
ParameterList(createParametersFromFields(finalOrWithEmptyInitializer)),
|
||||
Block(createInitStatementsFromFields(finalOrWithEmptyInitializer)),
|
||||
true))
|
||||
}
|
||||
|
||||
if (psiClass.isInterface()) {
|
||||
@@ -249,10 +249,10 @@ public open class Converter(val project: Project) {
|
||||
val docComments = getDocComments(field)
|
||||
if (field is PsiEnumConstant) {
|
||||
return EnumConstant(Identifier(field.getName()!!),
|
||||
docComments,
|
||||
modifiers,
|
||||
typeToType(field.getType()),
|
||||
elementToElement(field.getArgumentList()))
|
||||
docComments,
|
||||
modifiers,
|
||||
typeToType(field.getType()),
|
||||
elementToElement(field.getArgumentList()))
|
||||
}
|
||||
|
||||
var kType = typeToType(field.getType(), isAnnotatedAsNotNull(field.getModifierList()))
|
||||
@@ -261,11 +261,11 @@ public open class Converter(val project: Project) {
|
||||
}
|
||||
|
||||
return Field(Identifier(field.getName()!!),
|
||||
docComments,
|
||||
modifiers,
|
||||
kType,
|
||||
expressionToExpression(field.getInitializer(), field.getType()),
|
||||
countWritingAccesses(field, psiClass))
|
||||
docComments,
|
||||
modifiers,
|
||||
kType,
|
||||
expressionToExpression(field.getInitializer(), field.getType()),
|
||||
countWritingAccesses(field, psiClass))
|
||||
}
|
||||
|
||||
private fun methodToFunction(method: PsiMethod): Function {
|
||||
@@ -307,7 +307,7 @@ public open class Converter(val project: Project) {
|
||||
if (method.isConstructor()) {
|
||||
val isPrimary: Boolean = isConstructorPrimary(method)
|
||||
return Constructor(identifier, docComments, modifiers, returnType, typeParameters, params,
|
||||
Block(removeEmpty(body.statements), false), isPrimary)
|
||||
Block(removeEmpty(body.statements), false), isPrimary)
|
||||
}
|
||||
|
||||
return Function(identifier, docComments, modifiers, returnType, typeParameters, params, body)
|
||||
@@ -317,9 +317,9 @@ public open class Converter(val project: Project) {
|
||||
val result = ArrayList<Parameter>()
|
||||
for (parameter : PsiParameter? in method.getParameterList().getParameters()) {
|
||||
result.add(Parameter(Identifier(parameter?.getName()!!),
|
||||
typeToType(parameter?.getType(),
|
||||
isAnnotatedAsNotNull(parameter?.getModifierList())),
|
||||
isReadOnly(parameter, method.getBody())))
|
||||
typeToType(parameter?.getType(),
|
||||
isAnnotatedAsNotNull(parameter?.getModifierList())),
|
||||
isReadOnly(parameter, method.getBody())))
|
||||
}
|
||||
return ParameterList(result)
|
||||
}
|
||||
@@ -407,7 +407,7 @@ public open class Converter(val project: Project) {
|
||||
|
||||
public open fun elementsToElementList(elements: Array<out PsiElement?>): List<Element> {
|
||||
val result = ArrayList<Element>()
|
||||
for(element in elements) {
|
||||
for (element in elements) {
|
||||
result.add(elementToElement(element))
|
||||
}
|
||||
return result
|
||||
@@ -415,9 +415,9 @@ public open class Converter(val project: Project) {
|
||||
|
||||
public open fun typeElementToTypeElement(element: PsiTypeElement?): TypeElement {
|
||||
return TypeElement(if (element == null)
|
||||
EmptyType()
|
||||
else
|
||||
typeToType(element.getType()))
|
||||
EmptyType()
|
||||
else
|
||||
typeToType(element.getType()))
|
||||
}
|
||||
|
||||
public open fun typeToType(`type`: PsiType?): Type {
|
||||
@@ -444,7 +444,7 @@ public open class Converter(val project: Project) {
|
||||
|
||||
private fun typesToNotNullableTypeList(types: Array<out PsiType?>): List<Type> {
|
||||
val result = ArrayList<Type>()
|
||||
for(aType in types) {
|
||||
for (aType in types) {
|
||||
result.add(typeToType(aType).convertedToNotNull())
|
||||
}
|
||||
return result
|
||||
@@ -456,8 +456,8 @@ public open class Converter(val project: Project) {
|
||||
|
||||
public open fun parameterToParameter(parameter: PsiParameter, forceNotNull: Boolean = false): Parameter {
|
||||
return Parameter(Identifier(parameter.getName()!!),
|
||||
typeToType(parameter.getType(),
|
||||
forceNotNull || isAnnotatedAsNotNull(parameter.getModifierList())), true)
|
||||
typeToType(parameter.getType(),
|
||||
forceNotNull || isAnnotatedAsNotNull(parameter.getModifierList())), true)
|
||||
}
|
||||
|
||||
public open fun argumentsToExpressionList(expression: PsiCallExpression): List<Expression> {
|
||||
@@ -518,21 +518,21 @@ public open class Converter(val project: Project) {
|
||||
class object {
|
||||
public val NOT_NULL_ANNOTATIONS: Set<String> = ImmutableSet.of<String>("org.jetbrains.annotations.NotNull", "com.sun.istack.internal.NotNull", "javax.annotation.Nonnull")!!
|
||||
public val PRIMITIVE_TYPE_CONVERSIONS: Map<String, String> = ImmutableMap.builder<String, String>()
|
||||
?.put("byte", BYTE.asString())
|
||||
?.put("short", SHORT.asString())
|
||||
?.put("int", INT.asString())
|
||||
?.put("long", LONG.asString())
|
||||
?.put("float", FLOAT.asString())
|
||||
?.put("double", DOUBLE.asString())
|
||||
?.put("char", CHAR.asString())
|
||||
?.put(JAVA_LANG_BYTE, BYTE.asString())
|
||||
?.put(JAVA_LANG_SHORT, SHORT.asString())
|
||||
?.put(JAVA_LANG_INTEGER, INT.asString())
|
||||
?.put(JAVA_LANG_LONG, LONG.asString())
|
||||
?.put(JAVA_LANG_FLOAT, FLOAT.asString())
|
||||
?.put(JAVA_LANG_DOUBLE, DOUBLE.asString())
|
||||
?.put(JAVA_LANG_CHARACTER, CHAR.asString())
|
||||
?.build()!!
|
||||
?.put("byte", BYTE.asString())
|
||||
?.put("short", SHORT.asString())
|
||||
?.put("int", INT.asString())
|
||||
?.put("long", LONG.asString())
|
||||
?.put("float", FLOAT.asString())
|
||||
?.put("double", DOUBLE.asString())
|
||||
?.put("char", CHAR.asString())
|
||||
?.put(JAVA_LANG_BYTE, BYTE.asString())
|
||||
?.put(JAVA_LANG_SHORT, SHORT.asString())
|
||||
?.put(JAVA_LANG_INTEGER, INT.asString())
|
||||
?.put(JAVA_LANG_LONG, LONG.asString())
|
||||
?.put(JAVA_LANG_FLOAT, FLOAT.asString())
|
||||
?.put(JAVA_LANG_DOUBLE, DOUBLE.asString())
|
||||
?.put(JAVA_LANG_CHARACTER, CHAR.asString())
|
||||
?.build()!!
|
||||
|
||||
private fun quoteKeywords(packageName: String): String {
|
||||
return packageName.split("\\.").map { Identifier(it).toKotlin() }.makeString(".")
|
||||
@@ -611,9 +611,11 @@ public open class Converter(val project: Project) {
|
||||
return false
|
||||
}
|
||||
private fun removeEmpty(statements: List<Element>): List<Element> {
|
||||
return statements.filterNot { it == Statement.EMPTY_STATEMENT ||
|
||||
it == Expression.EMPTY_EXPRESSION ||
|
||||
it == Element.EMPTY_ELEMENT }
|
||||
return statements.filterNot {
|
||||
it == Statement.EMPTY_STATEMENT ||
|
||||
it == Expression.EMPTY_EXPRESSION ||
|
||||
it == Element.EMPTY_ELEMENT
|
||||
}
|
||||
}
|
||||
|
||||
private fun isNotOpenMethod(method: PsiMethod): Boolean {
|
||||
@@ -845,14 +847,14 @@ public fun countWritingAccesses(element: PsiElement?, container: PsiElement?): I
|
||||
return counter
|
||||
}
|
||||
|
||||
open class ReferenceCollector(): JavaRecursiveElementVisitor() {
|
||||
open class ReferenceCollector() : JavaRecursiveElementVisitor() {
|
||||
private val myCollectedReferences = ArrayList<PsiReferenceExpression>()
|
||||
|
||||
public open fun getCollectedReferences(): List<PsiReferenceExpression> {
|
||||
return myCollectedReferences
|
||||
}
|
||||
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit {
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
super.visitReferenceExpression(expression)
|
||||
if (expression != null) {
|
||||
myCollectedReferences.add(expression)
|
||||
|
||||
@@ -86,7 +86,7 @@ object JavaToKotlinTranslator {
|
||||
return null
|
||||
}
|
||||
|
||||
fun setClassIdentifiers(converter: Converter, psiFile: PsiElement): Unit {
|
||||
fun setClassIdentifiers(converter: Converter, psiFile: PsiElement) {
|
||||
val c = ClassVisitor()
|
||||
psiFile.accept(c)
|
||||
converter.clearClassIdentifiers()
|
||||
|
||||
@@ -16,5 +16,5 @@
|
||||
|
||||
package org.jetbrains.jet.j2k
|
||||
|
||||
public open class SetupJavaCoreEnvironmentException(s: String?): RuntimeException() {
|
||||
public open class SetupJavaCoreEnvironmentException(s: String?) : RuntimeException() {
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.Collections
|
||||
|
||||
public open class AnonymousClass(converter : Converter, members : List<Node>)
|
||||
: Class(converter,
|
||||
Identifier("anonClass"),
|
||||
arrayList(),
|
||||
Collections.emptySet<Modifier>(),
|
||||
Collections.emptyList<Element>(),
|
||||
Collections.emptyList<Type>(),
|
||||
Collections.emptyList<Expression>(),
|
||||
Collections.emptyList<Type>(), members) {
|
||||
public open class AnonymousClass(converter: Converter, members: List<Node>)
|
||||
: Class(converter,
|
||||
Identifier("anonClass"),
|
||||
arrayList(),
|
||||
Collections.emptySet<Modifier>(),
|
||||
Collections.emptyList<Element>(),
|
||||
Collections.emptyList<Type>(),
|
||||
Collections.emptyList<Expression>(),
|
||||
Collections.emptyList<Type>(), members) {
|
||||
public override fun toKotlin() = bodyToKotlin()
|
||||
}
|
||||
|
||||
@@ -18,11 +18,10 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import java.util.*
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
|
||||
public open class ArrayInitializerExpression(val `type` : Type, val initializers : List<Expression>) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
public open class ArrayInitializerExpression(val `type`: Type, val initializers: List<Expression>) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
return createArrayFunction() + "(" + createInitializers() + ")"
|
||||
}
|
||||
|
||||
@@ -30,8 +29,8 @@ public open class ArrayInitializerExpression(val `type` : Type, val initializers
|
||||
return initializers.map { explicitConvertIfNeeded(it) }.makeString(", ")
|
||||
}
|
||||
|
||||
private fun createArrayFunction() : String {
|
||||
var sType : String? = innerTypeStr()
|
||||
private fun createArrayFunction(): String {
|
||||
var sType: String? = innerTypeStr()
|
||||
if (Node.PRIMITIVE_TYPES.contains(sType)) {
|
||||
return sType + "Array"
|
||||
}
|
||||
@@ -39,13 +38,13 @@ public open class ArrayInitializerExpression(val `type` : Type, val initializers
|
||||
return StringUtil.decapitalize(`type`.convertedToNotNull().toKotlin())!!
|
||||
}
|
||||
|
||||
private fun innerTypeStr() : String {
|
||||
private fun innerTypeStr(): String {
|
||||
return `type`.convertedToNotNull().toKotlin().replace("Array", "").toLowerCase()
|
||||
}
|
||||
|
||||
private fun explicitConvertIfNeeded(i : Expression) : String {
|
||||
private fun explicitConvertIfNeeded(i: Expression): String {
|
||||
val doubleOrFloatTypes = hashSet("double", "float", "java.lang.double", "java.lang.float")
|
||||
val afterReplace : String = innerTypeStr().replace(">", "").replace("<", "").replace("?", "")
|
||||
val afterReplace: String = innerTypeStr().replace(">", "").replace("<", "").replace("?", "")
|
||||
if (doubleOrFloatTypes.contains(afterReplace))
|
||||
{
|
||||
if (i is LiteralExpression) {
|
||||
@@ -63,7 +62,7 @@ public open class ArrayInitializerExpression(val `type` : Type, val initializers
|
||||
}
|
||||
|
||||
class object {
|
||||
private open fun getConversion(afterReplace : String) : String {
|
||||
private open fun getConversion(afterReplace: String): String {
|
||||
if (afterReplace.contains("double"))
|
||||
return "." + OperatorConventions.DOUBLE + "()"
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.jetbrains.jet.j2k.ast.types.ArrayType
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.ast.types.PrimitiveType
|
||||
|
||||
public open class ArrayWithoutInitializationExpression(val `type` : Type, val expressions : List<Expression>) : Expression() {
|
||||
public override fun toKotlin() : String {
|
||||
public open class ArrayWithoutInitializationExpression(val `type`: Type, val expressions: List<Expression>) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
if (`type` is ArrayType) {
|
||||
return constructInnerType(`type`, expressions)
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public open class ArrayWithoutInitializationExpression(val `type` : Type, val ex
|
||||
return getConstructorName(`type`, expressions.size() != 0)
|
||||
}
|
||||
|
||||
private fun constructInnerType(hostType : ArrayType, expressions: List<Expression>) : String {
|
||||
private fun constructInnerType(hostType: ArrayType, expressions: List<Expression>): String {
|
||||
if (expressions.size() == 1) {
|
||||
return oneDim(hostType, expressions[0])
|
||||
}
|
||||
@@ -43,15 +43,15 @@ public open class ArrayWithoutInitializationExpression(val `type` : Type, val ex
|
||||
}
|
||||
|
||||
class object {
|
||||
private open fun oneDim(`type` : Type, size : Expression) : String {
|
||||
private open fun oneDim(`type`: Type, size: Expression): String {
|
||||
return oneDim(`type`, size, "")
|
||||
}
|
||||
|
||||
private open fun oneDim(`type` : Type, size : Expression, init : String) : String {
|
||||
private open fun oneDim(`type`: Type, size: Expression, init: String): String {
|
||||
return getConstructorName(`type`, !init.isEmpty()) + "(" + size.toKotlin() + init.withPrefix(", ") + ")"
|
||||
}
|
||||
|
||||
private open fun getConstructorName(`type` : Type, hasInit : Boolean) : String {
|
||||
private open fun getConstructorName(`type`: Type, hasInit: Boolean): String {
|
||||
return if (`type` is ArrayType)
|
||||
when (`type`.elementType) {
|
||||
is PrimitiveType ->
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class AssertStatement(val condition : Expression, val detail : Expression) : Statement() {
|
||||
public override fun toKotlin() : String {
|
||||
var detail : String? = (if (detail != Expression.EMPTY_EXPRESSION)
|
||||
public open class AssertStatement(val condition: Expression, val detail: Expression) : Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
var detail: String? = (if (detail != Expression.EMPTY_EXPRESSION)
|
||||
"(" + detail.toKotlin() + ")"
|
||||
else
|
||||
"")
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import java.util.LinkedList
|
||||
|
||||
public open class Block(val statements: List<Element>, val notEmpty: Boolean = false): Statement() {
|
||||
public open class Block(val statements: List<Element>, val notEmpty: Boolean = false) : Statement() {
|
||||
public override fun isEmpty(): Boolean {
|
||||
return !notEmpty && (statements.size() == 0 || statements.all { it == Statement.EMPTY_STATEMENT })
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public open class CallChainExpression(val expression : Expression, val identifier : Expression) : Expression() {
|
||||
public override fun isNullable() : Boolean {
|
||||
public open class CallChainExpression(val expression: Expression, val identifier: Expression) : Expression() {
|
||||
public override fun isNullable(): Boolean {
|
||||
if (!expression.isEmpty() && expression.isNullable()) return true
|
||||
return identifier.isNullable()
|
||||
}
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
public override fun toKotlin(): String {
|
||||
if (!expression.isEmpty()) {
|
||||
return expression.toKotlin() + (if (expression.isNullable()) "?." else ".") + identifier.toKotlin()
|
||||
}
|
||||
|
||||
@@ -16,40 +16,38 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.J2KConverterFlags
|
||||
import org.jetbrains.jet.j2k.ast.types.ClassType
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.HashSet
|
||||
import java.util.LinkedList
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class Class(converter : Converter,
|
||||
val name : Identifier,
|
||||
public open class Class(converter: Converter,
|
||||
val name: Identifier,
|
||||
val docComments: List<Node>,
|
||||
modifiers : Set<Modifier>,
|
||||
val typeParameters : List<Element>,
|
||||
val extendsTypes : List<Type>,
|
||||
val baseClassParams : List<Expression>,
|
||||
val implementsTypes : List<Type>,
|
||||
members : List<Node>) : Member(modifiers) {
|
||||
modifiers: Set<Modifier>,
|
||||
val typeParameters: List<Element>,
|
||||
val extendsTypes: List<Type>,
|
||||
val baseClassParams: List<Expression>,
|
||||
val implementsTypes: List<Type>,
|
||||
members: List<Node>) : Member(modifiers) {
|
||||
val members = getMembers(members, converter)
|
||||
|
||||
open val TYPE: String
|
||||
get() = "class"
|
||||
|
||||
private fun getPrimaryConstructor() : Constructor? {
|
||||
private fun getPrimaryConstructor(): Constructor? {
|
||||
return members.find { it is Constructor && it.isPrimary } as Constructor?
|
||||
}
|
||||
|
||||
open fun primaryConstructorSignatureToKotlin() : String {
|
||||
val maybeConstructor : Constructor? = getPrimaryConstructor()
|
||||
open fun primaryConstructorSignatureToKotlin(): String {
|
||||
val maybeConstructor: Constructor? = getPrimaryConstructor()
|
||||
return if (maybeConstructor != null) maybeConstructor.primarySignatureToKotlin() else "()"
|
||||
}
|
||||
|
||||
open fun primaryConstructorBodyToKotlin() : String? {
|
||||
val maybeConstructor : Constructor? = getPrimaryConstructor()
|
||||
open fun primaryConstructorBodyToKotlin(): String? {
|
||||
val maybeConstructor: Constructor? = getPrimaryConstructor()
|
||||
if (maybeConstructor != null && !(maybeConstructor.block?.isEmpty() ?: true)) {
|
||||
return maybeConstructor.primaryBodyToKotlin()
|
||||
}
|
||||
@@ -57,9 +55,9 @@ public open class Class(converter : Converter,
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun hasWhere() : Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() }
|
||||
private fun hasWhere(): Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() }
|
||||
|
||||
open fun typeParameterWhereToKotlin() : String {
|
||||
open fun typeParameterWhereToKotlin(): String {
|
||||
if (hasWhere()) {
|
||||
val wheres = typeParameters.filter { it is TypeParameter }.map { (it as TypeParameter).getWhereToKotlin() }
|
||||
return " where " + wheres.makeString(", ") + " "
|
||||
@@ -67,9 +65,9 @@ public open class Class(converter : Converter,
|
||||
return ""
|
||||
}
|
||||
|
||||
open fun membersExceptConstructors() : List<Node> = members.filterNot { it is Constructor }
|
||||
open fun membersExceptConstructors(): List<Node> = members.filterNot { it is Constructor }
|
||||
|
||||
open fun secondaryConstructorsAsStaticInitFunction() : List<Function> {
|
||||
open fun secondaryConstructorsAsStaticInitFunction(): List<Function> {
|
||||
return members.filter { it is Constructor && !it.isPrimary }.map { constructorToInit(it as Function) }
|
||||
}
|
||||
|
||||
@@ -83,12 +81,12 @@ public open class Class(converter : Converter,
|
||||
constructorTypeParameters.addAll(typeParameters)
|
||||
constructorTypeParameters.addAll(f.typeParameters)
|
||||
return Function(Identifier("init"), arrayList(), modifiers, ClassType(name, constructorTypeParameters, false),
|
||||
constructorTypeParameters, f.params, block)
|
||||
constructorTypeParameters, f.params, block)
|
||||
}
|
||||
|
||||
open fun typeParametersToKotlin() : String = typeParameters.toKotlin(", ", "<", ">")
|
||||
open fun typeParametersToKotlin(): String = typeParameters.toKotlin(", ", "<", ">")
|
||||
|
||||
open fun baseClassSignatureWithParams() : List<String> {
|
||||
open fun baseClassSignatureWithParams(): List<String> {
|
||||
if (TYPE.equals("class") && extendsTypes.size() == 1) {
|
||||
val baseParams = baseClassParams.toKotlin(", ")
|
||||
return arrayList(extendsTypes[0].toKotlin() + "(" + baseParams + ")")
|
||||
@@ -96,8 +94,8 @@ public open class Class(converter : Converter,
|
||||
return extendsTypes.map { it.toKotlin() }
|
||||
}
|
||||
|
||||
open fun implementTypesToKotlin() : String {
|
||||
val allTypes = ArrayList<String>()
|
||||
open fun implementTypesToKotlin(): String {
|
||||
val allTypes = ArrayList<String>()
|
||||
allTypes.addAll(baseClassSignatureWithParams())
|
||||
allTypes.addAll(implementsTypes.map { it.toKotlin() })
|
||||
return if (allTypes.size() == 0)
|
||||
@@ -106,8 +104,8 @@ public open class Class(converter : Converter,
|
||||
" : " + allTypes.makeString(", ")
|
||||
}
|
||||
|
||||
open fun modifiersToKotlin() : String {
|
||||
val modifierList = ArrayList<Modifier>()
|
||||
open fun modifiersToKotlin(): String {
|
||||
val modifierList = ArrayList<Modifier>()
|
||||
val modifier = accessModifier()
|
||||
if (modifier != null) {
|
||||
modifierList.add(modifier)
|
||||
@@ -126,42 +124,44 @@ public open class Class(converter : Converter,
|
||||
|
||||
open fun needAbstractModifier() = isAbstract()
|
||||
|
||||
open fun bodyToKotlin() : String {
|
||||
open fun bodyToKotlin(): String {
|
||||
return " {\n" + getNonStatic(membersExceptConstructors()).toKotlin("\n") + "\n" + primaryConstructorBodyToKotlin() + "\n" + classObjectToKotlin() + "\n}"
|
||||
}
|
||||
|
||||
private fun classObjectToKotlin() : String {
|
||||
private fun classObjectToKotlin(): String {
|
||||
val staticMembers = ArrayList<Node>()
|
||||
staticMembers.addAll(secondaryConstructorsAsStaticInitFunction())
|
||||
staticMembers.addAll(getStatic(membersExceptConstructors()))
|
||||
return staticMembers.toKotlin("\n", "class object {\n", "\n}")
|
||||
}
|
||||
|
||||
public override fun toKotlin() : String =
|
||||
docComments.toKotlin("\n", "", "\n") +
|
||||
modifiersToKotlin() +
|
||||
TYPE + " " + name.toKotlin() +
|
||||
typeParametersToKotlin() +
|
||||
primaryConstructorSignatureToKotlin() +
|
||||
implementTypesToKotlin() +
|
||||
typeParameterWhereToKotlin() +
|
||||
bodyToKotlin()
|
||||
public override fun toKotlin(): String =
|
||||
docComments.toKotlin("\n", "", "\n") +
|
||||
modifiersToKotlin() +
|
||||
TYPE + " " + name.toKotlin() +
|
||||
typeParametersToKotlin() +
|
||||
primaryConstructorSignatureToKotlin() +
|
||||
implementTypesToKotlin() +
|
||||
typeParameterWhereToKotlin() +
|
||||
bodyToKotlin()
|
||||
|
||||
class object {
|
||||
open fun getMembers(members : List<Node>, converter : Converter) : List<Node> {
|
||||
open fun getMembers(members: List<Node>, converter: Converter): List<Node> {
|
||||
if (converter.hasFlag(J2KConverterFlags.SKIP_NON_PUBLIC_MEMBERS)) {
|
||||
return members.filter { it is Comment ||
|
||||
(it as Member).accessModifier() == Modifier.PUBLIC ||
|
||||
(it as Member).accessModifier() == Modifier.PROTECTED }
|
||||
return members.filter {
|
||||
it is Comment ||
|
||||
(it as Member).accessModifier() == Modifier.PUBLIC ||
|
||||
(it as Member).accessModifier() == Modifier.PROTECTED
|
||||
}
|
||||
}
|
||||
return members
|
||||
}
|
||||
|
||||
private fun getStatic(members : List<Node>) : List<Node> {
|
||||
private fun getStatic(members: List<Node>): List<Node> {
|
||||
return members.filter { it is Member && it.isStatic() }
|
||||
}
|
||||
|
||||
private fun getNonStatic(members : List<Node>) : List<Node> {
|
||||
private fun getNonStatic(members: List<Node>): List<Node> {
|
||||
return members.filterNot { it is Member && it.isStatic() }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,20 +18,20 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class Constructor(identifier : Identifier,
|
||||
public open class Constructor(identifier: Identifier,
|
||||
docComments: List<Node>,
|
||||
modifiers : Set<Modifier>,
|
||||
`type` : Type,
|
||||
typeParameters : List<Element>,
|
||||
params : Element,
|
||||
block : Block,
|
||||
val isPrimary : Boolean) : Function(identifier, docComments, modifiers, `type`, typeParameters, params, block) {
|
||||
modifiers: Set<Modifier>,
|
||||
`type`: Type,
|
||||
typeParameters: List<Element>,
|
||||
params: Element,
|
||||
block: Block,
|
||||
val isPrimary: Boolean) : Function(identifier, docComments, modifiers, `type`, typeParameters, params, block) {
|
||||
|
||||
public open fun primarySignatureToKotlin() : String {
|
||||
public open fun primarySignatureToKotlin(): String {
|
||||
return "(" + params.toKotlin() + ")"
|
||||
}
|
||||
|
||||
public open fun primaryBodyToKotlin() : String {
|
||||
public open fun primaryBodyToKotlin(): String {
|
||||
return block!!.toKotlin()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class DummyStringExpression(val string: String): Expression() {
|
||||
public open class DummyStringExpression(val string: String) : Expression() {
|
||||
public override fun toKotlin(): String = string
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public abstract class Element(): Node() {
|
||||
public abstract class Element() : Node() {
|
||||
public open fun isEmpty(): Boolean = false
|
||||
|
||||
class object {
|
||||
@@ -28,6 +28,6 @@ public abstract class Element(): Node() {
|
||||
}
|
||||
}
|
||||
|
||||
public class Comment(val text: String): Element() {
|
||||
public class Comment(val text: String) : Element() {
|
||||
override fun toKotlin() = text
|
||||
}
|
||||
|
||||
@@ -19,33 +19,33 @@ package org.jetbrains.jet.j2k.ast
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class Enum(converter : Converter,
|
||||
name : Identifier,
|
||||
public open class Enum(converter: Converter,
|
||||
name: Identifier,
|
||||
docComments: List<Node>,
|
||||
modifiers : Set<Modifier>,
|
||||
typeParameters : List<Element>,
|
||||
extendsTypes : List<Type>,
|
||||
baseClassParams : List<Expression>,
|
||||
implementsTypes : List<Type>,
|
||||
members : List<Node>) : Class(converter, name, docComments, modifiers, typeParameters,
|
||||
modifiers: Set<Modifier>,
|
||||
typeParameters: List<Element>,
|
||||
extendsTypes: List<Type>,
|
||||
baseClassParams: List<Expression>,
|
||||
implementsTypes: List<Type>,
|
||||
members: List<Node>) : Class(converter, name, docComments, modifiers, typeParameters,
|
||||
extendsTypes, baseClassParams, implementsTypes, members) {
|
||||
|
||||
override fun primaryConstructorSignatureToKotlin() : String {
|
||||
val s : String = super.primaryConstructorSignatureToKotlin()
|
||||
override fun primaryConstructorSignatureToKotlin(): String {
|
||||
val s: String = super.primaryConstructorSignatureToKotlin()
|
||||
return if (s.equals("()")) "" else s
|
||||
}
|
||||
|
||||
override fun needOpenModifier() = false
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
public override fun toKotlin(): String {
|
||||
val primaryConstructorBody = primaryConstructorBodyToKotlin() ?: ""
|
||||
return modifiersToKotlin() +
|
||||
"enum class " + name.toKotlin() +
|
||||
primaryConstructorSignatureToKotlin() +
|
||||
typeParametersToKotlin() +
|
||||
implementTypesToKotlin() +
|
||||
" {\n" + membersExceptConstructors().toKotlin("\n") + "\n" +
|
||||
(if (primaryConstructorBody.isEmpty()) "" else primaryConstructorBody + "\n") +
|
||||
"}"
|
||||
"enum class " + name.toKotlin() +
|
||||
primaryConstructorSignatureToKotlin() +
|
||||
typeParametersToKotlin() +
|
||||
implementTypesToKotlin() +
|
||||
" {\n" + membersExceptConstructors().toKotlin("\n") + "\n" +
|
||||
(if (primaryConstructorBody.isEmpty()) "" else primaryConstructorBody + "\n") +
|
||||
"}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class EnumConstant(identifier : Identifier,
|
||||
public open class EnumConstant(identifier: Identifier,
|
||||
docComments: List<Node>,
|
||||
modifiers : Set<Modifier>,
|
||||
`type` : Type,
|
||||
params : Element) : Field(identifier, docComments, modifiers, `type`.convertedToNotNull(), params, 0) {
|
||||
modifiers: Set<Modifier>,
|
||||
`type`: Type,
|
||||
params: Element) : Field(identifier, docComments, modifiers, `type`.convertedToNotNull(), params, 0) {
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
public override fun toKotlin(): String {
|
||||
if (initializer.toKotlin().isEmpty()) {
|
||||
return identifier.toKotlin()
|
||||
}
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public abstract class Expression(): Statement() {
|
||||
public abstract class Expression() : Statement() {
|
||||
public open fun isNullable(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
class object {
|
||||
public val EMPTY_EXPRESSION: Expression = object: Expression() {
|
||||
public override fun toKotlin()= ""
|
||||
public override fun toKotlin() = ""
|
||||
public override fun isEmpty() = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class ExpressionList(val expressions: List<Expression>): Expression() {
|
||||
public open class ExpressionList(val expressions: List<Expression>) : Expression() {
|
||||
public override fun toKotlin(): String = expressions.map { it.toKotlin() }.makeString(", ")
|
||||
}
|
||||
|
||||
@@ -20,48 +20,48 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class ArrayAccessExpression(val expression: Expression, val index: Expression, val lvalue: Boolean) : Expression() {
|
||||
override fun toKotlin() = expression.toKotlin() +
|
||||
(if (!lvalue && expression.isNullable()) "!!" else "") +
|
||||
"[" + index.toKotlin() + "]"
|
||||
(if (!lvalue && expression.isNullable()) "!!" else "") +
|
||||
"[" + index.toKotlin() + "]"
|
||||
}
|
||||
|
||||
public open class AssignmentExpression(val left : Expression, val right : Expression, val op : String) : Expression() {
|
||||
override fun toKotlin() = left.toKotlin() + " "+ op + " "+ right.toKotlin()
|
||||
}
|
||||
|
||||
public class BangBangExpression(val expr: Expression): Expression() {
|
||||
override fun toKotlin() = expr.toKotlin() + "!!"
|
||||
}
|
||||
|
||||
public open class BinaryExpression(val left: Expression, val right: Expression, val op: String): Expression() {
|
||||
public open class AssignmentExpression(val left: Expression, val right: Expression, val op: String) : Expression() {
|
||||
override fun toKotlin() = left.toKotlin() + " " + op + " " + right.toKotlin()
|
||||
}
|
||||
|
||||
public open class ClassObjectAccessExpression(val typeElement: TypeElement): Expression() {
|
||||
public class BangBangExpression(val expr: Expression) : Expression() {
|
||||
override fun toKotlin() = expr.toKotlin() + "!!"
|
||||
}
|
||||
|
||||
public open class BinaryExpression(val left: Expression, val right: Expression, val op: String) : Expression() {
|
||||
override fun toKotlin() = left.toKotlin() + " " + op + " " + right.toKotlin()
|
||||
}
|
||||
|
||||
public open class ClassObjectAccessExpression(val typeElement: TypeElement) : Expression() {
|
||||
override fun toKotlin() = "javaClass<" + typeElement.toKotlinNotNull() + ">()"
|
||||
}
|
||||
|
||||
public open class IsOperator(val expression: Expression, val typeElement: TypeElement): Expression() {
|
||||
public open class IsOperator(val expression: Expression, val typeElement: TypeElement) : Expression() {
|
||||
override fun toKotlin() = expression.toKotlin() + " is " + typeElement.toKotlinNotNull()
|
||||
}
|
||||
|
||||
public open class TypeCastExpression(val `type` : Type, val expression : Expression) : Expression() {
|
||||
public open class TypeCastExpression(val `type`: Type, val expression: Expression) : Expression() {
|
||||
override fun toKotlin() = "(" + expression.toKotlin() + " as " + `type`.toKotlin() + ")"
|
||||
}
|
||||
|
||||
public open class LiteralExpression(val literalText: String): Expression() {
|
||||
public open class LiteralExpression(val literalText: String) : Expression() {
|
||||
override fun toKotlin() = literalText
|
||||
}
|
||||
|
||||
public open class ParenthesizedExpression(val expression : Expression) : Expression() {
|
||||
public open class ParenthesizedExpression(val expression: Expression) : Expression() {
|
||||
override fun toKotlin() = "(" + expression.toKotlin() + ")"
|
||||
}
|
||||
|
||||
public open class PrefixOperator(val op: String, val expression: Expression): Expression() {
|
||||
public open class PrefixOperator(val op: String, val expression: Expression) : Expression() {
|
||||
override fun toKotlin() = op + expression.toKotlin()
|
||||
override fun isNullable() = expression.isNullable()
|
||||
}
|
||||
|
||||
public open class PostfixOperator(val op: String, val expression: Expression): Expression() {
|
||||
public open class PostfixOperator(val op: String, val expression: Expression) : Expression() {
|
||||
override fun toKotlin() = expression.toKotlin() + op
|
||||
}
|
||||
|
||||
@@ -69,6 +69,6 @@ public open class ThisExpression(val identifier: Identifier) : Expression() {
|
||||
override fun toKotlin() = "this" + identifier.withPrefix("@")
|
||||
}
|
||||
|
||||
public open class SuperExpression(val identifier : Identifier) : Expression() {
|
||||
public open class SuperExpression(val identifier: Identifier) : Expression() {
|
||||
override fun toKotlin() = "super" + identifier.withPrefix("@")
|
||||
}
|
||||
|
||||
@@ -17,18 +17,17 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.LinkedList
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class Field(val identifier : Identifier,
|
||||
public open class Field(val identifier: Identifier,
|
||||
val docComments: List<Node>,
|
||||
modifiers : Set<Modifier>,
|
||||
val `type` : Type,
|
||||
val initializer : Element,
|
||||
val writingAccesses : Int) : Member(modifiers) {
|
||||
modifiers: Set<Modifier>,
|
||||
val `type`: Type,
|
||||
val initializer: Element,
|
||||
val writingAccesses: Int) : Member(modifiers) {
|
||||
|
||||
open fun modifiersToKotlin() : String {
|
||||
open fun modifiersToKotlin(): String {
|
||||
val modifierList = ArrayList<Modifier>()
|
||||
if (isAbstract()) {
|
||||
modifierList.add(Modifier.ABSTRACT)
|
||||
@@ -36,18 +35,18 @@ public open class Field(val identifier : Identifier,
|
||||
|
||||
val modifier = accessModifier()
|
||||
if (modifier != null) {
|
||||
modifierList.add(modifier)
|
||||
modifierList.add(modifier)
|
||||
}
|
||||
|
||||
return modifierList.toKotlin() + (if (isVal()) "val " else "var ")
|
||||
}
|
||||
|
||||
public open fun isVal() : Boolean = modifiers.contains(Modifier.FINAL)
|
||||
public override fun isStatic() : Boolean = modifiers.contains(Modifier.STATIC)
|
||||
public open fun isVal(): Boolean = modifiers.contains(Modifier.FINAL)
|
||||
public override fun isStatic(): Boolean = modifiers.contains(Modifier.STATIC)
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
val declaration : String = docComments.toKotlin("\n", "", "\n") +
|
||||
modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin()
|
||||
public override fun toKotlin(): String {
|
||||
val declaration: String = docComments.toKotlin("\n", "", "\n") +
|
||||
modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin()
|
||||
if (initializer.isEmpty()) {
|
||||
return declaration + ((if (isVal() && !isStatic() && writingAccesses != 0)
|
||||
""
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
public open class File(val packageName: String,
|
||||
val imports: MutableList<Import>,
|
||||
val body: MutableList<Node>,
|
||||
val mainFunction: String): Node() {
|
||||
val mainFunction: String) : Node() {
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
val common: String = imports.toKotlin("\n") + "\n\n" + body.toKotlin("\n") + "\n" + mainFunction
|
||||
|
||||
@@ -16,37 +16,36 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import java.util.LinkedList
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class Function(val name : Identifier,
|
||||
public open class Function(val name: Identifier,
|
||||
val docComments: List<Node>,
|
||||
modifiers : Set<Modifier>,
|
||||
val `type` : Type,
|
||||
val typeParameters : List<Element>,
|
||||
val params : Element,
|
||||
var block : Block?) : Member(modifiers) {
|
||||
private fun typeParametersToKotlin() : String {
|
||||
modifiers: Set<Modifier>,
|
||||
val `type`: Type,
|
||||
val typeParameters: List<Element>,
|
||||
val params: Element,
|
||||
var block: Block?) : Member(modifiers) {
|
||||
private fun typeParametersToKotlin(): String {
|
||||
return (if (typeParameters.size() > 0)
|
||||
"<" + typeParameters.map { it.toKotlin() }.makeString(", ") + ">"
|
||||
else
|
||||
"")
|
||||
}
|
||||
|
||||
private fun hasWhere() : Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() }
|
||||
private fun hasWhere(): Boolean = typeParameters.any { it is TypeParameter && it.hasWhere() }
|
||||
|
||||
private fun typeParameterWhereToKotlin() : String {
|
||||
private fun typeParameterWhereToKotlin(): String {
|
||||
if (hasWhere())
|
||||
{
|
||||
val wheres = typeParameters.filter { it is TypeParameter }.map { ((it as TypeParameter).getWhereToKotlin() )}
|
||||
val wheres = typeParameters.filter { it is TypeParameter }.map { ((it as TypeParameter).getWhereToKotlin() ) }
|
||||
return " where " + wheres.makeString(", ") + " "
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
open fun modifiersToKotlin() : String {
|
||||
open fun modifiersToKotlin(): String {
|
||||
val modifierList = ArrayList<Modifier>()
|
||||
val accessModifier = accessModifier()
|
||||
if (accessModifier != null) {
|
||||
@@ -62,9 +61,9 @@ public open class Function(val name : Identifier,
|
||||
}
|
||||
|
||||
if (!modifiers.contains(Modifier.ABSTRACT) &&
|
||||
!modifiers.contains(Modifier.OVERRIDE) &&
|
||||
!modifiers.contains(Modifier.FINAL) &&
|
||||
!modifiers.contains(Modifier.PRIVATE)) {
|
||||
!modifiers.contains(Modifier.OVERRIDE) &&
|
||||
!modifiers.contains(Modifier.FINAL) &&
|
||||
!modifiers.contains(Modifier.PRIVATE)) {
|
||||
modifierList.add(Modifier.OPEN)
|
||||
}
|
||||
|
||||
@@ -75,13 +74,13 @@ public open class Function(val name : Identifier,
|
||||
return modifierList.toKotlin()
|
||||
}
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
public override fun toKotlin(): String {
|
||||
return docComments.toKotlin("\n", "", "\n") +
|
||||
modifiersToKotlin() +
|
||||
"fun " + name.toKotlin() +
|
||||
typeParametersToKotlin() +
|
||||
"(" + params.toKotlin() + ") : " +
|
||||
`type`.toKotlin() + " "+ typeParameterWhereToKotlin() +
|
||||
block?.toKotlin()
|
||||
modifiersToKotlin() +
|
||||
"fun " + name.toKotlin() +
|
||||
typeParametersToKotlin() +
|
||||
"(" + params.toKotlin() + ") : " +
|
||||
`type`.toKotlin() + " " + typeParameterWhereToKotlin() +
|
||||
block?.toKotlin()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
|
||||
public open class Identifier(val name: String,
|
||||
val myNullable: Boolean = true,
|
||||
val quotingNeeded: Boolean = true): Expression() {
|
||||
val quotingNeeded: Boolean = true) : Expression() {
|
||||
public override fun isEmpty() = name.length() == 0
|
||||
|
||||
private open fun ifNeedQuote(): String {
|
||||
private open fun ifNeedQuote(): String {
|
||||
if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(name)) || name.contains("$")) {
|
||||
return quote(name)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class Import(val name: String): Node() {
|
||||
public open class Import(val name: String) : Node() {
|
||||
public override fun toKotlin() = "import " + name
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class Initializer(val block : Block, modifiers : Set<Modifier>) : Member(modifiers) {
|
||||
public override fun toKotlin() : String {
|
||||
public open class Initializer(val block: Block, modifiers: Set<Modifier>) : Member(modifiers) {
|
||||
public override fun toKotlin(): String {
|
||||
return block.toKotlin()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
public open class LocalVariable(val identifier: Identifier,
|
||||
val modifiersSet: Set<Modifier>,
|
||||
val `type`: Type,
|
||||
val initializer: Expression): Expression() {
|
||||
val initializer: Expression) : Expression() {
|
||||
|
||||
public open fun hasModifier(modifier: Modifier): Boolean = modifiersSet.contains(modifier)
|
||||
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public abstract class Member(val modifiers : Set<Modifier>) : Node() {
|
||||
open fun accessModifier() : Modifier? {
|
||||
public abstract class Member(val modifiers: Set<Modifier>) : Node() {
|
||||
open fun accessModifier(): Modifier? {
|
||||
return modifiers.find { m -> m == Modifier.PUBLIC || m == Modifier.PROTECTED || m == Modifier.PRIVATE }
|
||||
}
|
||||
|
||||
public open fun isAbstract() : Boolean = modifiers.contains(Modifier.ABSTRACT)
|
||||
public open fun isStatic() : Boolean = modifiers.contains(Modifier.STATIC)
|
||||
public open fun isAbstract(): Boolean = modifiers.contains(Modifier.ABSTRACT)
|
||||
public open fun isStatic(): Boolean = modifiers.contains(Modifier.STATIC)
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
public open class MethodCallExpression(val methodCall: Expression,
|
||||
val arguments: List<Expression>,
|
||||
val typeParameters: List<Type>,
|
||||
val resultIsNullable: Boolean = false): Expression() {
|
||||
val resultIsNullable: Boolean = false) : Expression() {
|
||||
public override fun isNullable(): Boolean = methodCall.isNullable() || resultIsNullable
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
@@ -33,8 +33,8 @@ public open class MethodCallExpression(val methodCall: Expression,
|
||||
class object {
|
||||
fun build(receiver: Expression, methodName: String, arguments: List<Expression> = arrayList()): MethodCallExpression {
|
||||
return MethodCallExpression(CallChainExpression(receiver, Identifier(methodName, false)),
|
||||
arguments,
|
||||
arrayList(), false)
|
||||
arguments,
|
||||
arrayList(), false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,12 +16,10 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.annotations.Nullable
|
||||
|
||||
public open class NewClassExpression(val name: Element,
|
||||
val arguments: List<Expression>,
|
||||
val qualifier: Expression = Expression.EMPTY_EXPRESSION,
|
||||
val anonymousClass: AnonymousClass? = null): Expression() {
|
||||
val anonymousClass: AnonymousClass? = null) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
val callOperator: String? = (if (qualifier.isNullable())
|
||||
"?."
|
||||
|
||||
@@ -19,13 +19,13 @@ 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` is 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` is VarArg)
|
||||
"vararg "
|
||||
else
|
||||
"")
|
||||
val `var` : String? = (if (readOnly)
|
||||
val `var`: String? = (if (readOnly)
|
||||
""
|
||||
else
|
||||
"var ")
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class ParameterList(val parameters : List<Parameter>) : Expression() {
|
||||
public open class ParameterList(val parameters: List<Parameter>) : Expression() {
|
||||
public override fun toKotlin() = parameters.map { it.toKotlin() }.makeString(", ")
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class PolyadicExpression(val expressions: List<Expression>, val token: String): Expression() {
|
||||
public open class PolyadicExpression(val expressions: List<Expression>, val token: String) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
val expressionsWithConversions = expressions.map { it.toKotlin() }
|
||||
return expressionsWithConversions.makeString(" " + token + " ")
|
||||
|
||||
@@ -18,6 +18,6 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class ReferenceElement(val reference : Identifier, val types : List<Type>) : Element() {
|
||||
public open class ReferenceElement(val reference: Identifier, val types: List<Type>) : Element() {
|
||||
public override fun toKotlin() = reference.toKotlin() + types.toKotlin(", ", "<", ">")
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public abstract class Statement(): Element() {
|
||||
public abstract class Statement() : Element() {
|
||||
class object {
|
||||
public val EMPTY_STATEMENT: Statement = object : Statement() {
|
||||
public override fun toKotlin() = ""
|
||||
@@ -25,7 +25,7 @@ public abstract class Statement(): Element() {
|
||||
}
|
||||
}
|
||||
|
||||
public open class DeclarationStatement(val elements: List<Element>): Statement() {
|
||||
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")
|
||||
}
|
||||
@@ -39,21 +39,21 @@ public open class DeclarationStatement(val elements: List<Element>): Statement()
|
||||
}
|
||||
}
|
||||
|
||||
public open class ExpressionListStatement(val expressions: List<Expression>): Expression() {
|
||||
public open class ExpressionListStatement(val expressions: List<Expression>) : Expression() {
|
||||
public override fun toKotlin() = expressions.toKotlin("\n")
|
||||
}
|
||||
|
||||
public open class LabelStatement(val name: Identifier, val statement: Element): Statement() {
|
||||
public open class LabelStatement(val name: Identifier, val statement: Element) : Statement() {
|
||||
public override fun toKotlin(): String = "@" + name.toKotlin() + " " + statement.toKotlin()
|
||||
}
|
||||
|
||||
public open class ReturnStatement(val expression: Expression): Statement() {
|
||||
public open class ReturnStatement(val expression: Expression) : Statement() {
|
||||
public override fun toKotlin() = "return " + expression.toKotlin()
|
||||
}
|
||||
|
||||
public open class IfStatement(val condition: Expression,
|
||||
val thenStatement: Element,
|
||||
val elseStatement: Element): Expression() {
|
||||
val elseStatement: Element) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n"
|
||||
if (elseStatement != Statement.EMPTY_STATEMENT) {
|
||||
@@ -66,40 +66,40 @@ public open class IfStatement(val condition: Expression,
|
||||
|
||||
// Loops --------------------------------------------------------------------------------------------------
|
||||
|
||||
public open class WhileStatement(val condition: Expression, val body: Element): Statement() {
|
||||
public open class WhileStatement(val condition: Expression, val body: Element) : Statement() {
|
||||
public override fun toKotlin() = "while (" + condition.toKotlin() + ")\n" + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class DoWhileStatement(condition: Expression, body: Element): WhileStatement(condition, body) {
|
||||
public open class DoWhileStatement(condition: Expression, body: Element) : WhileStatement(condition, body) {
|
||||
public override fun toKotlin() = "do\n" + body.toKotlin() + "\nwhile (" + condition.toKotlin() + ")"
|
||||
}
|
||||
|
||||
public open class ForeachStatement(val variable: Parameter,
|
||||
val expression: Expression,
|
||||
val body: Element): Statement() {
|
||||
val body: Element) : Statement() {
|
||||
public override fun toKotlin() = "for (" + variable.toKotlin() + " in " +
|
||||
expression.toKotlin() + ")\n" + body.toKotlin()
|
||||
expression.toKotlin() + ")\n" + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class ForeachWithRangeStatement(val identifier: Identifier,
|
||||
val start: Expression,
|
||||
val end: Expression,
|
||||
val body: Element): Statement() {
|
||||
val body: Element) : Statement() {
|
||||
public override fun toKotlin() = "for (" + identifier.toKotlin() + " in " +
|
||||
start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin()
|
||||
start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : 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_IDENTIFIER) : Statement() {
|
||||
public override fun toKotlin() = "continue" + label.withPrefix("@")
|
||||
}
|
||||
|
||||
// Exceptions ----------------------------------------------------------------------------------------------
|
||||
|
||||
public open class TryStatement(val block: Block, val catches: List<CatchStatement>, val finallyBlock: Block): Statement() {
|
||||
public open class TryStatement(val block: Block, val catches: List<CatchStatement>, val finallyBlock: Block) : Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
return "try\n" + block.toKotlin() + "\n" + catches.toKotlin("\n") + "\n" + (if (finallyBlock.isEmpty())
|
||||
""
|
||||
@@ -108,21 +108,21 @@ public open class TryStatement(val block: Block, val catches: List<CatchStatemen
|
||||
}
|
||||
}
|
||||
|
||||
public open class ThrowStatement(val expression: Expression): Expression() {
|
||||
public open class ThrowStatement(val expression: Expression) : Expression() {
|
||||
public override fun toKotlin() = "throw " + expression.toKotlin()
|
||||
}
|
||||
|
||||
public open class CatchStatement(val variable: Parameter, val block: Block): Statement() {
|
||||
public override fun toKotlin(): String = "catch (" + variable.toKotlin() + ") " + block.toKotlin()
|
||||
public open class CatchStatement(val variable: Parameter, val block: Block) : Statement() {
|
||||
public override fun toKotlin(): String = "catch (" + variable.toKotlin() + ") " + block.toKotlin()
|
||||
}
|
||||
|
||||
// Switch --------------------------------------------------------------------------------------------------
|
||||
|
||||
public open class SwitchContainer(val expression: Expression, val caseContainers: List<CaseContainer>): Statement() {
|
||||
public open class SwitchContainer(val expression: Expression, val caseContainers: List<CaseContainer>) : Statement() {
|
||||
public override fun toKotlin() = "when (" + expression.toKotlin() + ") {\n" + caseContainers.toKotlin("\n") + "\n}"
|
||||
}
|
||||
|
||||
public open class CaseContainer(val caseStatement: List<Element>, statements: List<Element>): Statement() {
|
||||
public open class CaseContainer(val caseStatement: List<Element>, statements: List<Element>) : Statement() {
|
||||
private val myBlock: Block
|
||||
|
||||
{
|
||||
@@ -133,16 +133,16 @@ public open class CaseContainer(val caseStatement: List<Element>, statements: Li
|
||||
public override fun toKotlin() = caseStatement.toKotlin(", ") + " -> " + myBlock.toKotlin()
|
||||
}
|
||||
|
||||
public open class SwitchLabelStatement(val expression: Expression): Statement() {
|
||||
public open class SwitchLabelStatement(val expression: Expression) : Statement() {
|
||||
public override fun toKotlin() = expression.toKotlin()
|
||||
}
|
||||
|
||||
public open class DefaultSwitchLabelStatement(): Statement() {
|
||||
public open class DefaultSwitchLabelStatement() : Statement() {
|
||||
public override fun toKotlin() = "else"
|
||||
}
|
||||
|
||||
// Other ------------------------------------------------------------------------------------------------------
|
||||
|
||||
public open class SynchronizedStatement(val expression: Expression, val block: Block): Statement() {
|
||||
public override fun toKotlin() = "synchronized (" + expression.toKotlin() + ") "+ block.toKotlin()
|
||||
public open class SynchronizedStatement(val expression: Expression, val block: Block) : Statement() {
|
||||
public override fun toKotlin() = "synchronized (" + expression.toKotlin() + ") " + block.toKotlin()
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ package org.jetbrains.jet.j2k.ast
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class Trait(converter : Converter,
|
||||
name : Identifier,
|
||||
public open class Trait(converter: Converter,
|
||||
name: Identifier,
|
||||
docComments: List<Node>,
|
||||
modifiers : Set<Modifier>,
|
||||
typeParameters : List<Element>,
|
||||
extendsTypes : List<Type>,
|
||||
baseClassParams : List<Expression>,
|
||||
implementsTypes : List<Type>,
|
||||
members : List<Node>) : Class(converter, name, docComments, modifiers, typeParameters,
|
||||
extendsTypes, baseClassParams, implementsTypes, members) {
|
||||
modifiers: Set<Modifier>,
|
||||
typeParameters: List<Element>,
|
||||
extendsTypes: List<Type>,
|
||||
baseClassParams: List<Expression>,
|
||||
implementsTypes: List<Type>,
|
||||
members: List<Node>) : Class(converter, name, docComments, modifiers, typeParameters,
|
||||
extendsTypes, baseClassParams, implementsTypes, members) {
|
||||
|
||||
override val TYPE: String
|
||||
get() = "trait"
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class TypeElement(val `type` : Type) : Element() {
|
||||
public open class TypeElement(val `type`: Type) : Element() {
|
||||
override fun toKotlin() = `type`.toKotlin()
|
||||
|
||||
public fun toKotlinNotNull(): String = `type`.convertedToNotNull().toKotlin()
|
||||
|
||||
@@ -18,9 +18,9 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class TypeParameter(val name : Identifier, val extendsTypes : List<Type>) : Element() {
|
||||
public open fun hasWhere() : Boolean = extendsTypes.size() > 1
|
||||
public open fun getWhereToKotlin() : String {
|
||||
public open class TypeParameter(val name: Identifier, val extendsTypes: List<Type>) : Element() {
|
||||
public open fun hasWhere(): Boolean = extendsTypes.size() > 1
|
||||
public open fun getWhereToKotlin(): String {
|
||||
if (hasWhere()) {
|
||||
return name.toKotlin() + " : " + extendsTypes.get(1).toKotlin()
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public open class TypeParameter(val name : Identifier, val extendsTypes : List<T
|
||||
return ""
|
||||
}
|
||||
|
||||
public override fun toKotlin() : String {
|
||||
public override fun toKotlin(): String {
|
||||
if (extendsTypes.size() > 0) {
|
||||
return name.toKotlin() + " : " + extendsTypes [0].toKotlin()
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ fun List<Node>.toKotlin(separator: String, prefix: String = "", suffix: String =
|
||||
if (size() > 0) {
|
||||
result.append(prefix)
|
||||
var first = true
|
||||
for(x in this) {
|
||||
for (x in this) {
|
||||
if (!first) result.append(separator)
|
||||
first = false
|
||||
result.append(x.toKotlin())
|
||||
@@ -33,7 +33,7 @@ fun List<Node>.toKotlin(separator: String, prefix: String = "", suffix: String =
|
||||
|
||||
fun Collection<Modifier>.toKotlin(separator: String = " "): String {
|
||||
val result = StringBuilder()
|
||||
for(x in this) {
|
||||
for (x in this) {
|
||||
result.append(x.name)
|
||||
result.append(separator)
|
||||
}
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nullable) {
|
||||
public override fun toKotlin() : String {
|
||||
public open class ArrayType(val elementType: Type, nullable: Boolean) : Type(nullable) {
|
||||
public override fun toKotlin(): String {
|
||||
if (elementType is PrimitiveType) {
|
||||
return elementType.toKotlin() + "Array" + isNullableStr()
|
||||
}
|
||||
@@ -25,5 +25,5 @@ public open class ArrayType(val elementType : Type, nullable: Boolean) : Type(nu
|
||||
return "Array<" + elementType.toKotlin() + ">" + isNullableStr()
|
||||
}
|
||||
|
||||
public override fun convertedToNotNull() : Type = ArrayType(elementType, false)
|
||||
public override fun convertedToNotNull(): Type = ArrayType(elementType, false)
|
||||
}
|
||||
|
||||
@@ -18,17 +18,16 @@ package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.Element
|
||||
import org.jetbrains.jet.j2k.ast.Identifier
|
||||
import java.util.Collections
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class ClassType(val `type` : Identifier, val parameters : List<Element>, nullable : Boolean) : Type(nullable) {
|
||||
public override fun toKotlin() : String {
|
||||
public open class ClassType(val `type`: Identifier, val parameters: List<Element>, nullable: Boolean) : Type(nullable) {
|
||||
public override fun toKotlin(): String {
|
||||
// TODO change to map() when KT-2051 is fixed
|
||||
val parametersToKotlin = ArrayList<String>()
|
||||
for(param in parameters) {
|
||||
for (param in parameters) {
|
||||
parametersToKotlin.add(param.toKotlin())
|
||||
}
|
||||
var params : String = if (parametersToKotlin.size() == 0)
|
||||
var params: String = if (parametersToKotlin.size() == 0)
|
||||
""
|
||||
else
|
||||
"<" + parametersToKotlin.makeString(", ") + ">"
|
||||
@@ -36,5 +35,5 @@ public open class ClassType(val `type` : Identifier, val parameters : List<Eleme
|
||||
}
|
||||
|
||||
|
||||
public override fun convertedToNotNull() : Type = ClassType(`type`, parameters, false)
|
||||
public override fun convertedToNotNull(): Type = ClassType(`type`, parameters, false)
|
||||
}
|
||||
|
||||
@@ -17,5 +17,5 @@
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class EmptyType() : Type(false) {
|
||||
public override fun toKotlin() : String = "UNRESOLVED_TYPE"
|
||||
public override fun toKotlin(): String = "UNRESOLVED_TYPE"
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class InProjectionType(val bound : Type) : Type(false) {
|
||||
public override fun toKotlin() : String = "in " + bound.toKotlin()
|
||||
public open class InProjectionType(val bound: Type) : Type(false) {
|
||||
public override fun toKotlin(): String = "in " + bound.toKotlin()
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class OutProjectionType(val bound : Type) : Type(false) {
|
||||
public override fun toKotlin() : String = "out " + bound.toKotlin()
|
||||
public open class OutProjectionType(val bound: Type) : Type(false) {
|
||||
public override fun toKotlin(): String = "out " + bound.toKotlin()
|
||||
}
|
||||
|
||||
@@ -18,6 +18,6 @@ package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.Identifier
|
||||
|
||||
public open class PrimitiveType(val `type` : Identifier) : Type(false) {
|
||||
public override fun toKotlin() : String = `type`.toKotlin()
|
||||
public open class PrimitiveType(val `type`: Identifier) : Type(false) {
|
||||
public override fun toKotlin(): String = `type`.toKotlin()
|
||||
}
|
||||
|
||||
@@ -17,5 +17,5 @@
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class StarProjectionType() : Type(false) {
|
||||
public override fun toKotlin() : String = "*"
|
||||
public override fun toKotlin(): String = "*"
|
||||
}
|
||||
|
||||
@@ -19,12 +19,12 @@ package org.jetbrains.jet.j2k.ast.types
|
||||
import org.jetbrains.jet.j2k.ast.Element
|
||||
|
||||
public abstract class Type(val nullable: Boolean) : Element() {
|
||||
public open fun convertedToNotNull() : Type {
|
||||
public open fun convertedToNotNull(): Type {
|
||||
if (nullable) throw UnsupportedOperationException("convertedToNotNull must be defined")
|
||||
return this
|
||||
}
|
||||
|
||||
public open fun isNullableStr() : String? {
|
||||
public open fun isNullableStr(): String? {
|
||||
return (if (nullable)
|
||||
"?"
|
||||
else
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class VarArg(val `type` : Type) : Type(false) {
|
||||
public override fun toKotlin() : String = `type`.toKotlin()
|
||||
public open class VarArg(val `type`: Type) : Type(false) {
|
||||
public override fun toKotlin(): String = `type`.toKotlin()
|
||||
}
|
||||
|
||||
@@ -20,14 +20,14 @@ import com.intellij.psi.JavaRecursiveElementVisitor
|
||||
import com.intellij.psi.PsiClass
|
||||
import java.util.HashSet
|
||||
|
||||
public open class ClassVisitor(): JavaRecursiveElementVisitor() {
|
||||
public open class ClassVisitor() : JavaRecursiveElementVisitor() {
|
||||
private val myClassIdentifiers = HashSet<String>()
|
||||
|
||||
public open fun getClassIdentifiers(): Set<String> {
|
||||
return HashSet<String>(myClassIdentifiers)
|
||||
}
|
||||
|
||||
public override fun visitClass(aClass: PsiClass?): Unit {
|
||||
public override fun visitClass(aClass: PsiClass?) {
|
||||
val qName = aClass?.getQualifiedName()
|
||||
if (qName != null) {
|
||||
myClassIdentifiers.add(qName)
|
||||
|
||||
@@ -23,45 +23,45 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.isAnnotatedAsNotNull
|
||||
import org.jetbrains.jet.j2k.isDefinitelyNotNull
|
||||
|
||||
public open class ElementVisitor(val myConverter : Converter) : JavaElementVisitor() {
|
||||
protected var myResult : Element = Element.EMPTY_ELEMENT
|
||||
public open class ElementVisitor(val myConverter: Converter) : JavaElementVisitor() {
|
||||
protected var myResult: Element = Element.EMPTY_ELEMENT
|
||||
|
||||
public fun getConverter() : Converter {
|
||||
public fun getConverter(): Converter {
|
||||
return myConverter
|
||||
}
|
||||
|
||||
public open fun getResult() : Element {
|
||||
public open fun getResult(): Element {
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitLocalVariable(variable : PsiLocalVariable?) : Unit {
|
||||
public override fun visitLocalVariable(variable: PsiLocalVariable?) {
|
||||
val theVariable = variable!!
|
||||
var kType = myConverter.typeToType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList()))
|
||||
if (theVariable.hasModifierProperty(PsiModifier.FINAL) && isDefinitelyNotNull(theVariable.getInitializer())) {
|
||||
kType = kType.convertedToNotNull();
|
||||
}
|
||||
myResult = LocalVariable(Identifier(theVariable.getName()!!),
|
||||
Converter.modifiersListToModifiersSet(theVariable.getModifierList()),
|
||||
kType,
|
||||
myConverter.expressionToExpression(theVariable.getInitializer(), theVariable.getType()))
|
||||
Converter.modifiersListToModifiersSet(theVariable.getModifierList()),
|
||||
kType,
|
||||
myConverter.expressionToExpression(theVariable.getInitializer(), theVariable.getType()))
|
||||
}
|
||||
|
||||
public override fun visitExpressionList(list : PsiExpressionList?) : Unit {
|
||||
public override fun visitExpressionList(list: PsiExpressionList?) {
|
||||
myResult = ExpressionList(myConverter.expressionsToExpressionList(list!!.getExpressions()))
|
||||
}
|
||||
|
||||
public override fun visitReferenceElement(reference : PsiJavaCodeReferenceElement?) : Unit {
|
||||
public override fun visitReferenceElement(reference: PsiJavaCodeReferenceElement?) {
|
||||
val theReference = reference!!
|
||||
val types : List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters())
|
||||
val types: List<Type> = myConverter.typesToTypeList(theReference.getTypeParameters())
|
||||
if (!theReference.isQualified()) {
|
||||
myResult = ReferenceElement(Identifier(theReference.getReferenceName()!!), types)
|
||||
}
|
||||
else {
|
||||
var result : String = Identifier(reference.getReferenceName()!!).toKotlin()
|
||||
var qualifier : PsiElement? = theReference.getQualifier()
|
||||
var result: String = Identifier(reference.getReferenceName()!!).toKotlin()
|
||||
var qualifier: PsiElement? = theReference.getQualifier()
|
||||
while (qualifier != null)
|
||||
{
|
||||
val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
|
||||
val p: PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
|
||||
result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result
|
||||
qualifier = p.getQualifier()
|
||||
}
|
||||
@@ -69,16 +69,16 @@ public open class ElementVisitor(val myConverter : Converter) : JavaElementVisit
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitTypeElement(`type` : PsiTypeElement?) : Unit {
|
||||
public override fun visitTypeElement(`type`: PsiTypeElement?) {
|
||||
myResult = TypeElement(myConverter.typeToType(`type`!!.getType()))
|
||||
}
|
||||
|
||||
public override fun visitTypeParameter(classParameter : PsiTypeParameter?) : Unit {
|
||||
public override fun visitTypeParameter(classParameter: PsiTypeParameter?) {
|
||||
myResult = TypeParameter(Identifier(classParameter!!.getName()!!),
|
||||
classParameter.getExtendsListTypes().map { myConverter.typeToType(it) } )
|
||||
classParameter.getExtendsListTypes().map { myConverter.typeToType(it) })
|
||||
}
|
||||
|
||||
public override fun visitParameterList(list : PsiParameterList?) : Unit {
|
||||
public override fun visitParameterList(list: PsiParameterList?) {
|
||||
myResult = ParameterList(myConverter.parametersToParameterList(list!!.getParameters()).requireNoNulls())
|
||||
}
|
||||
|
||||
|
||||
@@ -18,10 +18,8 @@ package org.jetbrains.jet.j2k.visitors
|
||||
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.*
|
||||
import org.jetbrains.jet.j2k.ast.types.EmptyType
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import java.util.ArrayList
|
||||
@@ -31,7 +29,7 @@ import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType
|
||||
import org.jetbrains.jet.j2k.isAnnotatedAsNotNull
|
||||
|
||||
public open class ExpressionVisitor(converter: Converter): StatementVisitor(converter) {
|
||||
public open class ExpressionVisitor(converter: Converter) : StatementVisitor(converter) {
|
||||
{
|
||||
myResult = Expression.EMPTY_EXPRESSION
|
||||
}
|
||||
@@ -40,20 +38,20 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
return myResult as Expression
|
||||
}
|
||||
|
||||
public override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression?): Unit {
|
||||
public override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression?) {
|
||||
val assignment = PsiTreeUtil.getParentOfType(expression, javaClass<PsiAssignmentExpression>())
|
||||
val lvalue = assignment != null && expression == assignment.getLExpression();
|
||||
myResult = ArrayAccessExpression(getConverter().expressionToExpression(expression?.getArrayExpression()),
|
||||
getConverter().expressionToExpression(expression?.getIndexExpression()),
|
||||
lvalue)
|
||||
getConverter().expressionToExpression(expression?.getIndexExpression()),
|
||||
lvalue)
|
||||
}
|
||||
|
||||
public override fun visitArrayInitializerExpression(expression: PsiArrayInitializerExpression?): Unit {
|
||||
public override fun visitArrayInitializerExpression(expression: PsiArrayInitializerExpression?) {
|
||||
myResult = ArrayInitializerExpression(getConverter().typeToType(expression?.getType()),
|
||||
getConverter().expressionsToExpressionList(expression?.getInitializers()!!))
|
||||
getConverter().expressionsToExpressionList(expression?.getInitializers()!!))
|
||||
}
|
||||
|
||||
public override fun visitAssignmentExpression(expression: PsiAssignmentExpression?): Unit {
|
||||
public override fun visitAssignmentExpression(expression: PsiAssignmentExpression?) {
|
||||
val tokenType: IElementType = expression?.getOperationSign()?.getTokenType()!!
|
||||
val secondOp: String = when(tokenType) {
|
||||
JavaTokenType.GTGTEQ -> "shr"
|
||||
@@ -75,7 +73,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitBinaryExpression(expression: PsiBinaryExpression?): Unit {
|
||||
public override fun visitBinaryExpression(expression: PsiBinaryExpression?) {
|
||||
val lhs = getConverter().expressionToExpression(expression?.getLOperand()!!, expression?.getType())
|
||||
val rhs = getConverter().expressionToExpression(expression?.getROperand(), expression?.getType())
|
||||
if (expression?.getOperationSign()?.getTokenType() == JavaTokenType.GTGTGT) {
|
||||
@@ -83,15 +81,15 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
else {
|
||||
myResult = BinaryExpression(lhs, rhs,
|
||||
getOperatorString(expression?.getOperationSign()?.getTokenType()!!))
|
||||
getOperatorString(expression?.getOperationSign()?.getTokenType()!!))
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitClassObjectAccessExpression(expression: PsiClassObjectAccessExpression?): Unit {
|
||||
public override fun visitClassObjectAccessExpression(expression: PsiClassObjectAccessExpression?) {
|
||||
myResult = ClassObjectAccessExpression(getConverter().typeElementToTypeElement(expression?.getOperand()))
|
||||
}
|
||||
|
||||
public override fun visitConditionalExpression(expression: PsiConditionalExpression?): Unit {
|
||||
public override fun visitConditionalExpression(expression: PsiConditionalExpression?) {
|
||||
val condition: PsiExpression? = expression?.getCondition()
|
||||
val `type`: PsiType? = condition?.getType()
|
||||
val e: Expression = (if (`type` != null)
|
||||
@@ -99,21 +97,21 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
else
|
||||
getConverter().expressionToExpression(condition))
|
||||
myResult = ParenthesizedExpression(IfStatement(e,
|
||||
getConverter().expressionToExpression(expression?.getThenExpression()),
|
||||
getConverter().expressionToExpression(expression?.getElseExpression())))
|
||||
getConverter().expressionToExpression(expression?.getThenExpression()),
|
||||
getConverter().expressionToExpression(expression?.getElseExpression())))
|
||||
}
|
||||
|
||||
public override fun visitExpressionList(list: PsiExpressionList?): Unit {
|
||||
public override fun visitExpressionList(list: PsiExpressionList?) {
|
||||
myResult = ExpressionList(getConverter().expressionsToExpressionList(list!!.getExpressions()))
|
||||
}
|
||||
|
||||
public override fun visitInstanceOfExpression(expression: PsiInstanceOfExpression?): Unit {
|
||||
public override fun visitInstanceOfExpression(expression: PsiInstanceOfExpression?) {
|
||||
val checkType: PsiTypeElement? = expression?.getCheckType()
|
||||
myResult = IsOperator(getConverter().expressionToExpression(expression?.getOperand()),
|
||||
myConverter.typeElementToTypeElement(checkType))
|
||||
}
|
||||
|
||||
public override fun visitLiteralExpression(expression: PsiLiteralExpression?): Unit {
|
||||
public override fun visitLiteralExpression(expression: PsiLiteralExpression?) {
|
||||
val value: Any? = expression?.getValue()
|
||||
var text: String = expression?.getText()!!
|
||||
val `type`: PsiType? = expression?.getType()
|
||||
@@ -143,20 +141,20 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
myResult = LiteralExpression(text)
|
||||
}
|
||||
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
convertMethodCallExpression(expression!!)
|
||||
}
|
||||
|
||||
protected fun convertMethodCallExpression(expression: PsiMethodCallExpression) {
|
||||
if (!SuperVisitor.isSuper(expression.getMethodExpression()) || !isInsidePrimaryConstructor(expression)) {
|
||||
myResult = MethodCallExpression(getConverter().expressionToExpression(expression.getMethodExpression()),
|
||||
getConverter().argumentsToExpressionList(expression),
|
||||
getConverter().typesToTypeList(expression.getTypeArguments()),
|
||||
getConverter().typeToType(expression.getType()).nullable)
|
||||
getConverter().argumentsToExpressionList(expression),
|
||||
getConverter().typesToTypeList(expression.getTypeArguments()),
|
||||
getConverter().typeToType(expression.getType()).nullable)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitNewExpression(expression: PsiNewExpression?): Unit {
|
||||
public override fun visitNewExpression(expression: PsiNewExpression?) {
|
||||
if (expression?.getArrayInitializer() != null)
|
||||
{
|
||||
myResult = createNewEmptyArray(expression)
|
||||
@@ -187,9 +185,9 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
getConverter().argumentsToExpressionList(expression!!),
|
||||
getConverter().expressionToExpression(expression.getQualifier()),
|
||||
(if (anonymousClass != null)
|
||||
getConverter().anonymousClassToAnonymousClass(anonymousClass)
|
||||
else
|
||||
null))
|
||||
getConverter().anonymousClassToAnonymousClass(anonymousClass)
|
||||
else
|
||||
null))
|
||||
}
|
||||
|
||||
val reference: PsiJavaCodeReferenceElement? = expression?.getClassReference()
|
||||
@@ -198,7 +196,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
else
|
||||
Collections.emptyList<Type>())
|
||||
return CallChainExpression(Identifier(constructor.getName(), false),
|
||||
MethodCallExpression(Identifier("init"), getConverter().expressionsToExpressionList(arguments), typeParameters, false))
|
||||
MethodCallExpression(Identifier("init"), getConverter().expressionsToExpressionList(arguments), typeParameters, false))
|
||||
}
|
||||
|
||||
private fun createNewEmptyArrayWithoutInitialization(expression: PsiNewExpression): Expression {
|
||||
@@ -211,16 +209,16 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
return getConverter().expressionToExpression(expression?.getArrayInitializer())
|
||||
}
|
||||
|
||||
public override fun visitParenthesizedExpression(expression: PsiParenthesizedExpression?): Unit {
|
||||
public override fun visitParenthesizedExpression(expression: PsiParenthesizedExpression?) {
|
||||
myResult = ParenthesizedExpression(getConverter().expressionToExpression(expression?.getExpression()))
|
||||
}
|
||||
|
||||
public override fun visitPostfixExpression(expression: PsiPostfixExpression?): Unit {
|
||||
public override fun visitPostfixExpression(expression: PsiPostfixExpression?) {
|
||||
myResult = PostfixOperator(getOperatorString(expression!!.getOperationSign().getTokenType()!!),
|
||||
getConverter().expressionToExpression(expression.getOperand()))
|
||||
getConverter().expressionToExpression(expression.getOperand()))
|
||||
}
|
||||
|
||||
public override fun visitPrefixExpression(expression: PsiPrefixExpression?): Unit {
|
||||
public override fun visitPrefixExpression(expression: PsiPrefixExpression?) {
|
||||
val operand = getConverter().expressionToExpression(expression?.getOperand(), expression?.getOperand()!!.getType())
|
||||
val token = expression?.getOperationTokenType()!!
|
||||
if (token == JavaTokenType.TILDE) {
|
||||
@@ -231,7 +229,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit {
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
val isFieldReference: Boolean = isFieldReference(expression!!, getContainingClass(expression))
|
||||
val insideSecondaryConstructor: Boolean = isInsideSecondaryConstructor(expression)
|
||||
val hasReceiver: Boolean = isFieldReference && insideSecondaryConstructor
|
||||
@@ -263,9 +261,9 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
}
|
||||
if (resolved is PsiMember && resolved.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
resolved.getContainingClass() != null &&
|
||||
PsiTreeUtil.getParentOfType(expression, javaClass<PsiClass>()) != resolved.getContainingClass() &&
|
||||
!isStaticallyImported(resolved, expression)) {
|
||||
resolved.getContainingClass() != null &&
|
||||
PsiTreeUtil.getParentOfType(expression, javaClass<PsiClass>()) != resolved.getContainingClass() &&
|
||||
!isStaticallyImported(resolved, expression)) {
|
||||
var member = resolved as PsiMember
|
||||
var result = Identifier(referencedName).toKotlin()
|
||||
while(member.getContainingClass() != null) {
|
||||
@@ -291,7 +289,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
return false;
|
||||
}
|
||||
|
||||
public override fun visitSuperExpression(expression: PsiSuperExpression?): Unit {
|
||||
public override fun visitSuperExpression(expression: PsiSuperExpression?) {
|
||||
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
||||
myResult = SuperExpression((if (qualifier != null)
|
||||
Identifier(qualifier.getQualifiedName()!!)
|
||||
@@ -299,7 +297,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
Identifier.EMPTY_IDENTIFIER))
|
||||
}
|
||||
|
||||
public override fun visitThisExpression(expression: PsiThisExpression?): Unit {
|
||||
public override fun visitThisExpression(expression: PsiThisExpression?) {
|
||||
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
||||
myResult = ThisExpression((if (qualifier != null)
|
||||
Identifier(qualifier.getQualifiedName()!!)
|
||||
@@ -307,7 +305,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
Identifier.EMPTY_IDENTIFIER))
|
||||
}
|
||||
|
||||
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?): Unit {
|
||||
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?) {
|
||||
val castType: PsiTypeElement? = expression?.getCastType()
|
||||
if (castType != null) {
|
||||
val operand = expression?.getOperand()
|
||||
@@ -319,12 +317,12 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
}
|
||||
else {
|
||||
myResult = TypeCastExpression(getConverter().typeToType(castType.getType()),
|
||||
getConverter().expressionToExpression(operand))
|
||||
getConverter().expressionToExpression(operand))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitPolyadicExpression(expression: PsiPolyadicExpression?): Unit {
|
||||
public override fun visitPolyadicExpression(expression: PsiPolyadicExpression?) {
|
||||
var parameters = ArrayList<Expression>()
|
||||
for (operand : PsiExpression in expression?.getOperands()!!) {
|
||||
parameters.add(getConverter().expressionToExpression(operand, expression?.getType()))
|
||||
@@ -400,7 +398,7 @@ public open class ExpressionVisitor(converter: Converter): StatementVisitor(conv
|
||||
if (tokenType == JavaTokenType.EXCL)
|
||||
return "!"
|
||||
|
||||
// System.out.println("UNSUPPORTED TOKEN TYPE: " + tokenType?.toString())
|
||||
// System.out.println("UNSUPPORTED TOKEN TYPE: " + tokenType?.toString())
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -524,5 +522,5 @@ private fun importResolvesTo(stmt: PsiImportStaticStatement?, member: PsiMember)
|
||||
val targetContainingClass = member.getContainingClass()
|
||||
var importedClass = stmt?.resolveTargetClass()
|
||||
return importedClass == targetContainingClass && (stmt?.isOnDemand() ?: false ||
|
||||
stmt?.getReferenceName() == member.getName())
|
||||
stmt?.getReferenceName() == member.getName())
|
||||
}
|
||||
|
||||
+3
-3
@@ -23,8 +23,8 @@ import org.jetbrains.jet.j2k.ast.Identifier
|
||||
import com.intellij.psi.CommonClassNames.JAVA_LANG_OBJECT
|
||||
import org.jetbrains.jet.j2k.ast.MethodCallExpression
|
||||
|
||||
public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter): ExpressionVisitor(converter) {
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
||||
public open class ExpressionVisitorForDirectObjectInheritors(converter: Converter) : ExpressionVisitor(converter) {
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
val methodExpression = expression?.getMethodExpression()!!
|
||||
if (superMethodInvocation(methodExpression, "hashCode")) {
|
||||
myResult = MethodCallExpression.build(Identifier("System", false), "identityHashCode", arrayList(Identifier("this")))
|
||||
@@ -34,7 +34,7 @@ public open class ExpressionVisitorForDirectObjectInheritors(converter: Converte
|
||||
}
|
||||
else if (superMethodInvocation(methodExpression, "toString")) {
|
||||
myResult = DummyStringExpression(java.lang.String.format("getJavaClass<%s>.getName() + '@' + Integer.toHexString(hashCode())",
|
||||
ExpressionVisitor.getClassName(methodExpression)))
|
||||
ExpressionVisitor.getClassName(methodExpression)))
|
||||
}
|
||||
else {
|
||||
convertMethodCallExpression(expression!!)
|
||||
|
||||
@@ -18,26 +18,22 @@ package org.jetbrains.jet.j2k.visitors
|
||||
|
||||
import com.intellij.psi.*
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.*
|
||||
import java.util.Arrays
|
||||
import java.util.Collections
|
||||
import java.util.LinkedList
|
||||
import org.jetbrains.jet.j2k.countWritingAccesses
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class StatementVisitor(converter: Converter): ElementVisitor(converter) {
|
||||
public override fun visitAssertStatement(statement: PsiAssertStatement?): Unit {
|
||||
public open class StatementVisitor(converter: Converter) : ElementVisitor(converter) {
|
||||
public override fun visitAssertStatement(statement: PsiAssertStatement?) {
|
||||
myResult = AssertStatement(getConverter().expressionToExpression(statement?.getAssertCondition()),
|
||||
getConverter().expressionToExpression(statement?.getAssertDescription()))
|
||||
getConverter().expressionToExpression(statement?.getAssertDescription()))
|
||||
}
|
||||
|
||||
public override fun visitBlockStatement(statement: PsiBlockStatement?): Unit {
|
||||
public override fun visitBlockStatement(statement: PsiBlockStatement?) {
|
||||
myResult = myConverter.blockToBlock(statement?.getCodeBlock(), true)
|
||||
}
|
||||
|
||||
public override fun visitBreakStatement(statement: PsiBreakStatement?): Unit {
|
||||
public override fun visitBreakStatement(statement: PsiBreakStatement?) {
|
||||
if (statement?.getLabelIdentifier() == null) {
|
||||
myResult = BreakStatement(Identifier.EMPTY_IDENTIFIER)
|
||||
}
|
||||
@@ -47,7 +43,7 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitContinueStatement(statement: PsiContinueStatement?): Unit {
|
||||
public override fun visitContinueStatement(statement: PsiContinueStatement?) {
|
||||
if (statement?.getLabelIdentifier() == null)
|
||||
{
|
||||
myResult = ContinueStatement(Identifier.EMPTY_IDENTIFIER)
|
||||
@@ -58,11 +54,11 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitDeclarationStatement(statement: PsiDeclarationStatement?): Unit {
|
||||
public override fun visitDeclarationStatement(statement: PsiDeclarationStatement?) {
|
||||
myResult = DeclarationStatement(getConverter().elementsToElementList(statement?.getDeclaredElements()!!))
|
||||
}
|
||||
|
||||
public override fun visitDoWhileStatement(statement: PsiDoWhileStatement?): Unit {
|
||||
public override fun visitDoWhileStatement(statement: PsiDoWhileStatement?) {
|
||||
val condition: PsiExpression? = statement?.getCondition()
|
||||
val expression: Expression = (if (condition != null && condition.getType() != null)
|
||||
getConverter().expressionToExpression(condition, condition.getType())
|
||||
@@ -71,16 +67,16 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
myResult = DoWhileStatement(expression, getConverter().statementToStatement(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitExpressionStatement(statement: PsiExpressionStatement?): Unit {
|
||||
public override fun visitExpressionStatement(statement: PsiExpressionStatement?) {
|
||||
myResult = getConverter().expressionToExpression(statement?.getExpression())
|
||||
}
|
||||
|
||||
public override fun visitExpressionListStatement(statement: PsiExpressionListStatement?): Unit {
|
||||
public override fun visitExpressionListStatement(statement: PsiExpressionListStatement?) {
|
||||
myResult = ExpressionListStatement(getConverter().expressionsToExpressionList(
|
||||
statement?.getExpressionList()?.getExpressions()!!))
|
||||
}
|
||||
|
||||
public override fun visitForStatement(statement: PsiForStatement?): Unit {
|
||||
public override fun visitForStatement(statement: PsiForStatement?) {
|
||||
val initialization: PsiStatement? = statement?.getInitialization()
|
||||
val update: PsiStatement? = statement?.getUpdate()
|
||||
val condition: PsiExpression? = statement?.getCondition()
|
||||
@@ -108,25 +104,25 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
else
|
||||
end)
|
||||
myResult = ForeachWithRangeStatement(Identifier(firstChild.getName()!!),
|
||||
getConverter().expressionToExpression(firstChild.getInitializer()),
|
||||
endExpression,
|
||||
getConverter().statementToStatement(body))
|
||||
getConverter().expressionToExpression(firstChild.getInitializer()),
|
||||
endExpression,
|
||||
getConverter().statementToStatement(body))
|
||||
}
|
||||
else {
|
||||
var forStatements = ArrayList<Element>()
|
||||
forStatements.add(getConverter().statementToStatement(initialization))
|
||||
forStatements.add(WhileStatement(
|
||||
if (condition == null)
|
||||
LiteralExpression("true")
|
||||
else
|
||||
getConverter().expressionToExpression(condition),
|
||||
Block(arrayListOf(getConverter().statementToStatement(body),
|
||||
Block(arrayListOf(getConverter().statementToStatement(update)), false)), false)))
|
||||
if (condition == null)
|
||||
LiteralExpression("true")
|
||||
else
|
||||
getConverter().expressionToExpression(condition),
|
||||
Block(arrayListOf(getConverter().statementToStatement(body),
|
||||
Block(arrayListOf(getConverter().statementToStatement(update)), false)), false)))
|
||||
myResult = Block(forStatements, false)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitForeachStatement(statement: PsiForeachStatement?): Unit {
|
||||
public override fun visitForeachStatement(statement: PsiForeachStatement?) {
|
||||
val iterator = {
|
||||
val iteratorExpr = getConverter().expressionToExpression(statement?.getIteratedValue())
|
||||
if (iteratorExpr.isNullable())
|
||||
@@ -135,33 +131,33 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
iteratorExpr
|
||||
}()
|
||||
myResult = ForeachStatement(getConverter().parameterToParameter(statement?.getIterationParameter()!!),
|
||||
iterator,
|
||||
getConverter().statementToStatement(statement?.getBody()))
|
||||
iterator,
|
||||
getConverter().statementToStatement(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitIfStatement(statement: PsiIfStatement?): Unit {
|
||||
public override fun visitIfStatement(statement: PsiIfStatement?) {
|
||||
val condition: PsiExpression? = statement?.getCondition()
|
||||
val expression: Expression = getConverter().expressionToExpression(condition, PsiType.BOOLEAN)
|
||||
myResult = IfStatement(expression,
|
||||
getConverter().statementToStatement(statement?.getThenBranch()),
|
||||
getConverter().statementToStatement(statement?.getElseBranch()))
|
||||
getConverter().statementToStatement(statement?.getThenBranch()),
|
||||
getConverter().statementToStatement(statement?.getElseBranch()))
|
||||
}
|
||||
|
||||
public override fun visitLabeledStatement(statement: PsiLabeledStatement?): Unit {
|
||||
public override fun visitLabeledStatement(statement: PsiLabeledStatement?) {
|
||||
myResult = LabelStatement(Converter.identifierToIdentifier(statement?.getLabelIdentifier()),
|
||||
getConverter().statementToStatement(statement?.getStatement()))
|
||||
getConverter().statementToStatement(statement?.getStatement()))
|
||||
}
|
||||
|
||||
public override fun visitSwitchLabelStatement(statement: PsiSwitchLabelStatement?): Unit {
|
||||
public override fun visitSwitchLabelStatement(statement: PsiSwitchLabelStatement?) {
|
||||
myResult = (if (statement?.isDefaultCase()!!)
|
||||
DefaultSwitchLabelStatement()
|
||||
else
|
||||
SwitchLabelStatement(getConverter().expressionToExpression(statement?.getCaseValue())))
|
||||
}
|
||||
|
||||
public override fun visitSwitchStatement(statement: PsiSwitchStatement?): Unit {
|
||||
public override fun visitSwitchStatement(statement: PsiSwitchStatement?) {
|
||||
myResult = SwitchContainer(getConverter().expressionToExpression(statement?.getExpression()),
|
||||
switchBodyToCases(statement?.getBody()))
|
||||
switchBodyToCases(statement?.getBody()))
|
||||
}
|
||||
|
||||
private open fun switchBodyToCases(body: PsiCodeBlock?): List<CaseContainer> {
|
||||
@@ -169,7 +165,7 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
val allSwitchStatements = ArrayList<PsiElement>()
|
||||
if (body != null) {
|
||||
// TODO Arrays.asList()
|
||||
for(s in body.getStatements()) allSwitchStatements.add(s)
|
||||
for (s in body.getStatements()) allSwitchStatements.add(s)
|
||||
}
|
||||
val result = ArrayList<CaseContainer>()
|
||||
var pendingLabels = ArrayList<Element>()
|
||||
@@ -202,33 +198,33 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
i += ls.size()
|
||||
}
|
||||
}
|
||||
if (!hasDefaultCase)
|
||||
if (!hasDefaultCase)
|
||||
result.add(CaseContainer(listOf(DefaultSwitchLabelStatement()), ArrayList()))
|
||||
return result
|
||||
return result
|
||||
}
|
||||
|
||||
public override fun visitSynchronizedStatement(statement: PsiSynchronizedStatement?): Unit {
|
||||
public override fun visitSynchronizedStatement(statement: PsiSynchronizedStatement?) {
|
||||
myResult = SynchronizedStatement(getConverter().expressionToExpression(statement?.getLockExpression()),
|
||||
getConverter().blockToBlock(statement?.getBody()))
|
||||
getConverter().blockToBlock(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitThrowStatement(statement: PsiThrowStatement?): Unit {
|
||||
public override fun visitThrowStatement(statement: PsiThrowStatement?) {
|
||||
myResult = ThrowStatement(getConverter().expressionToExpression(statement?.getException()))
|
||||
}
|
||||
|
||||
public override fun visitTryStatement(statement: PsiTryStatement?): Unit {
|
||||
public override fun visitTryStatement(statement: PsiTryStatement?) {
|
||||
val catches = ArrayList<CatchStatement>()
|
||||
val catchBlocks = statement?.getCatchBlocks()!!
|
||||
val catchBlockParameters = statement?.getCatchBlockParameters()!!
|
||||
for (i in 0..catchBlocks.size - 1) {
|
||||
catches.add(CatchStatement(getConverter().parameterToParameter(catchBlockParameters[i], true),
|
||||
getConverter().blockToBlock(catchBlocks[i], true)))
|
||||
getConverter().blockToBlock(catchBlocks[i], true)))
|
||||
}
|
||||
myResult = TryStatement(getConverter().blockToBlock(statement?.getTryBlock(), true),
|
||||
catches, getConverter().blockToBlock(statement?.getFinallyBlock(), true))
|
||||
catches, getConverter().blockToBlock(statement?.getFinallyBlock(), true))
|
||||
}
|
||||
|
||||
public override fun visitWhileStatement(statement: PsiWhileStatement?): Unit {
|
||||
public override fun visitWhileStatement(statement: PsiWhileStatement?) {
|
||||
var condition: PsiExpression? = statement?.getCondition()
|
||||
val expression: Expression = (if (condition != null && condition?.getType() != null)
|
||||
this.getConverter().expressionToExpression(condition, condition?.getType())
|
||||
@@ -237,7 +233,7 @@ public open class StatementVisitor(converter: Converter): ElementVisitor(convert
|
||||
myResult = WhileStatement(expression, getConverter().statementToStatement(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitReturnStatement(statement: PsiReturnStatement?): Unit {
|
||||
public override fun visitReturnStatement(statement: PsiReturnStatement?) {
|
||||
val returnValue: PsiExpression? = statement?.getReturnValue()
|
||||
val methodReturnType: PsiType? = getConverter().methodReturnType
|
||||
val expression: Expression = (if (returnValue != null && methodReturnType != null)
|
||||
|
||||
@@ -19,10 +19,10 @@ package org.jetbrains.jet.j2k.visitors
|
||||
import com.intellij.psi.*
|
||||
import java.util.HashSet
|
||||
|
||||
public open class SuperVisitor(): JavaRecursiveElementVisitor() {
|
||||
public open class SuperVisitor() : JavaRecursiveElementVisitor() {
|
||||
public val resolvedSuperCallParameters: HashSet<PsiExpressionList> = hashSet()
|
||||
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?): Unit {
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
if (expression != null && isSuper(expression.getMethodExpression())) {
|
||||
resolvedSuperCallParameters.add(expression.getArgumentList())
|
||||
}
|
||||
|
||||
@@ -17,13 +17,12 @@
|
||||
package org.jetbrains.jet.j2k.visitors
|
||||
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public open class ThisVisitor(): JavaRecursiveElementVisitor() {
|
||||
public open class ThisVisitor() : JavaRecursiveElementVisitor() {
|
||||
private val myResolvedConstructors = LinkedHashSet<PsiMethod>()
|
||||
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?): Unit {
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
for (r : PsiReference? in expression?.getReferences()!!) {
|
||||
if (r?.getCanonicalText() == "this") {
|
||||
val res: PsiElement? = r?.resolve()
|
||||
|
||||
@@ -26,14 +26,14 @@ import java.util.LinkedList
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisitor<Type>() {
|
||||
private var myResult : Type = EmptyType()
|
||||
public open fun getResult() : Type {
|
||||
public open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisitor<Type>() {
|
||||
private var myResult: Type = EmptyType()
|
||||
public open fun getResult(): Type {
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?) : Type {
|
||||
val name : String = primitiveType?.getCanonicalText()!!
|
||||
public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?): Type {
|
||||
val name: String = primitiveType?.getCanonicalText()!!
|
||||
if (name == "void") {
|
||||
myResult = PrimitiveType(Identifier("Unit"))
|
||||
}
|
||||
@@ -46,7 +46,7 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitArrayType(arrayType: PsiArrayType?) : Type {
|
||||
public override fun visitArrayType(arrayType: PsiArrayType?): Type {
|
||||
if (myResult is EmptyType) {
|
||||
myResult = ArrayType(myConverter.typeToType(arrayType?.getComponentType()), true)
|
||||
}
|
||||
@@ -54,12 +54,12 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitClassType(classType : PsiClassType?) : Type {
|
||||
public override fun visitClassType(classType: PsiClassType?): Type {
|
||||
if (classType == null) return myResult
|
||||
val identifier : Identifier = constructClassTypeIdentifier(classType)
|
||||
val resolvedClassTypeParams : List<Type> = createRawTypesForResolvedReference(classType)
|
||||
val identifier: Identifier = constructClassTypeIdentifier(classType)
|
||||
val resolvedClassTypeParams: List<Type> = createRawTypesForResolvedReference(classType)
|
||||
if (classType.getParameterCount() == 0 && resolvedClassTypeParams.size() > 0) {
|
||||
val starParamList : ArrayList<Type> = ArrayList<Type>()
|
||||
val starParamList: ArrayList<Type> = ArrayList<Type>()
|
||||
if (resolvedClassTypeParams.size() == 1) {
|
||||
if ((resolvedClassTypeParams.get(0) as ClassType).`type`.name == "Any") {
|
||||
starParamList.add(StarProjectionType())
|
||||
@@ -79,8 +79,8 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return myResult
|
||||
}
|
||||
|
||||
private fun constructClassTypeIdentifier(classType : PsiClassType) : Identifier {
|
||||
val psiClass : PsiClass? = classType.resolve()
|
||||
private fun constructClassTypeIdentifier(classType: PsiClassType): Identifier {
|
||||
val psiClass: PsiClass? = classType.resolve()
|
||||
if (psiClass != null) {
|
||||
val qualifiedName: String? = psiClass.getQualifiedName()
|
||||
if (qualifiedName != null) {
|
||||
@@ -110,15 +110,15 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return Identifier(classTypeName)
|
||||
}
|
||||
|
||||
private fun createRawTypesForResolvedReference(classType : PsiClassType) : List<Type> {
|
||||
private fun createRawTypesForResolvedReference(classType: PsiClassType): List<Type> {
|
||||
val typeParams = LinkedList<Type>()
|
||||
if (classType is PsiClassReferenceType) {
|
||||
val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference()
|
||||
val resolve : PsiElement? = reference?.resolve()
|
||||
val reference: PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference()
|
||||
val resolve: PsiElement? = reference?.resolve()
|
||||
if (resolve is PsiClass) {
|
||||
for (p : PsiTypeParameter? in (resolve as PsiClass).getTypeParameters()) {
|
||||
val superTypes = p!!.getSuperTypes()
|
||||
val boundType : Type = (if (superTypes.size > 0)
|
||||
val boundType: Type = (if (superTypes.size > 0)
|
||||
ClassType(Identifier(getClassTypeName(superTypes[0])),
|
||||
myConverter.typesToTypeList(superTypes[0].getParameters()),
|
||||
true)
|
||||
@@ -132,7 +132,7 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return typeParams
|
||||
}
|
||||
|
||||
public override fun visitWildcardType(wildcardType : PsiWildcardType?) : Type {
|
||||
public override fun visitWildcardType(wildcardType: PsiWildcardType?): Type {
|
||||
if (wildcardType!!.isExtends()) {
|
||||
myResult = OutProjectionType(myConverter.typeToType(wildcardType.getExtendsBound()))
|
||||
}
|
||||
@@ -146,22 +146,22 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitEllipsisType(ellipsisType : PsiEllipsisType?) : Type {
|
||||
public override fun visitEllipsisType(ellipsisType: PsiEllipsisType?): Type {
|
||||
myResult = VarArg(myConverter.typeToType(ellipsisType?.getComponentType()))
|
||||
return myResult
|
||||
}
|
||||
|
||||
class object {
|
||||
private fun createQualifiedName(classType : PsiClassType) : String {
|
||||
private fun createQualifiedName(classType: PsiClassType): String {
|
||||
if (classType is PsiClassReferenceType)
|
||||
{
|
||||
val reference : PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference()
|
||||
val reference: PsiJavaCodeReferenceElement? = (classType as PsiClassReferenceType).getReference()
|
||||
if (reference != null && reference.isQualified()) {
|
||||
var result : String = Identifier(reference.getReferenceName()!!).toKotlin()
|
||||
var qualifier : PsiElement? = reference.getQualifier()
|
||||
var result: String = Identifier(reference.getReferenceName()!!).toKotlin()
|
||||
var qualifier: PsiElement? = reference.getQualifier()
|
||||
while (qualifier != null)
|
||||
{
|
||||
val p : PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
|
||||
val p: PsiJavaCodeReferenceElement = (qualifier as PsiJavaCodeReferenceElement)
|
||||
result = Identifier(p.getReferenceName()!!).toKotlin() + "." + result
|
||||
qualifier = p.getQualifier()
|
||||
}
|
||||
@@ -172,8 +172,8 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun getClassTypeName(classType : PsiClassType) : String {
|
||||
var canonicalTypeStr : String? = classType.getCanonicalText()
|
||||
private fun getClassTypeName(classType: PsiClassType): String {
|
||||
var canonicalTypeStr: String? = classType.getCanonicalText()
|
||||
return when(canonicalTypeStr) {
|
||||
CommonClassNames.JAVA_LANG_OBJECT -> "Any"
|
||||
CommonClassNames.JAVA_LANG_BYTE -> "Byte"
|
||||
@@ -186,9 +186,9 @@ public open class TypeVisitor(private val myConverter : Converter) : PsiTypeVisi
|
||||
CommonClassNames.JAVA_LANG_BOOLEAN -> "Boolean"
|
||||
|
||||
else -> (if (classType.getClassName() != null)
|
||||
classType.getClassName()!!
|
||||
else
|
||||
classType.getCanonicalText())!!
|
||||
classType.getClassName()!!
|
||||
else
|
||||
classType.getCanonicalText())!!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user