Refactor Converter:
Minor: remove redundant public modifiers and fix formatting issues
This commit is contained in:
@@ -19,12 +19,11 @@ package org.jetbrains.jet.j2k
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiReferenceExpression
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.JavaRecursiveElementVisitor
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public fun isConstructorPrimary(constructor: PsiMethod): Boolean {
|
||||
fun isConstructorPrimary(constructor: PsiMethod): Boolean {
|
||||
val parent = constructor.getParent()
|
||||
if (parent is PsiClass) {
|
||||
if (parent.getConstructors().size == 1) {
|
||||
@@ -49,7 +48,7 @@ private fun getPrimaryConstructorForThisCase(psiClass: PsiClass): PsiMethod? {
|
||||
private class FindPrimaryConstructorVisitor() : JavaRecursiveElementVisitor() {
|
||||
private val myResolvedConstructors = LinkedHashSet<PsiMethod>()
|
||||
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
for (r in expression?.getReferences()!!) {
|
||||
if (r.getCanonicalText() == "this") {
|
||||
val res: PsiElement? = r.resolve()
|
||||
@@ -60,7 +59,7 @@ private class FindPrimaryConstructorVisitor() : JavaRecursiveElementVisitor() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun getPrimaryConstructor(): PsiMethod? {
|
||||
fun getPrimaryConstructor(): PsiMethod? {
|
||||
if (myResolvedConstructors.size() > 0) {
|
||||
val first: PsiMethod = myResolvedConstructors.iterator().next()
|
||||
for (m in myResolvedConstructors)
|
||||
|
||||
@@ -38,14 +38,14 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
|
||||
private val dispatcher: Dispatcher = Dispatcher(this)
|
||||
|
||||
public var methodReturnType: PsiType? = null
|
||||
var methodReturnType: PsiType? = null
|
||||
private set
|
||||
|
||||
public fun setClassIdentifiers(identifiers: MutableSet<String>) {
|
||||
classIdentifiersSet = identifiers
|
||||
}
|
||||
|
||||
public fun getClassIdentifiers(): Set<String> {
|
||||
fun getClassIdentifiers(): Set<String> {
|
||||
return Collections.unmodifiableSet(classIdentifiersSet)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return kElement?.toKotlin() ?: ""
|
||||
}
|
||||
|
||||
public fun convertTopElement(element: PsiElement?): Element? = when(element) {
|
||||
fun convertTopElement(element: PsiElement?): Element? = when(element) {
|
||||
is PsiJavaFile -> convertFile(element)
|
||||
is PsiClass -> convertClass(element)
|
||||
is PsiMethod -> convertMethod(element)
|
||||
@@ -78,7 +78,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return File(fileMembers, createMainFunction(javaFile))
|
||||
}
|
||||
|
||||
public fun convertAnonymousClass(anonymousClass: PsiAnonymousClass): AnonymousClass {
|
||||
fun convertAnonymousClass(anonymousClass: PsiAnonymousClass): AnonymousClass {
|
||||
return AnonymousClass(this, convertMembers(anonymousClass))
|
||||
}
|
||||
|
||||
@@ -270,22 +270,22 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return ParameterList(result)
|
||||
}
|
||||
|
||||
public fun convertBlock(block: PsiCodeBlock?, notEmpty: Boolean): Block {
|
||||
fun convertBlock(block: PsiCodeBlock?, notEmpty: Boolean): Block {
|
||||
if (block == null)
|
||||
return Block.Empty
|
||||
|
||||
return Block(convertStatements(block.getChildren().toList()), notEmpty)
|
||||
}
|
||||
|
||||
public fun convertBlock(block: PsiCodeBlock?): Block {
|
||||
fun convertBlock(block: PsiCodeBlock?): Block {
|
||||
return convertBlock(block, true)
|
||||
}
|
||||
|
||||
public fun convertStatements(statements: List<PsiElement>): StatementList {
|
||||
fun convertStatements(statements: List<PsiElement>): StatementList {
|
||||
return StatementList(statements.map { if (it is PsiStatement) convertStatement(it) else convertElement(it) })
|
||||
}
|
||||
|
||||
public fun convertStatement(s: PsiStatement?): Statement {
|
||||
fun convertStatement(s: PsiStatement?): Statement {
|
||||
if (s == null)
|
||||
return Statement.Empty
|
||||
|
||||
@@ -294,14 +294,14 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return statementVisitor.getResult() as Statement
|
||||
}
|
||||
|
||||
public fun convertExpressions(expressions: Array<PsiExpression>): List<Expression> {
|
||||
fun convertExpressions(expressions: Array<PsiExpression>): List<Expression> {
|
||||
val result = ArrayList<Expression>()
|
||||
for (e : PsiExpression? in expressions)
|
||||
result.add(convertExpression(e))
|
||||
return result
|
||||
}
|
||||
|
||||
public fun convertExpression(e: PsiExpression?): Expression {
|
||||
fun convertExpression(e: PsiExpression?): Expression {
|
||||
if (e == null)
|
||||
return Expression.Empty
|
||||
|
||||
@@ -310,7 +310,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return expressionVisitor.getResult()
|
||||
}
|
||||
|
||||
public fun convertElement(e: PsiElement?): Element {
|
||||
fun convertElement(e: PsiElement?): Element {
|
||||
if (e == null)
|
||||
return Element.Empty
|
||||
|
||||
@@ -319,7 +319,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return elementVisitor.getResult()
|
||||
}
|
||||
|
||||
public fun convertElements(elements: Array<out PsiElement?>): List<Element> {
|
||||
fun convertElements(elements: Array<out PsiElement?>): List<Element> {
|
||||
val result = ArrayList<Element>()
|
||||
for (element in elements) {
|
||||
result.add(convertElement(element))
|
||||
@@ -327,14 +327,14 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return result
|
||||
}
|
||||
|
||||
public fun convertTypeElement(element: PsiTypeElement?): TypeElement {
|
||||
fun convertTypeElement(element: PsiTypeElement?): TypeElement {
|
||||
return TypeElement(if (element == null)
|
||||
EmptyType()
|
||||
else
|
||||
convertType(element.getType()))
|
||||
}
|
||||
|
||||
public fun convertType(`type`: PsiType?): Type {
|
||||
fun convertType(`type`: PsiType?): Type {
|
||||
if (`type` == null)
|
||||
return EmptyType()
|
||||
|
||||
@@ -343,11 +343,11 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return typeVisitor.getResult()
|
||||
}
|
||||
|
||||
public fun convertTypes(types: Array<PsiType>): List<Type> {
|
||||
fun convertTypes(types: Array<PsiType>): List<Type> {
|
||||
return types.map { convertType(it) }
|
||||
}
|
||||
|
||||
public fun convertType(`type`: PsiType?, notNull: Boolean): Type {
|
||||
fun convertType(`type`: PsiType?, notNull: Boolean): Type {
|
||||
val result: Type = convertType(`type`)
|
||||
if (notNull) {
|
||||
return result.convertedToNotNull()
|
||||
@@ -364,17 +364,17 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return result
|
||||
}
|
||||
|
||||
public fun convertParameterList(parameters: Array<PsiParameter>): List<Parameter?> {
|
||||
fun convertParameterList(parameters: Array<PsiParameter>): List<Parameter?> {
|
||||
return parameters.map { convertParameter(it) }
|
||||
}
|
||||
|
||||
public fun convertParameter(parameter: PsiParameter, forceNotNull: Boolean = false): Parameter {
|
||||
fun convertParameter(parameter: PsiParameter, forceNotNull: Boolean = false): Parameter {
|
||||
return Parameter(Identifier(parameter.getName()!!),
|
||||
convertType(parameter.getType(),
|
||||
forceNotNull || isAnnotatedAsNotNull(parameter.getModifierList())), true)
|
||||
}
|
||||
|
||||
public fun convertArguments(expression: PsiCallExpression): List<Expression> {
|
||||
fun convertArguments(expression: PsiCallExpression): List<Expression> {
|
||||
val argumentList: PsiExpressionList? = expression.getArgumentList()
|
||||
val arguments: Array<PsiExpression> = (if (argumentList != null)
|
||||
argumentList.getExpressions()
|
||||
@@ -399,7 +399,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return result
|
||||
}
|
||||
|
||||
public fun convertExpression(argument: PsiExpression?, expectedType: PsiType?): Expression {
|
||||
fun convertExpression(argument: PsiExpression?, expectedType: PsiType?): Expression {
|
||||
if (argument == null)
|
||||
return Identifier.Empty
|
||||
|
||||
@@ -429,7 +429,7 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return expression
|
||||
}
|
||||
|
||||
public fun quoteKeywords(packageName: String): String {
|
||||
fun quoteKeywords(packageName: String): String {
|
||||
return packageName.split("\\.").map { Identifier(it).toKotlin() }.makeString(".")
|
||||
}
|
||||
|
||||
@@ -460,14 +460,14 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
return s + "(" + fields.map { initializers[it.identifier.toKotlin()] }.makeString(", ") + ")"
|
||||
}
|
||||
|
||||
public fun convertIdentifier(identifier: PsiIdentifier?): Identifier {
|
||||
fun convertIdentifier(identifier: PsiIdentifier?): Identifier {
|
||||
if (identifier == null)
|
||||
return Identifier.Empty
|
||||
|
||||
return Identifier(identifier.getText()!!)
|
||||
}
|
||||
|
||||
public fun convertModifierList(modifierList: PsiModifierList?): MutableSet<Modifier> {
|
||||
fun convertModifierList(modifierList: PsiModifierList?): MutableSet<Modifier> {
|
||||
val modifiersSet: HashSet<Modifier> = hashSetOf()
|
||||
if (modifierList != null) {
|
||||
if (modifierList.hasExplicitModifier(PsiModifier.ABSTRACT))
|
||||
@@ -516,8 +516,8 @@ public class Converter(val project: Project, val settings: ConverterSettings) {
|
||||
}
|
||||
}
|
||||
|
||||
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>()
|
||||
val NOT_NULL_ANNOTATIONS: Set<String> = ImmutableSet.of<String>("org.jetbrains.annotations.NotNull", "com.sun.istack.internal.NotNull", "javax.annotation.Nonnull")!!
|
||||
val PRIMITIVE_TYPE_CONVERSIONS: Map<String, String> = ImmutableMap.builder<String, String>()
|
||||
?.put("byte", BYTE.asString())
|
||||
?.put("short", SHORT.asString())
|
||||
?.put("int", INT.asString())
|
||||
@@ -535,7 +535,7 @@ public val PRIMITIVE_TYPE_CONVERSIONS: Map<String, String> = ImmutableMap.builde
|
||||
?.build()!!
|
||||
|
||||
|
||||
public fun countWritingAccesses(element: PsiElement?, container: PsiElement?): Int {
|
||||
fun countWritingAccesses(element: PsiElement?, container: PsiElement?): Int {
|
||||
var counter: Int = 0
|
||||
if (container != null) {
|
||||
val visitor: ReferenceCollector = ReferenceCollector()
|
||||
@@ -552,11 +552,11 @@ public fun countWritingAccesses(element: PsiElement?, container: PsiElement?): I
|
||||
open class ReferenceCollector() : JavaRecursiveElementVisitor() {
|
||||
private val myCollectedReferences = ArrayList<PsiReferenceExpression>()
|
||||
|
||||
public open fun getCollectedReferences(): List<PsiReferenceExpression> {
|
||||
open fun getCollectedReferences(): List<PsiReferenceExpression> {
|
||||
return myCollectedReferences
|
||||
}
|
||||
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
super.visitReferenceExpression(expression)
|
||||
if (expression != null) {
|
||||
myCollectedReferences.add(expression)
|
||||
@@ -564,11 +564,11 @@ open class ReferenceCollector() : JavaRecursiveElementVisitor() {
|
||||
}
|
||||
}
|
||||
|
||||
public fun isReadOnly(element: PsiElement?, container: PsiElement?): Boolean {
|
||||
fun isReadOnly(element: PsiElement?, container: PsiElement?): Boolean {
|
||||
return countWritingAccesses(element, container) == 0
|
||||
}
|
||||
|
||||
public fun isAnnotatedAsNotNull(modifierList: PsiModifierList?): Boolean {
|
||||
fun isAnnotatedAsNotNull(modifierList: PsiModifierList?): Boolean {
|
||||
if (modifierList != null) {
|
||||
val annotations: Array<PsiAnnotation> = modifierList.getAnnotations()
|
||||
for (a : PsiAnnotation in annotations) {
|
||||
@@ -581,13 +581,13 @@ public fun isAnnotatedAsNotNull(modifierList: PsiModifierList?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
public fun isDefinitelyNotNull(element: PsiElement?): Boolean = when(element) {
|
||||
fun isDefinitelyNotNull(element: PsiElement?): Boolean = when(element) {
|
||||
is PsiLiteralExpression -> element.getValue() != null
|
||||
is PsiNewExpression -> true
|
||||
else -> false
|
||||
}
|
||||
|
||||
public fun getDefaultInitializer(f: Field): String {
|
||||
fun getDefaultInitializer(f: Field): String {
|
||||
if (f.`type`.nullable) {
|
||||
return "null"
|
||||
}
|
||||
|
||||
@@ -21,7 +21,8 @@ public class ConverterSettings(
|
||||
val forceLocalVariableImmutability: Boolean,
|
||||
val specifyLocalVariableTypeByDefault: Boolean,
|
||||
val openByDefault: Boolean
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
public val PluginSettings: ConverterSettings = ConverterSettings(
|
||||
forceNotNullTypes = true,
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
import java.util.HashSet
|
||||
|
||||
object JavaToKotlinTranslator {
|
||||
public object JavaToKotlinTranslator {
|
||||
private val DISPOSABLE: Disposable? = Disposer.newDisposable()
|
||||
|
||||
private fun createFile(text: String): PsiFile? {
|
||||
@@ -40,7 +40,7 @@ object JavaToKotlinTranslator {
|
||||
return PsiFileFactory.getInstance(javaCoreEnvironment?.getProject())?.createFileFromText("test.java", JavaLanguage.INSTANCE, text)
|
||||
}
|
||||
|
||||
public fun createFile(project: Project, text: String): PsiFile? {
|
||||
fun createFile(project: Project, text: String): PsiFile? {
|
||||
return PsiFileFactory.getInstance(project)?.createFileFromText("test.java", JavaLanguage.INSTANCE, text)
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ object JavaToKotlinTranslator {
|
||||
.trim()
|
||||
}
|
||||
|
||||
public fun findAnnotations(): File? {
|
||||
fun findAnnotations(): File? {
|
||||
var classLoader = javaClass<JavaToKotlinTranslator>().getClassLoader()
|
||||
while (classLoader != null) {
|
||||
val loader = classLoader
|
||||
@@ -104,7 +104,7 @@ object JavaToKotlinTranslator {
|
||||
}
|
||||
}
|
||||
|
||||
public fun main(args: Array<String>) {
|
||||
fun main(args: Array<String>) {
|
||||
if (args.size == 1) {
|
||||
try {
|
||||
val kotlinCode = JavaToKotlinTranslator.generateKotlinCode(args[0])
|
||||
|
||||
@@ -25,10 +25,9 @@ import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiAnonymousClass
|
||||
import com.intellij.psi.PsiModifier
|
||||
import com.intellij.psi.PsiType
|
||||
import com.intellij.psi.PsiParameter
|
||||
import com.intellij.psi.PsiArrayType
|
||||
|
||||
public fun createMainFunction(file: PsiFile): String {
|
||||
fun createMainFunction(file: PsiFile): String {
|
||||
val classNamesWithMains = ArrayList<Pair<String, PsiMethod>>()
|
||||
for (c in (file as PsiJavaFile).getClasses()) {
|
||||
val main = findMainMethod(c)
|
||||
@@ -69,7 +68,7 @@ private fun findMainMethod(mainMethods: Array<PsiMethod>): PsiMethod? {
|
||||
return mainMethods.find { isMainMethod(it) }
|
||||
}
|
||||
|
||||
public fun isMainMethod(method: PsiMethod): Boolean {
|
||||
fun isMainMethod(method: PsiMethod): Boolean {
|
||||
if (method.getContainingClass() == null)
|
||||
return false
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.Collections
|
||||
|
||||
public class AnonymousClass(converter: Converter, members: List<Element>)
|
||||
class AnonymousClass(converter: Converter, members: List<Element>)
|
||||
: Class(converter,
|
||||
Identifier("anonClass"),
|
||||
MemberComments.Empty,
|
||||
@@ -29,5 +29,5 @@ public class AnonymousClass(converter: Converter, members: List<Element>)
|
||||
Collections.emptyList<Type>(),
|
||||
Collections.emptyList<Expression>(),
|
||||
Collections.emptyList<Type>(), members) {
|
||||
public override fun toKotlin() = bodyToKotlin()
|
||||
override fun toKotlin() = bodyToKotlin()
|
||||
}
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import org.jetbrains.jet.j2k.ast.types.ArrayType
|
||||
import org.jetbrains.jet.j2k.ast.types.isPrimitive
|
||||
|
||||
public open class ArrayInitializerExpression(val arrayType: ArrayType, val initializers: List<Expression>) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
open class ArrayInitializerExpression(val arrayType: ArrayType, val initializers: List<Expression>) : Expression() {
|
||||
override fun toKotlin(): String {
|
||||
return createArrayFunction() + "(" + createInitializers() + ")"
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
open class ArrayWithoutInitializationExpression(val `type`: Type, val expressions: List<Expression>) : Expression() {
|
||||
override fun toKotlin(): String {
|
||||
if (`type` is ArrayType) {
|
||||
return constructInnerType(`type`, expressions)
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public class AssertStatement(val condition: Expression, val detail: Expression) : Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
class AssertStatement(val condition: Expression, val detail: Expression) : Statement() {
|
||||
override fun toKotlin(): String {
|
||||
val lazyStringMessage = if (detail != Expression.Empty)
|
||||
" {" + detail.toKotlin() + "}"
|
||||
else
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
public fun Block(statements: List<Statement>, notEmpty: Boolean = false): Block {
|
||||
fun Block(statements: List<Statement>, notEmpty: Boolean = false): Block {
|
||||
val elements = ArrayList<Element>()
|
||||
elements.add(WhiteSpace.NewLine)
|
||||
elements.addAll(statements)
|
||||
@@ -26,15 +26,15 @@ public fun Block(statements: List<Statement>, notEmpty: Boolean = false): Block
|
||||
return Block(StatementList(elements), notEmpty)
|
||||
}
|
||||
|
||||
public class Block(val statementList: StatementList, val notEmpty: Boolean = false) : Statement() {
|
||||
class Block(val statementList: StatementList, val notEmpty: Boolean = false) : Statement() {
|
||||
|
||||
public val statements: List<Statement> = statementList.statements
|
||||
val statements: List<Statement> = statementList.statements
|
||||
|
||||
public override fun isEmpty(): Boolean {
|
||||
override fun isEmpty(): Boolean {
|
||||
return !notEmpty && statements.all { it.isEmpty() }
|
||||
}
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
if (!isEmpty()) {
|
||||
return "{${statementList.toKotlin()}}"
|
||||
}
|
||||
@@ -43,6 +43,6 @@ public class Block(val statementList: StatementList, val notEmpty: Boolean = fal
|
||||
}
|
||||
|
||||
class object {
|
||||
public val Empty: Block = Block(StatementList(ArrayList()))
|
||||
val Empty = Block(StatementList(ArrayList()))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public class CallChainExpression(val expression: Expression, val identifier: Expression) : Expression() {
|
||||
public override fun isNullable(): Boolean {
|
||||
class CallChainExpression(val expression: Expression, val identifier: Expression) : Expression() {
|
||||
override fun isNullable(): Boolean {
|
||||
if (!expression.isEmpty() && expression.isNullable()) return true
|
||||
return identifier.isNullable()
|
||||
}
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
if (!expression.isEmpty()) {
|
||||
return expression.toKotlin() + (if (expression.isNullable()) "?." else ".") + identifier.toKotlin()
|
||||
}
|
||||
|
||||
@@ -22,15 +22,17 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.HashSet
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class Class(val converter: Converter,
|
||||
val name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
val typeParameterList: TypeParameterList,
|
||||
val extendsTypes: List<Type>,
|
||||
val baseClassParams: List<Expression>,
|
||||
val implementsTypes: List<Type>,
|
||||
val members: List<Element>) : Member(comments, modifiers) {
|
||||
open class Class(
|
||||
val converter: Converter,
|
||||
val name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
val typeParameterList: TypeParameterList,
|
||||
val extendsTypes: List<Type>,
|
||||
val baseClassParams: List<Expression>,
|
||||
val implementsTypes: List<Type>,
|
||||
val members: List<Element>
|
||||
) : Member(comments, modifiers) {
|
||||
open val TYPE: String
|
||||
get() = "class"
|
||||
|
||||
|
||||
@@ -19,22 +19,24 @@ package org.jetbrains.jet.j2k.ast
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public class Constructor(converter: Converter,
|
||||
identifier: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
`type`: Type,
|
||||
typeParameters: TypeParameterList,
|
||||
params: Element,
|
||||
block: Block,
|
||||
val isPrimary: Boolean) : Function(converter, identifier, comments, modifiers,
|
||||
`type`, typeParameters, params, block) {
|
||||
class Constructor(
|
||||
converter: Converter,
|
||||
identifier: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
`type`: Type,
|
||||
typeParameters: TypeParameterList,
|
||||
params: Element,
|
||||
block: Block,
|
||||
val isPrimary: Boolean
|
||||
) : Function(converter, identifier, comments, modifiers,
|
||||
`type`, typeParameters, params, block) {
|
||||
|
||||
public fun primarySignatureToKotlin(): String {
|
||||
fun primarySignatureToKotlin(): String {
|
||||
return "(" + params.toKotlin() + ")"
|
||||
}
|
||||
|
||||
public fun primaryBodyToKotlin(): String {
|
||||
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 override fun toKotlin(): String = string
|
||||
open class DummyStringExpression(val string: String) : Expression() {
|
||||
override fun toKotlin(): String = string
|
||||
}
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public trait Element : Node {
|
||||
public fun isEmpty(): Boolean = false
|
||||
trait Element : Node {
|
||||
fun isEmpty(): Boolean = false
|
||||
|
||||
class object {
|
||||
public val Empty: Element = object : Element {
|
||||
override fun toKotlin() = ""
|
||||
override fun isEmpty() = true
|
||||
}
|
||||
object Empty : Element {
|
||||
override fun toKotlin() = ""
|
||||
override fun isEmpty() = true
|
||||
}
|
||||
}
|
||||
|
||||
public class Comment(val text: String) : Element {
|
||||
class Comment(val text: String) : Element {
|
||||
override fun toKotlin() = text
|
||||
}
|
||||
|
||||
@@ -19,16 +19,18 @@ package org.jetbrains.jet.j2k.ast
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public class Enum(converter: Converter,
|
||||
name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
typeParameterList: TypeParameterList,
|
||||
extendsTypes: List<Type>,
|
||||
baseClassParams: List<Expression>,
|
||||
implementsTypes: List<Type>,
|
||||
members: List<Element>) : Class(converter, name, comments, modifiers, typeParameterList,
|
||||
extendsTypes, baseClassParams, implementsTypes, members) {
|
||||
class Enum(
|
||||
converter: Converter,
|
||||
name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
typeParameterList: TypeParameterList,
|
||||
extendsTypes: List<Type>,
|
||||
baseClassParams: List<Expression>,
|
||||
implementsTypes: List<Type>,
|
||||
members: List<Element>
|
||||
) : Class(converter, name, comments, modifiers, typeParameterList,
|
||||
extendsTypes, baseClassParams, implementsTypes, members) {
|
||||
|
||||
override fun primaryConstructorSignatureToKotlin(): String {
|
||||
val s: String = super.primaryConstructorSignatureToKotlin()
|
||||
@@ -37,7 +39,7 @@ public class Enum(converter: Converter,
|
||||
|
||||
override fun isDefinitelyFinal() = true
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
val primaryConstructorBody = primaryConstructorBodyToKotlin() ?: ""
|
||||
return modifiersToKotlin() +
|
||||
"enum class " + name.toKotlin() +
|
||||
|
||||
@@ -18,13 +18,15 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class EnumConstant(identifier: Identifier,
|
||||
members: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
`type`: Type,
|
||||
params: Element) : Field(identifier, members, modifiers, `type`.convertedToNotNull(), params, 0) {
|
||||
open class EnumConstant(
|
||||
identifier: Identifier,
|
||||
members: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
`type`: Type,
|
||||
params: Element
|
||||
) : Field(identifier, members, modifiers, `type`.convertedToNotNull(), params, 0) {
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
if (initializer.toKotlin().isEmpty()) {
|
||||
return identifier.toKotlin()
|
||||
}
|
||||
|
||||
@@ -17,15 +17,13 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public abstract class Expression() : Statement() {
|
||||
public open fun isNullable(): Boolean {
|
||||
abstract class Expression() : Statement() {
|
||||
open fun isNullable(): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
class object {
|
||||
public val Empty: Expression = object: Expression() {
|
||||
public override fun toKotlin() = ""
|
||||
public override fun isEmpty() = true
|
||||
}
|
||||
object Empty : Expression() {
|
||||
override fun toKotlin() = ""
|
||||
override fun isEmpty() = true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public open class ExpressionList(val expressions: List<Expression>) : Expression() {
|
||||
public override fun toKotlin(): String = expressions.map { it.toKotlin() }.makeString(", ")
|
||||
open class ExpressionList(val expressions: List<Expression>) : Expression() {
|
||||
override fun toKotlin(): String = expressions.map { it.toKotlin() }.makeString(", ")
|
||||
override fun isEmpty(): Boolean = expressions.isEmpty()
|
||||
}
|
||||
|
||||
@@ -18,57 +18,57 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class ArrayAccessExpression(val expression: Expression, val index: Expression, val lvalue: Boolean) : Expression() {
|
||||
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() + "]"
|
||||
}
|
||||
|
||||
public open class AssignmentExpression(val left: Expression, val right: Expression, val op: String) : Expression() {
|
||||
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() {
|
||||
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() {
|
||||
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() {
|
||||
open class ClassObjectAccessExpression(val typeElement: TypeElement) : Expression() {
|
||||
override fun toKotlin() = "javaClass<" + typeElement.toKotlinNotNull() + ">()"
|
||||
}
|
||||
|
||||
public open class IsOperator(val expression: Expression, val typeElement: TypeElement) : Expression() {
|
||||
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() {
|
||||
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() {
|
||||
open class LiteralExpression(val literalText: String) : Expression() {
|
||||
override fun toKotlin() = literalText
|
||||
}
|
||||
|
||||
public open class ParenthesizedExpression(val expression: Expression) : Expression() {
|
||||
open class ParenthesizedExpression(val expression: Expression) : Expression() {
|
||||
override fun toKotlin() = "(" + expression.toKotlin() + ")"
|
||||
}
|
||||
|
||||
public open class PrefixOperator(val op: String, val expression: Expression) : Expression() {
|
||||
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() {
|
||||
open class PostfixOperator(val op: String, val expression: Expression) : Expression() {
|
||||
override fun toKotlin() = expression.toKotlin() + op
|
||||
}
|
||||
|
||||
public open class ThisExpression(val identifier: Identifier) : Expression() {
|
||||
open class ThisExpression(val identifier: Identifier) : Expression() {
|
||||
override fun toKotlin() = "this" + identifier.withPrefix("@")
|
||||
}
|
||||
|
||||
public open class SuperExpression(val identifier: Identifier) : Expression() {
|
||||
open class SuperExpression(val identifier: Identifier) : Expression() {
|
||||
override fun toKotlin() = "super" + identifier.withPrefix("@")
|
||||
}
|
||||
|
||||
@@ -20,12 +20,14 @@ import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.*
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class Field(val identifier: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
val `type`: Type,
|
||||
val initializer: Element,
|
||||
val writingAccesses: Int) : Member(comments, modifiers) {
|
||||
open class Field(
|
||||
val identifier: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
val `type`: Type,
|
||||
val initializer: Element,
|
||||
val writingAccesses: Int
|
||||
) : Member(comments, modifiers) {
|
||||
|
||||
fun modifiersToKotlin(): String {
|
||||
val modifierList = ArrayList<Modifier>()
|
||||
@@ -41,9 +43,9 @@ public open class Field(val identifier: Identifier,
|
||||
return modifierList.toKotlin() + (if (isVal()) "val " else "var ")
|
||||
}
|
||||
|
||||
public fun isVal(): Boolean = modifiers.contains(Modifier.FINAL)
|
||||
fun isVal(): Boolean = modifiers.contains(Modifier.FINAL)
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
val declaration: String = commentsToKotlin() +
|
||||
modifiersToKotlin() + identifier.toKotlin() + " : " + `type`.toKotlin()
|
||||
if (initializer.isEmpty()) {
|
||||
|
||||
@@ -16,14 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
class FileMemberList(elements: List<Element>): WhiteSpaceSeparatedElementList(elements, WhiteSpace.NewLine, false)
|
||||
class FileMemberList(elements: List<Element>) : WhiteSpaceSeparatedElementList(elements, WhiteSpace.NewLine, false)
|
||||
|
||||
class PackageStatement(val packageName: String): Element {
|
||||
class PackageStatement(val packageName: String) : Element {
|
||||
override fun toKotlin(): String = "package " + packageName
|
||||
}
|
||||
|
||||
public class File(val body: FileMemberList,
|
||||
val mainFunction: String) : Element {
|
||||
class File(
|
||||
val body: FileMemberList,
|
||||
val mainFunction: String
|
||||
) : Element {
|
||||
|
||||
override fun toKotlin(): String {
|
||||
return body.toKotlin() + mainFunction
|
||||
|
||||
@@ -21,14 +21,16 @@ import java.util.ArrayList
|
||||
import org.jetbrains.jet.j2k.ast.types.isUnit
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public open class Function(val converter: Converter,
|
||||
val name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
val `type`: Type,
|
||||
val typeParameterList: TypeParameterList,
|
||||
val params: Element,
|
||||
var block: Block?) : Member(comments, modifiers) {
|
||||
open class Function(
|
||||
val converter: Converter,
|
||||
val name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
val `type`: Type,
|
||||
val typeParameterList: TypeParameterList,
|
||||
val params: Element,
|
||||
var block: Block?
|
||||
) : Member(comments, modifiers) {
|
||||
|
||||
private fun modifiersToKotlin(): String {
|
||||
val resultingModifiers = ArrayList<Modifier>()
|
||||
@@ -63,7 +65,7 @@ public open class Function(val converter: Converter,
|
||||
|
||||
private fun returnTypeToKotlin() = if (!`type`.isUnit()) " : " + `type`.toKotlin() + " " else " "
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
return commentsToKotlin() +
|
||||
modifiersToKotlin() +
|
||||
"fun ${typeParameterList.toKotlin().withSuffix(" ")}${name.toKotlin()}" +
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class Identifier(val name: String,
|
||||
val myNullable: Boolean = true,
|
||||
val quotingNeeded: Boolean = true) : Expression() {
|
||||
public override fun isEmpty() = name.length() == 0
|
||||
open class Identifier(
|
||||
val name: String,
|
||||
val myNullable: Boolean = true,
|
||||
val quotingNeeded: Boolean = true
|
||||
) : Expression() {
|
||||
override fun isEmpty() = name.length() == 0
|
||||
|
||||
private open fun ifNeedQuote(): String {
|
||||
if (quotingNeeded && (ONLY_KOTLIN_KEYWORDS.contains(name)) || name.contains("$")) {
|
||||
@@ -30,16 +32,17 @@ public open class Identifier(val name: String,
|
||||
return name
|
||||
}
|
||||
|
||||
public override fun toKotlin(): String = ifNeedQuote()
|
||||
public override fun isNullable(): Boolean = myNullable
|
||||
override fun toKotlin(): String = ifNeedQuote()
|
||||
override fun isNullable(): Boolean = myNullable
|
||||
|
||||
class object {
|
||||
public val Empty: Identifier = Identifier("")
|
||||
val Empty = Identifier("")
|
||||
|
||||
private open fun quote(str: String): String {
|
||||
return "`" + str + "`"
|
||||
}
|
||||
|
||||
public val ONLY_KOTLIN_KEYWORDS: Set<String> = setOf(
|
||||
val ONLY_KOTLIN_KEYWORDS: Set<String> = setOf(
|
||||
"package", "as", "type", "val", "var", "fun", "is", "in", "object", "when", "trait", "This"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -24,11 +24,11 @@ import org.jetbrains.jet.util.QualifiedNamesUtil
|
||||
import org.jetbrains.jet.lang.resolve.java.mapping.JavaToKotlinClassMap
|
||||
|
||||
|
||||
public class Import(val name: String) : Element {
|
||||
public override fun toKotlin() = "import " + name
|
||||
class Import(val name: String) : Element {
|
||||
override fun toKotlin() = "import " + name
|
||||
}
|
||||
|
||||
public class ImportList(val imports: List<Import>) : Element {
|
||||
class ImportList(val imports: List<Import>) : Element {
|
||||
val filteredImports = imports.filter {
|
||||
!it.name.isEmpty() && it.name !in NOT_NULL_ANNOTATIONS
|
||||
}.filter {
|
||||
@@ -49,10 +49,10 @@ public class ImportList(val imports: List<Import>) : Element {
|
||||
override fun toKotlin() = filteredImports.toKotlin("\n")
|
||||
}
|
||||
|
||||
public fun Converter.convertImportList(importList: PsiImportList): ImportList =
|
||||
fun Converter.convertImportList(importList: PsiImportList): ImportList =
|
||||
ImportList(importList.getAllImportStatements() map { convertImport(it) })
|
||||
|
||||
public fun Converter.convertImport(i: PsiImportStatementBase): Import {
|
||||
fun Converter.convertImport(i: PsiImportStatementBase): Import {
|
||||
val reference = i.getImportReference()
|
||||
if (reference != null) {
|
||||
return Import(quoteKeywords(reference.getQualifiedName()!!) + if (i.isOnDemand()) ".*" else "")
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
//TODO: is a member?
|
||||
public class Initializer(val block: Block, modifiers: Set<Modifier>) : Member(MemberComments.Empty, modifiers) {
|
||||
public override fun toKotlin(): String {
|
||||
class Initializer(val block: Block, modifiers: Set<Modifier>) : Member(MemberComments.Empty, modifiers) {
|
||||
override fun toKotlin(): String {
|
||||
return block.toKotlin()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,13 +19,15 @@ package org.jetbrains.jet.j2k.ast
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public class LocalVariable(val identifier: Identifier,
|
||||
val modifiersSet: Set<Modifier>,
|
||||
val javaType: Type,
|
||||
val initializer: Expression,
|
||||
val converter: Converter) : Expression() {
|
||||
class LocalVariable(
|
||||
val identifier: Identifier,
|
||||
val modifiersSet: Set<Modifier>,
|
||||
val javaType: Type,
|
||||
val initializer: Expression,
|
||||
val converter: Converter
|
||||
) : Expression() {
|
||||
|
||||
public fun isImmutable(): Boolean =
|
||||
fun isImmutable(): Boolean =
|
||||
converter.settings.forceLocalVariableImmutability || modifiersSet.contains(Modifier.FINAL)
|
||||
|
||||
override fun toKotlin(): String {
|
||||
|
||||
@@ -18,31 +18,31 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
public class MemberComments(elements: List<Element>) : WhiteSpaceSeparatedElementList(elements, WhiteSpace.NoSpace) {
|
||||
class MemberComments(elements: List<Element>) : WhiteSpaceSeparatedElementList(elements, WhiteSpace.NoSpace) {
|
||||
class object {
|
||||
public val Empty: MemberComments = MemberComments(ArrayList())
|
||||
val Empty = MemberComments(ArrayList())
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class Member(val comments: MemberComments, val modifiers: Set<Modifier>) : Element {
|
||||
abstract class Member(val comments: MemberComments, val modifiers: Set<Modifier>) : Element {
|
||||
fun accessModifier(): Modifier? {
|
||||
return modifiers.find { m -> m == Modifier.PUBLIC || m == Modifier.PROTECTED || m == Modifier.PRIVATE }
|
||||
}
|
||||
|
||||
public fun isAbstract(): Boolean = modifiers.contains(Modifier.ABSTRACT)
|
||||
public fun isStatic(): Boolean = modifiers.contains(Modifier.STATIC)
|
||||
public fun commentsToKotlin(): String = comments.toKotlin()
|
||||
fun isAbstract(): Boolean = modifiers.contains(Modifier.ABSTRACT)
|
||||
fun isStatic(): Boolean = modifiers.contains(Modifier.STATIC)
|
||||
fun commentsToKotlin(): String = comments.toKotlin()
|
||||
}
|
||||
|
||||
//member itself and all the elements before it in the code (comments, whitespaces)
|
||||
class MemberHolder(val member: Member, val elements: List<Element>)
|
||||
|
||||
public class MemberList(elements: List<Element>) : WhiteSpaceSeparatedElementList(elements, WhiteSpace.NewLine) {
|
||||
class MemberList(elements: List<Element>) : WhiteSpaceSeparatedElementList(elements, WhiteSpace.NewLine) {
|
||||
val members: List<Member>
|
||||
get() = elements.filter { it is Member }.map { it as Member }
|
||||
}
|
||||
|
||||
public class ClassMembers(
|
||||
class ClassMembers(
|
||||
val primaryConstructor: Constructor?,
|
||||
val secondaryConstructors: MemberList,
|
||||
val allMembers: MemberList,
|
||||
|
||||
@@ -19,13 +19,15 @@ package org.jetbrains.jet.j2k.ast
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class MethodCallExpression(val methodCall: Expression,
|
||||
val arguments: List<Expression>,
|
||||
val typeParameters: List<Type>,
|
||||
val resultIsNullable: Boolean = false) : Expression() {
|
||||
public override fun isNullable(): Boolean = methodCall.isNullable() || resultIsNullable
|
||||
open class MethodCallExpression(
|
||||
val methodCall: Expression,
|
||||
val arguments: List<Expression>,
|
||||
val typeParameters: List<Type>,
|
||||
val resultIsNullable: Boolean = false
|
||||
) : Expression() {
|
||||
override fun isNullable(): Boolean = methodCall.isNullable() || resultIsNullable
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
val typeParamsToKotlin: String = typeParameters.toKotlin(", ", "<", ">")
|
||||
val argumentsMapped = arguments.map { it.toKotlin() }
|
||||
return methodCall.toKotlin() + typeParamsToKotlin + "(" + argumentsMapped.makeString(", ") + ")"
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public enum class Modifier(val name: String) {
|
||||
enum class Modifier(val name: String) {
|
||||
PUBLIC: Modifier("public")
|
||||
PROTECTED: Modifier("protected")
|
||||
PRIVATE: Modifier("private")
|
||||
|
||||
@@ -16,11 +16,13 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
public open class NewClassExpression(val name: Element,
|
||||
val arguments: List<Expression>,
|
||||
val qualifier: Expression = Expression.Empty,
|
||||
val anonymousClass: AnonymousClass? = null) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
open class NewClassExpression(
|
||||
val name: Element,
|
||||
val arguments: List<Expression>,
|
||||
val qualifier: Expression = Expression.Empty,
|
||||
val anonymousClass: AnonymousClass? = null
|
||||
) : Expression() {
|
||||
override fun toKotlin(): String {
|
||||
val callOperator: String? = (if (qualifier.isNullable())
|
||||
"?."
|
||||
else
|
||||
|
||||
@@ -16,9 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
|
||||
public trait Node {
|
||||
trait Node {
|
||||
public fun toKotlin(): String
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ 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 {
|
||||
open class Parameter(val identifier: Identifier, val `type`: Type, val readOnly: Boolean = true) : Expression() {
|
||||
override fun toKotlin(): String {
|
||||
val vararg: String = (if (`type` is VarArg)
|
||||
"vararg "
|
||||
else
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class ParameterList(val parameters: List<Parameter>) : Expression() {
|
||||
public override fun toKotlin() = parameters.map { it.toKotlin() }.makeString(", ")
|
||||
open class ParameterList(val parameters: List<Parameter>) : Expression() {
|
||||
override fun toKotlin() = parameters.map { it.toKotlin() }.makeString(", ")
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public open class PolyadicExpression(val expressions: List<Expression>, val token: String) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
open class PolyadicExpression(val expressions: List<Expression>, val token: String) : Expression() {
|
||||
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 class ReferenceElement(val reference: Identifier, val types: List<Type>) : Element {
|
||||
public override fun toKotlin() = reference.toKotlin() + types.toKotlin(", ", "<", ">")
|
||||
class ReferenceElement(val reference: Identifier, val types: List<Type>) : Element {
|
||||
override fun toKotlin() = reference.toKotlin() + types.toKotlin(", ", "<", ">")
|
||||
}
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public abstract class Statement() : Element {
|
||||
class object {
|
||||
public val Empty: Statement = object : Statement() {
|
||||
override fun toKotlin() = ""
|
||||
override fun isEmpty() = true
|
||||
}
|
||||
abstract class Statement() : Element {
|
||||
object Empty : Statement() {
|
||||
override fun toKotlin() = ""
|
||||
override fun isEmpty() = true
|
||||
}
|
||||
}
|
||||
|
||||
public open class DeclarationStatement(val elements: List<Element>) : Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
open class DeclarationStatement(val elements: List<Element>) : Statement() {
|
||||
override fun toKotlin(): String {
|
||||
return elements.filter { it is LocalVariable }.map { convertDeclaration(it as LocalVariable) }.makeString("\n")
|
||||
}
|
||||
|
||||
@@ -40,22 +38,24 @@ public open class DeclarationStatement(val elements: List<Element>) : Statement(
|
||||
}
|
||||
}
|
||||
|
||||
public open class ExpressionListStatement(val expressions: List<Expression>) : Expression() {
|
||||
public override fun toKotlin() = expressions.toKotlin("\n")
|
||||
open class ExpressionListStatement(val expressions: List<Expression>) : Expression() {
|
||||
override fun toKotlin() = expressions.toKotlin("\n")
|
||||
}
|
||||
|
||||
public open class LabelStatement(val name: Identifier, val statement: Element) : Statement() {
|
||||
public override fun toKotlin(): String = "@" + name.toKotlin() + " " + statement.toKotlin()
|
||||
open class LabelStatement(val name: Identifier, val statement: Element) : Statement() {
|
||||
override fun toKotlin(): String = "@" + name.toKotlin() + " " + statement.toKotlin()
|
||||
}
|
||||
|
||||
public open class ReturnStatement(val expression: Expression) : Statement() {
|
||||
public override fun toKotlin() = "return " + expression.toKotlin()
|
||||
open class ReturnStatement(val expression: Expression) : Statement() {
|
||||
override fun toKotlin() = "return " + expression.toKotlin()
|
||||
}
|
||||
|
||||
public open class IfStatement(val condition: Expression,
|
||||
val thenStatement: Element,
|
||||
val elseStatement: Element) : Expression() {
|
||||
public override fun toKotlin(): String {
|
||||
open class IfStatement(
|
||||
val condition: Expression,
|
||||
val thenStatement: Element,
|
||||
val elseStatement: Element
|
||||
) : Expression() {
|
||||
override fun toKotlin(): String {
|
||||
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin()
|
||||
if (elseStatement != Statement.Empty) {
|
||||
return result + "\nelse\n" + elseStatement.toKotlin()
|
||||
@@ -67,41 +67,43 @@ public open class IfStatement(val condition: Expression,
|
||||
|
||||
// Loops --------------------------------------------------------------------------------------------------
|
||||
|
||||
public open class WhileStatement(val condition: Expression, val body: Element) : Statement() {
|
||||
public override fun toKotlin() = "while (" + condition.toKotlin() + ")\n" + body.toKotlin()
|
||||
open class WhileStatement(val condition: Expression, val body: Element) : Statement() {
|
||||
override fun toKotlin() = "while (" + condition.toKotlin() + ")\n" + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class DoWhileStatement(condition: Expression, body: Element) : WhileStatement(condition, body) {
|
||||
public override fun toKotlin() = "do\n" + body.toKotlin() + "\nwhile (" + condition.toKotlin() + ")"
|
||||
open class DoWhileStatement(condition: Expression, body: Element) : WhileStatement(condition, body) {
|
||||
override fun toKotlin() = "do\n" + body.toKotlin() + "\nwhile (" + condition.toKotlin() + ")"
|
||||
}
|
||||
|
||||
public open class ForeachStatement(val variable: Parameter,
|
||||
val expression: Expression,
|
||||
val body: Element) : Statement() {
|
||||
public override fun toKotlin() = "for (" + variable.identifier.name + " in " +
|
||||
open class ForeachStatement(
|
||||
val variable: Parameter,
|
||||
val expression: Expression,
|
||||
val body: Element
|
||||
) : Statement() {
|
||||
override fun toKotlin() = "for (" + variable.identifier.name + " in " +
|
||||
expression.toKotlin() + ")\n" + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class ForeachWithRangeStatement(val identifier: Identifier,
|
||||
val start: Expression,
|
||||
val end: Expression,
|
||||
val body: Element) : Statement() {
|
||||
public override fun toKotlin() = "for (" + identifier.toKotlin() + " in " +
|
||||
open class ForeachWithRangeStatement(val identifier: Identifier,
|
||||
val start: Expression,
|
||||
val end: Expression,
|
||||
val body: Element) : Statement() {
|
||||
override fun toKotlin() = "for (" + identifier.toKotlin() + " in " +
|
||||
start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin()
|
||||
}
|
||||
|
||||
public open class BreakStatement(val label: Identifier = Identifier.Empty) : Statement() {
|
||||
public override fun toKotlin() = "break" + label.withPrefix("@")
|
||||
open class BreakStatement(val label: Identifier = Identifier.Empty) : Statement() {
|
||||
override fun toKotlin() = "break" + label.withPrefix("@")
|
||||
}
|
||||
|
||||
public open class ContinueStatement(val label: Identifier = Identifier.Empty) : Statement() {
|
||||
public override fun toKotlin() = "continue" + label.withPrefix("@")
|
||||
open class ContinueStatement(val label: Identifier = Identifier.Empty) : Statement() {
|
||||
override fun toKotlin() = "continue" + label.withPrefix("@")
|
||||
}
|
||||
|
||||
// Exceptions ----------------------------------------------------------------------------------------------
|
||||
|
||||
public open class TryStatement(val block: Block, val catches: List<CatchStatement>, val finallyBlock: Block) : Statement() {
|
||||
public override fun toKotlin(): String {
|
||||
open class TryStatement(val block: Block, val catches: List<CatchStatement>, val finallyBlock: Block) : Statement() {
|
||||
override fun toKotlin(): String {
|
||||
return "try\n" + block.toKotlin() + "\n" + catches.toKotlin("\n") + "\n" + (if (finallyBlock.isEmpty())
|
||||
""
|
||||
else
|
||||
@@ -109,21 +111,21 @@ public open class TryStatement(val block: Block, val catches: List<CatchStatemen
|
||||
}
|
||||
}
|
||||
|
||||
public open class ThrowStatement(val expression: Expression) : Expression() {
|
||||
public override fun toKotlin() = "throw " + expression.toKotlin()
|
||||
open class ThrowStatement(val expression: Expression) : Expression() {
|
||||
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()
|
||||
open class CatchStatement(val variable: Parameter, val block: Block) : Statement() {
|
||||
override fun toKotlin(): String = "catch (" + variable.toKotlin() + ") " + block.toKotlin()
|
||||
}
|
||||
|
||||
// Switch --------------------------------------------------------------------------------------------------
|
||||
|
||||
public open class SwitchContainer(val expression: Expression, val caseContainers: List<CaseContainer>) : Statement() {
|
||||
public override fun toKotlin() = "when (" + expression.toKotlin() + ") {\n" + caseContainers.toKotlin("\n") + "\n}"
|
||||
open class SwitchContainer(val expression: Expression, val caseContainers: List<CaseContainer>) : Statement() {
|
||||
override fun toKotlin() = "when (" + expression.toKotlin() + ") {\n" + caseContainers.toKotlin("\n") + "\n}"
|
||||
}
|
||||
|
||||
public open class CaseContainer(val caseStatement: List<Element>, statements: List<Statement>) : Statement() {
|
||||
open class CaseContainer(val caseStatement: List<Element>, statements: List<Statement>) : Statement() {
|
||||
private val myBlock: Block
|
||||
|
||||
{
|
||||
@@ -131,24 +133,24 @@ public open class CaseContainer(val caseStatement: List<Element>, statements: Li
|
||||
myBlock = Block(newStatements, true)
|
||||
}
|
||||
|
||||
public override fun toKotlin() = caseStatement.toKotlin(", ") + " -> " + myBlock.toKotlin()
|
||||
override fun toKotlin() = caseStatement.toKotlin(", ") + " -> " + myBlock.toKotlin()
|
||||
}
|
||||
|
||||
public open class SwitchLabelStatement(val expression: Expression) : Statement() {
|
||||
public override fun toKotlin() = expression.toKotlin()
|
||||
open class SwitchLabelStatement(val expression: Expression) : Statement() {
|
||||
override fun toKotlin() = expression.toKotlin()
|
||||
}
|
||||
|
||||
public open class DefaultSwitchLabelStatement() : Statement() {
|
||||
public override fun toKotlin() = "else"
|
||||
open class DefaultSwitchLabelStatement() : Statement() {
|
||||
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()
|
||||
open class SynchronizedStatement(val expression: Expression, val block: Block) : Statement() {
|
||||
override fun toKotlin() = "synchronized (" + expression.toKotlin() + ") " + block.toKotlin()
|
||||
}
|
||||
|
||||
public class StatementList(elements: List<Element>) : WhiteSpaceSeparatedElementList(elements, WhiteSpace.NewLine) {
|
||||
class StatementList(elements: List<Element>) : WhiteSpaceSeparatedElementList(elements, WhiteSpace.NewLine) {
|
||||
val statements: List<Statement>
|
||||
get() = elements.filter { it is Statement }.map { it as Statement }
|
||||
}
|
||||
@@ -19,16 +19,18 @@ package org.jetbrains.jet.j2k.ast
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public class Trait(converter: Converter,
|
||||
name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
typeParameterList: TypeParameterList,
|
||||
extendsTypes: List<Type>,
|
||||
baseClassParams: List<Expression>,
|
||||
implementsTypes: List<Type>,
|
||||
members: List<Element>) : Class(converter, name, comments, modifiers, typeParameterList,
|
||||
extendsTypes, baseClassParams, implementsTypes, members) {
|
||||
class Trait(
|
||||
converter: Converter,
|
||||
name: Identifier,
|
||||
comments: MemberComments,
|
||||
modifiers: Set<Modifier>,
|
||||
typeParameterList: TypeParameterList,
|
||||
extendsTypes: List<Type>,
|
||||
baseClassParams: List<Expression>,
|
||||
implementsTypes: List<Type>,
|
||||
members: List<Element>
|
||||
) : Class(converter, name, comments, modifiers, typeParameterList,
|
||||
extendsTypes, baseClassParams, implementsTypes, members) {
|
||||
|
||||
override val TYPE: String
|
||||
get() = "trait"
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class TypeElement(val `type`: Type) : Element {
|
||||
open class TypeElement(val `type`: Type) : Element {
|
||||
override fun toKotlin() = `type`.toKotlin()
|
||||
|
||||
public fun toKotlinNotNull(): String = `type`.convertedToNotNull().toKotlin()
|
||||
fun toKotlinNotNull(): String = `type`.convertedToNotNull().toKotlin()
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ import org.jetbrains.jet.j2k.Converter
|
||||
import com.intellij.psi.PsiTypeParameterList
|
||||
import java.util.ArrayList
|
||||
|
||||
public class TypeParameter(val name: Identifier, val extendsTypes: List<Type>) : Element {
|
||||
public fun hasWhere(): Boolean = extendsTypes.size() > 1
|
||||
public fun getWhereToKotlin(): String {
|
||||
class TypeParameter(val name: Identifier, val extendsTypes: List<Type>) : Element {
|
||||
fun hasWhere(): Boolean = extendsTypes.size() > 1
|
||||
fun getWhereToKotlin(): String {
|
||||
if (hasWhere()) {
|
||||
return name.toKotlin() + " : " + extendsTypes.get(1).toKotlin()
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class TypeParameter(val name: Identifier, val extendsTypes: List<Type>) :
|
||||
return ""
|
||||
}
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
if (extendsTypes.size() > 0) {
|
||||
return name.toKotlin() + " : " + extendsTypes [0].toKotlin()
|
||||
}
|
||||
@@ -41,14 +41,14 @@ public class TypeParameter(val name: Identifier, val extendsTypes: List<Type>) :
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeParameterList(val parameters: List<TypeParameter>) : Element {
|
||||
class TypeParameterList(val parameters: List<TypeParameter>) : Element {
|
||||
override fun toKotlin(): String = if (!parameters.isEmpty())
|
||||
parameters.map {
|
||||
it.toKotlin()
|
||||
}.makeString(", ", "<", ">")
|
||||
else ""
|
||||
|
||||
public fun whereToKotlin(): String {
|
||||
fun whereToKotlin(): String {
|
||||
if (hasWhere()) {
|
||||
val wheres = parameters.map { it.getWhereToKotlin() }
|
||||
return "where " + wheres.makeString(", ")
|
||||
@@ -61,15 +61,15 @@ public class TypeParameterList(val parameters: List<TypeParameter>) : Element {
|
||||
private fun hasWhere(): Boolean = parameters.any { it.hasWhere() }
|
||||
|
||||
class object {
|
||||
public val Empty: TypeParameterList = TypeParameterList(ArrayList())
|
||||
val Empty = TypeParameterList(ArrayList())
|
||||
}
|
||||
}
|
||||
|
||||
public fun Converter.convertTypeParameter(psiTypeParameter: PsiTypeParameter): TypeParameter {
|
||||
fun Converter.convertTypeParameter(psiTypeParameter: PsiTypeParameter): TypeParameter {
|
||||
return convertElement(psiTypeParameter) as TypeParameter
|
||||
}
|
||||
|
||||
public fun Converter.convertTypeParameterList(psiTypeParameterlist: PsiTypeParameterList?): TypeParameterList {
|
||||
fun Converter.convertTypeParameterList(psiTypeParameterlist: PsiTypeParameterList?): TypeParameterList {
|
||||
return if (psiTypeParameterlist == null) TypeParameterList.Empty
|
||||
else TypeParameterList(psiTypeParameterlist.getTypeParameters()!!.toList().map { convertTypeParameter(it) })
|
||||
}
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.j2k.ast
|
||||
|
||||
import java.util.ArrayList
|
||||
|
||||
public fun List<Node>.toKotlin(separator: String, prefix: String = "", suffix: String = ""): String {
|
||||
fun List<Node>.toKotlin(separator: String, prefix: String = "", suffix: String = ""): String {
|
||||
val result = StringBuilder()
|
||||
if (size() > 0) {
|
||||
result.append(prefix)
|
||||
@@ -33,7 +33,7 @@ public fun List<Node>.toKotlin(separator: String, prefix: String = "", suffix: S
|
||||
return result.toString()
|
||||
}
|
||||
|
||||
public fun Collection<Modifier>.toKotlin(separator: String = " "): String {
|
||||
fun Collection<Modifier>.toKotlin(separator: String = " "): String {
|
||||
val result = StringBuilder()
|
||||
for (x in this) {
|
||||
result.append(x.name)
|
||||
@@ -42,9 +42,9 @@ public fun Collection<Modifier>.toKotlin(separator: String = " "): String {
|
||||
return result.toString()
|
||||
}
|
||||
|
||||
public fun String.withSuffix(suffix: String): String = if (isEmpty()) "" else this + suffix
|
||||
public fun String.withPrefix(prefix: String): String = if (isEmpty()) "" else prefix + this
|
||||
public fun Expression.withPrefix(prefix: String): String = if (isEmpty()) "" else prefix + toKotlin()
|
||||
fun String.withSuffix(suffix: String): String = if (isEmpty()) "" else this + suffix
|
||||
fun String.withPrefix(prefix: String): String = if (isEmpty()) "" else prefix + this
|
||||
fun Expression.withPrefix(prefix: String): String = if (isEmpty()) "" else prefix + toKotlin()
|
||||
|
||||
open class WhiteSpaceSeparatedElementList(
|
||||
val elements: List<Element>,
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
package org.jetbrains.jet.j2k.ast
|
||||
|
||||
|
||||
public class WhiteSpace(val text: String) : Element {
|
||||
class WhiteSpace(val text: String) : Element {
|
||||
override fun toKotlin() = text
|
||||
override fun isEmpty() = text.isEmpty()
|
||||
|
||||
public fun compareTo(other: WhiteSpace): Int {
|
||||
fun compareTo(other: WhiteSpace): Int {
|
||||
|
||||
fun newLinesCount(w: WhiteSpace) = w.text.count { it == '\n' }
|
||||
|
||||
@@ -36,8 +36,8 @@ public class WhiteSpace(val text: String) : Element {
|
||||
}
|
||||
|
||||
class object {
|
||||
public val NewLine: WhiteSpace = WhiteSpace("\n")
|
||||
public val NoSpace: WhiteSpace = WhiteSpace("")
|
||||
val NewLine = WhiteSpace("\n")
|
||||
val NoSpace = WhiteSpace("")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,12 @@ package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public class ArrayType(val elementType: Type, nullable: Boolean,
|
||||
converter: Converter) : MayBeNullableType(nullable, converter) {
|
||||
public override fun toKotlin(): String {
|
||||
class ArrayType(
|
||||
val elementType: Type,
|
||||
nullable: Boolean,
|
||||
converter: Converter
|
||||
) : MayBeNullableType(nullable, converter) {
|
||||
override fun toKotlin(): String {
|
||||
if (elementType is PrimitiveType) {
|
||||
return elementType.toKotlin() + "Array" + isNullableStr()
|
||||
}
|
||||
@@ -28,5 +31,5 @@ public class ArrayType(val elementType: Type, nullable: Boolean,
|
||||
return "Array<" + elementType.toKotlin() + ">" + isNullableStr()
|
||||
}
|
||||
|
||||
public override fun convertedToNotNull(): Type = ArrayType(elementType, false, converter)
|
||||
override fun convertedToNotNull(): Type = ArrayType(elementType, false, converter)
|
||||
}
|
||||
|
||||
@@ -21,10 +21,10 @@ import org.jetbrains.jet.j2k.ast.Identifier
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public open class ClassType(val `type`: Identifier, val parameters: List<Element>, nullable: Boolean,
|
||||
converter: Converter) : MayBeNullableType(nullable, converter) {
|
||||
open class ClassType(val `type`: Identifier, val parameters: List<Element>, nullable: Boolean,
|
||||
converter: Converter) : MayBeNullableType(nullable, converter) {
|
||||
|
||||
public override fun toKotlin(): String {
|
||||
override fun toKotlin(): String {
|
||||
// TODO change to map() when KT-2051 is fixed
|
||||
val parametersToKotlin = ArrayList<String>()
|
||||
for (param in parameters) {
|
||||
@@ -38,5 +38,5 @@ public open class ClassType(val `type`: Identifier, val parameters: List<Element
|
||||
}
|
||||
|
||||
|
||||
public override fun convertedToNotNull(): Type = ClassType(`type`, parameters, false, converter)
|
||||
override fun convertedToNotNull(): Type = ClassType(`type`, parameters, false, converter)
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class EmptyType() : NotNullType {
|
||||
public override fun toKotlin(): String = "UNRESOLVED_TYPE"
|
||||
open class EmptyType() : NotNullType {
|
||||
override fun toKotlin(): String = "UNRESOLVED_TYPE"
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class InProjectionType(val bound: Type) : NotNullType {
|
||||
public override fun toKotlin(): String = "in " + bound.toKotlin()
|
||||
open class InProjectionType(val bound: Type) : NotNullType {
|
||||
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) : NotNullType {
|
||||
public override fun toKotlin(): String = "out " + bound.toKotlin()
|
||||
open class OutProjectionType(val bound: Type) : NotNullType {
|
||||
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) : NotNullType {
|
||||
public override fun toKotlin(): String = `type`.toKotlin()
|
||||
open class PrimitiveType(val `type`: Identifier) : NotNullType {
|
||||
override fun toKotlin(): String = `type`.toKotlin()
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class StarProjectionType() : NotNullType {
|
||||
public override fun toKotlin(): String = "*"
|
||||
open class StarProjectionType() : NotNullType {
|
||||
override fun toKotlin(): String = "*"
|
||||
}
|
||||
|
||||
@@ -19,27 +19,27 @@ package org.jetbrains.jet.j2k.ast.types
|
||||
import org.jetbrains.jet.j2k.ast.Element
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public fun Type.isPrimitive(): Boolean = this is PrimitiveType
|
||||
public fun Type.isUnit(): Boolean = this == UnitType
|
||||
fun Type.isPrimitive(): Boolean = this is PrimitiveType
|
||||
fun Type.isUnit(): Boolean = this == UnitType
|
||||
|
||||
public abstract class MayBeNullableType(nullable: Boolean, val converter: Converter): Type {
|
||||
override public val nullable: Boolean = !converter.settings.forceNotNullTypes && nullable
|
||||
abstract class MayBeNullableType(nullable: Boolean, val converter: Converter) : Type {
|
||||
override val nullable: Boolean = !converter.settings.forceNotNullTypes && nullable
|
||||
}
|
||||
|
||||
public trait NotNullType : Type {
|
||||
override public val nullable: Boolean
|
||||
trait NotNullType : Type {
|
||||
override val nullable: Boolean
|
||||
get() = false
|
||||
}
|
||||
|
||||
public object UnitType: NotNullType {
|
||||
object UnitType: NotNullType {
|
||||
override fun toKotlin() = "Unit"
|
||||
}
|
||||
|
||||
public trait Type : Element {
|
||||
trait Type : Element {
|
||||
|
||||
public val nullable: Boolean
|
||||
val nullable: Boolean
|
||||
|
||||
public open fun convertedToNotNull(): Type {
|
||||
open fun convertedToNotNull(): Type {
|
||||
if (nullable) throw UnsupportedOperationException("convertedToNotNull must be defined")
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -16,6 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.j2k.ast.types
|
||||
|
||||
public open class VarArg(val `type`: Type) : NotNullType {
|
||||
public override fun toKotlin(): String = `type`.toKotlin()
|
||||
open class VarArg(val `type`: Type) : NotNullType {
|
||||
override fun toKotlin(): String = `type`.toKotlin()
|
||||
}
|
||||
|
||||
@@ -23,11 +23,11 @@ import java.util.HashSet
|
||||
public open class ClassVisitor() : JavaRecursiveElementVisitor() {
|
||||
private val myClassIdentifiers = HashSet<String>()
|
||||
|
||||
public open fun getClassIdentifiers(): Set<String> {
|
||||
public fun getClassIdentifiers(): Set<String> {
|
||||
return HashSet<String>(myClassIdentifiers)
|
||||
}
|
||||
|
||||
public override fun visitClass(aClass: PsiClass?) {
|
||||
override fun visitClass(aClass: PsiClass?) {
|
||||
val qName = aClass?.getQualifiedName()
|
||||
if (qName != null) {
|
||||
myClassIdentifiers.add(qName)
|
||||
|
||||
@@ -18,6 +18,6 @@ package org.jetbrains.jet.j2k.visitors
|
||||
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
|
||||
public open class Dispatcher(converter: Converter) {
|
||||
public var expressionVisitor: ExpressionVisitor = ExpressionVisitor(converter)
|
||||
open class Dispatcher(converter: Converter) {
|
||||
var expressionVisitor: ExpressionVisitor = ExpressionVisitor(converter)
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@ import org.jetbrains.jet.j2k.*
|
||||
import org.jetbrains.jet.j2k.ast.*
|
||||
import org.jetbrains.jet.j2k.ast.types.Type
|
||||
|
||||
public open class ElementVisitor(val myConverter: Converter) : JavaElementVisitor() {
|
||||
open class ElementVisitor(val myConverter: Converter) : JavaElementVisitor() {
|
||||
protected var myResult: Element = Element.Empty
|
||||
|
||||
public fun getConverter(): Converter {
|
||||
fun getConverter(): Converter {
|
||||
return myConverter
|
||||
}
|
||||
|
||||
public open fun getResult(): Element {
|
||||
open fun getResult(): Element {
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitLocalVariable(variable: PsiLocalVariable?) {
|
||||
override fun visitLocalVariable(variable: PsiLocalVariable?) {
|
||||
val theVariable = variable!!
|
||||
var kType = myConverter.convertType(theVariable.getType(), isAnnotatedAsNotNull(theVariable.getModifierList()))
|
||||
if (theVariable.hasModifierProperty(PsiModifier.FINAL) && isDefinitelyNotNull(theVariable.getInitializer())) {
|
||||
@@ -45,11 +45,11 @@ public open class ElementVisitor(val myConverter: Converter) : JavaElementVisito
|
||||
myConverter)
|
||||
}
|
||||
|
||||
public override fun visitExpressionList(list: PsiExpressionList?) {
|
||||
override fun visitExpressionList(list: PsiExpressionList?) {
|
||||
myResult = ExpressionList(myConverter.convertExpressions(list!!.getExpressions()))
|
||||
}
|
||||
|
||||
public override fun visitReferenceElement(reference: PsiJavaCodeReferenceElement?) {
|
||||
override fun visitReferenceElement(reference: PsiJavaCodeReferenceElement?) {
|
||||
val theReference = reference!!
|
||||
val types: List<Type> = myConverter.convertTypes(theReference.getTypeParameters())
|
||||
if (!theReference.isQualified()) {
|
||||
@@ -68,20 +68,20 @@ public open class ElementVisitor(val myConverter: Converter) : JavaElementVisito
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitTypeElement(`type`: PsiTypeElement?) {
|
||||
override fun visitTypeElement(`type`: PsiTypeElement?) {
|
||||
myResult = TypeElement(myConverter.convertType(`type`!!.getType()))
|
||||
}
|
||||
|
||||
public override fun visitTypeParameter(classParameter: PsiTypeParameter?) {
|
||||
override fun visitTypeParameter(classParameter: PsiTypeParameter?) {
|
||||
myResult = TypeParameter(Identifier(classParameter!!.getName()!!),
|
||||
classParameter.getExtendsListTypes().map { myConverter.convertType(it) })
|
||||
}
|
||||
|
||||
public override fun visitParameterList(list: PsiParameterList?) {
|
||||
override fun visitParameterList(list: PsiParameterList?) {
|
||||
myResult = ParameterList(myConverter.convertParameterList(list!!.getParameters()).requireNoNulls())
|
||||
}
|
||||
|
||||
public override fun visitComment(comment: PsiComment?) {
|
||||
override fun visitComment(comment: PsiComment?) {
|
||||
myResult = Comment(comment!!.getText()!!)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,16 +29,16 @@ import org.jetbrains.jet.lang.types.lang.PrimitiveType
|
||||
import org.jetbrains.jet.j2k.*
|
||||
import org.jetbrains.jet.j2k.ast.types.ArrayType
|
||||
|
||||
public open class ExpressionVisitor(converter: Converter) : StatementVisitor(converter) {
|
||||
open class ExpressionVisitor(converter: Converter) : StatementVisitor(converter) {
|
||||
{
|
||||
myResult = Expression.Empty
|
||||
}
|
||||
|
||||
public override fun getResult(): Expression {
|
||||
override fun getResult(): Expression {
|
||||
return myResult as Expression
|
||||
}
|
||||
|
||||
public override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression?) {
|
||||
override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression?) {
|
||||
val assignment = PsiTreeUtil.getParentOfType(expression, javaClass<PsiAssignmentExpression>())
|
||||
val lvalue = assignment != null && expression == assignment.getLExpression();
|
||||
myResult = ArrayAccessExpression(getConverter().convertExpression(expression?.getArrayExpression()),
|
||||
@@ -46,14 +46,14 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
lvalue)
|
||||
}
|
||||
|
||||
public override fun visitArrayInitializerExpression(expression: PsiArrayInitializerExpression?) {
|
||||
override fun visitArrayInitializerExpression(expression: PsiArrayInitializerExpression?) {
|
||||
val expressionType = getConverter().convertType(expression?.getType())
|
||||
assert(expressionType is ArrayType) { "Array initializer must have array type" }
|
||||
myResult = ArrayInitializerExpression(expressionType as ArrayType,
|
||||
getConverter().convertExpressions(expression?.getInitializers()!!))
|
||||
}
|
||||
|
||||
public override fun visitAssignmentExpression(expression: PsiAssignmentExpression?) {
|
||||
override fun visitAssignmentExpression(expression: PsiAssignmentExpression?) {
|
||||
val tokenType: IElementType = expression?.getOperationSign()?.getTokenType()!!
|
||||
val secondOp: String = when(tokenType) {
|
||||
JavaTokenType.GTGTEQ -> "shr"
|
||||
@@ -75,7 +75,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitBinaryExpression(expression: PsiBinaryExpression?) {
|
||||
override fun visitBinaryExpression(expression: PsiBinaryExpression?) {
|
||||
val lhs = getConverter().convertExpression(expression?.getLOperand()!!, expression?.getType())
|
||||
val rhs = getConverter().convertExpression(expression?.getROperand(), expression?.getType())
|
||||
if (expression?.getOperationSign()?.getTokenType() == JavaTokenType.GTGTGT) {
|
||||
@@ -87,11 +87,11 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitClassObjectAccessExpression(expression: PsiClassObjectAccessExpression?) {
|
||||
override fun visitClassObjectAccessExpression(expression: PsiClassObjectAccessExpression?) {
|
||||
myResult = ClassObjectAccessExpression(getConverter().convertTypeElement(expression?.getOperand()))
|
||||
}
|
||||
|
||||
public override fun visitConditionalExpression(expression: PsiConditionalExpression?) {
|
||||
override fun visitConditionalExpression(expression: PsiConditionalExpression?) {
|
||||
val condition: PsiExpression? = expression?.getCondition()
|
||||
val `type`: PsiType? = condition?.getType()
|
||||
val e: Expression = (if (`type` != null)
|
||||
@@ -103,17 +103,17 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
getConverter().convertExpression(expression?.getElseExpression())))
|
||||
}
|
||||
|
||||
public override fun visitExpressionList(list: PsiExpressionList?) {
|
||||
override fun visitExpressionList(list: PsiExpressionList?) {
|
||||
myResult = ExpressionList(getConverter().convertExpressions(list!!.getExpressions()))
|
||||
}
|
||||
|
||||
public override fun visitInstanceOfExpression(expression: PsiInstanceOfExpression?) {
|
||||
override fun visitInstanceOfExpression(expression: PsiInstanceOfExpression?) {
|
||||
val checkType: PsiTypeElement? = expression?.getCheckType()
|
||||
myResult = IsOperator(getConverter().convertExpression(expression?.getOperand()),
|
||||
myConverter.convertTypeElement(checkType))
|
||||
}
|
||||
|
||||
public override fun visitLiteralExpression(expression: PsiLiteralExpression?) {
|
||||
override fun visitLiteralExpression(expression: PsiLiteralExpression?) {
|
||||
val value: Any? = expression?.getValue()
|
||||
var text: String = expression?.getText()!!
|
||||
val `type`: PsiType? = expression?.getType()
|
||||
@@ -143,7 +143,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
myResult = LiteralExpression(text)
|
||||
}
|
||||
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
convertMethodCallExpression(expression!!)
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitNewExpression(expression: PsiNewExpression?) {
|
||||
override fun visitNewExpression(expression: PsiNewExpression?) {
|
||||
if (expression?.getArrayInitializer() != null)
|
||||
{
|
||||
myResult = createNewEmptyArray(expression)
|
||||
@@ -211,16 +211,16 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
return getConverter().convertExpression(expression?.getArrayInitializer())
|
||||
}
|
||||
|
||||
public override fun visitParenthesizedExpression(expression: PsiParenthesizedExpression?) {
|
||||
override fun visitParenthesizedExpression(expression: PsiParenthesizedExpression?) {
|
||||
myResult = ParenthesizedExpression(getConverter().convertExpression(expression?.getExpression()))
|
||||
}
|
||||
|
||||
public override fun visitPostfixExpression(expression: PsiPostfixExpression?) {
|
||||
override fun visitPostfixExpression(expression: PsiPostfixExpression?) {
|
||||
myResult = PostfixOperator(getOperatorString(expression!!.getOperationSign().getTokenType()!!),
|
||||
getConverter().convertExpression(expression.getOperand()))
|
||||
}
|
||||
|
||||
public override fun visitPrefixExpression(expression: PsiPrefixExpression?) {
|
||||
override fun visitPrefixExpression(expression: PsiPrefixExpression?) {
|
||||
val operand = getConverter().convertExpression(expression?.getOperand(), expression?.getOperand()!!.getType())
|
||||
val token = expression?.getOperationTokenType()!!
|
||||
if (token == JavaTokenType.TILDE) {
|
||||
@@ -231,7 +231,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
override fun visitReferenceExpression(expression: PsiReferenceExpression?) {
|
||||
val isFieldReference: Boolean = isFieldReference(expression!!, getContainingClass(expression))
|
||||
val insideSecondaryConstructor: Boolean = isInsideSecondaryConstructor(expression)
|
||||
val hasReceiver: Boolean = isFieldReference && insideSecondaryConstructor
|
||||
@@ -243,7 +243,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
var identifier: Expression = Identifier(referencedName, isNullable)
|
||||
val __: String = "__"
|
||||
val qualifier = expression.getQualifierExpression()
|
||||
if (hasReceiver){
|
||||
if (hasReceiver) {
|
||||
identifier = CallChainExpression(Identifier(__, false), Identifier(referencedName, isNullable))
|
||||
}
|
||||
else if (insideSecondaryConstructor && isThis) {
|
||||
@@ -268,7 +268,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
!isStaticallyImported(resolved, expression)) {
|
||||
var member = resolved as PsiMember
|
||||
var result = Identifier(referencedName).toKotlin()
|
||||
while(member.getContainingClass() != null) {
|
||||
while (member.getContainingClass() != null) {
|
||||
result = Identifier(member.getContainingClass()!!.getName()!!).toKotlin() + "." + result
|
||||
member = member.getContainingClass()!!
|
||||
}
|
||||
@@ -291,7 +291,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
return false;
|
||||
}
|
||||
|
||||
public override fun visitSuperExpression(expression: PsiSuperExpression?) {
|
||||
override fun visitSuperExpression(expression: PsiSuperExpression?) {
|
||||
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
||||
myResult = SuperExpression((if (qualifier != null)
|
||||
Identifier(qualifier.getQualifiedName()!!)
|
||||
@@ -299,7 +299,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
Identifier.Empty))
|
||||
}
|
||||
|
||||
public override fun visitThisExpression(expression: PsiThisExpression?) {
|
||||
override fun visitThisExpression(expression: PsiThisExpression?) {
|
||||
val qualifier: PsiJavaCodeReferenceElement? = expression?.getQualifier()
|
||||
myResult = ThisExpression((if (qualifier != null)
|
||||
Identifier(qualifier.getQualifiedName()!!)
|
||||
@@ -307,7 +307,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
Identifier.Empty))
|
||||
}
|
||||
|
||||
public override fun visitTypeCastExpression(expression: PsiTypeCastExpression?) {
|
||||
override fun visitTypeCastExpression(expression: PsiTypeCastExpression?) {
|
||||
val castType: PsiTypeElement? = expression?.getCastType()
|
||||
if (castType != null) {
|
||||
val operand = expression?.getOperand()
|
||||
@@ -324,7 +324,7 @@ public open class ExpressionVisitor(converter: Converter) : StatementVisitor(con
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitPolyadicExpression(expression: PsiPolyadicExpression?) {
|
||||
override fun visitPolyadicExpression(expression: PsiPolyadicExpression?) {
|
||||
var parameters = ArrayList<Expression>()
|
||||
for (operand : PsiExpression in expression?.getOperands()!!) {
|
||||
parameters.add(getConverter().convertExpression(operand, expression?.getType()))
|
||||
|
||||
+2
-2
@@ -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?) {
|
||||
open class ExpressionVisitorForDirectObjectInheritors(converter: Converter) : ExpressionVisitor(converter) {
|
||||
override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
val methodExpression = expression?.getMethodExpression()!!
|
||||
if (superMethodInvocation(methodExpression, "hashCode")) {
|
||||
myResult = MethodCallExpression.build(Identifier("System", false), "identityHashCode", listOf(Identifier("this")))
|
||||
|
||||
@@ -22,17 +22,17 @@ import org.jetbrains.jet.j2k.ast.*
|
||||
import org.jetbrains.jet.j2k.countWritingAccesses
|
||||
import java.util.ArrayList
|
||||
|
||||
public open class StatementVisitor(converter: Converter) : ElementVisitor(converter) {
|
||||
public override fun visitAssertStatement(statement: PsiAssertStatement?) {
|
||||
open class StatementVisitor(converter: Converter) : ElementVisitor(converter) {
|
||||
override fun visitAssertStatement(statement: PsiAssertStatement?) {
|
||||
myResult = AssertStatement(getConverter().convertExpression(statement?.getAssertCondition()),
|
||||
getConverter().convertExpression(statement?.getAssertDescription()))
|
||||
}
|
||||
|
||||
public override fun visitBlockStatement(statement: PsiBlockStatement?) {
|
||||
override fun visitBlockStatement(statement: PsiBlockStatement?) {
|
||||
myResult = getConverter().convertBlock(statement?.getCodeBlock(), true)
|
||||
}
|
||||
|
||||
public override fun visitBreakStatement(statement: PsiBreakStatement?) {
|
||||
override fun visitBreakStatement(statement: PsiBreakStatement?) {
|
||||
if (statement?.getLabelIdentifier() == null) {
|
||||
myResult = BreakStatement(Identifier.Empty)
|
||||
}
|
||||
@@ -42,7 +42,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitContinueStatement(statement: PsiContinueStatement?) {
|
||||
override fun visitContinueStatement(statement: PsiContinueStatement?) {
|
||||
if (statement?.getLabelIdentifier() == null)
|
||||
{
|
||||
myResult = ContinueStatement(Identifier.Empty)
|
||||
@@ -53,11 +53,11 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitDeclarationStatement(statement: PsiDeclarationStatement?) {
|
||||
override fun visitDeclarationStatement(statement: PsiDeclarationStatement?) {
|
||||
myResult = DeclarationStatement(getConverter().convertElements(statement?.getDeclaredElements()!!))
|
||||
}
|
||||
|
||||
public override fun visitDoWhileStatement(statement: PsiDoWhileStatement?) {
|
||||
override fun visitDoWhileStatement(statement: PsiDoWhileStatement?) {
|
||||
val condition: PsiExpression? = statement?.getCondition()
|
||||
val expression: Expression = (if (condition != null && condition.getType() != null)
|
||||
getConverter().convertExpression(condition, condition.getType())
|
||||
@@ -66,16 +66,16 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
myResult = DoWhileStatement(expression, getConverter().convertStatement(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitExpressionStatement(statement: PsiExpressionStatement?) {
|
||||
override fun visitExpressionStatement(statement: PsiExpressionStatement?) {
|
||||
myResult = getConverter().convertExpression(statement?.getExpression())
|
||||
}
|
||||
|
||||
public override fun visitExpressionListStatement(statement: PsiExpressionListStatement?) {
|
||||
override fun visitExpressionListStatement(statement: PsiExpressionListStatement?) {
|
||||
myResult = ExpressionListStatement(getConverter().convertExpressions(
|
||||
statement?.getExpressionList()?.getExpressions()!!))
|
||||
}
|
||||
|
||||
public override fun visitForStatement(statement: PsiForStatement?) {
|
||||
override fun visitForStatement(statement: PsiForStatement?) {
|
||||
val initialization = statement?.getInitialization()
|
||||
val update = statement?.getUpdate()
|
||||
val condition = statement?.getCondition()
|
||||
@@ -122,7 +122,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
}
|
||||
}
|
||||
|
||||
public override fun visitForeachStatement(statement: PsiForeachStatement?) {
|
||||
override fun visitForeachStatement(statement: PsiForeachStatement?) {
|
||||
val iterator = {
|
||||
val iteratorExpr = getConverter().convertExpression(statement?.getIteratedValue())
|
||||
if (iteratorExpr.isNullable())
|
||||
@@ -135,7 +135,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
getConverter().convertStatement(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitIfStatement(statement: PsiIfStatement?) {
|
||||
override fun visitIfStatement(statement: PsiIfStatement?) {
|
||||
val condition: PsiExpression? = statement?.getCondition()
|
||||
val expression: Expression = getConverter().convertExpression(condition, PsiType.BOOLEAN)
|
||||
myResult = IfStatement(expression,
|
||||
@@ -143,19 +143,19 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
getConverter().convertStatement(statement?.getElseBranch()))
|
||||
}
|
||||
|
||||
public override fun visitLabeledStatement(statement: PsiLabeledStatement?) {
|
||||
override fun visitLabeledStatement(statement: PsiLabeledStatement?) {
|
||||
myResult = LabelStatement(getConverter().convertIdentifier(statement?.getLabelIdentifier()),
|
||||
getConverter().convertStatement(statement?.getStatement()))
|
||||
}
|
||||
|
||||
public override fun visitSwitchLabelStatement(statement: PsiSwitchLabelStatement?) {
|
||||
override fun visitSwitchLabelStatement(statement: PsiSwitchLabelStatement?) {
|
||||
myResult = (if (statement?.isDefaultCase()!!)
|
||||
DefaultSwitchLabelStatement()
|
||||
else
|
||||
SwitchLabelStatement(getConverter().convertExpression(statement?.getCaseValue())))
|
||||
}
|
||||
|
||||
public override fun visitSwitchStatement(statement: PsiSwitchStatement?) {
|
||||
override fun visitSwitchStatement(statement: PsiSwitchStatement?) {
|
||||
myResult = SwitchContainer(getConverter().convertExpression(statement?.getExpression()),
|
||||
switchBodyToCases(statement?.getBody()))
|
||||
}
|
||||
@@ -203,16 +203,16 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
return result
|
||||
}
|
||||
|
||||
public override fun visitSynchronizedStatement(statement: PsiSynchronizedStatement?) {
|
||||
override fun visitSynchronizedStatement(statement: PsiSynchronizedStatement?) {
|
||||
myResult = SynchronizedStatement(getConverter().convertExpression(statement?.getLockExpression()),
|
||||
getConverter().convertBlock(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitThrowStatement(statement: PsiThrowStatement?) {
|
||||
override fun visitThrowStatement(statement: PsiThrowStatement?) {
|
||||
myResult = ThrowStatement(getConverter().convertExpression(statement?.getException()))
|
||||
}
|
||||
|
||||
public override fun visitTryStatement(statement: PsiTryStatement?) {
|
||||
override fun visitTryStatement(statement: PsiTryStatement?) {
|
||||
val catches = ArrayList<CatchStatement>()
|
||||
val catchBlocks = statement?.getCatchBlocks()!!
|
||||
val catchBlockParameters = statement?.getCatchBlockParameters()!!
|
||||
@@ -224,7 +224,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
catches, getConverter().convertBlock(statement?.getFinallyBlock(), true))
|
||||
}
|
||||
|
||||
public override fun visitWhileStatement(statement: PsiWhileStatement?) {
|
||||
override fun visitWhileStatement(statement: PsiWhileStatement?) {
|
||||
var condition: PsiExpression? = statement?.getCondition()
|
||||
val expression: Expression = (if (condition != null && condition?.getType() != null)
|
||||
this.getConverter().convertExpression(condition, condition?.getType())
|
||||
@@ -233,7 +233,7 @@ public open class StatementVisitor(converter: Converter) : ElementVisitor(conver
|
||||
myResult = WhileStatement(expression, getConverter().convertStatement(statement?.getBody()))
|
||||
}
|
||||
|
||||
public override fun visitReturnStatement(statement: PsiReturnStatement?) {
|
||||
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 val resolvedSuperCallParameters: HashSet<PsiExpressionList> = HashSet()
|
||||
open class SuperVisitor() : JavaRecursiveElementVisitor() {
|
||||
val resolvedSuperCallParameters: HashSet<PsiExpressionList> = HashSet()
|
||||
|
||||
public override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
override fun visitMethodCallExpression(expression: PsiMethodCallExpression?) {
|
||||
if (expression != null && isSuper(expression.getMethodExpression())) {
|
||||
resolvedSuperCallParameters.add(expression.getArgumentList())
|
||||
}
|
||||
|
||||
@@ -28,13 +28,13 @@ import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType
|
||||
|
||||
private val PRIMITIVE_TYPES_NAMES = JvmPrimitiveType.values().map { it.getName() }
|
||||
|
||||
public open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisitor<Type>() {
|
||||
open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisitor<Type>() {
|
||||
private var myResult: Type = EmptyType()
|
||||
public open fun getResult(): Type {
|
||||
open fun getResult(): Type {
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?): Type {
|
||||
override fun visitPrimitiveType(primitiveType: PsiPrimitiveType?): Type {
|
||||
val name: String = primitiveType?.getCanonicalText()!!
|
||||
if (name == "void") {
|
||||
myResult = UnitType
|
||||
@@ -48,7 +48,7 @@ public open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisit
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitArrayType(arrayType: PsiArrayType?): Type {
|
||||
override fun visitArrayType(arrayType: PsiArrayType?): Type {
|
||||
if (myResult is EmptyType) {
|
||||
myResult = ArrayType(myConverter.convertType(arrayType?.getComponentType()), true, myConverter)
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisit
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitClassType(classType: PsiClassType?): Type {
|
||||
override fun visitClassType(classType: PsiClassType?): Type {
|
||||
if (classType == null) return myResult
|
||||
val identifier: Identifier = constructClassTypeIdentifier(classType)
|
||||
val resolvedClassTypeParams: List<Type> = createRawTypesForResolvedReference(classType)
|
||||
@@ -130,7 +130,7 @@ public open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisit
|
||||
return typeParams
|
||||
}
|
||||
|
||||
public override fun visitWildcardType(wildcardType: PsiWildcardType?): Type {
|
||||
override fun visitWildcardType(wildcardType: PsiWildcardType?): Type {
|
||||
if (wildcardType!!.isExtends()) {
|
||||
myResult = OutProjectionType(myConverter.convertType(wildcardType.getExtendsBound()))
|
||||
}
|
||||
@@ -144,7 +144,7 @@ public open class TypeVisitor(private val myConverter: Converter) : PsiTypeVisit
|
||||
return myResult
|
||||
}
|
||||
|
||||
public override fun visitEllipsisType(ellipsisType: PsiEllipsisType?): Type {
|
||||
override fun visitEllipsisType(ellipsisType: PsiEllipsisType?): Type {
|
||||
myResult = VarArg(myConverter.convertType(ellipsisType?.getComponentType()))
|
||||
return myResult
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.j2k.test
|
||||
|
||||
import java.io.File
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import junit.framework.Assert
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.jet.j2k.Converter
|
||||
@@ -35,17 +34,18 @@ import com.intellij.psi.codeStyle.CodeStyleManager
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.project.Project
|
||||
import kotlin.test.fail
|
||||
|
||||
public abstract class AbstractJavaToKotlinConverterPluginTest() : AbstractJavaToKotlinConverterTest("ide.kt", PluginSettings)
|
||||
public abstract class AbstractJavaToKotlinConverterBasicTest() : AbstractJavaToKotlinConverterTest("kt", TestSettings)
|
||||
|
||||
public abstract class AbstractJavaToKotlinConverterTest(val kotlinFileExtension: String,
|
||||
val settings: ConverterSettings) : LightIdeaTestCase() {
|
||||
abstract class AbstractJavaToKotlinConverterTest(
|
||||
val kotlinFileExtension: String,
|
||||
val settings: ConverterSettings
|
||||
) : LightIdeaTestCase() {
|
||||
|
||||
val testHeaderPattern = Pattern.compile("//(element|expression|statement|method|class|file|comp)\n")
|
||||
|
||||
protected fun doTest(javaPath: String) {
|
||||
public fun doTest(javaPath: String) {
|
||||
val project = LightPlatformTestCase.getProject()!!
|
||||
val converter = Converter(project, settings)
|
||||
val javaFile = File(javaPath)
|
||||
|
||||
Reference in New Issue
Block a user