New J2K: remove extra interfaces in AST structure & split AST definitions to proper files
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k
|
package org.jetbrains.kotlin.nj2k
|
||||||
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
||||||
|
|
||||||
|
|||||||
@@ -44,10 +44,9 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.nj2k.symbols.*
|
import org.jetbrains.kotlin.nj2k.symbols.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKLiteralExpression.LiteralType.*
|
import org.jetbrains.kotlin.nj2k.tree.JKLiteralExpression.LiteralType.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaPrimitiveType
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
import org.jetbrains.kotlin.psi.psiUtil.isExtensionDeclaration
|
||||||
@@ -71,17 +70,17 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
private val declarationMapper = DeclarationMapper(expressionTreeMapper)
|
private val declarationMapper = DeclarationMapper(expressionTreeMapper)
|
||||||
|
|
||||||
private fun PsiJavaFile.toJK(): JKFile =
|
private fun PsiJavaFile.toJK(): JKFile =
|
||||||
JKFileImpl(
|
JKFile(
|
||||||
packageStatement?.toJK() ?: JKPackageDeclarationImpl(JKNameIdentifierImpl("")),
|
packageStatement?.toJK() ?: JKPackageDeclaration(JKNameIdentifier("")),
|
||||||
importList.toJK(),
|
importList.toJK(),
|
||||||
with(declarationMapper) { classes.map { it.toJK() } }
|
with(declarationMapper) { classes.map { it.toJK() } }
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun PsiImportList?.toJK(): JKImportList =
|
private fun PsiImportList?.toJK(): JKImportList =
|
||||||
JKImportListImpl(this?.allImportStatements?.mapNotNull { it.toJK() }.orEmpty())
|
JKImportList(this?.allImportStatements?.mapNotNull { it.toJK() }.orEmpty())
|
||||||
|
|
||||||
private fun PsiPackageStatement.toJK(): JKPackageDeclaration =
|
private fun PsiPackageStatement.toJK(): JKPackageDeclaration =
|
||||||
JKPackageDeclarationImpl(JKNameIdentifierImpl(packageName))
|
JKPackageDeclaration(JKNameIdentifier(packageName))
|
||||||
.also {
|
.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
@@ -97,7 +96,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
?: target.safeAs<KtLightClassForDecompiledDeclaration>()?.fqName?.parent()?.asString()?.let { "$it.*" }
|
?: target.safeAs<KtLightClassForDecompiledDeclaration>()?.fqName?.parent()?.asString()?.let { "$it.*" }
|
||||||
?: rawName
|
?: rawName
|
||||||
|
|
||||||
return JKImportStatementImpl(JKNameIdentifierImpl(name))
|
return JKImportStatement(JKNameIdentifier(name))
|
||||||
.also {
|
.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
@@ -105,16 +104,16 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
private fun PsiIdentifier?.toJK(): JKNameIdentifier =
|
private fun PsiIdentifier?.toJK(): JKNameIdentifier =
|
||||||
this?.let {
|
this?.let {
|
||||||
JKNameIdentifierImpl(it.text).also {
|
JKNameIdentifier(it.text).also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
} ?: JKNameIdentifierImpl("")
|
} ?: JKNameIdentifier("")
|
||||||
|
|
||||||
|
|
||||||
private inner class ExpressionTreeMapper {
|
private inner class ExpressionTreeMapper {
|
||||||
fun PsiExpression?.toJK(): JKExpression {
|
fun PsiExpression?.toJK(): JKExpression {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
null -> JKStubExpressionImpl()
|
null -> JKStubExpression()
|
||||||
is PsiBinaryExpression -> toJK()
|
is PsiBinaryExpression -> toJK()
|
||||||
is PsiPrefixExpression -> toJK()
|
is PsiPrefixExpression -> toJK()
|
||||||
is PsiPostfixExpression -> toJK()
|
is PsiPostfixExpression -> toJK()
|
||||||
@@ -128,14 +127,14 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
is PsiAssignmentExpression -> toJK()
|
is PsiAssignmentExpression -> toJK()
|
||||||
is PsiInstanceOfExpression -> toJK()
|
is PsiInstanceOfExpression -> toJK()
|
||||||
is PsiThisExpression ->
|
is PsiThisExpression ->
|
||||||
JKThisExpressionImpl(
|
JKThisExpression(
|
||||||
qualifier?.referenceName?.let { JKLabelTextImpl(JKNameIdentifierImpl(it)) } ?: JKLabelEmptyImpl()
|
qualifier?.referenceName?.let { JKLabelText(JKNameIdentifier(it)) } ?: JKLabelEmpty()
|
||||||
)
|
)
|
||||||
is PsiSuperExpression ->
|
is PsiSuperExpression ->
|
||||||
JKSuperExpressionImpl(
|
JKSuperExpression(
|
||||||
qualifier?.referenceName?.let { JKLabelTextImpl(JKNameIdentifierImpl(it)) } ?: JKLabelEmptyImpl()
|
qualifier?.referenceName?.let { JKLabelText(JKNameIdentifier(it)) } ?: JKLabelEmpty()
|
||||||
)
|
)
|
||||||
is PsiConditionalExpression -> JKIfElseExpressionImpl(
|
is PsiConditionalExpression -> JKIfElseExpression(
|
||||||
condition.toJK(), thenExpression.toJK(), elseExpression.toJK()
|
condition.toJK(), thenExpression.toJK(), elseExpression.toJK()
|
||||||
)
|
)
|
||||||
is PsiPolyadicExpression -> {
|
is PsiPolyadicExpression -> {
|
||||||
@@ -143,7 +142,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
val type = type?.toJK() ?: typeFactory.types.nullableAny
|
val type = type?.toJK() ?: typeFactory.types.nullableAny
|
||||||
val jkOperands = operands.map { it.toJK().parenthesizeIfBinaryExpression() }
|
val jkOperands = operands.map { it.toJK().parenthesizeIfBinaryExpression() }
|
||||||
jkOperands.reduce { acc, operand ->
|
jkOperands.reduce { acc, operand ->
|
||||||
JKBinaryExpressionImpl(acc, operand, JKKtOperatorImpl(token, type))
|
JKBinaryExpression(acc, operand, JKKtOperatorImpl(token, type))
|
||||||
}.let { folded ->
|
}.let { folded ->
|
||||||
if (jkOperands.any { it.containsNewLine() }) folded.parenthesize()
|
if (jkOperands.any { it.containsNewLine() }) folded.parenthesize()
|
||||||
else folded
|
else folded
|
||||||
@@ -163,26 +162,26 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
fun PsiClassObjectAccessExpressionImpl.toJK(): JKClassLiteralExpression {
|
fun PsiClassObjectAccessExpressionImpl.toJK(): JKClassLiteralExpression {
|
||||||
val type = operand.type.toJK().updateNullabilityRecursively(Nullability.NotNull)
|
val type = operand.type.toJK().updateNullabilityRecursively(Nullability.NotNull)
|
||||||
return JKClassLiteralExpressionImpl(
|
return JKClassLiteralExpression(
|
||||||
JKTypeElementImpl(type),
|
JKTypeElement(type),
|
||||||
when (type) {
|
when (type) {
|
||||||
is JKJavaPrimitiveType -> JKClassLiteralExpression.LiteralType.JAVA_PRIMITIVE_CLASS
|
is JKJavaPrimitiveType -> JKClassLiteralExpression.ClassLiteralType.JAVA_PRIMITIVE_CLASS
|
||||||
is JKJavaVoidType -> JKClassLiteralExpression.LiteralType.JAVA_VOID_TYPE
|
is JKJavaVoidType -> JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE
|
||||||
else -> JKClassLiteralExpression.LiteralType.JAVA_CLASS
|
else -> JKClassLiteralExpression.ClassLiteralType.JAVA_CLASS
|
||||||
}
|
}
|
||||||
).also {
|
).also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiInstanceOfExpression.toJK(): JKKtIsExpression =
|
fun PsiInstanceOfExpression.toJK(): JKIsExpression =
|
||||||
JKKtIsExpressionImpl(operand.toJK(), JKTypeElementImpl(checkType?.type?.toJK() ?: JKNoTypeImpl))
|
JKIsExpression(operand.toJK(), JKTypeElement(checkType?.type?.toJK() ?: JKNoTypeImpl))
|
||||||
.also {
|
.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiAssignmentExpression.toJK(): JKJavaAssignmentExpression {
|
fun PsiAssignmentExpression.toJK(): JKJavaAssignmentExpression {
|
||||||
return JKJavaAssignmentExpressionImpl(
|
return JKJavaAssignmentExpression(
|
||||||
lExpression.toJK(),
|
lExpression.toJK(),
|
||||||
rExpression.toJK(),
|
rExpression.toJK(),
|
||||||
createOperator(operationSign.tokenType, type)
|
createOperator(operationSign.tokenType, type)
|
||||||
@@ -201,7 +200,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
else -> JKOperatorToken.fromElementType(operationSign.tokenType)
|
else -> JKOperatorToken.fromElementType(operationSign.tokenType)
|
||||||
}
|
}
|
||||||
return JKBinaryExpressionImpl(
|
return JKBinaryExpression(
|
||||||
lOperand.toJK(),
|
lOperand.toJK(),
|
||||||
rOperand.toJK(),
|
rOperand.toJK(),
|
||||||
JKKtOperatorImpl(
|
JKKtOperatorImpl(
|
||||||
@@ -216,16 +215,16 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
fun PsiLiteralExpression.toJK(): JKLiteralExpression {
|
fun PsiLiteralExpression.toJK(): JKLiteralExpression {
|
||||||
require(this is PsiLiteralExpressionImpl)
|
require(this is PsiLiteralExpressionImpl)
|
||||||
|
|
||||||
return when (this.literalElementType) {
|
return when (literalElementType) {
|
||||||
JavaTokenType.NULL_KEYWORD -> JKNullLiteral()
|
JavaTokenType.NULL_KEYWORD -> JKLiteralExpression("null", NULL)
|
||||||
JavaTokenType.TRUE_KEYWORD -> JKBooleanLiteral(true)
|
JavaTokenType.TRUE_KEYWORD -> JKLiteralExpression("true", BOOLEAN)
|
||||||
JavaTokenType.FALSE_KEYWORD -> JKBooleanLiteral(false)
|
JavaTokenType.FALSE_KEYWORD -> JKLiteralExpression("false", BOOLEAN)
|
||||||
JavaTokenType.STRING_LITERAL -> JKJavaLiteralExpressionImpl(text, STRING)
|
JavaTokenType.STRING_LITERAL -> JKLiteralExpression(text, STRING)
|
||||||
JavaTokenType.CHARACTER_LITERAL -> JKJavaLiteralExpressionImpl(text, CHAR)
|
JavaTokenType.CHARACTER_LITERAL -> JKLiteralExpression(text, CHAR)
|
||||||
JavaTokenType.INTEGER_LITERAL -> JKJavaLiteralExpressionImpl(text, INT)
|
JavaTokenType.INTEGER_LITERAL -> JKLiteralExpression(text, INT)
|
||||||
JavaTokenType.LONG_LITERAL -> JKJavaLiteralExpressionImpl(text, LONG)
|
JavaTokenType.LONG_LITERAL -> JKLiteralExpression(text, LONG)
|
||||||
JavaTokenType.FLOAT_LITERAL -> JKJavaLiteralExpressionImpl(text, FLOAT)
|
JavaTokenType.FLOAT_LITERAL -> JKLiteralExpression(text, FLOAT)
|
||||||
JavaTokenType.DOUBLE_LITERAL -> JKJavaLiteralExpressionImpl(text, DOUBLE)
|
JavaTokenType.DOUBLE_LITERAL -> JKLiteralExpression(text, DOUBLE)
|
||||||
else -> error("Unknown literal element type: ${this.literalElementType}")
|
else -> error("Unknown literal element type: ${this.literalElementType}")
|
||||||
}.also {
|
}.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
@@ -240,23 +239,23 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
fun PsiPrefixExpression.toJK(): JKExpression = when (operationSign.tokenType) {
|
fun PsiPrefixExpression.toJK(): JKExpression = when (operationSign.tokenType) {
|
||||||
JavaTokenType.TILDE -> operand.toJK().callOn(symbolProvider.provideMethodSymbol("kotlin.Int.inv"))
|
JavaTokenType.TILDE -> operand.toJK().callOn(symbolProvider.provideMethodSymbol("kotlin.Int.inv"))
|
||||||
else -> JKPrefixExpressionImpl(operand.toJK(), createOperator(operationSign.tokenType, type))
|
else -> JKPrefixExpression(operand.toJK(), createOperator(operationSign.tokenType, type))
|
||||||
}.also {
|
}.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiPostfixExpression.toJK(): JKExpression =
|
fun PsiPostfixExpression.toJK(): JKExpression =
|
||||||
JKPostfixExpressionImpl(operand.toJK(), createOperator(operationSign.tokenType, type)).also {
|
JKPostfixExpression(operand.toJK(), createOperator(operationSign.tokenType, type)).also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiLambdaExpression.toJK(): JKExpression {
|
fun PsiLambdaExpression.toJK(): JKExpression {
|
||||||
return JKLambdaExpressionImpl(
|
return JKLambdaExpression(
|
||||||
body.let {
|
body.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is PsiExpression -> JKExpressionStatementImpl(it.toJK())
|
is PsiExpression -> JKExpressionStatement(it.toJK())
|
||||||
is PsiCodeBlock -> JKBlockStatementImpl(with(declarationMapper) { it.toJK() })
|
is PsiCodeBlock -> JKBlockStatement(with(declarationMapper) { it.toJK() })
|
||||||
else -> JKBlockStatementImpl(JKBodyStubImpl)
|
else -> JKBlockStatement(JKBodyStub)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
with(declarationMapper) { parameterList.parameters.map { it.toJK() } },
|
with(declarationMapper) { parameterList.parameters.map { it.toJK() } },
|
||||||
@@ -294,11 +293,11 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
return when {
|
return when {
|
||||||
methodExpression.referenceNameElement is PsiKeyword -> {
|
methodExpression.referenceNameElement is PsiKeyword -> {
|
||||||
val callee = when ((methodExpression.referenceNameElement as PsiKeyword).tokenType) {
|
val callee = when ((methodExpression.referenceNameElement as PsiKeyword).tokenType) {
|
||||||
SUPER_KEYWORD -> JKSuperExpressionImpl()
|
SUPER_KEYWORD -> JKSuperExpression()
|
||||||
THIS_KEYWORD -> JKThisExpressionImpl(JKLabelEmptyImpl())
|
THIS_KEYWORD -> JKThisExpression(JKLabelEmpty())
|
||||||
else -> throwCanNotConvertError("unknown keyword in callee position")
|
else -> throwCanNotConvertError("unknown keyword in callee position")
|
||||||
}
|
}
|
||||||
JKDelegationConstructorCallImpl(symbol as JKMethodSymbol, callee, arguments.toJK())
|
JKDelegationConstructorCall(symbol as JKMethodSymbol, callee, arguments.toJK())
|
||||||
}
|
}
|
||||||
|
|
||||||
target is KtLightMethod -> {
|
target is KtLightMethod -> {
|
||||||
@@ -308,14 +307,14 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
if (origin.isExtensionDeclaration()) {
|
if (origin.isExtensionDeclaration()) {
|
||||||
val receiver = arguments.expressions.firstOrNull()?.toJK()?.parenthesizeIfBinaryExpression()
|
val receiver = arguments.expressions.firstOrNull()?.toJK()?.parenthesizeIfBinaryExpression()
|
||||||
origin.fqName?.also { importStorage.addImport(it) }
|
origin.fqName?.also { importStorage.addImport(it) }
|
||||||
JKJavaMethodCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideDirectSymbol(origin) as JKMethodSymbol,
|
symbolProvider.provideDirectSymbol(origin) as JKMethodSymbol,
|
||||||
arguments.expressions.drop(1).map { it.toJK() }.toArgumentList(),
|
arguments.expressions.drop(1).map { it.toJK() }.toArgumentList(),
|
||||||
typeArguments
|
typeArguments
|
||||||
).qualified(receiver)
|
).qualified(receiver)
|
||||||
} else {
|
} else {
|
||||||
origin.fqName?.also { importStorage.addImport(it) }
|
origin.fqName?.also { importStorage.addImport(it) }
|
||||||
JKJavaMethodCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideDirectSymbol(origin) as JKMethodSymbol,
|
symbolProvider.provideDirectSymbol(origin) as JKMethodSymbol,
|
||||||
arguments.toJK(),
|
arguments.toJK(),
|
||||||
typeArguments
|
typeArguments
|
||||||
@@ -329,13 +328,12 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
else origin as KtNamedDeclaration
|
else origin as KtNamedDeclaration
|
||||||
val parameterCount = target.parameterList.parameters.size
|
val parameterCount = target.parameterList.parameters.size
|
||||||
val propertyAccessExpression =
|
val propertyAccessExpression =
|
||||||
JKFieldAccessExpressionImpl(symbolProvider.provideDirectSymbol(property) as JKFieldSymbol)
|
JKFieldAccessExpression(symbolProvider.provideDirectSymbol(property) as JKFieldSymbol)
|
||||||
val isExtension = property.isExtensionDeclaration()
|
val isExtension = property.isExtensionDeclaration()
|
||||||
val isTopLevel = origin.getStrictParentOfType<KtClassOrObject>() == null
|
val isTopLevel = origin.getStrictParentOfType<KtClassOrObject>() == null
|
||||||
val propertyAccess = if (isTopLevel) {
|
val propertyAccess = if (isTopLevel) {
|
||||||
if (isExtension) JKQualifiedExpressionImpl(
|
if (isExtension) JKQualifiedExpression(
|
||||||
arguments.expressions.first().toJK(),
|
arguments.expressions.first().toJK(),
|
||||||
JKJavaQualifierImpl.DOT,
|
|
||||||
propertyAccessExpression
|
propertyAccessExpression
|
||||||
)
|
)
|
||||||
else propertyAccessExpression
|
else propertyAccessExpression
|
||||||
@@ -347,7 +345,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
1 /* setter */ -> {
|
1 /* setter */ -> {
|
||||||
val argument = (arguments.expressions[if (isExtension) 1 else 0]).toJK()
|
val argument = (arguments.expressions[if (isExtension) 1 else 0]).toJK()
|
||||||
JKJavaAssignmentExpressionImpl(
|
JKJavaAssignmentExpression(
|
||||||
propertyAccess,
|
propertyAccess,
|
||||||
argument,
|
argument,
|
||||||
createOperator(JavaTokenType.EQ, type)//TODO correct type
|
createOperator(JavaTokenType.EQ, type)//TODO correct type
|
||||||
@@ -358,7 +356,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
JKJavaMethodCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
JKMultiverseMethodSymbol(target, typeFactory),
|
JKMultiverseMethodSymbol(target, typeFactory),
|
||||||
arguments.toJK(),
|
arguments.toJK(),
|
||||||
typeArguments
|
typeArguments
|
||||||
@@ -368,10 +366,10 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
symbol is JKMethodSymbol ->
|
symbol is JKMethodSymbol ->
|
||||||
JKJavaMethodCallExpressionImpl(symbol, arguments.toJK(), typeArguments)
|
JKCallExpressionImpl(symbol, arguments.toJK(), typeArguments)
|
||||||
.qualified(qualifier)
|
.qualified(qualifier)
|
||||||
symbol is JKFieldSymbol ->
|
symbol is JKFieldSymbol ->
|
||||||
JKFieldAccessExpressionImpl(symbol).qualified(qualifier)
|
JKFieldAccessExpression(symbol).qualified(qualifier)
|
||||||
else -> throwCanNotConvertError("unexpected symbol ${symbol::class}")
|
else -> throwCanNotConvertError("unexpected symbol ${symbol::class}")
|
||||||
}.also {
|
}.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
@@ -385,7 +383,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}?.takeUnless { type ->
|
}?.takeUnless { type ->
|
||||||
type.isKotlinFunctionalType
|
type.isKotlinFunctionalType
|
||||||
}?.toJK()
|
}?.toJK()
|
||||||
?.asTypeElement() ?: JKTypeElementImpl(JKNoTypeImpl)
|
?.asTypeElement() ?: JKTypeElement(JKNoTypeImpl)
|
||||||
|
|
||||||
fun PsiMethodReferenceExpression.toJK(): JKMethodReferenceExpression {
|
fun PsiMethodReferenceExpression.toJK(): JKMethodReferenceExpression {
|
||||||
val symbol = symbolProvider.provideSymbolForReference<JKSymbol>(this).let { symbol ->
|
val symbol = symbolProvider.provideSymbolForReference<JKSymbol>(this).let { symbol ->
|
||||||
@@ -396,8 +394,8 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return JKMethodReferenceExpressionImpl(
|
return JKMethodReferenceExpression(
|
||||||
qualifierExpression?.toJK() ?: JKStubExpressionImpl(),
|
qualifierExpression?.toJK() ?: JKStubExpression(),
|
||||||
symbol,
|
symbol,
|
||||||
functionalType(),
|
functionalType(),
|
||||||
isConstructor
|
isConstructor
|
||||||
@@ -409,19 +407,19 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
val target = resolve()
|
val target = resolve()
|
||||||
if (target is KtLightClassForFacade
|
if (target is KtLightClassForFacade
|
||||||
|| target is KtLightClassForDecompiledDeclaration
|
|| target is KtLightClassForDecompiledDeclaration
|
||||||
) return JKStubExpressionImpl()
|
) return JKStubExpression()
|
||||||
if (target is KtLightField
|
if (target is KtLightField
|
||||||
&& target.name == "INSTANCE"
|
&& target.name == "INSTANCE"
|
||||||
&& target.containingClass.kotlinOrigin is KtObjectDeclaration
|
&& target.containingClass.kotlinOrigin is KtObjectDeclaration
|
||||||
) {
|
) {
|
||||||
return qualifierExpression?.toJK() ?: JKStubExpressionImpl()
|
return qualifierExpression?.toJK() ?: JKStubExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
val symbol = symbolProvider.provideSymbolForReference<JKSymbol>(this)
|
val symbol = symbolProvider.provideSymbolForReference<JKSymbol>(this)
|
||||||
return when (symbol) {
|
return when (symbol) {
|
||||||
is JKClassSymbol -> JKClassAccessExpressionImpl(symbol)
|
is JKClassSymbol -> JKClassAccessExpression(symbol)
|
||||||
is JKFieldSymbol -> JKFieldAccessExpressionImpl(symbol)
|
is JKFieldSymbol -> JKFieldAccessExpression(symbol)
|
||||||
is JKPackageSymbol -> JKPackageAccessExpressionImpl(symbol)
|
is JKPackageSymbol -> JKPackageAccessExpression(symbol)
|
||||||
else -> throwCanNotConvertError("unexpected symbol ${symbol::class}")
|
else -> throwCanNotConvertError("unexpected symbol ${symbol::class}")
|
||||||
}.qualified(qualifierExpression?.toJK()).also {
|
}.qualified(qualifierExpression?.toJK()).also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
@@ -429,9 +427,9 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PsiArrayInitializerExpression.toJK(): JKExpression {
|
fun PsiArrayInitializerExpression.toJK(): JKExpression {
|
||||||
return JKJavaNewArrayImpl(
|
return JKJavaNewArray(
|
||||||
initializers.map { it.toJK() },
|
initializers.map { it.toJK() },
|
||||||
JKTypeElementImpl(type?.toJK().safeAs<JKJavaArrayType>()?.type ?: JKContextType)
|
JKTypeElement(type?.toJK().safeAs<JKJavaArrayType>()?.type ?: JKContextType)
|
||||||
).also {
|
).also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
@@ -455,9 +453,9 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
child = child.nextSibling
|
child = child.nextSibling
|
||||||
}
|
}
|
||||||
JKJavaNewEmptyArrayImpl(
|
JKJavaNewEmptyArray(
|
||||||
dimensions.map { it?.toJK() ?: JKStubExpressionImpl() },
|
dimensions.map { it?.toJK() ?: JKStubExpression() },
|
||||||
JKTypeElementImpl(generateSequence(type?.toJK()) { it.safeAs<JKJavaArrayType>()?.type }.last())
|
JKTypeElement(generateSequence(type?.toJK()) { it.safeAs<JKJavaArrayType>()?.type }.last())
|
||||||
).also {
|
).also {
|
||||||
it.psi = this
|
it.psi = this
|
||||||
}
|
}
|
||||||
@@ -476,29 +474,28 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
?: classOrAnonymousClassReference
|
?: classOrAnonymousClassReference
|
||||||
?.typeParameters
|
?.typeParameters
|
||||||
?.let { typeParameters ->
|
?.let { typeParameters ->
|
||||||
JKTypeArgumentListImpl(typeParameters.map { JKTypeElementImpl(it.toJK()) })
|
JKTypeArgumentList(typeParameters.map { JKTypeElement(it.toJK()) })
|
||||||
} ?: JKTypeArgumentListImpl()
|
} ?: JKTypeArgumentList()
|
||||||
JKJavaNewExpressionImpl(
|
JKNewExpression(
|
||||||
classSymbol,
|
classSymbol,
|
||||||
argumentList?.toJK() ?: JKArgumentListImpl(),
|
argumentList?.toJK() ?: JKArgumentList(),
|
||||||
typeArgumentList,
|
typeArgumentList,
|
||||||
with(declarationMapper) { anonymousClass?.createClassBody() } ?: JKEmptyClassBodyImpl()
|
with(declarationMapper) { anonymousClass?.createClassBody() } ?: JKClassBody(),
|
||||||
|
anonymousClass != null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return qualifier?.let {
|
return newExpression.qualified(qualifier?.toJK())
|
||||||
JKQualifiedExpressionImpl(it.toJK(), JKJavaQualifierImpl.DOT, newExpression)
|
|
||||||
} ?: newExpression
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiReferenceParameterList.toJK(): JKTypeArgumentList =
|
fun PsiReferenceParameterList.toJK(): JKTypeArgumentList =
|
||||||
JKTypeArgumentListImpl(this.typeArguments.map { JKTypeElementImpl(it.toJK()) })
|
JKTypeArgumentList(typeArguments.map { JKTypeElement(it.toJK()) })
|
||||||
.also {
|
.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun PsiArrayAccessExpression.toJK(): JKExpression {
|
fun PsiArrayAccessExpression.toJK(): JKExpression {
|
||||||
return JKArrayAccessExpressionImpl(
|
return JKArrayAccessExpression(
|
||||||
arrayExpression.toJK(),
|
arrayExpression.toJK(),
|
||||||
indexExpression?.toJK() ?: throwCanNotConvertError()
|
indexExpression?.toJK() ?: throwCanNotConvertError()
|
||||||
).also {
|
).also {
|
||||||
@@ -507,7 +504,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PsiTypeCastExpression.toJK(): JKExpression {
|
fun PsiTypeCastExpression.toJK(): JKExpression {
|
||||||
return JKTypeCastExpressionImpl(
|
return JKTypeCastExpression(
|
||||||
operand?.toJK() ?: throwCanNotConvertError(),
|
operand?.toJK() ?: throwCanNotConvertError(),
|
||||||
castType?.type?.toJK()?.asTypeElement() ?: throwCanNotConvertError()
|
castType?.type?.toJK()?.asTypeElement() ?: throwCanNotConvertError()
|
||||||
).also {
|
).also {
|
||||||
@@ -516,7 +513,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PsiParenthesizedExpression.toJK(): JKExpression {
|
fun PsiParenthesizedExpression.toJK(): JKExpression {
|
||||||
return JKParenthesizedExpressionImpl(expression.toJK())
|
return JKParenthesizedExpression(expression.toJK())
|
||||||
.also {
|
.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
@@ -532,7 +529,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
&& lastExpressionType is PsiArrayType
|
&& lastExpressionType is PsiArrayType
|
||||||
) {
|
) {
|
||||||
val staredExpression =
|
val staredExpression =
|
||||||
JKPrefixExpressionImpl(
|
JKPrefixExpression(
|
||||||
jkExpressions.last(),
|
jkExpressions.last(),
|
||||||
JKKtSpreadOperator(lastExpressionType.toJK())
|
JKKtSpreadOperator(lastExpressionType.toJK())
|
||||||
).withNonCodeElementsFrom(jkExpressions.last())
|
).withNonCodeElementsFrom(jkExpressions.last())
|
||||||
@@ -550,45 +547,42 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
private inner class DeclarationMapper(val expressionTreeMapper: ExpressionTreeMapper) {
|
private inner class DeclarationMapper(val expressionTreeMapper: ExpressionTreeMapper) {
|
||||||
|
|
||||||
fun PsiTypeParameterList.toJK(): JKTypeParameterList =
|
fun PsiTypeParameterList.toJK(): JKTypeParameterList =
|
||||||
JKTypeParameterListImpl(typeParameters.map { it.toJK() })
|
JKTypeParameterList(typeParameters.map { it.toJK() })
|
||||||
.also {
|
.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiTypeParameter.toJK(): JKTypeParameter =
|
fun PsiTypeParameter.toJK(): JKTypeParameter =
|
||||||
JKTypeParameterImpl(
|
JKTypeParameter(
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
extendsListTypes.map { JKTypeElementImpl(it.toJK()) }
|
extendsListTypes.map { JKTypeElement(it.toJK()) }
|
||||||
).also {
|
).also {
|
||||||
symbolProvider.provideUniverseSymbol(this, it)
|
symbolProvider.provideUniverseSymbol(this, it)
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiClass.toJK(): JKClass =
|
fun PsiClass.toJK(): JKClass =
|
||||||
JKClassImpl(
|
JKClass(
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
inheritanceInfo(),
|
inheritanceInfo(),
|
||||||
classKind(),
|
classKind(),
|
||||||
typeParameterList?.toJK() ?: JKTypeParameterListImpl(),
|
typeParameterList?.toJK() ?: JKTypeParameterList(),
|
||||||
createClassBody(),
|
createClassBody(),
|
||||||
annotationList(this),
|
annotationList(this),
|
||||||
otherModifiers(),
|
otherModifiers(),
|
||||||
visibility(),
|
visibility(),
|
||||||
modality()
|
modality()
|
||||||
).also { jkClassImpl ->
|
).also { klass ->
|
||||||
jkClassImpl.psi = this
|
klass.psi = this
|
||||||
symbolProvider.provideUniverseSymbol(this, jkClassImpl)
|
symbolProvider.provideUniverseSymbol(this, klass)
|
||||||
}.also {
|
klass.assignNonCodeElements(this)
|
||||||
it.assignNonCodeElements(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun PsiClass.inheritanceInfo(): JKInheritanceInfo {
|
fun PsiClass.inheritanceInfo(): JKInheritanceInfo {
|
||||||
val implTypes =
|
val implTypes = implementsList?.referencedTypes?.map { JKTypeElement(it.toJK()) }.orEmpty()
|
||||||
implementsList?.referencedTypes?.map { JKTypeElementImpl(it.toJK()) }.orEmpty()
|
val extensionType = extendsList?.referencedTypes?.map { JKTypeElement(it.toJK()) }.orEmpty()
|
||||||
val extensionType =
|
return JKInheritanceInfo(extensionType, implTypes)
|
||||||
extendsList?.referencedTypes?.map { JKTypeElementImpl(it.toJK()) }.orEmpty()
|
|
||||||
return JKInheritanceInfoImpl(extensionType, implTypes)
|
|
||||||
.also {
|
.also {
|
||||||
if (implementsList != null) {
|
if (implementsList != null) {
|
||||||
it.assignNonCodeElements(implementsList!!)
|
it.assignNonCodeElements(implementsList!!)
|
||||||
@@ -597,7 +591,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PsiClass.createClassBody() =
|
fun PsiClass.createClassBody() =
|
||||||
JKClassBodyImpl(
|
JKClassBody(
|
||||||
children.mapNotNull {
|
children.mapNotNull {
|
||||||
when (it) {
|
when (it) {
|
||||||
is PsiEnumConstant -> it.toJK()
|
is PsiEnumConstant -> it.toJK()
|
||||||
@@ -614,21 +608,20 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
it.rightBrace.assignNonCodeElements(rBrace)
|
it.rightBrace.assignNonCodeElements(rBrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiClassInitializer.toJK(): JKDeclaration =
|
fun PsiClassInitializer.toJK(): JKDeclaration = when {
|
||||||
(if (hasModifier(JvmModifier.STATIC))
|
hasModifier(JvmModifier.STATIC) -> JKJavaStaticInitDeclaration(body.toJK())
|
||||||
JKJavaStaticInitDeclarationImpl(body.toJK())
|
else -> JKKtInitDeclaration(body.toJK())
|
||||||
else JKKtInitDeclarationImpl(body.toJK()))
|
}.also {
|
||||||
.also {
|
it.assignNonCodeElements(this)
|
||||||
it.assignNonCodeElements(this)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun PsiEnumConstant.toJK(): JKEnumConstant =
|
fun PsiEnumConstant.toJK(): JKEnumConstant =
|
||||||
JKEnumConstantImpl(
|
JKEnumConstant(
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
with(expressionTreeMapper) { argumentList?.toJK() ?: JKArgumentListImpl() },
|
with(expressionTreeMapper) { argumentList?.toJK() ?: JKArgumentList() },
|
||||||
initializingClass?.createClassBody() ?: JKEmptyClassBodyImpl(),
|
initializingClass?.createClassBody() ?: JKClassBody(),
|
||||||
JKTypeElementImpl(
|
JKTypeElement(
|
||||||
JKClassTypeImpl(
|
JKClassTypeImpl(
|
||||||
symbolProvider.provideDirectSymbol(containingClass ?: throwCanNotConvertError()) as JKClassSymbol,
|
symbolProvider.provideDirectSymbol(containingClass ?: throwCanNotConvertError()) as JKClassSymbol,
|
||||||
emptyList()
|
emptyList()
|
||||||
@@ -637,13 +630,12 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
).also {
|
).also {
|
||||||
symbolProvider.provideUniverseSymbol(this, it)
|
symbolProvider.provideUniverseSymbol(this, it)
|
||||||
it.psi = this
|
it.psi = this
|
||||||
}.also {
|
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun PsiMember.modality() =
|
fun PsiMember.modality() =
|
||||||
modality({ ast, psi -> ast.assignNonCodeElements(psi) })
|
modality { ast, psi -> ast.assignNonCodeElements(psi) }
|
||||||
|
|
||||||
fun PsiMember.otherModifiers() =
|
fun PsiMember.otherModifiers() =
|
||||||
modifierList?.children?.mapNotNull { child ->
|
modifierList?.children?.mapNotNull { child ->
|
||||||
@@ -658,7 +650,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}?.let {
|
}?.let {
|
||||||
JKOtherModifierElementImpl(it).withAssignedNonCodeElements(child)
|
JKOtherModifierElement(it).withAssignedNonCodeElements(child)
|
||||||
}
|
}
|
||||||
}.orEmpty()
|
}.orEmpty()
|
||||||
|
|
||||||
@@ -666,28 +658,27 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
private fun PsiMember.visibility(): JKVisibilityModifierElement =
|
private fun PsiMember.visibility(): JKVisibilityModifierElement =
|
||||||
visibility(referenceSearcher) { ast, psi -> ast.assignNonCodeElements(psi) }
|
visibility(referenceSearcher) { ast, psi -> ast.assignNonCodeElements(psi) }
|
||||||
|
|
||||||
fun PsiField.toJK(): JKJavaField {
|
fun PsiField.toJK(): JKField {
|
||||||
return JKJavaFieldImpl(
|
return JKField(
|
||||||
JKTypeElementImpl(type.toJK()).withAssignedNonCodeElements(typeElement),
|
JKTypeElement(type.toJK()).withAssignedNonCodeElements(typeElement),
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
with(expressionTreeMapper) { initializer.toJK() },
|
with(expressionTreeMapper) { initializer.toJK() },
|
||||||
annotationList(this),
|
annotationList(this),
|
||||||
otherModifiers(),
|
otherModifiers(),
|
||||||
visibility(),
|
visibility(),
|
||||||
modality(),
|
modality(),
|
||||||
JKMutabilityModifierElementImpl(Mutability.UNKNOWN)
|
JKMutabilityModifierElement(Mutability.UNKNOWN)
|
||||||
).also {
|
).also {
|
||||||
symbolProvider.provideUniverseSymbol(this, it)
|
symbolProvider.provideUniverseSymbol(this, it)
|
||||||
it.psi = this
|
it.psi = this
|
||||||
}.also {
|
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T : PsiModifierListOwner> T.annotationList(docCommentOwner: PsiDocCommentOwner?): JKAnnotationList {
|
fun <T : PsiModifierListOwner> T.annotationList(docCommentOwner: PsiDocCommentOwner?): JKAnnotationList {
|
||||||
val plainAnnotations = annotations.map { it.cast<PsiAnnotation>().toJK() }
|
val plainAnnotations = annotations.map { it.cast<PsiAnnotation>().toJK() }
|
||||||
val deprecatedAnnotation = docCommentOwner?.docComment?.deprecatedAnnotation() ?: return JKAnnotationListImpl(plainAnnotations)
|
val deprecatedAnnotation = docCommentOwner?.docComment?.deprecatedAnnotation() ?: return JKAnnotationList(plainAnnotations)
|
||||||
return JKAnnotationListImpl(
|
return JKAnnotationList(
|
||||||
plainAnnotations.mapNotNull { annotation ->
|
plainAnnotations.mapNotNull { annotation ->
|
||||||
if (annotation.classSymbol.fqName == "java.lang.Deprecated") null else annotation
|
if (annotation.classSymbol.fqName == "java.lang.Deprecated") null else annotation
|
||||||
} + deprecatedAnnotation
|
} + deprecatedAnnotation
|
||||||
@@ -695,20 +686,20 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PsiAnnotation.toJK(): JKAnnotation =
|
fun PsiAnnotation.toJK(): JKAnnotation =
|
||||||
JKAnnotationImpl(
|
JKAnnotation(
|
||||||
symbolProvider.provideSymbolForReference<JKSymbol>(
|
symbolProvider.provideSymbolForReference<JKSymbol>(
|
||||||
nameReferenceElement ?: throwCanNotConvertError()
|
nameReferenceElement ?: throwCanNotConvertError()
|
||||||
).safeAs<JKClassSymbol>()
|
).safeAs<JKClassSymbol>()
|
||||||
?: JKUnresolvedClassSymbol(nameReferenceElement?.text ?: throwCanNotConvertError(), typeFactory),
|
?: JKUnresolvedClassSymbol(nameReferenceElement?.text ?: throwCanNotConvertError(), typeFactory),
|
||||||
parameterList.attributes.map { parameter ->
|
parameterList.attributes.map { parameter ->
|
||||||
if (parameter.nameIdentifier != null) {
|
if (parameter.nameIdentifier != null) {
|
||||||
JKAnnotationNameParameterImpl(
|
JKAnnotationNameParameter(
|
||||||
parameter.value?.toJK() ?: JKStubExpressionImpl(),
|
parameter.value?.toJK() ?: JKStubExpression(),
|
||||||
JKNameIdentifierImpl(parameter.name ?: throwCanNotConvertError())
|
JKNameIdentifier(parameter.name ?: throwCanNotConvertError())
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
JKAnnotationParameterImpl(
|
JKAnnotationParameterImpl(
|
||||||
parameter.value?.toJK() ?: JKStubExpressionImpl()
|
parameter.value?.toJK() ?: JKStubExpression()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -718,7 +709,7 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
fun PsiDocComment.deprecatedAnnotation(): JKAnnotation? =
|
fun PsiDocComment.deprecatedAnnotation(): JKAnnotation? =
|
||||||
findTagByName("deprecated")?.let { tag ->
|
findTagByName("deprecated")?.let { tag ->
|
||||||
JKAnnotationImpl(
|
JKAnnotation(
|
||||||
symbolProvider.provideClassSymbol("kotlin.Deprecated"),
|
symbolProvider.provideClassSymbol("kotlin.Deprecated"),
|
||||||
listOf(
|
listOf(
|
||||||
JKAnnotationParameterImpl(stringLiteral(tag.content(), typeFactory))
|
JKAnnotationParameterImpl(stringLiteral(tag.content(), typeFactory))
|
||||||
@@ -731,40 +722,40 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
is PsiExpression -> with(expressionTreeMapper) { toJK() }
|
is PsiExpression -> with(expressionTreeMapper) { toJK() }
|
||||||
is PsiAnnotation -> toJK()
|
is PsiAnnotation -> toJK()
|
||||||
is PsiArrayInitializerMemberValue ->
|
is PsiArrayInitializerMemberValue ->
|
||||||
JKKtAnnotationArrayInitializerExpressionImpl(
|
JKKtAnnotationArrayInitializerExpression(initializers.map { it.toJK() })
|
||||||
initializers.map { it.toJK() }
|
|
||||||
)
|
|
||||||
else -> throwCanNotConvertError()
|
else -> throwCanNotConvertError()
|
||||||
}.also {
|
}.also {
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun PsiAnnotationMethod.toJK(): JKJavaAnnotationMethod =
|
fun PsiAnnotationMethod.toJK(): JKJavaAnnotationMethod =
|
||||||
JKJavaAnnotationMethodImpl(
|
JKJavaAnnotationMethod(
|
||||||
returnType?.toJK()?.asTypeElement()
|
returnType?.toJK()?.asTypeElement()
|
||||||
?: JKTypeElementImpl(JKJavaVoidType).takeIf { isConstructor }
|
?: JKTypeElement(JKJavaVoidType).takeIf { isConstructor }
|
||||||
?: throwCanNotConvertError("type of PsiAnnotationMethod can not be retrieved"),
|
?: throwCanNotConvertError("type of PsiAnnotationMethod can not be retrieved"),
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
defaultValue?.toJK() ?: JKStubExpressionImpl()
|
defaultValue?.toJK() ?: JKStubExpression(),
|
||||||
|
otherModifiers(),
|
||||||
|
visibility(),
|
||||||
|
modality()
|
||||||
).also {
|
).also {
|
||||||
it.psi = this
|
it.psi = this
|
||||||
symbolProvider.provideUniverseSymbol(this, it)
|
symbolProvider.provideUniverseSymbol(this, it)
|
||||||
}.also {
|
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun PsiMethod.toJK(): JKJavaMethod {
|
fun PsiMethod.toJK(): JKMethod {
|
||||||
return JKJavaMethodImpl(
|
return JKMethodImpl(
|
||||||
returnType?.toJK()?.asTypeElement()
|
returnType?.toJK()?.asTypeElement()
|
||||||
?: JKTypeElementImpl(JKJavaVoidType).takeIf { isConstructor }
|
?: JKTypeElement(JKJavaVoidType).takeIf { isConstructor }
|
||||||
?: throwCanNotConvertError("type of PsiAnnotationMethod can not be retrieved"),
|
?: throwCanNotConvertError("type of PsiAnnotationMethod can not be retrieved"),
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
parameterList.parameters.map { it.toJK() },
|
parameterList.parameters.map { it.toJK() },
|
||||||
body?.toJK() ?: JKBodyStubImpl,
|
body?.toJK() ?: JKBodyStub,
|
||||||
typeParameterList?.toJK() ?: JKTypeParameterListImpl(),
|
typeParameterList?.toJK() ?: JKTypeParameterList(),
|
||||||
annotationList(this),
|
annotationList(this),
|
||||||
throwsList.referencedTypes.map { JKTypeElementImpl(it.toJK()) },
|
throwsList.referencedTypes.map { JKTypeElement(it.toJK()) },
|
||||||
otherModifiers(),
|
otherModifiers(),
|
||||||
visibility(),
|
visibility(),
|
||||||
modality()
|
modality()
|
||||||
@@ -783,9 +774,9 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
fun PsiParameter.toJK(): JKParameter {
|
fun PsiParameter.toJK(): JKParameter {
|
||||||
val rawType = type.toJK()
|
val rawType = type.toJK()
|
||||||
val type =
|
val type =
|
||||||
if (isVarArgs && rawType is JKJavaArrayType) JKTypeElementImpl(rawType.type)
|
if (isVarArgs && rawType is JKJavaArrayType) JKTypeElement(rawType.type)
|
||||||
else rawType.asTypeElement()
|
else rawType.asTypeElement()
|
||||||
return JKParameterImpl(
|
return JKParameter(
|
||||||
type,
|
type,
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
isVarArgs,
|
isVarArgs,
|
||||||
@@ -808,11 +799,11 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
|
|
||||||
fun PsiLocalVariable.toJK(): JKLocalVariable =
|
fun PsiLocalVariable.toJK(): JKLocalVariable =
|
||||||
JKLocalVariableImpl(
|
JKLocalVariable(
|
||||||
JKTypeElementImpl(type.toJK()).withAssignedNonCodeElements(typeElement),
|
JKTypeElement(type.toJK()).withAssignedNonCodeElements(typeElement),
|
||||||
nameIdentifier.toJK(),
|
nameIdentifier.toJK(),
|
||||||
with(expressionTreeMapper) { initializer.toJK() },
|
with(expressionTreeMapper) { initializer.toJK() },
|
||||||
JKMutabilityModifierElementImpl(
|
JKMutabilityModifierElement(
|
||||||
if (hasModifierProperty(PsiModifier.FINAL)) Mutability.IMMUTABLE
|
if (hasModifierProperty(PsiModifier.FINAL)) Mutability.IMMUTABLE
|
||||||
else Mutability.UNKNOWN
|
else Mutability.UNKNOWN
|
||||||
),
|
),
|
||||||
@@ -826,11 +817,11 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
|
|
||||||
fun PsiStatement?.toJK(): JKStatement {
|
fun PsiStatement?.toJK(): JKStatement {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
null -> JKExpressionStatementImpl(JKStubExpressionImpl())
|
null -> JKExpressionStatement(JKStubExpression())
|
||||||
is PsiExpressionStatement -> JKExpressionStatementImpl(with(expressionTreeMapper) { expression.toJK() })
|
is PsiExpressionStatement -> JKExpressionStatement(with(expressionTreeMapper) { expression.toJK() })
|
||||||
is PsiReturnStatement -> JKReturnStatementImpl(with(expressionTreeMapper) { returnValue.toJK() })
|
is PsiReturnStatement -> JKReturnStatement(with(expressionTreeMapper) { returnValue.toJK() })
|
||||||
is PsiDeclarationStatement ->
|
is PsiDeclarationStatement ->
|
||||||
JKDeclarationStatementImpl(declaredElements.map {
|
JKDeclarationStatement(declaredElements.map {
|
||||||
when (it) {
|
when (it) {
|
||||||
is PsiClass -> it.toJK()
|
is PsiClass -> it.toJK()
|
||||||
is PsiLocalVariable -> it.toJK()
|
is PsiLocalVariable -> it.toJK()
|
||||||
@@ -838,91 +829,87 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
is PsiAssertStatement ->
|
is PsiAssertStatement ->
|
||||||
JKJavaAssertStatementImpl(
|
JKJavaAssertStatement(
|
||||||
with(expressionTreeMapper) { assertCondition.toJK() },
|
with(expressionTreeMapper) { assertCondition.toJK() },
|
||||||
with(expressionTreeMapper) { assertDescription?.toJK() } ?: JKStubExpressionImpl())
|
with(expressionTreeMapper) { assertDescription?.toJK() } ?: JKStubExpression())
|
||||||
is PsiIfStatement ->
|
is PsiIfStatement ->
|
||||||
if (elseElement == null)
|
with(expressionTreeMapper) {
|
||||||
JKIfStatementImpl(with(expressionTreeMapper) { condition.toJK() }, thenBranch.toJK())
|
JKIfElseStatement(condition.toJK(), thenBranch.toJK(), elseBranch.toJK())
|
||||||
else
|
}
|
||||||
JKIfElseStatementImpl(with(expressionTreeMapper) { condition.toJK() }, thenBranch.toJK(), elseBranch.toJK())
|
|
||||||
|
|
||||||
is PsiForStatement -> JKJavaForLoopStatementImpl(
|
|
||||||
|
is PsiForStatement -> JKJavaForLoopStatement(
|
||||||
initialization.toJK(),
|
initialization.toJK(),
|
||||||
with(expressionTreeMapper) { condition.toJK() },
|
with(expressionTreeMapper) { condition.toJK() },
|
||||||
when (update) {
|
when (update) {
|
||||||
is PsiExpressionListStatement ->
|
is PsiExpressionListStatement ->
|
||||||
(update as PsiExpressionListStatement).expressionList.expressions.map {
|
(update as PsiExpressionListStatement).expressionList.expressions.map {
|
||||||
JKExpressionStatementImpl(with(expressionTreeMapper) { it.toJK() })
|
JKExpressionStatement(with(expressionTreeMapper) { it.toJK() })
|
||||||
}
|
}
|
||||||
else -> listOf(update.toJK())
|
else -> listOf(update.toJK())
|
||||||
},
|
},
|
||||||
body.toJK()
|
body.toJK()
|
||||||
)
|
)
|
||||||
is PsiForeachStatement ->
|
is PsiForeachStatement ->
|
||||||
JKForInStatementImpl(
|
JKForInStatement(
|
||||||
iterationParameter.toJK(),
|
iterationParameter.toJK(),
|
||||||
with(expressionTreeMapper) { iteratedValue?.toJK() ?: JKStubExpressionImpl() },
|
with(expressionTreeMapper) { iteratedValue?.toJK() ?: JKStubExpression() },
|
||||||
body?.toJK() ?: blockStatement()
|
body?.toJK() ?: blockStatement()
|
||||||
)
|
)
|
||||||
is PsiBlockStatement -> JKBlockStatementImpl(codeBlock.toJK())
|
is PsiBlockStatement -> JKBlockStatement(codeBlock.toJK())
|
||||||
is PsiWhileStatement -> JKWhileStatementImpl(with(expressionTreeMapper) { condition.toJK() }, body.toJK())
|
is PsiWhileStatement -> JKWhileStatement(with(expressionTreeMapper) { condition.toJK() }, body.toJK())
|
||||||
is PsiDoWhileStatement -> JKDoWhileStatementImpl(body.toJK(), with(expressionTreeMapper) { condition.toJK() })
|
is PsiDoWhileStatement -> JKDoWhileStatement(body.toJK(), with(expressionTreeMapper) { condition.toJK() })
|
||||||
|
|
||||||
is PsiSwitchStatement -> {
|
is PsiSwitchStatement -> {
|
||||||
val cases = mutableListOf<JKJavaSwitchCase>()
|
val cases = mutableListOf<JKJavaSwitchCase>()
|
||||||
for (statement in body?.statements.orEmpty()) {
|
for (statement in body?.statements.orEmpty()) {
|
||||||
when (statement) {
|
when (statement) {
|
||||||
is PsiSwitchLabelStatement ->
|
is PsiSwitchLabelStatement ->
|
||||||
cases += if (statement.isDefaultCase)
|
cases += when {
|
||||||
JKJavaDefaultSwitchCaseImpl(emptyList()).withAssignedNonCodeElements(statement)
|
statement.isDefaultCase -> JKJavaDefaultSwitchCase(emptyList())
|
||||||
else
|
else -> JKJavaLabelSwitchCase(
|
||||||
JKJavaLabelSwitchCaseImpl(
|
|
||||||
with(expressionTreeMapper) { statement.caseValue.toJK() },
|
with(expressionTreeMapper) { statement.caseValue.toJK() },
|
||||||
emptyList()
|
emptyList()
|
||||||
).withAssignedNonCodeElements(statement)
|
)
|
||||||
|
}.withAssignedNonCodeElements(statement)
|
||||||
else ->
|
else ->
|
||||||
cases.lastOrNull()?.also { it.statements = it.statements + statement.toJK() }
|
cases.lastOrNull()?.also { it.statements = it.statements + statement.toJK() }
|
||||||
?: run {
|
?: run {
|
||||||
cases += JKJavaLabelSwitchCaseImpl(
|
cases += JKJavaLabelSwitchCase(
|
||||||
JKStubExpressionImpl(),
|
JKStubExpression(),
|
||||||
listOf(statement.toJK())
|
listOf(statement.toJK())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
JKJavaSwitchStatementImpl(with(expressionTreeMapper) { expression.toJK() }, cases)
|
JKJavaSwitchStatement(with(expressionTreeMapper) { expression.toJK() }, cases)
|
||||||
}
|
|
||||||
is PsiBreakStatement -> {
|
|
||||||
if (labelIdentifier != null)
|
|
||||||
JKBreakWithLabelStatementImpl(JKNameIdentifierImpl(labelIdentifier!!.text))
|
|
||||||
else
|
|
||||||
JKBreakStatementImpl()
|
|
||||||
}
|
}
|
||||||
|
is PsiBreakStatement ->
|
||||||
|
JKBreakStatement(labelIdentifier?.let { JKLabelText(JKNameIdentifier(it.text)) } ?: JKLabelEmpty())
|
||||||
is PsiContinueStatement -> {
|
is PsiContinueStatement -> {
|
||||||
val label = labelIdentifier?.let {
|
val label = labelIdentifier?.let {
|
||||||
JKLabelTextImpl(JKNameIdentifierImpl(it.text))
|
JKLabelText(JKNameIdentifier(it.text))
|
||||||
} ?: JKLabelEmptyImpl()
|
} ?: JKLabelEmpty()
|
||||||
JKContinueStatementImpl(label)
|
JKContinueStatement(label)
|
||||||
}
|
}
|
||||||
is PsiLabeledStatement -> {
|
is PsiLabeledStatement -> {
|
||||||
val (labels, statement) = collectLabels()
|
val (labels, statement) = collectLabels()
|
||||||
JKLabeledStatementImpl(statement.toJK(), labels.map { JKNameIdentifierImpl(it.text) }).asStatement()
|
JKLabeledExpression(statement.toJK(), labels.map { JKNameIdentifier(it.text) }).asStatement()
|
||||||
}
|
}
|
||||||
is PsiEmptyStatement -> JKEmptyStatementImpl()
|
is PsiEmptyStatement -> JKEmptyStatement()
|
||||||
is PsiThrowStatement ->
|
is PsiThrowStatement ->
|
||||||
JKJavaThrowStatementImpl(with(expressionTreeMapper) { exception.toJK() })
|
JKJavaThrowStatement(with(expressionTreeMapper) { exception.toJK() })
|
||||||
is PsiTryStatement ->
|
is PsiTryStatement ->
|
||||||
JKJavaTryStatementImpl(
|
JKJavaTryStatement(
|
||||||
resourceList?.toList()?.map { (it as PsiLocalVariable).toJK() }.orEmpty(),
|
resourceList?.toList()?.map { (it as PsiLocalVariable).toJK() }.orEmpty(),
|
||||||
tryBlock?.toJK() ?: JKBodyStubImpl,
|
tryBlock?.toJK() ?: JKBodyStub,
|
||||||
finallyBlock?.toJK() ?: JKBodyStubImpl,
|
finallyBlock?.toJK() ?: JKBodyStub,
|
||||||
catchSections.map { it.toJK() }
|
catchSections.map { it.toJK() }
|
||||||
)
|
)
|
||||||
is PsiSynchronizedStatement ->
|
is PsiSynchronizedStatement ->
|
||||||
JKJavaSynchronizedStatementImpl(
|
JKJavaSynchronizedStatement(
|
||||||
with(expressionTreeMapper) { lockExpression?.toJK() } ?: JKStubExpressionImpl(),
|
with(expressionTreeMapper) { lockExpression?.toJK() } ?: JKStubExpression(),
|
||||||
body?.toJK() ?: JKBodyStubImpl
|
body?.toJK() ?: JKBodyStub
|
||||||
)
|
)
|
||||||
else -> throwCanNotConvertError()
|
else -> throwCanNotConvertError()
|
||||||
}.also {
|
}.also {
|
||||||
@@ -934,17 +921,15 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun PsiCatchSection.toJK(): JKJavaTryCatchSection =
|
fun PsiCatchSection.toJK(): JKJavaTryCatchSection =
|
||||||
JKJavaTryCatchSectionImpl(
|
JKJavaTryCatchSection(
|
||||||
parameter?.toJK() ?: throwCanNotConvertError(),
|
parameter?.toJK() ?: throwCanNotConvertError(),
|
||||||
catchBlock?.toJK() ?: JKBodyStubImpl
|
catchBlock?.toJK() ?: JKBodyStub
|
||||||
).also {
|
).also {
|
||||||
it.psi = this
|
it.psi = this
|
||||||
}.also {
|
|
||||||
it.assignNonCodeElements(this)
|
it.assignNonCodeElements(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO better way than generateSequence.last??
|
|
||||||
fun PsiLabeledStatement.collectLabels(): Pair<List<PsiIdentifier>, PsiStatement> =
|
fun PsiLabeledStatement.collectLabels(): Pair<List<PsiIdentifier>, PsiStatement> =
|
||||||
generateSequence(emptyList<PsiIdentifier>() to this as PsiStatement) { (labels, statement) ->
|
generateSequence(emptyList<PsiIdentifier>() to this as PsiStatement) { (labels, statement) ->
|
||||||
if (statement !is PsiLabeledStatementImpl) return@generateSequence null
|
if (statement !is PsiLabeledStatementImpl) return@generateSequence null
|
||||||
@@ -967,10 +952,10 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
if (psi.parent is PsiReferenceList) {
|
if (psi.parent is PsiReferenceList) {
|
||||||
val factory = JavaPsiFacade.getInstance(psi.project).elementFactory
|
val factory = JavaPsiFacade.getInstance(psi.project).elementFactory
|
||||||
val type = factory.createType(psi)
|
val type = factory.createType(psi)
|
||||||
JKTypeElementImpl(type.toJK().updateNullabilityRecursively(Nullability.NotNull))
|
JKTypeElement(type.toJK().updateNullabilityRecursively(Nullability.NotNull))
|
||||||
} else null
|
} else null
|
||||||
else -> null
|
else -> null
|
||||||
}?.let { JKTreeRootImpl(it) }
|
}?.let { JKTreeRoot(it) }
|
||||||
|
|
||||||
private val tokenCache = mutableMapOf<PsiElement, JKNonCodeElement>()
|
private val tokenCache = mutableMapOf<PsiElement, JKNonCodeElement>()
|
||||||
|
|
||||||
@@ -979,9 +964,9 @@ class JavaToJKTreeBuilder constructor(
|
|||||||
if (this in tokenCache) return tokenCache.getValue(this)
|
if (this in tokenCache) return tokenCache.getValue(this)
|
||||||
val token = when {
|
val token = when {
|
||||||
this is PsiDocComment ->
|
this is PsiDocComment ->
|
||||||
JKCommentElementImpl(IdeaDocCommentConverter.convertDocComment(this))
|
JKCommentElement(IdeaDocCommentConverter.convertDocComment(this))
|
||||||
this is PsiComment -> JKCommentElementImpl(text)
|
this is PsiComment -> JKCommentElement(text)
|
||||||
this is PsiWhiteSpace -> JKSpaceElementImpl(text)
|
this is PsiWhiteSpace -> JKSpaceElement(text)
|
||||||
text == ";" -> null
|
text == ";" -> null
|
||||||
text == "" -> null
|
text == "" -> null
|
||||||
else -> error("Token should be either token or whitespace")
|
else -> error("Token should be either token or whitespace")
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.name.FqName
|
|||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.getDisplayName
|
import org.jetbrains.kotlin.nj2k.symbols.getDisplayName
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitorWithCommentsPrinting
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitorWithCommentsPrinting
|
||||||
import org.jetbrains.kotlin.nj2k.types.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
@@ -120,7 +119,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.printWithNoIndent("try ")
|
printer.printWithNoIndent("try ")
|
||||||
ktTryExpression.tryBlock.accept(this)
|
ktTryExpression.tryBlock.accept(this)
|
||||||
ktTryExpression.catchSections.forEach { it.accept(this) }
|
ktTryExpression.catchSections.forEach { it.accept(this) }
|
||||||
if (ktTryExpression.finallyBlock != JKBodyStubImpl) {
|
if (ktTryExpression.finallyBlock != JKBodyStub) {
|
||||||
printer.printWithNoIndent("finally ")
|
printer.printWithNoIndent("finally ")
|
||||||
ktTryExpression.finallyBlock.accept(this)
|
ktTryExpression.finallyBlock.accept(this)
|
||||||
}
|
}
|
||||||
@@ -192,18 +191,15 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitBreakStatementRaw(breakStatement: JKBreakStatement) {
|
override fun visitBreakStatementRaw(breakStatement: JKBreakStatement) {
|
||||||
printer.printWithNoIndent("break")
|
printer.printWithNoIndent("break")
|
||||||
|
breakStatement.label.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBreakWithLabelStatementRaw(breakWithLabelStatement: JKBreakWithLabelStatement) {
|
|
||||||
printer.printWithNoIndent("break@")
|
|
||||||
breakWithLabelStatement.label.accept(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun renderModifiersList(modifiersList: JKModifiersListOwner) {
|
private fun renderModifiersList(modifiersList: JKModifiersListOwner) {
|
||||||
val hasOverrideModifier = modifiersList.safeAs<JKOtherModifiersOwner>()
|
val hasOverrideModifier = modifiersList.safeAs<JKOtherModifiersOwner>()
|
||||||
?.otherModifierElements
|
?.otherModifierElements
|
||||||
?.any { it.otherModifier == OtherModifier.OVERRIDE } == true
|
?.any { it.otherModifier == OtherModifier.OVERRIDE } == true
|
||||||
printer.renderList(modifiersList.modifierElements(), " ") { modifierElement ->
|
modifiersList.forEachModifier { modifierElement ->
|
||||||
if (modifierElement.modifier == Modality.FINAL || modifierElement.modifier == Visibility.PUBLIC) {
|
if (modifierElement.modifier == Modality.FINAL || modifierElement.modifier == Visibility.PUBLIC) {
|
||||||
if (hasOverrideModifier) {
|
if (hasOverrideModifier) {
|
||||||
modifierElement.accept(this)
|
modifierElement.accept(this)
|
||||||
@@ -214,6 +210,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
} else {
|
} else {
|
||||||
modifierElement.accept(this)
|
modifierElement.accept(this)
|
||||||
}
|
}
|
||||||
|
printer.printWithNoIndent(" ")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -233,13 +230,11 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
val primaryConstructor = klass.primaryConstructor()
|
val primaryConstructor = klass.primaryConstructor()
|
||||||
primaryConstructor?.accept(this)
|
primaryConstructor?.accept(this)
|
||||||
|
|
||||||
|
|
||||||
if (klass.inheritance.present()) {
|
if (klass.inheritance.present()) {
|
||||||
printer.printWithNoIndent(" : ")
|
printer.printWithNoIndent(" : ")
|
||||||
klass.inheritance.accept(this)
|
klass.inheritance.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO should it be here?
|
|
||||||
renderExtraTypeParametersUpperBounds(klass.typeParameterList)
|
renderExtraTypeParametersUpperBounds(klass.typeParameterList)
|
||||||
|
|
||||||
klass.classBody.accept(this)
|
klass.classBody.accept(this)
|
||||||
@@ -279,7 +274,6 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.renderList(enumConstants) {
|
printer.renderList(enumConstants) {
|
||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun renderNonEnumClassDeclarations(declarations: List<JKDeclaration>) {
|
private fun renderNonEnumClassDeclarations(declarations: List<JKDeclaration>) {
|
||||||
@@ -289,30 +283,22 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun visitKtPropertyRaw(ktProperty: JKKtProperty) {
|
override fun visitFieldRaw(field: JKField) {
|
||||||
ktProperty.annotationList.accept(this)
|
field.annotationList.accept(this)
|
||||||
if (ktProperty.annotationList.annotations.isNotEmpty()) {
|
if (field.annotationList.annotations.isNotEmpty()) {
|
||||||
printer.println()
|
printer.println()
|
||||||
}
|
}
|
||||||
renderModifiersList(ktProperty)
|
renderModifiersList(field)
|
||||||
|
|
||||||
printer.printWithNoIndent(" ")
|
printer.printWithNoIndent(" ")
|
||||||
ktProperty.name.accept(this)
|
field.name.accept(this)
|
||||||
if (ktProperty.type.present()) {
|
if (field.type.present()) {
|
||||||
printer.printWithNoIndent(":")
|
printer.printWithNoIndent(":")
|
||||||
ktProperty.type.accept(this)
|
field.type.accept(this)
|
||||||
}
|
}
|
||||||
if (ktProperty.initializer !is JKStubExpression) {
|
if (field.initializer !is JKStubExpression) {
|
||||||
printer.printWithNoIndent(" = ")
|
printer.printWithNoIndent(" = ")
|
||||||
ktProperty.initializer.accept(this)
|
field.initializer.accept(this)
|
||||||
}
|
|
||||||
if (ktProperty.getter !is JKKtEmptyGetterOrSetter) {
|
|
||||||
printer.printlnWithNoIndent()
|
|
||||||
ktProperty.getter.accept(this)
|
|
||||||
}
|
|
||||||
if (ktProperty.setter !is JKKtEmptyGetterOrSetter) {
|
|
||||||
printer.printlnWithNoIndent()
|
|
||||||
ktProperty.setter.accept(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -323,7 +309,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
enumConstant.arguments.accept(this)
|
enumConstant.arguments.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (enumConstant.body !is JKEmptyClassBody) {
|
if (enumConstant.body.declarations.isNotEmpty()) {
|
||||||
enumConstant.body.accept(this)
|
enumConstant.body.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,10 +322,11 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtIsExpressionRaw(ktIsExpression: JKKtIsExpression) {
|
|
||||||
ktIsExpression.expression.accept(this)
|
override fun visitIsExpressionRaw(isExpression: JKIsExpression) {
|
||||||
|
isExpression.expression.accept(this)
|
||||||
printer.printWithNoIndent(" is ")
|
printer.printWithNoIndent(" is ")
|
||||||
ktIsExpression.type.accept(this)
|
isExpression.type.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitParameterRaw(parameter: JKParameter) {
|
override fun visitParameterRaw(parameter: JKParameter) {
|
||||||
@@ -352,7 +339,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
if (parameter.parent is JKKtPrimaryConstructor
|
if (parameter.parent is JKKtPrimaryConstructor
|
||||||
&& (parameter.parent?.parent?.parent as? JKClass)?.classKind == JKClass.ClassKind.ANNOTATION
|
&& (parameter.parent?.parent?.parent as? JKClass)?.classKind == JKClass.ClassKind.ANNOTATION
|
||||||
) {//TODO get rid of
|
) {
|
||||||
printer.print(" val ")
|
printer.print(" val ")
|
||||||
}
|
}
|
||||||
parameter.name.accept(this)
|
parameter.name.accept(this)
|
||||||
@@ -382,29 +369,29 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtFunctionRaw(ktFunction: JKKtFunction) {
|
override fun visitMethodRaw(method: JKMethod) {
|
||||||
printer.printIndent()
|
printer.printIndent()
|
||||||
if (ktFunction.annotationList.annotations.isNotEmpty()) {
|
if (method.annotationList.annotations.isNotEmpty()) {
|
||||||
ktFunction.annotationList.accept(this)
|
method.annotationList.accept(this)
|
||||||
printer.printlnWithNoIndent(" ")
|
printer.printlnWithNoIndent(" ")
|
||||||
}
|
}
|
||||||
renderModifiersList(ktFunction)
|
renderModifiersList(method)
|
||||||
printer.printWithNoIndent(" fun ")
|
printer.printWithNoIndent(" fun ")
|
||||||
ktFunction.typeParameterList.accept(this)
|
method.typeParameterList.accept(this)
|
||||||
|
|
||||||
elementInfoStorage.getOrCreateInfoForElement(ktFunction).let {
|
elementInfoStorage.getOrCreateInfoForElement(method).let {
|
||||||
printer.printWithNoIndent(it.render())
|
printer.printWithNoIndent(it.render())
|
||||||
}
|
}
|
||||||
ktFunction.name.accept(this)
|
method.name.accept(this)
|
||||||
renderTokenElement(ktFunction.leftParen)
|
renderTokenElement(method.leftParen)
|
||||||
printer.renderList(ktFunction.parameters) {
|
printer.renderList(method.parameters) {
|
||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
renderTokenElement(ktFunction.rightParen)
|
renderTokenElement(method.rightParen)
|
||||||
printer.printWithNoIndent(": ")
|
printer.printWithNoIndent(": ")
|
||||||
ktFunction.returnType.accept(this)
|
method.returnType.accept(this)
|
||||||
renderExtraTypeParametersUpperBounds(ktFunction.typeParameterList)
|
renderExtraTypeParametersUpperBounds(method.typeParameterList)
|
||||||
ktFunction.block.accept(this)
|
method.block.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitIfElseExpressionRaw(ifElseExpression: JKIfElseExpression) {
|
override fun visitIfElseExpressionRaw(ifElseExpression: JKIfElseExpression) {
|
||||||
@@ -412,49 +399,28 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
ifElseExpression.condition.accept(this)
|
ifElseExpression.condition.accept(this)
|
||||||
printer.printWithNoIndent(")")
|
printer.printWithNoIndent(")")
|
||||||
ifElseExpression.thenBranch.accept(this)
|
ifElseExpression.thenBranch.accept(this)
|
||||||
printer.printWithNoIndent(" else ")
|
if (ifElseExpression.elseBranch !is JKStubExpression) {
|
||||||
ifElseExpression.elseBranch.accept(this)
|
printer.printWithNoIndent(" else ")
|
||||||
}
|
ifElseExpression.elseBranch.accept(this)
|
||||||
|
|
||||||
override fun visitIfStatementRaw(ifStatement: JKIfStatement) {
|
|
||||||
printer.printWithNoIndent("if (")
|
|
||||||
ifStatement.condition.accept(this)
|
|
||||||
printer.printWithNoIndent(")")
|
|
||||||
if (ifStatement.thenBranch.isEmpty()) {
|
|
||||||
printer.printWithNoIndent(";")
|
|
||||||
} else {
|
|
||||||
ifStatement.thenBranch.accept(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun visitIfElseStatementRaw(ifElseStatement: JKIfElseStatement) {
|
override fun visitIfElseStatementRaw(ifElseStatement: JKIfElseStatement) {
|
||||||
visitIfStatement(ifElseStatement)
|
printer.printWithNoIndent("if (")
|
||||||
printer.printWithNoIndent(" else ")
|
ifElseStatement.condition.accept(this)
|
||||||
ifElseStatement.elseBranch.accept(this)
|
printer.printWithNoIndent(")")
|
||||||
}
|
if (ifElseStatement.thenBranch.isEmpty()) {
|
||||||
|
printer.printWithNoIndent(";")
|
||||||
override fun visitKtGetterOrSetterRaw(ktGetterOrSetter: JKKtGetterOrSetter) {
|
} else {
|
||||||
printer.indented {
|
ifElseStatement.thenBranch.accept(this)
|
||||||
renderModifiersList(ktGetterOrSetter)
|
}
|
||||||
printer.printWithNoIndent(" ")
|
if (!ifElseStatement.elseBranch.isEmpty()) {
|
||||||
when (ktGetterOrSetter.kind) {
|
printer.printWithNoIndent(" else ")
|
||||||
JKKtGetterOrSetter.Kind.GETTER -> printer.printWithNoIndent("get")
|
ifElseStatement.elseBranch.accept(this)
|
||||||
JKKtGetterOrSetter.Kind.SETTER -> printer.printWithNoIndent("set")
|
|
||||||
}
|
|
||||||
if (!ktGetterOrSetter.body.isEmpty()) {
|
|
||||||
when (ktGetterOrSetter.kind) {
|
|
||||||
JKKtGetterOrSetter.Kind.GETTER -> printer.printWithNoIndent("() ")
|
|
||||||
JKKtGetterOrSetter.Kind.SETTER -> printer.printWithNoIndent("(value) ")
|
|
||||||
}
|
|
||||||
ktGetterOrSetter.body.accept(this)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
printer.printlnWithNoIndent()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtEmptyGetterOrSetterRaw(ktEmptyGetterOrSetter: JKKtEmptyGetterOrSetter) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitBinaryExpressionRaw(binaryExpression: JKBinaryExpression) {
|
override fun visitBinaryExpressionRaw(binaryExpression: JKBinaryExpression) {
|
||||||
binaryExpression.left.accept(this)
|
binaryExpression.left.accept(this)
|
||||||
@@ -517,12 +483,12 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.printWithNoIndent(" ")
|
printer.printWithNoIndent(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitLabeledStatementRaw(labeledStatement: JKLabeledStatement) {
|
override fun visitLabeledExpressionRaw(labeledExpression: JKLabeledExpression) {
|
||||||
for (label in labeledStatement.labels) {
|
for (label in labeledExpression.labels) {
|
||||||
label.accept(this)
|
label.accept(this)
|
||||||
printer.printWithNoIndent("@")
|
printer.printWithNoIndent("@")
|
||||||
}
|
}
|
||||||
labeledStatement.statement.accept(this)
|
labeledExpression.statement.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitNameIdentifierRaw(nameIdentifier: JKNameIdentifier) {
|
override fun visitNameIdentifierRaw(nameIdentifier: JKNameIdentifier) {
|
||||||
@@ -536,20 +502,10 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
|
|
||||||
override fun visitQualifiedExpressionRaw(qualifiedExpression: JKQualifiedExpression) {
|
override fun visitQualifiedExpressionRaw(qualifiedExpression: JKQualifiedExpression) {
|
||||||
qualifiedExpression.receiver.accept(this)
|
qualifiedExpression.receiver.accept(this)
|
||||||
printer.printWithNoIndent(
|
printer.printWithNoIndent(".")
|
||||||
when (qualifiedExpression.operator) {
|
|
||||||
is JKJavaQualifierImpl.DOT /*<-remove this TODO!*/, is JKKtQualifierImpl.DOT -> "."
|
|
||||||
is JKKtQualifierImpl.SAFE -> "?."
|
|
||||||
else -> TODO()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
qualifiedExpression.selector.accept(this)
|
qualifiedExpression.selector.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitExpressionListRaw(expressionList: JKExpressionList) {
|
|
||||||
printer.renderList(expressionList.expressions) { it.accept(this) }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
override fun visitArgumentListRaw(argumentList: JKArgumentList) {
|
override fun visitArgumentListRaw(argumentList: JKArgumentList) {
|
||||||
printer.renderList(argumentList.arguments) { it.accept(this) }
|
printer.renderList(argumentList.arguments) { it.accept(this) }
|
||||||
@@ -565,11 +521,11 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
namedArgument.value.accept(this)
|
namedArgument.value.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitMethodCallExpressionRaw(methodCallExpression: JKMethodCallExpression) {
|
override fun visitCallExpressionRaw(callExpression: JKCallExpression) {
|
||||||
printer.printWithNoIndent(FqName(methodCallExpression.identifier.fqName).shortName().asString().escaped())
|
printer.printWithNoIndent(FqName(callExpression.identifier.fqName).shortName().asString().escaped())
|
||||||
methodCallExpression.typeArgumentList.accept(this)
|
callExpression.typeArgumentList.accept(this)
|
||||||
printer.par {
|
printer.par {
|
||||||
methodCallExpression.arguments.accept(this)
|
callExpression.arguments.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,19 +599,19 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
ktConvertedFromForLoopSyntheticWhileStatement.whileStatement.accept(this)
|
ktConvertedFromForLoopSyntheticWhileStatement.whileStatement.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitJavaNewExpressionRaw(javaNewExpression: JKJavaNewExpression) {
|
override fun visitNewExpressionRaw(newExpression: JKNewExpression) {
|
||||||
if (javaNewExpression.isAnonymousClass()) {
|
if (newExpression.isAnonymousClass) {
|
||||||
printer.printWithNoIndent("object : ")
|
printer.printWithNoIndent("object : ")
|
||||||
}
|
}
|
||||||
printer.renderClassSymbol(javaNewExpression.classSymbol, javaNewExpression)
|
printer.renderClassSymbol(newExpression.classSymbol, newExpression)
|
||||||
javaNewExpression.typeArgumentList.accept(this)
|
newExpression.typeArgumentList.accept(this)
|
||||||
if (!javaNewExpression.classSymbol.isInterface() || javaNewExpression.arguments.arguments.isNotEmpty()) {
|
if (!newExpression.classSymbol.isInterface() || newExpression.arguments.arguments.isNotEmpty()) {
|
||||||
printer.par(ParenthesisKind.ROUND) {
|
printer.par(ParenthesisKind.ROUND) {
|
||||||
javaNewExpression.arguments.accept(this)
|
newExpression.arguments.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (javaNewExpression.isAnonymousClass()) {
|
if (newExpression.isAnonymousClass) {
|
||||||
javaNewExpression.classBody.accept(this)
|
newExpression.classBody.accept(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,8 +637,6 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
renderTokenElement(classBody.rightBrace)
|
renderTokenElement(classBody.rightBrace)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitEmptyClassBodyRaw(emptyClassBody: JKEmptyClassBody) {}
|
|
||||||
|
|
||||||
override fun visitTypeElementRaw(typeElement: JKTypeElement) {
|
override fun visitTypeElementRaw(typeElement: JKTypeElement) {
|
||||||
printer.renderType(typeElement.type, typeElement)
|
printer.renderType(typeElement.type, typeElement)
|
||||||
}
|
}
|
||||||
@@ -716,13 +670,6 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.printWithNoIndent(fieldAccessExpression.identifier.name.escaped())
|
printer.printWithNoIndent(fieldAccessExpression.identifier.name.escaped())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitArrayAccessExpressionRaw(arrayAccessExpression: JKArrayAccessExpression) {
|
|
||||||
arrayAccessExpression.expression.accept(this)
|
|
||||||
printer.print(".get(")
|
|
||||||
arrayAccessExpression.indexExpression.accept(this)
|
|
||||||
printer.print(")")
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitPackageAccessExpressionRaw(packageAccessExpression: JKPackageAccessExpression) {
|
override fun visitPackageAccessExpressionRaw(packageAccessExpression: JKPackageAccessExpression) {
|
||||||
printer.printWithNoIndent(packageAccessExpression.identifier.name.escaped())
|
printer.printWithNoIndent(packageAccessExpression.identifier.name.escaped())
|
||||||
}
|
}
|
||||||
@@ -754,19 +701,19 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtConstructorRaw(ktConstructor: JKKtConstructor) {
|
override fun visitConstructorRaw(constructor: JKConstructor) {
|
||||||
ktConstructor.annotationList.accept(this)
|
constructor.annotationList.accept(this)
|
||||||
if (ktConstructor.annotationList.annotations.isNotEmpty()) {
|
if (constructor.annotationList.annotations.isNotEmpty()) {
|
||||||
printer.println()
|
printer.println()
|
||||||
}
|
}
|
||||||
renderModifiersList(ktConstructor)
|
renderModifiersList(constructor)
|
||||||
printer.print(" constructor")
|
printer.print(" constructor")
|
||||||
renderParameterList(ktConstructor.parameters)
|
renderParameterList(constructor.parameters)
|
||||||
if (ktConstructor.delegationCall !is JKStubExpression) {
|
if (constructor.delegationCall !is JKStubExpression) {
|
||||||
builder.append(" : ")
|
builder.append(" : ")
|
||||||
ktConstructor.delegationCall.accept(this)
|
constructor.delegationCall.accept(this)
|
||||||
}
|
}
|
||||||
ktConstructor.block.accept(this)
|
constructor.block.accept(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitKtPrimaryConstructorRaw(ktPrimaryConstructor: JKKtPrimaryConstructor) {
|
override fun visitKtPrimaryConstructorRaw(ktPrimaryConstructor: JKKtPrimaryConstructor) {
|
||||||
@@ -781,8 +728,6 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitBodyStub(bodyStub: JKBodyStub) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitLambdaExpressionRaw(lambdaExpression: JKLambdaExpression) {
|
override fun visitLambdaExpressionRaw(lambdaExpression: JKLambdaExpression) {
|
||||||
val printLambda = {
|
val printLambda = {
|
||||||
@@ -846,7 +791,7 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
printer.printWithNoIndent("when(")
|
printer.printWithNoIndent("when(")
|
||||||
ktWhenStatement.expression.accept(this)
|
ktWhenStatement.expression.accept(this)
|
||||||
printer.printWithNoIndent(")")
|
printer.printWithNoIndent(")")
|
||||||
printer.block(multiline = true) {
|
printer.block() {
|
||||||
printer.renderList(ktWhenStatement.cases, { printer.printlnWithNoIndent() }) {
|
printer.renderList(ktWhenStatement.cases, { printer.printlnWithNoIndent() }) {
|
||||||
it.accept(this)
|
it.accept(this)
|
||||||
}
|
}
|
||||||
@@ -880,16 +825,16 @@ class NewCodeBuilder(context: NewJ2kConverterContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitClassLiteralExpressionRaw(classLiteralExpression: JKClassLiteralExpression) {
|
override fun visitClassLiteralExpressionRaw(classLiteralExpression: JKClassLiteralExpression) {
|
||||||
if (classLiteralExpression.literalType == JKClassLiteralExpression.LiteralType.JAVA_VOID_TYPE) {
|
if (classLiteralExpression.literalType == JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE) {
|
||||||
printer.printWithNoIndent("Void.TYPE")
|
printer.printWithNoIndent("Void.TYPE")
|
||||||
} else {
|
} else {
|
||||||
printer.renderType(classLiteralExpression.classType.type, classLiteralExpression)
|
printer.renderType(classLiteralExpression.classType.type, classLiteralExpression)
|
||||||
printer.printWithNoIndent("::")
|
printer.printWithNoIndent("::")
|
||||||
when (classLiteralExpression.literalType) {
|
when (classLiteralExpression.literalType) {
|
||||||
JKClassLiteralExpression.LiteralType.KOTLIN_CLASS -> printer.printWithNoIndent("class")
|
JKClassLiteralExpression.ClassLiteralType.KOTLIN_CLASS -> printer.printWithNoIndent("class")
|
||||||
JKClassLiteralExpression.LiteralType.JAVA_CLASS -> printer.printWithNoIndent("class.java")
|
JKClassLiteralExpression.ClassLiteralType.JAVA_CLASS -> printer.printWithNoIndent("class.java")
|
||||||
JKClassLiteralExpression.LiteralType.JAVA_PRIMITIVE_CLASS -> printer.printWithNoIndent("class.javaPrimitiveType")
|
JKClassLiteralExpression.ClassLiteralType.JAVA_PRIMITIVE_CLASS -> printer.printWithNoIndent("class.javaPrimitiveType")
|
||||||
JKClassLiteralExpression.LiteralType.JAVA_VOID_TYPE -> {
|
JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE -> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -939,7 +884,7 @@ private class JKPrinter(
|
|||||||
this.popIndent()
|
this.popIndent()
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun block(multiline: Boolean = false, crossinline body: () -> Unit) {
|
inline fun block(crossinline body: () -> Unit) {
|
||||||
par(ParenthesisKind.CURVED) {
|
par(ParenthesisKind.CURVED) {
|
||||||
indented(body)
|
indented(body)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKElementBase
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.withNonCodeElementsFrom
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
fun <T : JKElement> T.copyTree(): T =
|
|
||||||
when (this) {
|
|
||||||
is JKElementBase ->
|
|
||||||
this.copy().withNonCodeElementsFrom(this) as T
|
|
||||||
else -> TODO("Not supported+$this.toString()")
|
|
||||||
}
|
|
||||||
|
|
||||||
fun <T : JKElement> T.copyTreeAndDetach(): T =
|
|
||||||
this.copyTree().also {
|
|
||||||
if (it.parent != null) it.detach(it.parent!!)
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -14,11 +14,16 @@ import org.jetbrains.kotlin.j2k.ast.Nullability
|
|||||||
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
|
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
|
||||||
import org.jetbrains.kotlin.nj2k.*
|
import org.jetbrains.kotlin.nj2k.*
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseMethodSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseMethodSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.JKMethod
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKCapturedType
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.psi
|
import org.jetbrains.kotlin.nj2k.tree.JKTypeElement
|
||||||
|
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.isCollectionType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKCapturedType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKParametrizedType
|
import org.jetbrains.kotlin.nj2k.types.JKParametrizedType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKStarProjectionType
|
import org.jetbrains.kotlin.nj2k.types.JKStarProjectionType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class AddElementsInfoConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class AddElementsInfoConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
|
|||||||
+2
-5
@@ -7,9 +7,6 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBinaryExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKParenthesizedExpressionImpl
|
|
||||||
|
|
||||||
|
|
||||||
class AddParenthesisForLineBreaksInBinaryExpression(override val context: NewJ2kConverterContext) :
|
class AddParenthesisForLineBreaksInBinaryExpression(override val context: NewJ2kConverterContext) :
|
||||||
RecursiveApplicableConversionBase(context) {
|
RecursiveApplicableConversionBase(context) {
|
||||||
@@ -19,8 +16,8 @@ class AddParenthesisForLineBreaksInBinaryExpression(override val context: NewJ2k
|
|||||||
if (element.left.rightNonCodeElements.any {
|
if (element.left.rightNonCodeElements.any {
|
||||||
it is JKSpaceElement && '\n' in it.text
|
it is JKSpaceElement && '\n' in it.text
|
||||||
}) {
|
}) {
|
||||||
return JKParenthesizedExpressionImpl(
|
return JKParenthesizedExpression(
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
element::left.detached(),
|
element::left.detached(),
|
||||||
element::right.detached(),
|
element::right.detached(),
|
||||||
element.operator
|
element.operator
|
||||||
|
|||||||
@@ -7,10 +7,14 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.modality
|
||||||
import org.jetbrains.kotlin.nj2k.toExpression
|
import org.jetbrains.kotlin.nj2k.toExpression
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.isArrayType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.replaceJavaClassWithKotlinClassType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.updateNullabilityRecursively
|
||||||
|
|
||||||
class AnnotationClassConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class AnnotationClassConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
@@ -19,14 +23,14 @@ class AnnotationClassConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
val javaAnnotationMethods =
|
val javaAnnotationMethods =
|
||||||
element.classBody.declarations
|
element.classBody.declarations
|
||||||
.filterIsInstance<JKJavaAnnotationMethod>()
|
.filterIsInstance<JKJavaAnnotationMethod>()
|
||||||
val constructor = JKKtPrimaryConstructorImpl(
|
val constructor = JKKtPrimaryConstructor(
|
||||||
JKNameIdentifierImpl(""),
|
JKNameIdentifier(""),
|
||||||
javaAnnotationMethods.map { it.asKotlinAnnotationParameter() },
|
javaAnnotationMethods.map { it.asKotlinAnnotationParameter() },
|
||||||
JKStubExpressionImpl(),
|
JKStubExpression(),
|
||||||
JKAnnotationListImpl(),
|
JKAnnotationList(),
|
||||||
emptyList(),
|
emptyList(),
|
||||||
JKVisibilityModifierElementImpl(Visibility.PUBLIC),
|
JKVisibilityModifierElement(Visibility.PUBLIC),
|
||||||
JKModalityModifierElementImpl(Modality.FINAL)
|
JKModalityModifierElement(Modality.FINAL)
|
||||||
)
|
)
|
||||||
element.modality = Modality.FINAL
|
element.modality = Modality.FINAL
|
||||||
element.classBody.declarations += constructor
|
element.classBody.declarations += constructor
|
||||||
@@ -34,24 +38,24 @@ class AnnotationClassConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
return recurse(element)
|
return recurse(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKJavaAnnotationMethod.asKotlinAnnotationParameter(): JKParameterImpl {
|
private fun JKJavaAnnotationMethod.asKotlinAnnotationParameter(): JKParameter {
|
||||||
val type = returnType.type
|
val type = returnType.type
|
||||||
.updateNullabilityRecursively(Nullability.NotNull)
|
.updateNullabilityRecursively(Nullability.NotNull)
|
||||||
.replaceJavaClassWithKotlinClassType(symbolProvider)
|
.replaceJavaClassWithKotlinClassType(symbolProvider)
|
||||||
val initializer = this::defaultValue.detached().toExpression(symbolProvider)
|
val initializer = this::defaultValue.detached().toExpression(symbolProvider)
|
||||||
val isVarArgs = type is JKJavaArrayType && name.value == "value"
|
val isVarArgs = type is JKJavaArrayType && name.value == "value"
|
||||||
return JKParameterImpl(
|
return JKParameter(
|
||||||
JKTypeElementImpl(
|
JKTypeElement(
|
||||||
if (!isVarArgs) type else (type as JKJavaArrayType).type
|
if (!isVarArgs) type else (type as JKJavaArrayType).type
|
||||||
),
|
),
|
||||||
JKNameIdentifierImpl(name.value),
|
JKNameIdentifier(name.value),
|
||||||
isVarArgs = isVarArgs,
|
isVarArgs = isVarArgs,
|
||||||
initializer =
|
initializer =
|
||||||
if (type.isArrayType()
|
if (type.isArrayType()
|
||||||
&& initializer !is JKKtAnnotationArrayInitializerExpression
|
&& initializer !is JKKtAnnotationArrayInitializerExpression
|
||||||
&& initializer !is JKStubExpression
|
&& initializer !is JKStubExpression
|
||||||
) {
|
) {
|
||||||
JKKtAnnotationArrayInitializerExpressionImpl(initializer)
|
JKKtAnnotationArrayInitializerExpression(initializer)
|
||||||
} else initializer
|
} else initializer
|
||||||
).also { parameter ->
|
).also { parameter ->
|
||||||
if (leftNonCodeElements.any { it is JKCommentElement }) {
|
if (leftNonCodeElements.any { it is JKCommentElement }) {
|
||||||
|
|||||||
@@ -12,10 +12,7 @@ import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
|||||||
import org.jetbrains.kotlin.nj2k.primaryConstructor
|
import org.jetbrains.kotlin.nj2k.primaryConstructor
|
||||||
import org.jetbrains.kotlin.nj2k.toExpression
|
import org.jetbrains.kotlin.nj2k.toExpression
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKAnnotationNameParameterImpl
|
import org.jetbrains.kotlin.nj2k.types.isArrayType
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKAnnotationParameterImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtAnnotationArrayInitializerExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKNameIdentifierImpl
|
|
||||||
|
|
||||||
class AnnotationConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class AnnotationConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
@@ -43,15 +40,15 @@ class AnnotationConversion(context: NewJ2kConverterContext) : RecursiveApplicabl
|
|||||||
&& annotation.isVarargsArgument(annotationParameter.name.value)
|
&& annotation.isVarargsArgument(annotationParameter.name.value)
|
||||||
&& annotationParameter.value !is JKKtAnnotationArrayInitializerExpression -> {
|
&& annotationParameter.value !is JKKtAnnotationArrayInitializerExpression -> {
|
||||||
listOf(
|
listOf(
|
||||||
JKAnnotationNameParameterImpl(
|
JKAnnotationNameParameter(
|
||||||
JKKtAnnotationArrayInitializerExpressionImpl(annotationParameter::value.detached()),
|
JKKtAnnotationArrayInitializerExpression(annotationParameter::value.detached()),
|
||||||
JKNameIdentifierImpl(annotationParameter.name.value)
|
JKNameIdentifier(annotationParameter.name.value)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
annotationParameter is JKAnnotationNameParameterImpl ->
|
annotationParameter is JKAnnotationNameParameter ->
|
||||||
listOf(
|
listOf(
|
||||||
JKAnnotationNameParameterImpl(
|
JKAnnotationNameParameter(
|
||||||
annotationParameter::value.detached(),
|
annotationParameter::value.detached(),
|
||||||
annotationParameter::name.detached()
|
annotationParameter::name.detached()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import org.jetbrains.kotlin.j2k.ast.Nullability
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.toArgumentList
|
import org.jetbrains.kotlin.nj2k.toArgumentList
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaPrimitiveType
|
|
||||||
import org.jetbrains.kotlin.resolve.CollectionLiteralResolver
|
import org.jetbrains.kotlin.resolve.CollectionLiteralResolver
|
||||||
|
|
||||||
|
|
||||||
@@ -27,9 +27,9 @@ class ArrayInitializerConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
else
|
else
|
||||||
CollectionLiteralResolver.ARRAY_OF_FUNCTION.asString()
|
CollectionLiteralResolver.ARRAY_OF_FUNCTION.asString()
|
||||||
val typeArguments =
|
val typeArguments =
|
||||||
if (primitiveArrayType == null) JKTypeArgumentListImpl(listOf(element::type.detached()))
|
if (primitiveArrayType == null) JKTypeArgumentList(listOf(element::type.detached()))
|
||||||
else JKTypeArgumentListImpl()
|
else JKTypeArgumentList()
|
||||||
newElement = JKJavaMethodCallExpressionImpl(
|
newElement = JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.$arrayConstructorName"),
|
symbolProvider.provideMethodSymbol("kotlin.$arrayConstructorName"),
|
||||||
element.initializer.also { element.initializer = emptyList() }.toArgumentList(),
|
element.initializer.also { element.initializer = emptyList() }.toArgumentList(),
|
||||||
typeArguments
|
typeArguments
|
||||||
@@ -46,33 +46,33 @@ class ArrayInitializerConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
private fun buildArrayInitializer(dimensions: List<JKExpression>, type: JKType): JKExpression {
|
private fun buildArrayInitializer(dimensions: List<JKExpression>, type: JKType): JKExpression {
|
||||||
if (dimensions.size == 1) {
|
if (dimensions.size == 1) {
|
||||||
return if (type !is JKJavaPrimitiveType) {
|
return if (type !is JKJavaPrimitiveType) {
|
||||||
JKJavaMethodCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.arrayOfNulls"),
|
symbolProvider.provideMethodSymbol("kotlin.arrayOfNulls"),
|
||||||
JKArgumentListImpl(dimensions[0]),
|
JKArgumentList(dimensions[0]),
|
||||||
JKTypeArgumentListImpl(listOf(JKTypeElementImpl(type)))
|
JKTypeArgumentList(listOf(JKTypeElement(type)))
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
JKJavaNewExpressionImpl(
|
JKNewExpression(
|
||||||
symbolProvider.provideClassSymbol(type.arrayFqName()),
|
symbolProvider.provideClassSymbol(type.arrayFqName()),
|
||||||
JKArgumentListImpl(dimensions[0]),
|
JKArgumentList(dimensions[0]),
|
||||||
JKTypeArgumentListImpl(emptyList())
|
JKTypeArgumentList(emptyList())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dimensions[1] !is JKStubExpression) {
|
if (dimensions[1] !is JKStubExpression) {
|
||||||
val arrayType = dimensions.drop(1).fold(type) { currentType, _ ->
|
val arrayType = dimensions.drop(1).fold(type) { currentType, _ ->
|
||||||
JKJavaArrayTypeImpl(currentType)
|
JKJavaArrayType(currentType)
|
||||||
}
|
}
|
||||||
return JKJavaNewExpressionImpl(
|
return JKNewExpression(
|
||||||
symbolProvider.provideClassSymbol("kotlin.Array"),
|
symbolProvider.provideClassSymbol("kotlin.Array"),
|
||||||
JKArgumentListImpl(
|
JKArgumentList(
|
||||||
dimensions[0],
|
dimensions[0],
|
||||||
JKLambdaExpressionImpl(
|
JKLambdaExpression(
|
||||||
JKExpressionStatementImpl(buildArrayInitializer(dimensions.subList(1, dimensions.size), type)),
|
JKExpressionStatement(buildArrayInitializer(dimensions.subList(1, dimensions.size), type)),
|
||||||
emptyList()
|
emptyList()
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
JKTypeArgumentListImpl(listOf(JKTypeElementImpl(arrayType)))
|
JKTypeArgumentList(listOf(JKTypeElement(arrayType)))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
var resultType = JKClassTypeImpl(
|
var resultType = JKClassTypeImpl(
|
||||||
@@ -87,10 +87,10 @@ class ArrayInitializerConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
Nullability.Default
|
Nullability.Default
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return JKJavaMethodCallExpressionImpl(
|
return JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.arrayOfNulls"),
|
symbolProvider.provideMethodSymbol("kotlin.arrayOfNulls"),
|
||||||
JKArgumentListImpl(dimensions[0]),
|
JKArgumentList(dimensions[0]),
|
||||||
JKTypeArgumentListImpl(listOf(JKTypeElementImpl(resultType)))
|
JKTypeArgumentList(listOf(JKTypeElement(resultType)))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,8 +13,9 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseFieldSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseFieldSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKFieldAccessExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.type
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ class ArrayOperationsConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
val selector = element.selector as? JKFieldAccessExpression ?: return recurse(element)
|
val selector = element.selector as? JKFieldAccessExpression ?: return recurse(element)
|
||||||
if (element.receiver.isArrayOrVarargTypeParameter() && selector.identifier.name == "length") {
|
if (element.receiver.isArrayOrVarargTypeParameter() && selector.identifier.name == "length") {
|
||||||
val sizeCall =
|
val sizeCall =
|
||||||
JKFieldAccessExpressionImpl(
|
JKFieldAccessExpression(
|
||||||
symbolProvider.provideFieldSymbol("kotlin.Array.size")
|
symbolProvider.provideFieldSymbol("kotlin.Array.size")
|
||||||
)
|
)
|
||||||
element.selector = sizeCall
|
element.selector = sizeCall
|
||||||
|
|||||||
@@ -7,12 +7,7 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.kotlinAssert
|
import org.jetbrains.kotlin.nj2k.kotlinAssert
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKJavaAssertStatement
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKStubExpression
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.detached
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKExpressionStatementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKLambdaExpressionImpl
|
|
||||||
|
|
||||||
|
|
||||||
class AssertStatementConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class AssertStatementConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -20,12 +15,12 @@ class AssertStatementConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
if (element !is JKJavaAssertStatement) return recurse(element)
|
if (element !is JKJavaAssertStatement) return recurse(element)
|
||||||
val messageExpression =
|
val messageExpression =
|
||||||
if (element.description is JKStubExpression) null
|
if (element.description is JKStubExpression) null
|
||||||
else JKLambdaExpressionImpl(
|
else JKLambdaExpression(
|
||||||
JKExpressionStatementImpl(element::description.detached()),
|
JKExpressionStatement(element::description.detached()),
|
||||||
emptyList()
|
emptyList()
|
||||||
)
|
)
|
||||||
return recurse(
|
return recurse(
|
||||||
JKExpressionStatementImpl(
|
JKExpressionStatement(
|
||||||
kotlinAssert(
|
kotlinAssert(
|
||||||
element::condition.detached(),
|
element::condition.detached(),
|
||||||
messageExpression,
|
messageExpression,
|
||||||
|
|||||||
+9
-11
@@ -6,9 +6,8 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.copyTreeAndDetach
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -57,7 +56,7 @@ class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) :
|
|||||||
val assignment = expression as? JKJavaAssignmentExpression ?: return null
|
val assignment = expression as? JKJavaAssignmentExpression ?: return null
|
||||||
return when {
|
return when {
|
||||||
canBeConvertedToBlock() && assignment.expression is JKJavaAssignmentExpression ->
|
canBeConvertedToBlock() && assignment.expression is JKJavaAssignmentExpression ->
|
||||||
JKBlockStatementImpl(JKBlockImpl(assignment.unfoldToStatementsList(assignmentTarget = null)))
|
JKBlockStatement(JKBlockImpl(assignment.unfoldToStatementsList(assignmentTarget = null)))
|
||||||
else -> createKtAssignmentStatement(
|
else -> createKtAssignmentStatement(
|
||||||
assignment::field.detached(),
|
assignment::field.detached(),
|
||||||
assignment::expression.detached(),
|
assignment::expression.detached(),
|
||||||
@@ -69,7 +68,6 @@ class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) :
|
|||||||
private fun JKExpressionStatement.canBeConvertedToBlock() = when (val parent = parent) {
|
private fun JKExpressionStatement.canBeConvertedToBlock() = when (val parent = parent) {
|
||||||
is JKLoopStatement -> parent.body == this
|
is JKLoopStatement -> parent.body == this
|
||||||
is JKIfElseStatement -> parent.thenBranch == this || parent.elseBranch == this
|
is JKIfElseStatement -> parent.thenBranch == this || parent.elseBranch == this
|
||||||
is JKIfStatement -> parent.thenBranch == this
|
|
||||||
is JKJavaSwitchCase -> true
|
is JKJavaSwitchCase -> true
|
||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
@@ -110,7 +108,7 @@ class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) :
|
|||||||
null -> statements
|
null -> statements
|
||||||
else -> {
|
else -> {
|
||||||
assignmentTarget.initializer = statements.last().field.copyTreeAndDetach()
|
assignmentTarget.initializer = statements.last().field.copyTreeAndDetach()
|
||||||
statements + JKDeclarationStatementImpl(listOf(assignmentTarget))
|
statements + JKDeclarationStatement(listOf(assignmentTarget))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,14 +116,14 @@ class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) :
|
|||||||
private fun JKJavaAssignmentExpression.toExpressionChainLink(receiver: JKExpression): JKExpression {
|
private fun JKJavaAssignmentExpression.toExpressionChainLink(receiver: JKExpression): JKExpression {
|
||||||
val assignment = createKtAssignmentStatement(
|
val assignment = createKtAssignmentStatement(
|
||||||
this::field.detached(),
|
this::field.detached(),
|
||||||
JKKtItExpressionImpl(operator.returnType),
|
JKKtItExpression(operator.returnType),
|
||||||
operator
|
operator
|
||||||
).withNonCodeElementsFrom(this)
|
).withNonCodeElementsFrom(this)
|
||||||
return when {
|
return when {
|
||||||
operator.isSimpleToken() ->
|
operator.isSimpleToken() ->
|
||||||
JKAssignmentChainAlsoLinkImpl(receiver, assignment, field.copyTreeAndDetach())
|
JKAssignmentChainAlsoLink(receiver, assignment, field.copyTreeAndDetach())
|
||||||
else ->
|
else ->
|
||||||
JKAssignmentChainLetLinkImpl(receiver, assignment, field.copyTreeAndDetach())
|
JKAssignmentChainLetLink(receiver, assignment, field.copyTreeAndDetach())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,9 +137,9 @@ class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) :
|
|||||||
operator: JKOperator
|
operator: JKOperator
|
||||||
) = when {
|
) = when {
|
||||||
operator.isOnlyJavaToken() ->
|
operator.isOnlyJavaToken() ->
|
||||||
JKKtAssignmentStatementImpl(
|
JKKtAssignmentStatement(
|
||||||
field,
|
field,
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
field.copyTreeAndDetach(),
|
field.copyTreeAndDetach(),
|
||||||
expression,
|
expression,
|
||||||
JKKtOperatorImpl(
|
JKKtOperatorImpl(
|
||||||
@@ -151,7 +149,7 @@ class AssignmentExpressionUnfoldingConversion(context: NewJ2kConverterContext) :
|
|||||||
),
|
),
|
||||||
JKOperatorToken.EQ
|
JKOperatorToken.EQ
|
||||||
)
|
)
|
||||||
else -> JKKtAssignmentStatementImpl(field, expression, operator.token)
|
else -> JKKtAssignmentStatement(field, expression, operator.token)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKOperator.isSimpleToken() = when {
|
private fun JKOperator.isSimpleToken() = when {
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
|
|
||||||
class BlockToRunConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class BlockToRunConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
@@ -19,15 +19,15 @@ class BlockToRunConversion(context: NewJ2kConverterContext) : RecursiveApplicabl
|
|||||||
if (parentDeclaration.psi == null) return recurse(element)
|
if (parentDeclaration.psi == null) return recurse(element)
|
||||||
|
|
||||||
element.invalidate()
|
element.invalidate()
|
||||||
val lambda = JKLambdaExpressionImpl(
|
val lambda = JKLambdaExpression(
|
||||||
JKBlockStatementImpl(element.block),
|
JKBlockStatement(element.block),
|
||||||
emptyList()
|
emptyList()
|
||||||
)
|
)
|
||||||
val call = JKKtCallExpressionImpl(
|
val call = JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.run"),
|
symbolProvider.provideMethodSymbol("kotlin.run"),
|
||||||
JKArgumentListImpl(lambda)
|
JKArgumentList(lambda)
|
||||||
)
|
)
|
||||||
return recurse(JKExpressionStatementImpl(call).withNonCodeElementsFrom(element))
|
return recurse(JKExpressionStatement(call).withNonCodeElementsFrom(element))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -7,29 +7,29 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKArgumentListImpl
|
import org.jetbrains.kotlin.nj2k.types.primitiveTypes
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtCallExpressionImpl
|
|
||||||
|
|
||||||
class BoxedTypeOperationsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class BoxedTypeOperationsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
return recurse(
|
return recurse(
|
||||||
when (element) {
|
when (element) {
|
||||||
is JKMethodCallExpression ->
|
is JKCallExpression ->
|
||||||
convertBoxedTypeUnwrapping(element)
|
convertBoxedTypeUnwrapping(element)
|
||||||
is JKJavaNewExpression -> convertCreationOfBoxedType(element)
|
is JKNewExpression -> convertCreationOfBoxedType(element)
|
||||||
else -> null
|
else -> null
|
||||||
} ?: element
|
} ?: element
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertCreationOfBoxedType(newExpression: JKJavaNewExpression): JKExpression? {
|
private fun convertCreationOfBoxedType(newExpression: JKNewExpression): JKExpression? {
|
||||||
if (newExpression.classSymbol.fqName !in boxedTypeFqNames) return null
|
if (newExpression.classSymbol.fqName !in boxedTypeFqNames) return null
|
||||||
val singleArgument = newExpression.arguments.arguments.singleOrNull() ?: return null
|
val singleArgument = newExpression.arguments.arguments.singleOrNull() ?: return null
|
||||||
return singleArgument::value.detached()
|
return singleArgument::value.detached()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun convertBoxedTypeUnwrapping(methodCallExpression: JKMethodCallExpression): JKExpression? {
|
private fun convertBoxedTypeUnwrapping(methodCallExpression: JKCallExpression): JKExpression? {
|
||||||
val (boxedJavaType, operationType) =
|
val (boxedJavaType, operationType) =
|
||||||
primitiveTypeUnwrapRegexp.matchEntire(methodCallExpression.identifier.fqName)
|
primitiveTypeUnwrapRegexp.matchEntire(methodCallExpression.identifier.fqName)
|
||||||
?.groupValues
|
?.groupValues
|
||||||
@@ -38,11 +38,11 @@ class BoxedTypeOperationsConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
} ?: return null
|
} ?: return null
|
||||||
val primitiveTypeName = boxedTypeToPrimitiveType[boxedJavaType] ?: return null
|
val primitiveTypeName = boxedTypeToPrimitiveType[boxedJavaType] ?: return null
|
||||||
if (operationType !in primitiveTypeNames) return null
|
if (operationType !in primitiveTypeNames) return null
|
||||||
return JKKtCallExpressionImpl(
|
return JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol(
|
symbolProvider.provideMethodSymbol(
|
||||||
"kotlin.${primitiveTypeName.capitalize()}.to${operationType.capitalize()}"
|
"kotlin.${primitiveTypeName.capitalize()}.to${operationType.capitalize()}"
|
||||||
),
|
),
|
||||||
JKArgumentListImpl()
|
JKArgumentList()
|
||||||
).withNonCodeElementsFrom(methodCallExpression)
|
).withNonCodeElementsFrom(methodCallExpression)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
|||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedField
|
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedField
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.deepestFqName
|
import org.jetbrains.kotlin.nj2k.symbols.deepestFqName
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.types.isArrayType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.isStringType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.type
|
||||||
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -52,7 +55,7 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun JKExpression.getConversion(): Conversion? = when (this) {
|
private fun JKExpression.getConversion(): Conversion? = when (this) {
|
||||||
is JKMethodCallExpression ->
|
is JKCallExpression ->
|
||||||
conversions[identifier.deepestFqName()]?.firstOrNull { conversion ->
|
conversions[identifier.deepestFqName()]?.firstOrNull { conversion ->
|
||||||
if (conversion.from !is Method) return@firstOrNull false
|
if (conversion.from !is Method) return@firstOrNull false
|
||||||
if (conversion.filter?.invoke(this) == false) return@firstOrNull false
|
if (conversion.filter?.invoke(this) == false) return@firstOrNull false
|
||||||
@@ -66,7 +69,7 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
is JKJavaNewExpression ->
|
is JKNewExpression ->
|
||||||
conversions[classSymbol.deepestFqName()]?.firstOrNull { conversion ->
|
conversions[classSymbol.deepestFqName()]?.firstOrNull { conversion ->
|
||||||
if (conversion.from !is NewExpression) return@firstOrNull false
|
if (conversion.from !is NewExpression) return@firstOrNull false
|
||||||
if (conversion.filter?.invoke(this) == false) return@firstOrNull false
|
if (conversion.filter?.invoke(this) == false) return@firstOrNull false
|
||||||
@@ -86,23 +89,23 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
) : ResultBuilder {
|
) : ResultBuilder {
|
||||||
override fun build(from: JKExpression): JKExpression =
|
override fun build(from: JKExpression): JKExpression =
|
||||||
when (from) {
|
when (from) {
|
||||||
is JKMethodCallExpression ->
|
is JKCallExpression ->
|
||||||
JKKtCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol(fqName),
|
symbolProvider.provideMethodSymbol(fqName),
|
||||||
argumentsProvider(from::arguments.detached()),
|
argumentsProvider(from::arguments.detached()),
|
||||||
from::typeArgumentList.detached()
|
from::typeArgumentList.detached()
|
||||||
).withNonCodeElementsFrom(from)
|
).withNonCodeElementsFrom(from)
|
||||||
is JKFieldAccessExpression ->
|
is JKFieldAccessExpression ->
|
||||||
JKKtCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol(fqName),
|
symbolProvider.provideMethodSymbol(fqName),
|
||||||
JKArgumentListImpl(),
|
JKArgumentList(),
|
||||||
JKTypeArgumentListImpl()
|
JKTypeArgumentList()
|
||||||
).withNonCodeElementsFrom(from)
|
).withNonCodeElementsFrom(from)
|
||||||
is JKJavaNewExpression ->
|
is JKNewExpression ->
|
||||||
JKKtCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol(fqName),
|
symbolProvider.provideMethodSymbol(fqName),
|
||||||
argumentsProvider(from::arguments.detached()),
|
argumentsProvider(from::arguments.detached()),
|
||||||
JKTypeArgumentListImpl()
|
JKTypeArgumentList()
|
||||||
).withNonCodeElementsFrom(from)
|
).withNonCodeElementsFrom(from)
|
||||||
else -> error("Bad conversion")
|
else -> error("Bad conversion")
|
||||||
}
|
}
|
||||||
@@ -113,12 +116,12 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
) : ResultBuilder {
|
) : ResultBuilder {
|
||||||
override fun build(from: JKExpression): JKExpression =
|
override fun build(from: JKExpression): JKExpression =
|
||||||
when (from) {
|
when (from) {
|
||||||
is JKMethodCallExpression ->
|
is JKCallExpression ->
|
||||||
JKFieldAccessExpressionImpl(
|
JKFieldAccessExpression(
|
||||||
symbolProvider.provideFieldSymbol(fqName)
|
symbolProvider.provideFieldSymbol(fqName)
|
||||||
).withNonCodeElementsFrom(from)
|
).withNonCodeElementsFrom(from)
|
||||||
is JKFieldAccessExpression ->
|
is JKFieldAccessExpression ->
|
||||||
JKFieldAccessExpressionImpl(
|
JKFieldAccessExpression(
|
||||||
symbolProvider.provideFieldSymbol(fqName)
|
symbolProvider.provideFieldSymbol(fqName)
|
||||||
).withNonCodeElementsFrom(from)
|
).withNonCodeElementsFrom(from)
|
||||||
else -> error("Bad conversion")
|
else -> error("Bad conversion")
|
||||||
@@ -130,14 +133,13 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
) : ResultBuilder {
|
) : ResultBuilder {
|
||||||
override fun build(from: JKExpression): JKExpression =
|
override fun build(from: JKExpression): JKExpression =
|
||||||
when (from) {
|
when (from) {
|
||||||
is JKMethodCallExpression -> {
|
is JKCallExpression -> {
|
||||||
val arguments = from.arguments::arguments.detached()
|
val arguments = from.arguments::arguments.detached()
|
||||||
JKQualifiedExpressionImpl(
|
JKQualifiedExpression(
|
||||||
arguments.first()::value.detached().parenthesizeIfBinaryExpression(),
|
arguments.first()::value.detached().parenthesizeIfBinaryExpression(),
|
||||||
JKKtQualifierImpl.DOT,
|
JKCallExpressionImpl(
|
||||||
JKKtCallExpressionImpl(
|
|
||||||
symbolProvider.provideMethodSymbol(fqName),
|
symbolProvider.provideMethodSymbol(fqName),
|
||||||
JKArgumentListImpl(arguments.drop(1)),
|
JKArgumentList(arguments.drop(1)),
|
||||||
from::typeArgumentList.detached()
|
from::typeArgumentList.detached()
|
||||||
)
|
)
|
||||||
).withNonCodeElementsFrom(from)
|
).withNonCodeElementsFrom(from)
|
||||||
@@ -247,9 +249,9 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
convertTo Method("kotlin.collections.toTypedArray")
|
convertTo Method("kotlin.collections.toTypedArray")
|
||||||
withByArgumentsFilter {
|
withByArgumentsFilter {
|
||||||
it.singleOrNull()?.let { parameter ->
|
it.singleOrNull()?.let { parameter ->
|
||||||
parameter.safeAs<JKMethodCallExpression>()?.identifier?.fqName == "kotlin.arrayOfNulls"
|
parameter.safeAs<JKCallExpression>()?.identifier?.fqName == "kotlin.arrayOfNulls"
|
||||||
} == true
|
} == true
|
||||||
} withArgumentsProvider { JKArgumentListImpl() },
|
} withArgumentsProvider { JKArgumentList() },
|
||||||
|
|
||||||
Method("java.util.List.remove") convertTo Method("kotlin.collections.MutableCollection.removeAt"),
|
Method("java.util.List.remove") convertTo Method("kotlin.collections.MutableCollection.removeAt"),
|
||||||
Method("java.util.Map.Entry.getKey") convertTo Field("kotlin.collections.Map.Entry.key"),
|
Method("java.util.Map.Entry.getKey") convertTo Field("kotlin.collections.Map.Entry.key"),
|
||||||
@@ -269,11 +271,11 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
withByArgumentsFilter { it.singleOrNull()?.type(typeFactory)?.isStringType() == true }
|
withByArgumentsFilter { it.singleOrNull()?.type(typeFactory)?.isStringType() == true }
|
||||||
withArgumentsProvider { arguments ->
|
withArgumentsProvider { arguments ->
|
||||||
val argument = arguments.arguments.single()::value.detached()
|
val argument = arguments.arguments.single()::value.detached()
|
||||||
val call = JKKtCallExpressionImpl(
|
val call = JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.text.charset"),
|
symbolProvider.provideMethodSymbol("kotlin.text.charset"),
|
||||||
JKArgumentListImpl(argument)
|
JKArgumentList(argument)
|
||||||
)
|
)
|
||||||
JKArgumentListImpl(call)
|
JKArgumentList(call)
|
||||||
},
|
},
|
||||||
Method("java.lang.String.getBytes") convertTo Method("kotlin.text.toByteArray"),
|
Method("java.lang.String.getBytes") convertTo Method("kotlin.text.toByteArray"),
|
||||||
Method("java.lang.String.valueOf")
|
Method("java.lang.String.valueOf")
|
||||||
@@ -289,7 +291,7 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
val srcEndArgument = argumentList.arguments[1]::value.detached()
|
val srcEndArgument = argumentList.arguments[1]::value.detached()
|
||||||
val dstArgument = argumentList.arguments[2]::value.detached()
|
val dstArgument = argumentList.arguments[2]::value.detached()
|
||||||
val dstBeginArgument = argumentList.arguments[3]::value.detached()
|
val dstBeginArgument = argumentList.arguments[3]::value.detached()
|
||||||
JKArgumentListImpl(dstArgument, dstBeginArgument, srcBeginArgument, srcEndArgument)
|
JKArgumentList(dstArgument, dstBeginArgument, srcBeginArgument, srcEndArgument)
|
||||||
},
|
},
|
||||||
|
|
||||||
Method("java.lang.String.valueOf")
|
Method("java.lang.String.valueOf")
|
||||||
@@ -310,7 +312,7 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
detachedArguments.first()::value.detached().callOn(
|
detachedArguments.first()::value.detached().callOn(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.text.toRegex")
|
symbolProvider.provideMethodSymbol("kotlin.text.toRegex")
|
||||||
)
|
)
|
||||||
JKArgumentListImpl(listOf(JKArgumentImpl(first)) + detachedArguments.drop(1))
|
JKArgumentList(listOf(JKArgumentImpl(first)) + detachedArguments.drop(1))
|
||||||
},
|
},
|
||||||
Method("java.lang.String.replaceFirst")
|
Method("java.lang.String.replaceFirst")
|
||||||
convertTo Method("kotlin.text.replaceFirst")
|
convertTo Method("kotlin.text.replaceFirst")
|
||||||
@@ -321,15 +323,15 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
symbolProvider.provideMethodSymbol("kotlin.text.toRegex")
|
symbolProvider.provideMethodSymbol("kotlin.text.toRegex")
|
||||||
|
|
||||||
)
|
)
|
||||||
JKArgumentListImpl(listOf(JKArgumentImpl(first)) + detachedArguments.drop(1))
|
JKArgumentList(listOf(JKArgumentImpl(first)) + detachedArguments.drop(1))
|
||||||
},
|
},
|
||||||
Method("java.lang.String.equalsIgnoreCase")
|
Method("java.lang.String.equalsIgnoreCase")
|
||||||
convertTo Method("kotlin.text.equals")
|
convertTo Method("kotlin.text.equals")
|
||||||
withArgumentsProvider { arguments ->
|
withArgumentsProvider { arguments ->
|
||||||
JKArgumentListImpl(
|
JKArgumentList(
|
||||||
arguments::arguments.detached() + JKNamedArgumentImpl(
|
arguments::arguments.detached() + JKNamedArgument(
|
||||||
JKBooleanLiteral(true),
|
JKLiteralExpression("true", JKLiteralExpression.LiteralType.BOOLEAN),
|
||||||
JKNameIdentifierImpl("ignoreCase")
|
JKNameIdentifier("ignoreCase")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -337,10 +339,10 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
Method("java.lang.String.compareToIgnoreCase")
|
Method("java.lang.String.compareToIgnoreCase")
|
||||||
convertTo Method("kotlin.text.compareTo")
|
convertTo Method("kotlin.text.compareTo")
|
||||||
withArgumentsProvider { arguments ->
|
withArgumentsProvider { arguments ->
|
||||||
JKArgumentListImpl(
|
JKArgumentList(
|
||||||
arguments::arguments.detached() + JKNamedArgumentImpl(
|
arguments::arguments.detached() + JKNamedArgument(
|
||||||
JKBooleanLiteral(true),
|
JKLiteralExpression("true", JKLiteralExpression.LiteralType.BOOLEAN),
|
||||||
JKNameIdentifierImpl("ignoreCase")
|
JKNameIdentifier("ignoreCase")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -350,22 +352,22 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
withByArgumentsFilter { it.size == 5 }
|
withByArgumentsFilter { it.size == 5 }
|
||||||
withArgumentsProvider { arguments ->
|
withArgumentsProvider { arguments ->
|
||||||
val detachedArguments = arguments::arguments.detached()
|
val detachedArguments = arguments::arguments.detached()
|
||||||
JKArgumentListImpl(
|
JKArgumentList(
|
||||||
detachedArguments.drop(1) + JKNamedArgumentImpl(
|
detachedArguments.drop(1) + JKNamedArgument(
|
||||||
detachedArguments.first()::value.detached().also {
|
detachedArguments.first()::value.detached().also {
|
||||||
it.clearNonCodeElements()
|
it.clearNonCodeElements()
|
||||||
},
|
},
|
||||||
JKNameIdentifierImpl("ignoreCase")
|
JKNameIdentifier("ignoreCase")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
Method("java.lang.String.concat") convertTo
|
Method("java.lang.String.concat") convertTo
|
||||||
CustomExpression { expression ->
|
CustomExpression { expression ->
|
||||||
if (expression !is JKMethodCallExpression) error("Expression should be JKMethodCallExpression")
|
if (expression !is JKCallExpression) error("Expression should be JKCallExpression")
|
||||||
val firstArgument = expression.parent.cast<JKQualifiedExpression>()::receiver.detached()
|
val firstArgument = expression.parent.cast<JKQualifiedExpression>()::receiver.detached()
|
||||||
val secondArgument = expression.arguments.arguments.first()::value.detached()
|
val secondArgument = expression.arguments.arguments.first()::value.detached()
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
firstArgument,
|
firstArgument,
|
||||||
secondArgument,
|
secondArgument,
|
||||||
JKKtOperatorImpl(JKOperatorToken.PLUS, typeFactory.types.possiblyNullString)
|
JKKtOperatorImpl(JKOperatorToken.PLUS, typeFactory.types.possiblyNullString)
|
||||||
@@ -378,7 +380,7 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
andAfter { expression ->
|
andAfter { expression ->
|
||||||
val arguments =
|
val arguments =
|
||||||
expression.cast<JKQualifiedExpression>()
|
expression.cast<JKQualifiedExpression>()
|
||||||
.selector.cast<JKMethodCallExpression>()
|
.selector.cast<JKCallExpression>()
|
||||||
.arguments
|
.arguments
|
||||||
val limitArgument = arguments.arguments[1].value
|
val limitArgument = arguments.arguments[1].value
|
||||||
val limit = limitArgument.asLiteralTextWithPrefix()?.toIntOrNull()
|
val limit = limitArgument.asLiteralTextWithPrefix()?.toIntOrNull()
|
||||||
@@ -391,8 +393,8 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
}.callOn(
|
}.callOn(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.collections.dropLastWhile"),
|
symbolProvider.provideMethodSymbol("kotlin.collections.dropLastWhile"),
|
||||||
listOf(
|
listOf(
|
||||||
JKLambdaExpressionImpl(
|
JKLambdaExpression(
|
||||||
JKFieldAccessExpressionImpl(
|
JKFieldAccessExpression(
|
||||||
JKUnresolvedField(//TODO replace with `it` parameter
|
JKUnresolvedField(//TODO replace with `it` parameter
|
||||||
"it",
|
"it",
|
||||||
typeFactory
|
typeFactory
|
||||||
@@ -407,7 +409,7 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
val lastArgument = arguments.arguments.last().value.copyTreeAndDetach()
|
val lastArgument = arguments.arguments.last().value.copyTreeAndDetach()
|
||||||
.callOn(
|
.callOn(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.ranges.coerceAtLeast"),
|
symbolProvider.provideMethodSymbol("kotlin.ranges.coerceAtLeast"),
|
||||||
listOf(JKKtLiteralExpressionImpl("0", JKLiteralExpression.LiteralType.INT))
|
listOf(JKLiteralExpression("0", JKLiteralExpression.LiteralType.INT))
|
||||||
)
|
)
|
||||||
arguments.arguments = arguments.arguments.dropLast(1) + JKArgumentImpl(lastArgument)
|
arguments.arguments = arguments.arguments.dropLast(1) + JKArgumentImpl(lastArgument)
|
||||||
}
|
}
|
||||||
@@ -422,17 +424,17 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
Method("java.lang.String.trim")
|
Method("java.lang.String.trim")
|
||||||
convertTo Method("kotlin.text.trim")
|
convertTo Method("kotlin.text.trim")
|
||||||
withArgumentsProvider {
|
withArgumentsProvider {
|
||||||
JKArgumentListImpl(
|
JKArgumentList(
|
||||||
JKLambdaExpressionImpl(
|
JKLambdaExpression(
|
||||||
JKExpressionStatementImpl(
|
JKExpressionStatement(
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
JKFieldAccessExpressionImpl(
|
JKFieldAccessExpression(
|
||||||
JKUnresolvedField(//TODO replace with `it` parameter
|
JKUnresolvedField(//TODO replace with `it` parameter
|
||||||
"it",
|
"it",
|
||||||
typeFactory
|
typeFactory
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
JKKtLiteralExpressionImpl("' '", JKLiteralExpression.LiteralType.CHAR),
|
JKLiteralExpression("' '", JKLiteralExpression.LiteralType.CHAR),
|
||||||
JKKtOperatorImpl(
|
JKKtOperatorImpl(
|
||||||
JKOperatorToken.LTEQ,
|
JKOperatorToken.LTEQ,
|
||||||
typeFactory.types.boolean
|
typeFactory.types.boolean
|
||||||
@@ -444,11 +446,11 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
Method("java.lang.String.format") convertTo CustomExpression { expression ->
|
Method("java.lang.String.format") convertTo CustomExpression { expression ->
|
||||||
JKClassAccessExpressionImpl(
|
JKClassAccessExpression(
|
||||||
symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.string)
|
symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.string)
|
||||||
).callOn(
|
).callOn(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.text.String.format"),
|
symbolProvider.provideMethodSymbol("kotlin.text.String.format"),
|
||||||
(expression as JKMethodCallExpression).arguments::arguments.detached()
|
(expression as JKCallExpression).arguments::arguments.detached()
|
||||||
)
|
)
|
||||||
} withReplaceType ReplaceType.REPLACE_WITH_QUALIFIER,
|
} withReplaceType ReplaceType.REPLACE_WITH_QUALIFIER,
|
||||||
|
|
||||||
@@ -469,13 +471,12 @@ class BuiltinMembersConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
|
|
||||||
|
|
||||||
private fun JKExpression.callOn(symbol: JKMethodSymbol, arguments: List<JKArgument> = emptyList()) =
|
private fun JKExpression.callOn(symbol: JKMethodSymbol, arguments: List<JKArgument> = emptyList()) =
|
||||||
JKQualifiedExpressionImpl(
|
JKQualifiedExpression(
|
||||||
this,
|
this,
|
||||||
JKKtQualifierImpl.DOT,
|
JKCallExpressionImpl(
|
||||||
JKKtCallExpressionImpl(
|
|
||||||
symbol,
|
symbol,
|
||||||
JKArgumentListImpl(arguments),
|
JKArgumentList(arguments),
|
||||||
JKTypeArgumentListImpl()
|
JKTypeArgumentList()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -6,12 +6,11 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.declarationList
|
||||||
import org.jetbrains.kotlin.nj2k.getCompanion
|
import org.jetbrains.kotlin.nj2k.getCompanion
|
||||||
|
import org.jetbrains.kotlin.nj2k.psi
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKAnnotationListImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKClassImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKModalityModifierElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.psi
|
|
||||||
|
|
||||||
class ClassToObjectPromotionConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class ClassToObjectPromotionConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
@@ -37,7 +36,7 @@ class ClassToObjectPromotionConversion(context: NewJ2kConverterContext) : Recurs
|
|||||||
companion.invalidate()
|
companion.invalidate()
|
||||||
element.invalidate()
|
element.invalidate()
|
||||||
return recurse(
|
return recurse(
|
||||||
JKClassImpl(
|
JKClass(
|
||||||
element.name,
|
element.name,
|
||||||
element.inheritance,
|
element.inheritance,
|
||||||
JKClass.ClassKind.OBJECT,
|
JKClass.ClassKind.OBJECT,
|
||||||
@@ -49,10 +48,10 @@ class ClassToObjectPromotionConversion(context: NewJ2kConverterContext) : Recurs
|
|||||||
it is JKClass && it.classKind != JKClass.ClassKind.COMPANION
|
it is JKClass && it.classKind != JKClass.ClassKind.COMPANION
|
||||||
}.map { it.detached(element.classBody) }
|
}.map { it.detached(element.classBody) }
|
||||||
},
|
},
|
||||||
JKAnnotationListImpl(),
|
JKAnnotationList(),
|
||||||
element.otherModifierElements,
|
element.otherModifierElements,
|
||||||
element.visibilityElement,
|
element.visibilityElement,
|
||||||
JKModalityModifierElementImpl(Modality.FINAL)
|
JKModalityModifierElement(Modality.FINAL)
|
||||||
).withNonCodeElementsFrom(element)
|
).withNonCodeElementsFrom(element)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
|||||||
import org.jetbrains.kotlin.nj2k.symbols.JKSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.fqNameToImport
|
import org.jetbrains.kotlin.nj2k.symbols.fqNameToImport
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -24,9 +25,9 @@ class CollectImportsConversion(context: NewJ2kConverterContext) : RecursiveAppli
|
|||||||
when (element) {
|
when (element) {
|
||||||
is JKClassAccessExpression -> addSymbol(element.identifier)
|
is JKClassAccessExpression -> addSymbol(element.identifier)
|
||||||
is JKFieldAccessExpression -> addSymbol(element.identifier)
|
is JKFieldAccessExpression -> addSymbol(element.identifier)
|
||||||
is JKMethodCallExpression -> addSymbol(element.identifier)
|
is JKCallExpression -> addSymbol(element.identifier)
|
||||||
is JKAnnotation -> addSymbol(element.classSymbol)
|
is JKAnnotation -> addSymbol(element.classSymbol)
|
||||||
is JKJavaNewExpression -> addSymbol(element.classSymbol)
|
is JKNewExpression -> addSymbol(element.classSymbol)
|
||||||
is JKInheritanceInfo -> {
|
is JKInheritanceInfo -> {
|
||||||
element.implements
|
element.implements
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,18 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKStubExpressionImpl
|
|
||||||
|
|
||||||
class ConstructorConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class ConstructorConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaMethod) return recurse(element)
|
if (element !is JKMethod) return recurse(element)
|
||||||
val outerClass = element.parentOfType<JKClass>() ?: return recurse(element)
|
val outerClass = element.parentOfType<JKClass>() ?: return recurse(element)
|
||||||
if (element.name.value != outerClass.name.value) return recurse(element)
|
if (element.name.value != outerClass.name.value) return recurse(element)
|
||||||
|
|
||||||
element.invalidate()
|
element.invalidate()
|
||||||
val delegationCall = lookupDelegationCall(element.block) ?: JKStubExpressionImpl()
|
val delegationCall = lookupDelegationCall(element.block) ?: JKStubExpression()
|
||||||
|
|
||||||
return JKKtConstructorImpl(
|
return JKConstructorImpl(
|
||||||
element.name,
|
element.name,
|
||||||
element.parameters,
|
element.parameters,
|
||||||
element.block,
|
element.block,
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.nj2k.*
|
import org.jetbrains.kotlin.nj2k.*
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseMethodSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseMethodSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKFieldAccessExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.psi
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class DefaultArgumentsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class DefaultArgumentsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -98,7 +98,7 @@ class DefaultArgumentsConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
if (target is JKParameter) {
|
if (target is JKParameter) {
|
||||||
val newSymbol =
|
val newSymbol =
|
||||||
symbolProvider.provideUniverseSymbol(calledMethod.parameters[method.parameters.indexOf(target)])
|
symbolProvider.provideUniverseSymbol(calledMethod.parameters[method.parameters.indexOf(target)])
|
||||||
return JKFieldAccessExpressionImpl(newSymbol)
|
return JKFieldAccessExpression(newSymbol)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,13 +109,14 @@ class DefaultArgumentsConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
element.declarations -= method
|
element.declarations -= method
|
||||||
calledMethod.withNonCodeElementsFrom(method)
|
calledMethod.withNonCodeElementsFrom(method)
|
||||||
}
|
}
|
||||||
|
if (element.parentOfType<JKClass>()?.classKind != JKClass.ClassKind.ANNOTATION) {
|
||||||
for (method in element.declarations) {
|
for (method in element.declarations) {
|
||||||
if (method !is JKJavaMethod) continue
|
if (method !is JKMethod) continue
|
||||||
if (method.hasParametersWithDefaultValues()
|
if (method.hasParametersWithDefaultValues()
|
||||||
&& (method.visibility == Visibility.PUBLIC || method.visibility == Visibility.INTERNAL)
|
&& (method.visibility == Visibility.PUBLIC || method.visibility == Visibility.INTERNAL)
|
||||||
) {
|
) {
|
||||||
method.annotationList.annotations += jvmAnnotation("JvmOverloads", symbolProvider)
|
method.annotationList.annotations += jvmAnnotation("JvmOverloads", symbolProvider)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,11 +129,11 @@ class DefaultArgumentsConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
if (first is JKNameIdentifier && second is JKNameIdentifier) return first.value == second.value
|
if (first is JKNameIdentifier && second is JKNameIdentifier) return first.value == second.value
|
||||||
if (first is JKLiteralExpression && second is JKLiteralExpression) return first.literal == second.literal
|
if (first is JKLiteralExpression && second is JKLiteralExpression) return first.literal == second.literal
|
||||||
if (first is JKFieldAccessExpression && second is JKFieldAccessExpression && first.identifier != second.identifier) return false
|
if (first is JKFieldAccessExpression && second is JKFieldAccessExpression && first.identifier != second.identifier) return false
|
||||||
if (first is JKMethodCallExpression && second is JKMethodCallExpression && first.identifier != second.identifier) return false
|
if (first is JKCallExpression && second is JKCallExpression && first.identifier != second.identifier) return false
|
||||||
return if (first is JKBranchElement && second is JKBranchElement) {
|
return if (first is JKTreeElement && second is JKTreeElement) {
|
||||||
first.children.zip(second.children) { childOfFirst, childOfSecond ->
|
first.children.zip(second.children) { childOfFirst, childOfSecond ->
|
||||||
when {
|
when {
|
||||||
childOfFirst is JKBranchElement && childOfSecond is JKBranchElement -> {
|
childOfFirst is JKTreeElement && childOfSecond is JKTreeElement -> {
|
||||||
areTheSameExpressions(
|
areTheSameExpressions(
|
||||||
childOfFirst,
|
childOfFirst,
|
||||||
childOfSecond
|
childOfSecond
|
||||||
@@ -155,14 +156,14 @@ class DefaultArgumentsConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
private fun JKMethod.hasParametersWithDefaultValues() =
|
private fun JKMethod.hasParametersWithDefaultValues() =
|
||||||
parameters.any { it.initializer !is JKStubExpression }
|
parameters.any { it.initializer !is JKStubExpression }
|
||||||
|
|
||||||
private fun lookupCall(statement: JKStatement): JKMethodCallExpression? {
|
private fun lookupCall(statement: JKStatement): JKCallExpression? {
|
||||||
val expression = when (statement) {
|
val expression = when (statement) {
|
||||||
is JKExpressionStatement -> statement.expression
|
is JKExpressionStatement -> statement.expression
|
||||||
is JKReturnStatement -> statement.expression
|
is JKReturnStatement -> statement.expression
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
return when (expression) {
|
return when (expression) {
|
||||||
is JKMethodCallExpression -> expression
|
is JKCallExpression -> expression
|
||||||
is JKQualifiedExpression -> {
|
is JKQualifiedExpression -> {
|
||||||
if (expression.receiver !is JKThisExpression) return null
|
if (expression.receiver !is JKThisExpression) return null
|
||||||
expression.selector.safeAs()
|
expression.selector.safeAs()
|
||||||
@@ -170,5 +171,4 @@ class DefaultArgumentsConversion(context: NewJ2kConverterContext) : RecursiveApp
|
|||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ import com.intellij.psi.PsiEnumConstant
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.*
|
import org.jetbrains.kotlin.nj2k.symbols.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKClassAccessExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKFieldAccessExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtQualifierImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKQualifiedExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
||||||
|
|
||||||
|
|
||||||
@@ -23,10 +21,9 @@ class EnumFieldAccessConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
val enumsClassSymbol = element.identifier.enumClassSymbol() ?: return recurse(element)
|
val enumsClassSymbol = element.identifier.enumClassSymbol() ?: return recurse(element)
|
||||||
|
|
||||||
return recurse(
|
return recurse(
|
||||||
JKQualifiedExpressionImpl(
|
JKQualifiedExpression(
|
||||||
JKClassAccessExpressionImpl(enumsClassSymbol),
|
JKClassAccessExpression(enumsClassSymbol),
|
||||||
JKKtQualifierImpl.DOT,
|
JKFieldAccessExpression(element.identifier)
|
||||||
JKFieldAccessExpressionImpl(element.identifier)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,17 +9,17 @@ import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
|||||||
import org.jetbrains.kotlin.nj2k.equalsExpression
|
import org.jetbrains.kotlin.nj2k.equalsExpression
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.deepestFqName
|
import org.jetbrains.kotlin.nj2k.symbols.deepestFqName
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKParenthesizedExpressionImpl
|
|
||||||
|
|
||||||
class EqualsOperatorConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class EqualsOperatorConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKQualifiedExpression) return recurse(element)
|
if (element !is JKQualifiedExpression) return recurse(element)
|
||||||
if (element.receiver is JKSuperExpression) return recurse(element)
|
if (element.receiver is JKSuperExpression) return recurse(element)
|
||||||
val selector = element.selector as? JKMethodCallExpression ?: return (element)
|
val selector = element.selector as? JKCallExpression ?: return (element)
|
||||||
val argument = selector.arguments.arguments.singleOrNull() ?: return recurse(element)
|
val argument = selector.arguments.arguments.singleOrNull() ?: return recurse(element)
|
||||||
if (selector.identifier.deepestFqName() == "java.lang.Object.equals") {
|
if (selector.identifier.deepestFqName() == "java.lang.Object.equals") {
|
||||||
return recurse(
|
return recurse(
|
||||||
JKParenthesizedExpressionImpl(
|
JKParenthesizedExpression(
|
||||||
equalsExpression(
|
equalsExpression(
|
||||||
element::receiver.detached(),
|
element::receiver.detached(),
|
||||||
argument::value.detached(),
|
argument::value.detached(),
|
||||||
|
|||||||
@@ -7,31 +7,13 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
|
|
||||||
class FieldToPropertyConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
|
||||||
|
class FieldToPropertyConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaField) return recurse(element)
|
if (element !is JKField) return recurse(element)
|
||||||
element.invalidate()
|
element.mutability = if (element.modality == Modality.FINAL) Mutability.IMMUTABLE else Mutability.MUTABLE
|
||||||
val mutability =
|
element.modality = Modality.FINAL
|
||||||
if (element.modality == Modality.FINAL) Mutability.IMMUTABLE
|
return recurse(element)
|
||||||
else Mutability.MUTABLE
|
|
||||||
return recurse(
|
|
||||||
JKKtPropertyImpl(
|
|
||||||
element.type,
|
|
||||||
element.name,
|
|
||||||
element.initializer,
|
|
||||||
JKKtEmptyGetterOrSetterImpl(),
|
|
||||||
JKKtEmptyGetterOrSetterImpl(),
|
|
||||||
element.annotationList,
|
|
||||||
element.otherModifierElements,
|
|
||||||
element.visibilityElement,
|
|
||||||
JKModalityModifierElementImpl(Modality.FINAL),
|
|
||||||
JKMutabilityModifierElementImpl(mutability).withNonCodeElementsFrom(element.modalityElement)
|
|
||||||
).also {
|
|
||||||
it.psi = element.psi
|
|
||||||
it.takeNonCodeElementsFrom(element)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
|||||||
import org.jetbrains.kotlin.nj2k.tree.JKImportList
|
import org.jetbrains.kotlin.nj2k.tree.JKImportList
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
|
|
||||||
|
|
||||||
class FilterImportsConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class FilterImportsConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKImportList) return recurse(element)
|
if (element !is JKImportList) return recurse(element)
|
||||||
|
|||||||
@@ -13,8 +13,11 @@ import org.jetbrains.kotlin.lexer.KtTokens
|
|||||||
import org.jetbrains.kotlin.nj2k.*
|
import org.jetbrains.kotlin.nj2k.*
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.deepestFqName
|
import org.jetbrains.kotlin.nj2k.symbols.deepestFqName
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKJavaPrimitiveType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKNoTypeImpl
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.type
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
|
|
||||||
|
|
||||||
@@ -35,23 +38,23 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
val whileBody = createWhileBody(loopStatement)
|
val whileBody = createWhileBody(loopStatement)
|
||||||
val condition =
|
val condition =
|
||||||
if (loopStatement.condition !is JKStubExpression) loopStatement::condition.detached()
|
if (loopStatement.condition !is JKStubExpression) loopStatement::condition.detached()
|
||||||
else JKBooleanLiteral(true)
|
else JKLiteralExpression("true", JKLiteralExpression.LiteralType.BOOLEAN)
|
||||||
val whileStatement = JKWhileStatementImpl(condition, whileBody)
|
val whileStatement = JKWhileStatement(condition, whileBody)
|
||||||
|
|
||||||
if (loopStatement.initializer is JKEmptyStatement) return whileStatement
|
if (loopStatement.initializer is JKEmptyStatement) return whileStatement
|
||||||
|
|
||||||
val convertedFromForLoopSyntheticWhileStatement =
|
val convertedFromForLoopSyntheticWhileStatement =
|
||||||
JKKtConvertedFromForLoopSyntheticWhileStatementImpl(
|
JKKtConvertedFromForLoopSyntheticWhileStatement(
|
||||||
loopStatement::initializer.detached(),
|
loopStatement::initializer.detached(),
|
||||||
whileStatement
|
whileStatement
|
||||||
)
|
)
|
||||||
|
|
||||||
val notNeedParentBlock = loopStatement.parent is JKBlock
|
val notNeedParentBlock = loopStatement.parent is JKBlock
|
||||||
|| loopStatement.parent is JKLabeledStatement && loopStatement.parent?.parent is JKBlock
|
|| loopStatement.parent is JKLabeledExpression && loopStatement.parent?.parent is JKBlock
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
loopStatement.hasNameConflict() ->
|
loopStatement.hasNameConflict() ->
|
||||||
JKExpressionStatementImpl(
|
JKExpressionStatement(
|
||||||
runExpression(
|
runExpression(
|
||||||
convertedFromForLoopSyntheticWhileStatement,
|
convertedFromForLoopSyntheticWhileStatement,
|
||||||
symbolProvider
|
symbolProvider
|
||||||
@@ -71,8 +74,8 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
if (elementPsi.findContinuedStatement()?.toContinuedLoop() != loopStatement.psi<PsiForStatement>()) return recurse(element)
|
if (elementPsi.findContinuedStatement()?.toContinuedLoop() != loopStatement.psi<PsiForStatement>()) return recurse(element)
|
||||||
val statements = loopStatement.updaters.map { it.copyTreeAndDetach() } + element.copyTreeAndDetach()
|
val statements = loopStatement.updaters.map { it.copyTreeAndDetach() } + element.copyTreeAndDetach()
|
||||||
return if (element.parent is JKBlock)
|
return if (element.parent is JKBlock)
|
||||||
JKBlockStatementWithoutBracketsImpl(statements)
|
JKBlockStatementWithoutBrackets(statements)
|
||||||
else JKBlockStatementImpl(JKBlockImpl(statements))
|
else JKBlockStatement(JKBlockImpl(statements))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,15 +94,15 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
|
|
||||||
val statements =
|
val statements =
|
||||||
if (hasNameConflict) {
|
if (hasNameConflict) {
|
||||||
listOf(JKExpressionStatementImpl(runExpression(body, symbolProvider))) + loopStatement::updaters.detached()
|
listOf(JKExpressionStatement(runExpression(body, symbolProvider))) + loopStatement::updaters.detached()
|
||||||
} else {
|
} else {
|
||||||
body.block::statements.detached() + loopStatement::updaters.detached()
|
body.block::statements.detached() + loopStatement::updaters.detached()
|
||||||
}
|
}
|
||||||
return JKBlockStatementImpl(JKBlockImpl(statements))
|
return JKBlockStatement(JKBlockImpl(statements))
|
||||||
} else {
|
} else {
|
||||||
val statements =
|
val statements =
|
||||||
listOf(body as JKStatement) + loopStatement::updaters.detached()
|
listOf(body as JKStatement) + loopStatement::updaters.detached()
|
||||||
return JKBlockStatementImpl(JKBlockImpl(statements))
|
return JKBlockStatement(JKBlockImpl(statements))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,15 +139,15 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
val range = forIterationRange(start, right, reversed, inclusive, loopVarPsi)
|
val range = forIterationRange(start, right, reversed, inclusive, loopVarPsi)
|
||||||
val explicitType =
|
val explicitType =
|
||||||
if (context.converter.settings.specifyLocalVariableTypeByDefault)
|
if (context.converter.settings.specifyLocalVariableTypeByDefault)
|
||||||
JKJavaPrimitiveTypeImpl.INT
|
JKJavaPrimitiveType.INT
|
||||||
else JKNoTypeImpl
|
else JKNoTypeImpl
|
||||||
val loopVarDeclaration =
|
val loopVarDeclaration =
|
||||||
JKForLoopVariableImpl(
|
JKForLoopVariable(
|
||||||
JKTypeElementImpl(explicitType),
|
JKTypeElement(explicitType),
|
||||||
loopVar::name.detached(),
|
loopVar::name.detached(),
|
||||||
JKStubExpressionImpl()
|
JKStubExpression()
|
||||||
)
|
)
|
||||||
return JKForInStatementImpl(
|
return JKForInStatement(
|
||||||
loopVarDeclaration,
|
loopVarDeclaration,
|
||||||
range,
|
range,
|
||||||
loopStatement::body.detached()
|
loopStatement::body.detached()
|
||||||
@@ -176,13 +179,13 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
convertBound(bound, if (inclusiveComparison) 0 else +1),
|
convertBound(bound, if (inclusiveComparison) 0 else +1),
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
bound !is JKKtLiteralExpression && !inclusiveComparison ->
|
bound !is JKLiteralExpression && !inclusiveComparison ->
|
||||||
untilToExpression(
|
untilToExpression(
|
||||||
start,
|
start,
|
||||||
convertBound(bound, 0),
|
convertBound(bound, 0),
|
||||||
context
|
context
|
||||||
)
|
)
|
||||||
else -> JKBinaryExpressionImpl(
|
else -> JKBinaryExpression(
|
||||||
start,
|
start,
|
||||||
convertBound(bound, if (inclusiveComparison) 0 else -1),
|
convertBound(bound, if (inclusiveComparison) 0 else -1),
|
||||||
JKKtOperatorImpl(
|
JKKtOperatorImpl(
|
||||||
@@ -198,13 +201,13 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
|
|
||||||
if (bound is JKLiteralExpression && bound.type == JKLiteralExpression.LiteralType.INT) {
|
if (bound is JKLiteralExpression && bound.type == JKLiteralExpression.LiteralType.INT) {
|
||||||
val value = bound.literal.toInt()
|
val value = bound.literal.toInt()
|
||||||
return JKKtLiteralExpressionImpl((value + correction).toString(), bound.type)
|
return JKLiteralExpression((value + correction).toString(), bound.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
val sign = if (correction > 0) JKOperatorToken.PLUS else JKOperatorToken.MINUS
|
val sign = if (correction > 0) JKOperatorToken.PLUS else JKOperatorToken.MINUS
|
||||||
return JKBinaryExpressionImpl(
|
return JKBinaryExpression(
|
||||||
bound,
|
bound,
|
||||||
JKKtLiteralExpressionImpl(abs(correction).toString(), JKLiteralExpression.LiteralType.INT),
|
JKLiteralExpression(abs(correction).toString(), JKLiteralExpression.LiteralType.INT),
|
||||||
JKKtOperatorImpl(
|
JKKtOperatorImpl(
|
||||||
sign,
|
sign,
|
||||||
typeFactory.types.int
|
typeFactory.types.int
|
||||||
@@ -239,12 +242,11 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
?: return null
|
?: return null
|
||||||
|
|
||||||
return if (reversed) {
|
return if (reversed) {
|
||||||
JKQualifiedExpressionImpl(
|
JKQualifiedExpression(
|
||||||
indices,
|
indices,
|
||||||
JKKtQualifierImpl.DOT,
|
JKCallExpressionImpl(
|
||||||
JKJavaMethodCallExpressionImpl(
|
|
||||||
symbolProvider.provideMethodSymbol("kotlin.collections.reversed"),
|
symbolProvider.provideMethodSymbol("kotlin.collections.reversed"),
|
||||||
JKArgumentListImpl()
|
JKArgumentList()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else indices
|
} else indices
|
||||||
@@ -252,7 +254,7 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
|
|
||||||
|
|
||||||
private fun indicesByCollectionSize(javaSizeCall: JKQualifiedExpression): JKQualifiedExpression? {
|
private fun indicesByCollectionSize(javaSizeCall: JKQualifiedExpression): JKQualifiedExpression? {
|
||||||
val methodCall = javaSizeCall.selector as? JKMethodCallExpression ?: return null
|
val methodCall = javaSizeCall.selector as? JKCallExpression ?: return null
|
||||||
return if (methodCall.identifier.deepestFqName() == "java.util.Collection.size"
|
return if (methodCall.identifier.deepestFqName() == "java.util.Collection.size"
|
||||||
&& methodCall.arguments.arguments.isEmpty()
|
&& methodCall.arguments.arguments.isEmpty()
|
||||||
) toIndicesCall(javaSizeCall) else null
|
) toIndicesCall(javaSizeCall) else null
|
||||||
@@ -269,10 +271,10 @@ class ForConversion(context: NewJ2kConverterContext) : RecursiveApplicableConver
|
|||||||
|
|
||||||
private fun toIndicesCall(javaSizeCall: JKQualifiedExpression): JKQualifiedExpression? {
|
private fun toIndicesCall(javaSizeCall: JKQualifiedExpression): JKQualifiedExpression? {
|
||||||
if (javaSizeCall.psi == null) return null
|
if (javaSizeCall.psi == null) return null
|
||||||
val selector = JKFieldAccessExpressionImpl(
|
val selector = JKFieldAccessExpression(
|
||||||
symbolProvider.provideFieldSymbol("kotlin.collections.indices")
|
symbolProvider.provideFieldSymbol("kotlin.collections.indices")
|
||||||
)
|
)
|
||||||
return JKQualifiedExpressionImpl(javaSizeCall::receiver.detached(), javaSizeCall.operator, selector)
|
return JKQualifiedExpression(javaSizeCall::receiver.detached(), selector)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKJavaForLoopStatement.hasNameConflict(): Boolean {
|
private fun JKJavaForLoopStatement.hasNameConflict(): Boolean {
|
||||||
|
|||||||
+6
-6
@@ -8,14 +8,14 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBlockStatementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKLambdaExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class FunctionAsAnonymousObjectToLambdaConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class FunctionAsAnonymousObjectToLambdaConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaNewExpression) return recurse(element)
|
if (element !is JKNewExpression) return recurse(element)
|
||||||
if (element.isAnonymousClass()
|
if (element.isAnonymousClass
|
||||||
&& element.classSymbol.isKtFunction()
|
&& element.classSymbol.isKtFunction()
|
||||||
) {
|
) {
|
||||||
val invokeFunction = element.classBody.declarations.singleOrNull()
|
val invokeFunction = element.classBody.declarations.singleOrNull()
|
||||||
@@ -23,8 +23,8 @@ class FunctionAsAnonymousObjectToLambdaConversion(context: NewJ2kConverterContex
|
|||||||
?.takeIf { it.name.value == "invoke" }
|
?.takeIf { it.name.value == "invoke" }
|
||||||
?: return recurse(element)
|
?: return recurse(element)
|
||||||
return recurse(
|
return recurse(
|
||||||
JKLambdaExpressionImpl(
|
JKLambdaExpression(
|
||||||
JKBlockStatementImpl(invokeFunction::block.detached()),
|
JKBlockStatement(invokeFunction::block.detached()),
|
||||||
invokeFunction::parameters.detached()
|
invokeFunction::parameters.detached()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,14 +6,13 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.copyTreeAndDetach
|
|
||||||
import org.jetbrains.kotlin.nj2k.isEquals
|
import org.jetbrains.kotlin.nj2k.isEquals
|
||||||
import org.jetbrains.kotlin.nj2k.parenthesizeIfBinaryExpression
|
import org.jetbrains.kotlin.nj2k.parenthesizeIfBinaryExpression
|
||||||
|
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.isUnresolved
|
import org.jetbrains.kotlin.nj2k.symbols.isUnresolved
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.parameterTypesWithUnfoldedVarargs
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ class ImplicitCastsConversion(context: NewJ2kConverterContext) : RecursiveApplic
|
|||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
when (element) {
|
when (element) {
|
||||||
is JKVariable -> convertVariable(element)
|
is JKVariable -> convertVariable(element)
|
||||||
is JKMethodCallExpression -> convertMethodCallExpression(element)
|
is JKCallExpression -> convertMethodCallExpression(element)
|
||||||
is JKBinaryExpression -> return recurse(convertBinaryExpression(element))
|
is JKBinaryExpression -> return recurse(convertBinaryExpression(element))
|
||||||
is JKKtAssignmentStatement -> convertAssignmentStatement(element)
|
is JKKtAssignmentStatement -> convertAssignmentStatement(element)
|
||||||
}
|
}
|
||||||
@@ -31,23 +30,22 @@ class ImplicitCastsConversion(context: NewJ2kConverterContext) : RecursiveApplic
|
|||||||
|
|
||||||
private fun convertBinaryExpression(binaryExpression: JKBinaryExpression): JKExpression {
|
private fun convertBinaryExpression(binaryExpression: JKBinaryExpression): JKExpression {
|
||||||
fun JKBinaryExpression.convertBinaryOperationWithChar(): JKBinaryExpression {
|
fun JKBinaryExpression.convertBinaryOperationWithChar(): JKBinaryExpression {
|
||||||
val leftType = left.type(typeFactory)?.asPrimitiveType() ?: return this
|
val leftType = left.calculateType(typeFactory).asPrimitiveType() ?: return this
|
||||||
val rightType = right.type(typeFactory)?.asPrimitiveType() ?: return this
|
val rightType = right.calculateType(typeFactory).asPrimitiveType() ?: return this
|
||||||
|
|
||||||
val leftOperandCastedCasted by lazy {
|
val leftOperandCastedCasted by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
::left.detached().let { it.castTo(rightType, strict = true) ?: it },
|
::left.detached().let { it.castTo(rightType, strict = true) ?: it },
|
||||||
::right.detached(),
|
::right.detached(),
|
||||||
operator
|
operator
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val rightOperandCastedCasted by lazy {
|
val rightOperandCastedCasted by lazy(LazyThreadSafetyMode.NONE) {
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
::left.detached(),
|
::left.detached(),
|
||||||
::right.detached().let { it.castTo(leftType, strict = true) ?: it },
|
::right.detached().let { it.castTo(leftType, strict = true) ?: it },
|
||||||
operator
|
operator
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,21 +71,20 @@ class ImplicitCastsConversion(context: NewJ2kConverterContext) : RecursiveApplic
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun convertAssignmentStatement(statement: JKKtAssignmentStatement) {
|
private fun convertAssignmentStatement(statement: JKKtAssignmentStatement) {
|
||||||
val expressionType = statement.field.type(typeFactory) ?: return
|
val expressionType = statement.field.calculateType(typeFactory) ?: return
|
||||||
statement.expression.castTo(expressionType)?.also {
|
statement.expression.castTo(expressionType)?.also {
|
||||||
statement.expression = it
|
statement.expression = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun convertMethodCallExpression(expression: JKMethodCallExpression) {
|
private fun convertMethodCallExpression(expression: JKCallExpression) {
|
||||||
if (expression.identifier.isUnresolved) return
|
if (expression.identifier.isUnresolved) return
|
||||||
val parameterTypes = expression.identifier.parameterTypesWithUnfoldedVarargs() ?: return
|
val parameterTypes = expression.identifier.parameterTypesWithLastArgumentUnfoldedAsVararg() ?: return
|
||||||
val newArguments =
|
val newArguments = expression.arguments.arguments.mapIndexed { argumentIndex, argument ->
|
||||||
(expression.arguments.arguments.asSequence() zip parameterTypes)
|
val toType = parameterTypes.getOrNull(argumentIndex) ?: parameterTypes.last()
|
||||||
.map { (expression, toType) ->
|
argument.value.castTo(toType)
|
||||||
expression.value.castTo(toType)
|
}
|
||||||
}.toList()
|
|
||||||
val needUpdate = newArguments.any { it != null }
|
val needUpdate = newArguments.any { it != null }
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
for ((newArgument, oldArgument) in newArguments zip expression.arguments.arguments) {
|
for ((newArgument, oldArgument) in newArguments zip expression.arguments.arguments) {
|
||||||
@@ -100,15 +97,14 @@ class ImplicitCastsConversion(context: NewJ2kConverterContext) : RecursiveApplic
|
|||||||
|
|
||||||
private fun JKExpression.castStringToRegex(toType: JKType): JKExpression? {
|
private fun JKExpression.castStringToRegex(toType: JKType): JKExpression? {
|
||||||
if (toType.safeAs<JKClassType>()?.classReference?.fqName != "java.util.regex.Pattern") return null
|
if (toType.safeAs<JKClassType>()?.classReference?.fqName != "java.util.regex.Pattern") return null
|
||||||
val expressionType = type(typeFactory) ?: return null
|
val expressionType = calculateType(typeFactory)
|
||||||
if (!expressionType.isStringType()) return null
|
if (!expressionType.isStringType()) return null
|
||||||
return JKQualifiedExpressionImpl(
|
return JKQualifiedExpression(
|
||||||
copyTreeAndDetach().parenthesizeIfBinaryExpression(),
|
copyTreeAndDetach().parenthesizeIfBinaryExpression(),
|
||||||
JKKtQualifierImpl.DOT,
|
JKCallExpressionImpl(
|
||||||
JKKtCallExpressionImpl(
|
|
||||||
symbolProvider.provideMethodSymbol("kotlin.text.toRegex"),
|
symbolProvider.provideMethodSymbol("kotlin.text.toRegex"),
|
||||||
JKArgumentListImpl(),
|
JKArgumentList(),
|
||||||
JKTypeArgumentListImpl()
|
JKTypeArgumentList()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -116,26 +112,26 @@ class ImplicitCastsConversion(context: NewJ2kConverterContext) : RecursiveApplic
|
|||||||
|
|
||||||
private fun JKExpression.castToAsPrimitiveTypes(toType: JKType, strict: Boolean): JKExpression? {
|
private fun JKExpression.castToAsPrimitiveTypes(toType: JKType, strict: Boolean): JKExpression? {
|
||||||
if (this is JKPrefixExpression
|
if (this is JKPrefixExpression
|
||||||
&& (operator.token.text == "+" || operator.token.text == "-")
|
&& (operator.token == JKOperatorToken.PLUS || operator.token == JKOperatorToken.MINUS)
|
||||||
) {
|
) {
|
||||||
val casted = expression.castToAsPrimitiveTypes(toType, strict) ?: return null
|
val casted = expression.castToAsPrimitiveTypes(toType, strict) ?: return null
|
||||||
return JKPrefixExpressionImpl(casted, operator)
|
return JKPrefixExpression(casted, operator)
|
||||||
}
|
}
|
||||||
val expressionTypeAsPrimitive = type(typeFactory)?.asPrimitiveType() ?: return null
|
val expressionTypeAsPrimitive = calculateType(typeFactory).asPrimitiveType() ?: return null
|
||||||
val toTypeAsPrimitive = toType.asPrimitiveType() ?: return null
|
val toTypeAsPrimitive = toType.asPrimitiveType() ?: return null
|
||||||
if (toTypeAsPrimitive == expressionTypeAsPrimitive) return null
|
if (toTypeAsPrimitive == expressionTypeAsPrimitive) return null
|
||||||
|
|
||||||
if (this is JKLiteralExpression) {
|
if (this is JKLiteralExpression) {
|
||||||
if (!strict
|
if (!strict
|
||||||
&& expressionTypeAsPrimitive == JKJavaPrimitiveTypeImpl.INT
|
&& expressionTypeAsPrimitive == JKJavaPrimitiveType.INT
|
||||||
&& (toTypeAsPrimitive == JKJavaPrimitiveTypeImpl.LONG ||
|
&& (toTypeAsPrimitive == JKJavaPrimitiveType.LONG ||
|
||||||
toTypeAsPrimitive == JKJavaPrimitiveTypeImpl.SHORT ||
|
toTypeAsPrimitive == JKJavaPrimitiveType.SHORT ||
|
||||||
toTypeAsPrimitive == JKJavaPrimitiveTypeImpl.BYTE)
|
toTypeAsPrimitive == JKJavaPrimitiveType.BYTE)
|
||||||
) return null
|
) return null
|
||||||
val expectedType = toTypeAsPrimitive.toLiteralType() ?: JKLiteralExpression.LiteralType.INT
|
val expectedType = toTypeAsPrimitive.toLiteralType() ?: JKLiteralExpression.LiteralType.INT
|
||||||
|
|
||||||
if (expressionTypeAsPrimitive.isNumberType() && toTypeAsPrimitive.isNumberType()) {
|
if (expressionTypeAsPrimitive.isNumberType() && toTypeAsPrimitive.isNumberType()) {
|
||||||
return JKJavaLiteralExpressionImpl(
|
return JKLiteralExpression(
|
||||||
literal,
|
literal,
|
||||||
expectedType
|
expectedType
|
||||||
)
|
)
|
||||||
@@ -144,22 +140,27 @@ class ImplicitCastsConversion(context: NewJ2kConverterContext) : RecursiveApplic
|
|||||||
|
|
||||||
val initialTypeName = expressionTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()
|
val initialTypeName = expressionTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()
|
||||||
val conversionFunctionName = "to${toTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()}"
|
val conversionFunctionName = "to${toTypeAsPrimitive.jvmPrimitiveType.javaKeywordName.capitalize()}"
|
||||||
return JKQualifiedExpressionImpl(
|
return JKQualifiedExpression(
|
||||||
this.copyTreeAndDetach(),
|
copyTreeAndDetach(),
|
||||||
JKKtQualifierImpl.DOT,
|
JKCallExpressionImpl(
|
||||||
JKJavaMethodCallExpressionImpl(
|
|
||||||
symbolProvider.provideMethodSymbol("kotlin.$initialTypeName.$conversionFunctionName"),
|
symbolProvider.provideMethodSymbol("kotlin.$initialTypeName.$conversionFunctionName"),
|
||||||
JKArgumentListImpl()
|
JKArgumentList()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun JKExpression.castTo(toType: JKType, strict: Boolean = false): JKExpression? {
|
private fun JKExpression.castTo(toType: JKType, strict: Boolean = false): JKExpression? {
|
||||||
val expressionType = type(typeFactory)
|
val expressionType = calculateType(typeFactory)
|
||||||
if (expressionType == toType) return null
|
if (expressionType == toType) return null
|
||||||
castToAsPrimitiveTypes(toType, strict)?.also { return it }
|
castToAsPrimitiveTypes(toType, strict)?.also { return it }
|
||||||
castStringToRegex(toType)?.also { return it }
|
castStringToRegex(toType)?.also { return it }
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun JKMethodSymbol.parameterTypesWithLastArgumentUnfoldedAsVararg(): List<JKType>? {
|
||||||
|
val realParameterTypes = parameterTypes ?: return null
|
||||||
|
if (realParameterTypes.isEmpty()) return null
|
||||||
|
val lastArrayType = realParameterTypes.lastOrNull()?.arrayInnerType() ?: return realParameterTypes
|
||||||
|
return realParameterTypes.subList(0, realParameterTypes.lastIndex) + lastArrayType
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -6,13 +6,12 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.declarationList
|
||||||
import org.jetbrains.kotlin.nj2k.findUsages
|
import org.jetbrains.kotlin.nj2k.findUsages
|
||||||
|
import org.jetbrains.kotlin.nj2k.modality
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBooleanLiteral
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKJavaLiteralExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKJavaPrimitiveTypeImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKNullLiteral
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaPrimitiveType
|
import org.jetbrains.kotlin.nj2k.types.JKJavaPrimitiveType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKTypeParameterType
|
import org.jetbrains.kotlin.nj2k.types.JKTypeParameterType
|
||||||
@@ -26,7 +25,7 @@ class ImplicitInitializerConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaField) return recurse(element)
|
if (element !is JKField) return recurse(element)
|
||||||
if (element.initializer !is JKStubExpression) return recurse(element)
|
if (element.initializer !is JKStubExpression) return recurse(element)
|
||||||
|
|
||||||
val initializationState = element.initializationState()
|
val initializationState = element.initializationState()
|
||||||
@@ -40,7 +39,7 @@ class ImplicitInitializerConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
}
|
}
|
||||||
|
|
||||||
val newInitializer = when (val fieldType = element.type.type) {
|
val newInitializer = when (val fieldType = element.type.type) {
|
||||||
is JKClassType, is JKTypeParameterType -> JKNullLiteral()
|
is JKClassType, is JKTypeParameterType -> JKLiteralExpression("null", JKLiteralExpression.LiteralType.NULL)
|
||||||
is JKJavaPrimitiveType -> createPrimitiveTypeInitializer(fieldType)
|
is JKJavaPrimitiveType -> createPrimitiveTypeInitializer(fieldType)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
@@ -50,11 +49,11 @@ class ImplicitInitializerConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
return element
|
return element
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKJavaField.initializationState(): InitializationState {
|
private fun JKField.initializationState(): InitializationState {
|
||||||
val fieldSymbol = symbolProvider.provideUniverseSymbol(this)
|
val fieldSymbol = symbolProvider.provideUniverseSymbol(this)
|
||||||
val containingClass = parentOfType<JKClass>() ?: return InitializationState.NON_INITIALIZED
|
val containingClass = parentOfType<JKClass>() ?: return InitializationState.NON_INITIALIZED
|
||||||
val symbolToConstructor = containingClass.declarationList
|
val symbolToConstructor = containingClass.declarationList
|
||||||
.filterIsInstance<JKKtConstructor>()
|
.filterIsInstance<JKConstructor>()
|
||||||
.map { symbolProvider.provideUniverseSymbol(it) to it }
|
.map { symbolProvider.provideUniverseSymbol(it) to it }
|
||||||
.toMap()
|
.toMap()
|
||||||
|
|
||||||
@@ -63,7 +62,7 @@ class ImplicitInitializerConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
?.identifier
|
?.identifier
|
||||||
|
|
||||||
val constructors = containingClass.declarationList
|
val constructors = containingClass.declarationList
|
||||||
.filterIsInstance<JKKtConstructor>()
|
.filterIsInstance<JKConstructor>()
|
||||||
.map { symbolProvider.provideUniverseSymbol(it) to false }
|
.map { symbolProvider.provideUniverseSymbol(it) to false }
|
||||||
.toMap()
|
.toMap()
|
||||||
.toMutableMap()
|
.toMutableMap()
|
||||||
@@ -74,11 +73,11 @@ class ImplicitInitializerConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
when {
|
when {
|
||||||
parent is JKKtAssignmentStatement -> parent
|
parent is JKKtAssignmentStatement -> parent
|
||||||
parent is JKQualifiedExpression && parent.receiver is JKThisExpression ->
|
parent is JKQualifiedExpression && parent.receiver is JKThisExpression ->
|
||||||
parent.parent as? JKKtAssignmentStatement
|
parent.parent as? JKKtAssignmentStatement
|
||||||
else -> null
|
else -> null
|
||||||
} ?: return@mapNotNull null
|
} ?: return@mapNotNull null
|
||||||
val constructor =
|
val constructor =
|
||||||
(assignmentStatement.parent as? JKBlock)?.parent as? JKKtConstructor ?: return@mapNotNull null
|
(assignmentStatement.parent as? JKBlock)?.parent as? JKConstructor ?: return@mapNotNull null
|
||||||
|
|
||||||
val isInitializer = when (parent) {
|
val isInitializer = when (parent) {
|
||||||
is JKKtAssignmentStatement -> (parent.field as? JKFieldAccessExpression)?.identifier == fieldSymbol
|
is JKKtAssignmentStatement -> (parent.field as? JKFieldAccessExpression)?.identifier == fieldSymbol
|
||||||
@@ -118,9 +117,9 @@ class ImplicitInitializerConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
|
|
||||||
private fun createPrimitiveTypeInitializer(primitiveType: JKJavaPrimitiveType): JKLiteralExpression =
|
private fun createPrimitiveTypeInitializer(primitiveType: JKJavaPrimitiveType): JKLiteralExpression =
|
||||||
when (primitiveType) {
|
when (primitiveType) {
|
||||||
JKJavaPrimitiveTypeImpl.BOOLEAN ->
|
JKJavaPrimitiveType.BOOLEAN ->
|
||||||
JKBooleanLiteral(false)
|
JKLiteralExpression("false", JKLiteralExpression.LiteralType.STRING)
|
||||||
else ->
|
else ->
|
||||||
JKJavaLiteralExpressionImpl("0", JKLiteralExpression.LiteralType.INT)
|
JKLiteralExpression("0", JKLiteralExpression.LiteralType.INT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,11 +6,11 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.OtherModifier
|
import org.jetbrains.kotlin.nj2k.isLocalClass
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKClass
|
import org.jetbrains.kotlin.nj2k.tree.JKClass
|
||||||
|
import org.jetbrains.kotlin.nj2k.tree.JKOtherModifierElement
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKOtherModifierElementImpl
|
import org.jetbrains.kotlin.nj2k.tree.OtherModifier
|
||||||
import org.jetbrains.kotlin.nj2k.tree.isLocalClass
|
|
||||||
|
|
||||||
class InnerClassConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class InnerClassConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
@@ -34,7 +34,7 @@ class InnerClassConversion(context : NewJ2kConverterContext) : RecursiveApplicab
|
|||||||
outer.classKind != JKClass.ClassKind.INTERFACE &&
|
outer.classKind != JKClass.ClassKind.INTERFACE &&
|
||||||
element.classKind != JKClass.ClassKind.ENUM
|
element.classKind != JKClass.ClassKind.ENUM
|
||||||
) {
|
) {
|
||||||
element.otherModifierElements += JKOtherModifierElementImpl(OtherModifier.INNER)
|
element.otherModifierElements += JKOtherModifierElement(OtherModifier.INNER)
|
||||||
}
|
}
|
||||||
return recurseArmed(element, element)
|
return recurseArmed(element, element)
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-28
@@ -6,50 +6,32 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.declarationList
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKNoType
|
||||||
|
|
||||||
|
|
||||||
class InsertDefaultPrimaryConstructorConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class InsertDefaultPrimaryConstructorConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKClass) return recurse(element)
|
if (element !is JKClass) return recurse(element)
|
||||||
if (element.classKind != JKClass.ClassKind.CLASS) return recurse(element)
|
if (element.classKind != JKClass.ClassKind.CLASS) return recurse(element)
|
||||||
if (element.declarationList.any { it is JKKtConstructor }) return recurse(element)
|
if (element.declarationList.any { it is JKConstructor }) return recurse(element)
|
||||||
|
|
||||||
val constructor = JKKtPrimaryConstructorImpl(
|
val constructor = JKKtPrimaryConstructor(
|
||||||
JKNameIdentifierImpl(element.name.value),
|
JKNameIdentifier(element.name.value),
|
||||||
emptyList(),
|
emptyList(),
|
||||||
JKStubExpressionImpl(),
|
JKStubExpression(),
|
||||||
JKAnnotationListImpl(),
|
JKAnnotationList(),
|
||||||
emptyList(),
|
emptyList(),
|
||||||
JKVisibilityModifierElementImpl(Visibility.PUBLIC),
|
JKVisibilityModifierElement(Visibility.PUBLIC),
|
||||||
JKModalityModifierElementImpl(Modality.FINAL)
|
JKModalityModifierElement(Modality.FINAL)
|
||||||
)
|
)
|
||||||
|
|
||||||
element.classBody.declarations += constructor
|
element.classBody.declarations += constructor
|
||||||
|
|
||||||
val superClassSymbol =
|
|
||||||
(element.inheritance.extends.singleOrNull() as? JKClassType)?.classReference
|
|
||||||
|
|
||||||
if (superClassSymbol is JKUniverseClassSymbol) {
|
|
||||||
val superClass = recurse(superClassSymbol.target)
|
|
||||||
val superConstructor = symbolProvider.provideUniverseSymbol(
|
|
||||||
superClass.declarationList.singleOrNull { it is JKKtConstructor && it.parameters.isEmpty() } as? JKMethod ?: return recurse(
|
|
||||||
element
|
|
||||||
)
|
|
||||||
)
|
|
||||||
constructor.delegationCall = JKDelegationConstructorCallImpl(superConstructor, JKSuperExpressionImpl(), JKArgumentListImpl())
|
|
||||||
}
|
|
||||||
|
|
||||||
return recurse(element)
|
return recurse(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val JKClassSymbol.kind
|
|
||||||
get() = when (this) {
|
|
||||||
is JKUniverseClassSymbol -> target.classKind
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.declarationList
|
||||||
import org.jetbrains.kotlin.nj2k.getOrCreateCompanionObject
|
import org.jetbrains.kotlin.nj2k.getOrCreateCompanionObject
|
||||||
|
import org.jetbrains.kotlin.nj2k.modality
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,10 +6,8 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import com.intellij.psi.PsiMember
|
import com.intellij.psi.PsiMember
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.psi
|
|
||||||
import org.jetbrains.kotlin.nj2k.visibility
|
|
||||||
|
|
||||||
class InternalDeclarationConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class InternalDeclarationConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
|
|||||||
@@ -6,11 +6,9 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.copyTreeAndDetach
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKAnnotationParameterImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKFieldAccessExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtLiteralExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class JavaAnnotationsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class JavaAnnotationsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -32,15 +30,14 @@ class JavaAnnotationsConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
annotation.classSymbol = symbolProvider.provideClassSymbol("kotlin.Deprecated")
|
annotation.classSymbol = symbolProvider.provideClassSymbol("kotlin.Deprecated")
|
||||||
if (annotation.arguments.isEmpty()) {
|
if (annotation.arguments.isEmpty()) {
|
||||||
annotation.arguments +=
|
annotation.arguments +=
|
||||||
JKAnnotationParameterImpl(JKKtLiteralExpressionImpl("\"\"", JKLiteralExpression.LiteralType.STRING))
|
JKAnnotationParameterImpl(JKLiteralExpression("\"\"", JKLiteralExpression.LiteralType.STRING))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (annotation.classSymbol.fqName == "java.lang.annotation.Target") {
|
if (annotation.classSymbol.fqName == "java.lang.annotation.Target") {
|
||||||
annotation.classSymbol = symbolProvider.provideClassSymbol("kotlin.annotation.Target")
|
annotation.classSymbol = symbolProvider.provideClassSymbol("kotlin.annotation.Target")
|
||||||
|
|
||||||
val arguments = annotation.arguments.singleOrNull()?.let { parameter ->
|
val arguments = annotation.arguments.singleOrNull()?.let { parameter ->
|
||||||
val value = parameter.value
|
when (val value = parameter.value) {
|
||||||
when (value) {
|
|
||||||
is JKKtAnnotationArrayInitializerExpression -> value.initializers
|
is JKKtAnnotationArrayInitializerExpression -> value.initializers
|
||||||
else -> listOf(value)
|
else -> listOf(value)
|
||||||
}
|
}
|
||||||
@@ -51,7 +48,7 @@ class JavaAnnotationsConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
value.fieldAccessFqName()
|
value.fieldAccessFqName()
|
||||||
?.let { targetMappings[it] }
|
?.let { targetMappings[it] }
|
||||||
?.map { fqName ->
|
?.map { fqName ->
|
||||||
JKFieldAccessExpressionImpl(symbolProvider.provideFieldSymbol(fqName))
|
JKFieldAccessExpression(symbolProvider.provideFieldSymbol(fqName))
|
||||||
} ?: listOf(value.copyTreeAndDetach())
|
} ?: listOf(value.copyTreeAndDetach())
|
||||||
}
|
}
|
||||||
annotation.arguments = newArguments.map { JKAnnotationParameterImpl(it) }
|
annotation.arguments = newArguments.map { JKAnnotationParameterImpl(it) }
|
||||||
|
|||||||
+12
-30
@@ -19,39 +19,21 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.throwAnnotation
|
import org.jetbrains.kotlin.nj2k.throwAnnotation
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.JKMethodImpl
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtFunctionImpl
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.psi
|
import org.jetbrains.kotlin.nj2k.types.updateNullabilityRecursively
|
||||||
|
|
||||||
class JavaMethodToKotlinFunctionConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class JavaMethodToKotlinFunctionConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaMethod) return recurse(element)
|
if (element !is JKMethodImpl) return recurse(element)
|
||||||
|
|
||||||
element.invalidate()
|
if (element.throwsList.isNotEmpty()) {
|
||||||
val kotlinFunction = JKKtFunctionImpl(
|
element.annotationList.annotations +=
|
||||||
element.returnType,
|
throwAnnotation(
|
||||||
element.name,
|
element.throwsList.map { it.type.updateNullabilityRecursively(Nullability.NotNull) },
|
||||||
element.parameters,
|
symbolProvider
|
||||||
element.block,
|
)
|
||||||
element.typeParameterList,
|
}
|
||||||
element.annotationList.also {
|
return recurse(element)
|
||||||
if (element.throwsList.isNotEmpty()) {
|
|
||||||
it.annotations +=
|
|
||||||
throwAnnotation(
|
|
||||||
element.throwsList.map { it.type.updateNullabilityRecursively(Nullability.NotNull) },
|
|
||||||
symbolProvider
|
|
||||||
)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
element.otherModifierElements,
|
|
||||||
element.visibilityElement,
|
|
||||||
element.modalityElement
|
|
||||||
).also {
|
|
||||||
it.psi = element.psi
|
|
||||||
symbolProvider.transferSymbol(it, element)
|
|
||||||
it.leftParen.takeNonCodeElementsFrom(element.leftParen)
|
|
||||||
it.rightParen.takeNonCodeElementsFrom(element.rightParen)
|
|
||||||
}.withNonCodeElementsFrom(element)
|
|
||||||
return recurse(kotlinFunction)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.nj2k.annotationByFqName
|
|||||||
import org.jetbrains.kotlin.nj2k.jvmAnnotation
|
import org.jetbrains.kotlin.nj2k.jvmAnnotation
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
|
|
||||||
|
|
||||||
class JavaModifiersConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class JavaModifiersConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element is JKModalityOwner && element is JKAnnotationListOwner) {
|
if (element is JKModalityOwner && element is JKAnnotationListOwner) {
|
||||||
|
|||||||
@@ -9,16 +9,21 @@ import com.intellij.psi.PsiMethod
|
|||||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.modality
|
||||||
|
import org.jetbrains.kotlin.nj2k.psi
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKClassTypeImpl
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKJavaVoidType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.updateNullability
|
||||||
|
|
||||||
class JavaStandardMethodsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class JavaStandardMethodsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKClass) return recurse(element)
|
if (element !is JKClass) return recurse(element)
|
||||||
for (declaration in element.classBody.declarations) {
|
for (declaration in element.classBody.declarations) {
|
||||||
if (declaration !is JKJavaMethodImpl) continue
|
if (declaration !is JKMethodImpl) continue
|
||||||
if (fixToStringMethod(declaration)) continue
|
if (fixToStringMethod(declaration)) continue
|
||||||
if (fixFinalizeMethod(declaration, element)) continue
|
if (fixFinalizeMethod(declaration, element)) continue
|
||||||
if (fixCloneMethod(declaration)) {
|
if (fixCloneMethod(declaration)) {
|
||||||
@@ -30,7 +35,7 @@ class JavaStandardMethodsConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
} == true
|
} == true
|
||||||
if (hasNoCloneableInSuperClasses) {
|
if (hasNoCloneableInSuperClasses) {
|
||||||
element.inheritance.implements +=
|
element.inheritance.implements +=
|
||||||
JKTypeElementImpl(
|
JKTypeElement(
|
||||||
JKClassTypeImpl(
|
JKClassTypeImpl(
|
||||||
JKUnresolvedClassSymbol("Cloneable", typeFactory),
|
JKUnresolvedClassSymbol("Cloneable", typeFactory),
|
||||||
emptyList(), Nullability.NotNull
|
emptyList(), Nullability.NotNull
|
||||||
@@ -43,27 +48,27 @@ class JavaStandardMethodsConversion(context: NewJ2kConverterContext) : Recursive
|
|||||||
return recurse(element)
|
return recurse(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fixToStringMethod(method: JKJavaMethodImpl): Boolean {
|
private fun fixToStringMethod(method: JKMethodImpl): Boolean {
|
||||||
if (method.name.value != "toString") return false
|
if (method.name.value != "toString") return false
|
||||||
if (method.parameters.isNotEmpty()) return false
|
if (method.parameters.isNotEmpty()) return false
|
||||||
val type = (method.returnType.type as? JKClassType)
|
val type = (method.returnType.type as? JKClassType)
|
||||||
?.takeIf { it.classReference.name == "String" }
|
?.takeIf { it.classReference.name == "String" }
|
||||||
?.updateNullability(Nullability.NotNull) ?: return false
|
?.updateNullability(Nullability.NotNull) ?: return false
|
||||||
method.returnType = JKTypeElementImpl(type)
|
method.returnType = JKTypeElement(type)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fixCloneMethod(method: JKJavaMethodImpl): Boolean {
|
private fun fixCloneMethod(method: JKMethodImpl): Boolean {
|
||||||
if (method.name.value != "clone") return false
|
if (method.name.value != "clone") return false
|
||||||
if (method.parameters.isNotEmpty()) return false
|
if (method.parameters.isNotEmpty()) return false
|
||||||
val type = (method.returnType.type as? JKClassType)
|
val type = (method.returnType.type as? JKClassType)
|
||||||
?.takeIf { it.classReference.name == "Object" }
|
?.takeIf { it.classReference.name == "Object" }
|
||||||
?.updateNullability(Nullability.NotNull) ?: return false
|
?.updateNullability(Nullability.NotNull) ?: return false
|
||||||
method.returnType = JKTypeElementImpl(type)
|
method.returnType = JKTypeElement(type)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun fixFinalizeMethod(method: JKJavaMethodImpl, containingClass: JKClass): Boolean {
|
private fun fixFinalizeMethod(method: JKMethodImpl, containingClass: JKClass): Boolean {
|
||||||
if (method.name.value != "finalize") return false
|
if (method.name.value != "finalize") return false
|
||||||
if (method.parameters.isNotEmpty()) return false
|
if (method.parameters.isNotEmpty()) return false
|
||||||
if (method.returnType.type != JKJavaVoidType) return false
|
if (method.returnType.type != JKJavaVoidType) return false
|
||||||
|
|||||||
+3
-3
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.load.java.NOT_NULL_ANNOTATIONS
|
|||||||
import org.jetbrains.kotlin.load.java.NULLABLE_ANNOTATIONS
|
import org.jetbrains.kotlin.load.java.NULLABLE_ANNOTATIONS
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKTypeElementImpl
|
import org.jetbrains.kotlin.nj2k.types.updateNullability
|
||||||
|
|
||||||
|
|
||||||
class JetbrainsNullableAnnotationsConverter(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class JetbrainsNullableAnnotationsConverter(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -23,11 +23,11 @@ class JetbrainsNullableAnnotationsConverter(context: NewJ2kConverterContext) : R
|
|||||||
when (element) {
|
when (element) {
|
||||||
is JKVariable -> {
|
is JKVariable -> {
|
||||||
annotationsToRemove += annotation
|
annotationsToRemove += annotation
|
||||||
element.type = JKTypeElementImpl(element.type.type.updateNullability(nullability))
|
element.type = JKTypeElement(element.type.type.updateNullability(nullability))
|
||||||
}
|
}
|
||||||
is JKMethod -> {
|
is JKMethod -> {
|
||||||
annotationsToRemove += annotation
|
annotationsToRemove += annotation
|
||||||
element.returnType = JKTypeElementImpl(element.returnType.type.updateNullability(nullability))
|
element.returnType = JKTypeElement(element.returnType.type.updateNullability(nullability))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,28 +8,27 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.asStatement
|
import org.jetbrains.kotlin.nj2k.asStatement
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBlockStatementWithoutBracketsImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtConvertedFromForLoopSyntheticWhileStatementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKLabeledStatementImpl
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
|
|
||||||
class LabeledStatementConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class LabeledStatementConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKExpressionStatement) return recurse(element)
|
if (element !is JKExpressionStatement) return recurse(element)
|
||||||
val labeledStatement = element.expression as? JKLabeledStatement ?: return recurse(element)
|
val labeledStatement = element.expression as? JKLabeledExpression ?: return recurse(element)
|
||||||
val convertedFromForLoopSyntheticWhileStatement = labeledStatement.statement
|
val convertedFromForLoopSyntheticWhileStatement = labeledStatement.statement
|
||||||
.safeAs<JKBlockStatement>()
|
.safeAs<JKBlockStatement>()
|
||||||
?.block
|
?.block
|
||||||
?.statements
|
?.statements
|
||||||
?.singleOrNull()
|
?.singleOrNull()
|
||||||
?.safeAs<JKKtConvertedFromForLoopSyntheticWhileStatementImpl>() ?: return recurse(element)
|
?.safeAs<JKKtConvertedFromForLoopSyntheticWhileStatement>() ?: return recurse(element)
|
||||||
|
|
||||||
return recurse(
|
return recurse(
|
||||||
JKBlockStatementWithoutBracketsImpl(
|
JKBlockStatementWithoutBrackets(
|
||||||
listOf(
|
listOf(
|
||||||
convertedFromForLoopSyntheticWhileStatement::variableDeclaration.detached(),
|
convertedFromForLoopSyntheticWhileStatement::variableDeclaration.detached(),
|
||||||
JKLabeledStatementImpl(
|
JKLabeledExpression(
|
||||||
convertedFromForLoopSyntheticWhileStatement::whileStatement.detached(),
|
convertedFromForLoopSyntheticWhileStatement::whileStatement.detached(),
|
||||||
labeledStatement::labels.detached()
|
labeledStatement::labels.detached()
|
||||||
).asStatement()
|
).asStatement()
|
||||||
|
|||||||
@@ -5,90 +5,76 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.JKLiteralExpression
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtLiteralExpressionImpl
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
import java.math.BigInteger
|
import java.math.BigInteger
|
||||||
|
|
||||||
class LiteralConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class LiteralConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaLiteralExpression) return recurse(element)
|
if (element !is JKLiteralExpression) return recurse(element)
|
||||||
return element.convertLiteral()
|
element.convertLiteral()
|
||||||
|
return recurse(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKLiteralExpression.convertLiteral(): JKLiteralExpression =
|
private fun JKLiteralExpression.convertLiteral() {
|
||||||
when (type) {
|
literal = when (type) {
|
||||||
JKLiteralExpression.LiteralType.DOUBLE -> toDoubleLiteral()
|
JKLiteralExpression.LiteralType.DOUBLE -> toDoubleLiteral()
|
||||||
JKLiteralExpression.LiteralType.FLOAT -> toFloatLiteral()
|
JKLiteralExpression.LiteralType.FLOAT -> toFloatLiteral()
|
||||||
JKLiteralExpression.LiteralType.LONG -> toLongLiteral()
|
JKLiteralExpression.LiteralType.LONG -> toLongLiteral()
|
||||||
JKLiteralExpression.LiteralType.INT -> toIntLiteral()
|
JKLiteralExpression.LiteralType.INT -> toIntLiteral()
|
||||||
JKLiteralExpression.LiteralType.CHAR -> convertCharLiteral()
|
JKLiteralExpression.LiteralType.CHAR -> convertCharLiteral()
|
||||||
JKLiteralExpression.LiteralType.STRING -> toStringLiteral()
|
JKLiteralExpression.LiteralType.STRING -> toStringLiteral()
|
||||||
else -> this
|
else -> return
|
||||||
}.withNonCodeElementsFrom(this)
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun JKLiteralExpression.toDoubleLiteral() =
|
private fun JKLiteralExpression.toDoubleLiteral() =
|
||||||
JKKtLiteralExpressionImpl(
|
literal.cleanFloatAndDoubleLiterals().let { text ->
|
||||||
literal.cleanFloatAndDoubleLiterals()
|
if (!text.contains(".") && !text.contains("e", true))
|
||||||
.let { text ->
|
"$text."
|
||||||
if (!text.contains(".") && !text.contains("e", true))
|
else text
|
||||||
"$text."
|
}.let { text ->
|
||||||
else text
|
if (text.endsWith(".")) "${text}0" else text
|
||||||
}.let { text ->
|
}
|
||||||
if (text.endsWith(".")) "${text}0" else text
|
|
||||||
},
|
|
||||||
JKLiteralExpression.LiteralType.DOUBLE
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
private fun JKLiteralExpression.toFloatLiteral() =
|
private fun JKLiteralExpression.toFloatLiteral() =
|
||||||
JKKtLiteralExpressionImpl(
|
literal.cleanFloatAndDoubleLiterals().let { text ->
|
||||||
literal.cleanFloatAndDoubleLiterals()
|
if (!text.endsWith("f")) "${text}f"
|
||||||
.let { text ->
|
else text
|
||||||
if (!text.endsWith("f")) "${text}f"
|
}
|
||||||
else text
|
|
||||||
},
|
|
||||||
JKLiteralExpression.LiteralType.FLOAT
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun JKLiteralExpression.toStringLiteral() =
|
private fun JKLiteralExpression.toStringLiteral() =
|
||||||
JKKtLiteralExpressionImpl(literal.replace("((?:\\\\)*)\\\\([0-3]?[0-7]{1,2})".toRegex()) { matchResult ->
|
literal.replace("""((?:\\)*)\\([0-3]?[0-7]{1,2})""".toRegex()) { matchResult ->
|
||||||
val leadingBackslashes = matchResult.groupValues[1]
|
val leadingBackslashes = matchResult.groupValues[1]
|
||||||
if (leadingBackslashes.length % 2 == 0)
|
if (leadingBackslashes.length % 2 == 0)
|
||||||
String.format("%s\\u%04x", leadingBackslashes, Integer.parseInt(matchResult.groupValues[2], 8))
|
String.format("%s\\u%04x", leadingBackslashes, Integer.parseInt(matchResult.groupValues[2], 8))
|
||||||
else matchResult.value
|
else matchResult.value
|
||||||
}.replace("\\$([A-Za-z]+|\\{)".toRegex(), "\\\\$0"), JKLiteralExpression.LiteralType.STRING)
|
}.replace("""(?<!\\)\$([A-Za-z]+|\{)""".toRegex(), "\\\\$0")
|
||||||
|
|
||||||
|
|
||||||
private fun JKLiteralExpression.convertCharLiteral(): JKKtLiteralExpression =
|
private fun JKLiteralExpression.convertCharLiteral() =
|
||||||
JKKtLiteralExpressionImpl(
|
literal.replace("""\\([0-3]?[0-7]{1,2})""".toRegex()) {
|
||||||
literal.replace("\\\\([0-3]?[0-7]{1,2})".toRegex()) {
|
String.format("\\u%04x", Integer.parseInt(it.groupValues[1], 8))
|
||||||
String.format("\\u%04x", Integer.parseInt(it.groupValues[1], 8))
|
}
|
||||||
},
|
|
||||||
JKLiteralExpression.LiteralType.CHAR
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
private fun JKLiteralExpression.toIntLiteral(): JKKtLiteralExpression =
|
private fun JKLiteralExpression.toIntLiteral() =
|
||||||
JKKtLiteralExpressionImpl(
|
literal
|
||||||
literal
|
.cleanIntAndLongLiterals()
|
||||||
.cleanIntAndLongLiterals()
|
.convertHexLiteral(isLongLiteral = false)
|
||||||
.convertHexLiteral(isLongLiteral = false)
|
.convertBinaryLiteral(isLongLiteral = false)
|
||||||
.convertBinaryLiteral(isLongLiteral = false)
|
.convertOctalLiteral(isLongLiteral = false)
|
||||||
.convertOctalLiteral(isLongLiteral = false),
|
|
||||||
JKLiteralExpression.LiteralType.INT
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
private fun JKLiteralExpression.toLongLiteral(): JKKtLiteralExpression =
|
private fun JKLiteralExpression.toLongLiteral() =
|
||||||
JKKtLiteralExpressionImpl(
|
literal
|
||||||
literal
|
.cleanIntAndLongLiterals()
|
||||||
.cleanIntAndLongLiterals()
|
.convertHexLiteral(isLongLiteral = true)
|
||||||
.convertHexLiteral(isLongLiteral = true)
|
.convertBinaryLiteral(isLongLiteral = true)
|
||||||
.convertBinaryLiteral(isLongLiteral = true)
|
.convertOctalLiteral(isLongLiteral = true) + "L"
|
||||||
.convertOctalLiteral(isLongLiteral = true) + "L",
|
|
||||||
JKLiteralExpression.LiteralType.LONG
|
|
||||||
)
|
|
||||||
|
|
||||||
private fun String.convertHexLiteral(isLongLiteral: Boolean): String {
|
private fun String.convertHexLiteral(isLongLiteral: Boolean): String {
|
||||||
if (!startsWith("0x", ignoreCase = true)) return this
|
if (!startsWith("0x", ignoreCase = true)) return this
|
||||||
|
|||||||
@@ -8,11 +8,9 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKAnnotationImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKJavaArrayTypeImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKTypeElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.updateNullability
|
||||||
|
|
||||||
|
|
||||||
//TODO temporary
|
//TODO temporary
|
||||||
@@ -24,14 +22,14 @@ class MainFunctionConversion(context: NewJ2kConverterContext) : RecursiveApplica
|
|||||||
val oldType = type.type as JKJavaArrayType
|
val oldType = type.type as JKJavaArrayType
|
||||||
val oldTypeParameter = oldType.type as JKClassType
|
val oldTypeParameter = oldType.type as JKClassType
|
||||||
val newType =
|
val newType =
|
||||||
JKJavaArrayTypeImpl(
|
JKJavaArrayType(
|
||||||
oldTypeParameter.updateNullability(Nullability.NotNull),
|
oldTypeParameter.updateNullability(Nullability.NotNull),
|
||||||
Nullability.NotNull
|
Nullability.NotNull
|
||||||
)
|
)
|
||||||
type = JKTypeElementImpl(newType)
|
type = JKTypeElement(newType)
|
||||||
}
|
}
|
||||||
element.annotationList.annotations +=
|
element.annotationList.annotations +=
|
||||||
JKAnnotationImpl(
|
JKAnnotation(
|
||||||
symbolProvider.provideClassSymbol("kotlin.jvm.JvmStatic"),
|
symbolProvider.provideClassSymbol("kotlin.jvm.JvmStatic"),
|
||||||
emptyList()
|
emptyList()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
|||||||
import org.jetbrains.kotlin.nj2k.SequentialBaseConversion
|
import org.jetbrains.kotlin.nj2k.SequentialBaseConversion
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
|
|
||||||
|
|
||||||
abstract class MatchBasedConversion(override val context: NewJ2kConverterContext) : SequentialBaseConversion {
|
abstract class MatchBasedConversion(override val context: NewJ2kConverterContext) : SequentialBaseConversion {
|
||||||
fun <R : JKTreeElement, T> applyRecursive(element: R, data: T, func: (JKTreeElement, T) -> JKTreeElement): R =
|
fun <R : JKTreeElement, T> applyRecursive(element: R, data: T, func: (JKTreeElement, T) -> JKTreeElement): R =
|
||||||
org.jetbrains.kotlin.nj2k.tree.applyRecursive(element, data, ::onElementChanged, func)
|
org.jetbrains.kotlin.nj2k.tree.applyRecursive(element, data, ::onElementChanged, func)
|
||||||
|
|||||||
+16
-18
@@ -7,16 +7,14 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import com.intellij.lang.jvm.JvmModifier
|
import com.intellij.lang.jvm.JvmModifier
|
||||||
import org.jetbrains.kotlin.codegen.kotlinType
|
import org.jetbrains.kotlin.codegen.kotlinType
|
||||||
import org.jetbrains.kotlin.codegen.optimization.common.analyze
|
|
||||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.nullIfStubExpression
|
import org.jetbrains.kotlin.nj2k.nullIfStubExpression
|
||||||
import org.jetbrains.kotlin.nj2k.qualified
|
import org.jetbrains.kotlin.nj2k.qualified
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.*
|
import org.jetbrains.kotlin.nj2k.symbols.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKClassType
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKTypeParameterType
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -37,11 +35,11 @@ class MethodReferenceToLambdaConversion(context: NewJ2kConverterContext) : Recur
|
|||||||
?.safeAs<JKClassAccessExpression>()
|
?.safeAs<JKClassAccessExpression>()
|
||||||
?.takeIf { symbol.safeAs<JKMethodSymbol>()?.isStatic == false && !element.isConstructorCall }
|
?.takeIf { symbol.safeAs<JKMethodSymbol>()?.isStatic == false && !element.isConstructorCall }
|
||||||
?.let { classAccessExpression ->
|
?.let { classAccessExpression ->
|
||||||
JKParameterImpl(
|
JKParameter(
|
||||||
JKTypeElementImpl(
|
JKTypeElement(
|
||||||
parametersTypesByFunctionalInterface?.firstOrNull() ?: JKClassTypeImpl(classAccessExpression.identifier)
|
parametersTypesByFunctionalInterface?.firstOrNull() ?: JKClassTypeImpl(classAccessExpression.identifier)
|
||||||
),
|
),
|
||||||
JKNameIdentifierImpl(RECEIVER_NAME),
|
JKNameIdentifier(RECEIVER_NAME),
|
||||||
isVarArgs = false
|
isVarArgs = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -55,9 +53,9 @@ class MethodReferenceToLambdaConversion(context: NewJ2kConverterContext) : Recur
|
|||||||
(symbol.parameterNames ?: return recurse(element)).zip(
|
(symbol.parameterNames ?: return recurse(element)).zip(
|
||||||
explicitParameterTypesByFunctionalInterface ?: symbol.parameterTypes ?: return recurse(element)
|
explicitParameterTypesByFunctionalInterface ?: symbol.parameterTypes ?: return recurse(element)
|
||||||
) { name, type ->
|
) { name, type ->
|
||||||
JKParameterImpl(
|
JKParameter(
|
||||||
JKTypeElementImpl(type),
|
JKTypeElement(type),
|
||||||
JKNameIdentifierImpl(name),
|
JKNameIdentifier(name),
|
||||||
isVarArgs = false
|
isVarArgs = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -65,32 +63,32 @@ class MethodReferenceToLambdaConversion(context: NewJ2kConverterContext) : Recur
|
|||||||
|
|
||||||
val arguments = parameters.map { parameter ->
|
val arguments = parameters.map { parameter ->
|
||||||
val parameterSymbol = symbolProvider.provideUniverseSymbol(parameter)
|
val parameterSymbol = symbolProvider.provideUniverseSymbol(parameter)
|
||||||
JKArgumentImpl(JKFieldAccessExpressionImpl(parameterSymbol))
|
JKArgumentImpl(JKFieldAccessExpression(parameterSymbol))
|
||||||
}
|
}
|
||||||
val callExpression =
|
val callExpression =
|
||||||
when (symbol) {
|
when (symbol) {
|
||||||
is JKMethodSymbol ->
|
is JKMethodSymbol ->
|
||||||
JKKtCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbol,
|
symbol,
|
||||||
JKArgumentListImpl(arguments)
|
JKArgumentList(arguments)
|
||||||
)
|
)
|
||||||
is JKClassSymbol -> JKJavaNewExpressionImpl(symbol, JKArgumentListImpl(), JKTypeArgumentListImpl())
|
is JKClassSymbol -> JKNewExpression(symbol, JKArgumentList(), JKTypeArgumentList())
|
||||||
is JKUnresolvedSymbol -> return recurse(element)
|
is JKUnresolvedSymbol -> return recurse(element)
|
||||||
else -> error("Symbol should be either method symbol or class symbol, but it is ${symbol::class}")
|
else -> error("Symbol should be either method symbol or class symbol, but it is ${symbol::class}")
|
||||||
}
|
}
|
||||||
val qualifier = when {
|
val qualifier = when {
|
||||||
receiverParameter != null ->
|
receiverParameter != null ->
|
||||||
JKFieldAccessExpressionImpl(symbolProvider.provideUniverseSymbol(receiverParameter))
|
JKFieldAccessExpression(symbolProvider.provideUniverseSymbol(receiverParameter))
|
||||||
element.isConstructorCall -> element.qualifier.safeAs<JKQualifiedExpression>()?.let { it::receiver.detached() }
|
element.isConstructorCall -> element.qualifier.safeAs<JKQualifiedExpression>()?.let { it::receiver.detached() }
|
||||||
else -> element::qualifier.detached().nullIfStubExpression()
|
else -> element::qualifier.detached().nullIfStubExpression()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val lambda = JKLambdaExpressionImpl(
|
val lambda = JKLambdaExpression(
|
||||||
JKExpressionStatementImpl(callExpression.qualified(qualifier)),
|
JKExpressionStatement(callExpression.qualified(qualifier)),
|
||||||
listOfNotNull(receiverParameter) + parameters,
|
listOfNotNull(receiverParameter) + parameters,
|
||||||
element::functionalType.detached(),
|
element::functionalType.detached(),
|
||||||
JKTypeElementImpl(
|
JKTypeElement(
|
||||||
when (symbol) {
|
when (symbol) {
|
||||||
is JKMethodSymbol -> symbol.returnType ?: JKNoTypeImpl
|
is JKMethodSymbol -> symbol.returnType ?: JKNoTypeImpl
|
||||||
is JKClassSymbol -> JKClassTypeImpl(symbol)
|
is JKClassSymbol -> JKClassTypeImpl(symbol)
|
||||||
|
|||||||
@@ -8,15 +8,16 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
import com.intellij.psi.PsiMethod
|
import com.intellij.psi.PsiMethod
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.modality
|
||||||
|
import org.jetbrains.kotlin.nj2k.psi
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKOtherModifierElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.psi
|
|
||||||
|
|
||||||
class ModalityConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class ModalityConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
when (element) {
|
when (element) {
|
||||||
is JKClass -> processClass(element)
|
is JKClass -> processClass(element)
|
||||||
is JKJavaMethod -> processMethod(element)
|
is JKMethod -> processMethod(element)
|
||||||
is JKField -> processField(element)
|
is JKField -> processField(element)
|
||||||
}
|
}
|
||||||
return recurse(element)
|
return recurse(element)
|
||||||
@@ -36,7 +37,7 @@ class ModalityConversion(context: NewJ2kConverterContext) : RecursiveApplicableC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processMethod(method: JKJavaMethod) {
|
private fun processMethod(method: JKMethod) {
|
||||||
val psi = method.psi<PsiMethod>() ?: return
|
val psi = method.psi<PsiMethod>() ?: return
|
||||||
val containingClass = method.parentOfType<JKClass>() ?: return
|
val containingClass = method.parentOfType<JKClass>() ?: return
|
||||||
when {
|
when {
|
||||||
@@ -44,7 +45,7 @@ class ModalityConversion(context: NewJ2kConverterContext) : RecursiveApplicableC
|
|||||||
&& psi.findSuperMethods().isNotEmpty() -> {
|
&& psi.findSuperMethods().isNotEmpty() -> {
|
||||||
method.modality = Modality.FINAL
|
method.modality = Modality.FINAL
|
||||||
if (!method.hasOtherModifier(OtherModifier.OVERRIDE)) {
|
if (!method.hasOtherModifier(OtherModifier.OVERRIDE)) {
|
||||||
method.otherModifierElements += JKOtherModifierElementImpl(OtherModifier.OVERRIDE)
|
method.otherModifierElements += JKOtherModifierElement(OtherModifier.OVERRIDE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
method.modality == Modality.OPEN
|
method.modality == Modality.OPEN
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.nj2k.tree.JKClassBody
|
|||||||
import org.jetbrains.kotlin.nj2k.tree.JKKtInitDeclaration
|
import org.jetbrains.kotlin.nj2k.tree.JKKtInitDeclaration
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
|
|
||||||
|
|
||||||
class MoveInitBlocksToTheEndConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class MoveInitBlocksToTheEndConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKClassBody) return recurse(element)
|
if (element !is JKClassBody) return recurse(element)
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
|||||||
import org.jetbrains.kotlin.nj2k.tree.JKClass
|
import org.jetbrains.kotlin.nj2k.tree.JKClass
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
|
|
||||||
class NonCodeElementsConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
|
||||||
|
class NonCodeElementsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
when (element) {
|
when (element) {
|
||||||
is JKClass -> {
|
is JKClass -> {
|
||||||
|
|||||||
@@ -8,7 +8,8 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.callOn
|
import org.jetbrains.kotlin.nj2k.callOn
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBinaryExpressionImpl
|
import org.jetbrains.kotlin.nj2k.types.isStringType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.type
|
||||||
|
|
||||||
|
|
||||||
class AnyWithStringConcatenationConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class AnyWithStringConcatenationConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -19,7 +20,7 @@ class AnyWithStringConcatenationConversion(context: NewJ2kConverterContext) : Re
|
|||||||
&& element.left.type(typeFactory)?.isStringType() == false
|
&& element.left.type(typeFactory)?.isStringType() == false
|
||||||
) {
|
) {
|
||||||
return recurse(
|
return recurse(
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
element::left.detached().callOn(symbolProvider.provideMethodSymbol("kotlin.Any.toString")),
|
element::left.detached().callOn(symbolProvider.provideMethodSymbol("kotlin.Any.toString")),
|
||||||
element::right.detached(),
|
element::right.detached(),
|
||||||
element.operator
|
element.operator
|
||||||
|
|||||||
+8
-10
@@ -9,9 +9,7 @@ import org.jetbrains.kotlin.j2k.ast.Nullability
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.hasWritableUsages
|
import org.jetbrains.kotlin.nj2k.hasWritableUsages
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaPrimitiveType
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKVarianceTypeParameterType
|
|
||||||
|
|
||||||
|
|
||||||
class ParameterModificationInMethodCallsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class ParameterModificationInMethodCallsConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -26,7 +24,7 @@ class ParameterModificationInMethodCallsConversion(context: NewJ2kConverterConte
|
|||||||
symbolProvider.provideClassSymbol(parameter.type.type.arrayFqName()),
|
symbolProvider.provideClassSymbol(parameter.type.type.arrayFqName()),
|
||||||
if (parameter.type.type is JKJavaPrimitiveType) emptyList()
|
if (parameter.type.type is JKJavaPrimitiveType) emptyList()
|
||||||
else listOf(
|
else listOf(
|
||||||
JKVarianceTypeParameterTypeImpl(
|
JKVarianceTypeParameterType(
|
||||||
JKVarianceTypeParameterType.Variance.OUT,
|
JKVarianceTypeParameterType.Variance.OUT,
|
||||||
parameter.type.type
|
parameter.type.type
|
||||||
)
|
)
|
||||||
@@ -35,16 +33,16 @@ class ParameterModificationInMethodCallsConversion(context: NewJ2kConverterConte
|
|||||||
)
|
)
|
||||||
|
|
||||||
} else parameter.type.type
|
} else parameter.type.type
|
||||||
JKLocalVariableImpl(
|
JKLocalVariable(
|
||||||
JKTypeElementImpl(parameterType),
|
JKTypeElement(parameterType),
|
||||||
JKNameIdentifierImpl(parameter.name.value),
|
JKNameIdentifier(parameter.name.value),
|
||||||
JKFieldAccessExpressionImpl(symbolProvider.provideUniverseSymbol(parameter)),
|
JKFieldAccessExpression(symbolProvider.provideUniverseSymbol(parameter)),
|
||||||
JKMutabilityModifierElementImpl(Mutability.MUTABLE)
|
JKMutabilityModifierElement(Mutability.MUTABLE)
|
||||||
)
|
)
|
||||||
} else null
|
} else null
|
||||||
}
|
}
|
||||||
if (newVariables.isNotEmpty()) {
|
if (newVariables.isNotEmpty()) {
|
||||||
element.block.statements = listOf(JKDeclarationStatementImpl(newVariables)) + element.block.statements
|
element.block.statements = listOf(JKDeclarationStatement(newVariables)) + element.block.statements
|
||||||
}
|
}
|
||||||
return recurse(element)
|
return recurse(element)
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -6,10 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.declarationList
|
||||||
import org.jetbrains.kotlin.nj2k.replace
|
import org.jetbrains.kotlin.nj2k.replace
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtInitDeclarationImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtPrimaryConstructorImpl
|
|
||||||
|
|
||||||
class PrimaryConstructorDetectConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class PrimaryConstructorDetectConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
@@ -22,7 +22,7 @@ class PrimaryConstructorDetectConversion(context: NewJ2kConverterContext) : Recu
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun processClass(element: JKClass) {
|
private fun processClass(element: JKClass) {
|
||||||
val constructors = element.declarationList.filterIsInstance<JKKtConstructor>()
|
val constructors = element.declarationList.filterIsInstance<JKConstructor>()
|
||||||
if (constructors.any { it is JKKtPrimaryConstructor }) return
|
if (constructors.any { it is JKKtPrimaryConstructor }) return
|
||||||
val primaryConstructorCandidate = detectPrimaryConstructor(constructors) ?: return
|
val primaryConstructorCandidate = detectPrimaryConstructor(constructors) ?: return
|
||||||
val delegationCall = primaryConstructorCandidate.delegationCall as? JKDelegationConstructorCall
|
val delegationCall = primaryConstructorCandidate.delegationCall as? JKDelegationConstructorCall
|
||||||
@@ -31,10 +31,10 @@ class PrimaryConstructorDetectConversion(context: NewJ2kConverterContext) : Recu
|
|||||||
|
|
||||||
primaryConstructorCandidate.invalidate()
|
primaryConstructorCandidate.invalidate()
|
||||||
if (primaryConstructorCandidate.block.statements.isNotEmpty()) {
|
if (primaryConstructorCandidate.block.statements.isNotEmpty()) {
|
||||||
val initDeclaration = JKKtInitDeclarationImpl(primaryConstructorCandidate.block)
|
val initDeclaration = JKKtInitDeclaration(primaryConstructorCandidate.block)
|
||||||
.withNonCodeElementsFrom(primaryConstructorCandidate)
|
.withNonCodeElementsFrom(primaryConstructorCandidate)
|
||||||
primaryConstructorCandidate.clearNonCodeElements()
|
primaryConstructorCandidate.clearNonCodeElements()
|
||||||
for (modifierElement in primaryConstructorCandidate.modifierElements()) {
|
primaryConstructorCandidate.forEachModifier { modifierElement ->
|
||||||
modifierElement.clearNonCodeElements()
|
modifierElement.clearNonCodeElements()
|
||||||
}
|
}
|
||||||
element.classBody.declarations =
|
element.classBody.declarations =
|
||||||
@@ -44,7 +44,7 @@ class PrimaryConstructorDetectConversion(context: NewJ2kConverterContext) : Recu
|
|||||||
}
|
}
|
||||||
|
|
||||||
val primaryConstructor =
|
val primaryConstructor =
|
||||||
JKKtPrimaryConstructorImpl(
|
JKKtPrimaryConstructor(
|
||||||
primaryConstructorCandidate.name,
|
primaryConstructorCandidate.name,
|
||||||
primaryConstructorCandidate.parameters,
|
primaryConstructorCandidate.parameters,
|
||||||
primaryConstructorCandidate.delegationCall,
|
primaryConstructorCandidate.delegationCall,
|
||||||
@@ -59,7 +59,7 @@ class PrimaryConstructorDetectConversion(context: NewJ2kConverterContext) : Recu
|
|||||||
element.classBody.declarations += primaryConstructor
|
element.classBody.declarations += primaryConstructor
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun detectPrimaryConstructor(constructors: List<JKKtConstructor>): JKKtConstructor? {
|
private fun detectPrimaryConstructor(constructors: List<JKConstructor>): JKConstructor? {
|
||||||
val constructorsWithoutOtherConstructorCall =
|
val constructorsWithoutOtherConstructorCall =
|
||||||
constructors.filterNot { (it.delegationCall as? JKDelegationConstructorCall)?.expression is JKThisExpression }
|
constructors.filterNot { (it.delegationCall as? JKDelegationConstructorCall)?.expression is JKThisExpression }
|
||||||
return constructorsWithoutOtherConstructorCall.singleOrNull()
|
return constructorsWithoutOtherConstructorCall.singleOrNull()
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
||||||
|
|
||||||
|
|
||||||
abstract class RecursiveApplicableConversionBase(context: NewJ2kConverterContext) : MatchBasedConversion(context) {
|
abstract class RecursiveApplicableConversionBase(context: NewJ2kConverterContext) : MatchBasedConversion(context) {
|
||||||
override fun onElementChanged(new: JKTreeElement, old: JKTreeElement) {
|
override fun onElementChanged(new: JKTreeElement, old: JKTreeElement) {
|
||||||
somethingChanged = true
|
somethingChanged = true
|
||||||
|
|||||||
+1
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
|
|
||||||
|
|
||||||
class RemoveWrongExtraModifiersForSingleFunctionsConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class RemoveWrongExtraModifiersForSingleFunctionsConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKOtherModifiersOwner) return recurse(element)
|
if (element !is JKOtherModifiersOwner) return recurse(element)
|
||||||
|
|||||||
+6
-8
@@ -7,11 +7,9 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.asStatement
|
import org.jetbrains.kotlin.nj2k.asStatement
|
||||||
import org.jetbrains.kotlin.nj2k.copyTreeAndDetach
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKLabelTextImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKLabeledStatementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKNameIdentifierImpl
|
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
class ReturnStatementInLambdaExpressionConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class ReturnStatementInLambdaExpressionConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
@@ -34,13 +32,13 @@ class ReturnStatementInLambdaExpressionConversion(context : NewJ2kConverterConte
|
|||||||
statement.block.statements += last::expression.detached().asStatement()
|
statement.block.statements += last::expression.detached().asStatement()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val parentMethodName = element.parent?.parent?.parent.safeAs<JKMethodCallExpression>()?.identifier?.name
|
val parentMethodName = element.parent?.parent?.parent.safeAs<JKCallExpression>()?.identifier?.name
|
||||||
if (parentMethodName == null) {
|
if (parentMethodName == null) {
|
||||||
val atLeastOneReturnStatementExists = applyLabelToAllReturnStatements(statement, element, DEFAULT_LABEL_NAME)
|
val atLeastOneReturnStatementExists = applyLabelToAllReturnStatements(statement, element, DEFAULT_LABEL_NAME)
|
||||||
return if (atLeastOneReturnStatementExists) {
|
return if (atLeastOneReturnStatementExists) {
|
||||||
JKLabeledStatementImpl(
|
JKLabeledExpression(
|
||||||
recurse(element.copyTreeAndDetach()).asStatement(),
|
recurse(element.copyTreeAndDetach()).asStatement(),
|
||||||
listOf(JKNameIdentifierImpl(DEFAULT_LABEL_NAME))
|
listOf(JKNameIdentifier(DEFAULT_LABEL_NAME))
|
||||||
)
|
)
|
||||||
} else recurse(element)
|
} else recurse(element)
|
||||||
}
|
}
|
||||||
@@ -58,7 +56,7 @@ class ReturnStatementInLambdaExpressionConversion(context : NewJ2kConverterConte
|
|||||||
fun addLabelToReturnStatement(returnStatement: JKReturnStatement) {
|
fun addLabelToReturnStatement(returnStatement: JKReturnStatement) {
|
||||||
if (returnStatement.label is JKLabelEmpty && returnStatement.parentOfType<JKLambdaExpression>() == lambdaExpression) {
|
if (returnStatement.label is JKLabelEmpty && returnStatement.parentOfType<JKLambdaExpression>() == lambdaExpression) {
|
||||||
atLeastOneReturnStatementExists = true
|
atLeastOneReturnStatementExists = true
|
||||||
returnStatement.label = JKLabelTextImpl(JKNameIdentifierImpl(label))
|
returnStatement.label = JKLabelText(JKNameIdentifier(label))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.nj2k.createCompanion
|
|||||||
import org.jetbrains.kotlin.nj2k.getCompanion
|
import org.jetbrains.kotlin.nj2k.getCompanion
|
||||||
import org.jetbrains.kotlin.nj2k.replace
|
import org.jetbrains.kotlin.nj2k.replace
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtInitDeclarationImpl
|
|
||||||
|
|
||||||
class StaticInitDeclarationConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class StaticInitDeclarationConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
@@ -34,5 +34,5 @@ class StaticInitDeclarationConversion(context : NewJ2kConverterContext) : Recurs
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun JKJavaStaticInitDeclaration.toKtInitDeclaration() =
|
private fun JKJavaStaticInitDeclaration.toKtInitDeclaration() =
|
||||||
JKKtInitDeclarationImpl(::block.detached()).withNonCodeElementsFrom(this)
|
JKKtInitDeclaration(::block.detached()).withNonCodeElementsFrom(this)
|
||||||
}
|
}
|
||||||
@@ -5,25 +5,20 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
|
|
||||||
import com.intellij.lang.jvm.JvmModifier
|
import com.intellij.lang.jvm.JvmModifier
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.PsiModifierListOwner
|
import com.intellij.psi.PsiModifierListOwner
|
||||||
import com.intellij.psi.util.parentOfType
|
|
||||||
import org.jetbrains.kotlin.j2k.getContainingClass
|
import org.jetbrains.kotlin.j2k.getContainingClass
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.asQualifierWithThisAsSelector
|
import org.jetbrains.kotlin.nj2k.asQualifierWithThisAsSelector
|
||||||
import org.jetbrains.kotlin.nj2k.copyTreeAndDetach
|
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKClassAccessExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtQualifierImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKQualifiedExpressionImpl
|
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
@@ -33,16 +28,15 @@ class StaticMemberAccessConversion(context: NewJ2kConverterContext) : RecursiveA
|
|||||||
val symbol =
|
val symbol =
|
||||||
when (element) {
|
when (element) {
|
||||||
is JKFieldAccessExpression -> element.identifier
|
is JKFieldAccessExpression -> element.identifier
|
||||||
is JKMethodCallExpression -> element.identifier
|
is JKCallExpression -> element.identifier
|
||||||
else -> null
|
else -> null
|
||||||
} ?: return recurse(element)
|
} ?: return recurse(element)
|
||||||
if (element.asQualifierWithThisAsSelector() != null) return recurse(element)
|
if (element.asQualifierWithThisAsSelector() != null) return recurse(element)
|
||||||
if (symbol.isStaticMember()) {
|
if (symbol.isStaticMember()) {
|
||||||
val containingClassSymbol = symbol.containingClassSymbol() ?: return recurse(element)
|
val containingClassSymbol = symbol.containingClassSymbol() ?: return recurse(element)
|
||||||
return recurse(
|
return recurse(
|
||||||
JKQualifiedExpressionImpl(
|
JKQualifiedExpression(
|
||||||
JKClassAccessExpressionImpl(containingClassSymbol),
|
JKClassAccessExpression(containingClassSymbol),
|
||||||
JKKtQualifierImpl.DOT,
|
|
||||||
element.copyTreeAndDetach() as JKExpression
|
element.copyTreeAndDetach() as JKExpression
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -50,18 +44,15 @@ class StaticMemberAccessConversion(context: NewJ2kConverterContext) : RecursiveA
|
|||||||
return recurse(element)
|
return recurse(element)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKSymbol.isStaticMember(): Boolean {
|
private fun JKSymbol.isStaticMember(): Boolean = when (val target = target) {
|
||||||
val target = target
|
is PsiModifierListOwner -> target.hasModifier(JvmModifier.STATIC)
|
||||||
return when (target) {
|
is KtElement -> target.getStrictParentOfType<KtClassOrObject>()
|
||||||
is PsiModifierListOwner -> target.hasModifier(JvmModifier.STATIC)
|
?.safeAs<KtObjectDeclaration>()
|
||||||
is KtElement -> target.getStrictParentOfType<KtClassOrObject>()
|
?.isCompanion() == true
|
||||||
?.safeAs<KtObjectDeclaration>()
|
is JKTreeElement ->
|
||||||
?.isCompanion() == true
|
target.safeAs<JKOtherModifiersOwner>()?.hasOtherModifier(OtherModifier.STATIC) == true
|
||||||
is JKTreeElement ->
|
|| target.parentOfType<JKClass>()?.classKind == JKClass.ClassKind.OBJECT
|
||||||
target.safeAs<JKOtherModifiersOwner>()?.hasOtherModifier(OtherModifier.STATIC) == true
|
else -> false
|
||||||
|| target.parentOfType<JKClass>()?.classKind == JKClass.ClassKind.OBJECT
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun JKSymbol.containingClassSymbol(): JKClassSymbol? {
|
private fun JKSymbol.containingClassSymbol(): JKClassSymbol? {
|
||||||
|
|||||||
+3
-1
@@ -6,10 +6,12 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
|
import org.jetbrains.kotlin.nj2k.declarationList
|
||||||
import org.jetbrains.kotlin.nj2k.getOrCreateCompanionObject
|
import org.jetbrains.kotlin.nj2k.getOrCreateCompanionObject
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
|
|
||||||
class StaticsToCompanionExtractConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
|
||||||
|
class StaticsToCompanionExtractConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKClass) return recurse(element)
|
if (element !is JKClass) return recurse(element)
|
||||||
if (element.classKind == JKClass.ClassKind.COMPANION || element.classKind == JKClass.ClassKind.OBJECT) return element
|
if (element.classKind == JKClass.ClassKind.COMPANION || element.classKind == JKClass.ClassKind.OBJECT) return element
|
||||||
|
|||||||
@@ -11,15 +11,14 @@ import com.intellij.psi.controlFlow.ControlFlowUtil
|
|||||||
import com.intellij.psi.controlFlow.LocalsOrMyInstanceFieldsControlFlowPolicy
|
import com.intellij.psi.controlFlow.LocalsOrMyInstanceFieldsControlFlowPolicy
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.blockStatement
|
import org.jetbrains.kotlin.nj2k.blockStatement
|
||||||
import org.jetbrains.kotlin.nj2k.copyTreeAndDetach
|
|
||||||
import org.jetbrains.kotlin.nj2k.runExpression
|
import org.jetbrains.kotlin.nj2k.runExpression
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
|
|
||||||
|
|
||||||
class SwitchStatementConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class SwitchStatementConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaSwitchStatementImpl) return recurse(element)
|
if (element !is JKJavaSwitchStatement) return recurse(element)
|
||||||
element.invalidate()
|
element.invalidate()
|
||||||
element.cases.forEach { case ->
|
element.cases.forEach { case ->
|
||||||
case.statements.forEach { it.detach(case) }
|
case.statements.forEach { it.detach(case) }
|
||||||
@@ -28,7 +27,7 @@ class SwitchStatementConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
val cases = switchCasesToWhenCases(element.cases).moveElseCaseToTheEnd()
|
val cases = switchCasesToWhenCases(element.cases).moveElseCaseToTheEnd()
|
||||||
val whenStatement = JKKtWhenStatementImpl(element.expression, cases)
|
val whenStatement = JKKtWhenStatement(element.expression, cases)
|
||||||
return recurse(whenStatement)
|
return recurse(whenStatement)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,16 +59,16 @@ class SwitchStatementConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
|
|
||||||
val statementLabels = javaLabels
|
val statementLabels = javaLabels
|
||||||
.filterIsInstance<JKJavaLabelSwitchCase>()
|
.filterIsInstance<JKJavaLabelSwitchCase>()
|
||||||
.map { JKKtValueWhenLabelImpl(it.label) }
|
.map { JKKtValueWhenLabel(it.label) }
|
||||||
val elseLabel = javaLabels
|
val elseLabel = javaLabels
|
||||||
.find { it is JKJavaDefaultSwitchCaseImpl }
|
.find { it is JKJavaDefaultSwitchCase }
|
||||||
?.let { JKKtElseWhenLabelImpl() }
|
?.let { JKKtElseWhenLabel() }
|
||||||
val elseWhenCase = elseLabel?.let { label ->
|
val elseWhenCase = elseLabel?.let { label ->
|
||||||
JKKtWhenCaseImpl(listOf(label), statements.map { it.copyTreeAndDetach() }.singleBlockOrWrapToRun())
|
JKKtWhenCase(listOf(label), statements.map { it.copyTreeAndDetach() }.singleBlockOrWrapToRun())
|
||||||
}
|
}
|
||||||
val mainWhenCase =
|
val mainWhenCase =
|
||||||
if (statementLabels.isNotEmpty()) {
|
if (statementLabels.isNotEmpty()) {
|
||||||
JKKtWhenCaseImpl(statementLabels, statements.singleBlockOrWrapToRun())
|
JKKtWhenCase(statementLabels, statements.singleBlockOrWrapToRun())
|
||||||
} else null
|
} else null
|
||||||
listOfNotNull(mainWhenCase) +
|
listOfNotNull(mainWhenCase) +
|
||||||
listOfNotNull(elseWhenCase) +
|
listOfNotNull(elseWhenCase) +
|
||||||
@@ -81,11 +80,11 @@ class SwitchStatementConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
|
|
||||||
private fun List<JKStatement>.singleBlockOrWrapToRun(): JKStatement =
|
private fun List<JKStatement>.singleBlockOrWrapToRun(): JKStatement =
|
||||||
singleOrNull()
|
singleOrNull()
|
||||||
?: JKBlockStatementImpl(
|
?: JKBlockStatement(
|
||||||
JKBlockImpl(map { statement ->
|
JKBlockImpl(map { statement ->
|
||||||
when (statement) {
|
when (statement) {
|
||||||
is JKBlockStatement ->
|
is JKBlockStatement ->
|
||||||
JKExpressionStatementImpl(
|
JKExpressionStatement(
|
||||||
runExpression(statement, symbolProvider)
|
runExpression(statement, symbolProvider)
|
||||||
)
|
)
|
||||||
else -> statement
|
else -> statement
|
||||||
@@ -101,7 +100,7 @@ class SwitchStatementConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun isSwitchBreak(statement: JKStatement) =
|
private fun isSwitchBreak(statement: JKStatement) =
|
||||||
statement is JKBreakStatement && statement !is JKBreakWithLabelStatement
|
statement is JKBreakStatement && statement.label is JKLabelEmpty
|
||||||
|
|
||||||
private fun List<JKStatement>.fallsThrough(): Boolean =
|
private fun List<JKStatement>.fallsThrough(): Boolean =
|
||||||
all { it.fallsThrough() }
|
all { it.fallsThrough() }
|
||||||
@@ -113,7 +112,7 @@ class SwitchStatementConversion(context: NewJ2kConverterContext) : RecursiveAppl
|
|||||||
this is JKReturnStatement ||
|
this is JKReturnStatement ||
|
||||||
this is JKContinueStatement -> false
|
this is JKContinueStatement -> false
|
||||||
this is JKBlockStatement -> block.statements.fallsThrough()
|
this is JKBlockStatement -> block.statements.fallsThrough()
|
||||||
this is JKIfStatement ||
|
this is JKIfElseStatement ||
|
||||||
this is JKJavaSwitchStatement ||
|
this is JKJavaSwitchStatement ||
|
||||||
this is JKKtWhenStatement ->
|
this is JKKtWhenStatement ->
|
||||||
this.psi!!.canCompleteNormally()
|
this.psi!!.canCompleteNormally()
|
||||||
|
|||||||
@@ -6,29 +6,26 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKJavaSynchronizedStatement
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.withNonCodeElementsFrom
|
|
||||||
|
|
||||||
|
|
||||||
class SynchronizedStatementConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
class SynchronizedStatementConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaSynchronizedStatement) return recurse(element)
|
if (element !is JKJavaSynchronizedStatement) return recurse(element)
|
||||||
element.invalidate()
|
element.invalidate()
|
||||||
val lambdaBody = JKLambdaExpressionImpl(
|
val lambdaBody = JKLambdaExpression(
|
||||||
JKBlockStatementImpl(element.body),
|
JKBlockStatement(element.body),
|
||||||
emptyList()
|
emptyList()
|
||||||
)
|
)
|
||||||
val synchronizedCall =
|
val synchronizedCall =
|
||||||
JKKtCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.synchronized"),
|
symbolProvider.provideMethodSymbol("kotlin.synchronized"),
|
||||||
JKArgumentListImpl(
|
JKArgumentList(
|
||||||
element.lockExpression,
|
element.lockExpression,
|
||||||
lambdaBody
|
lambdaBody
|
||||||
)
|
)
|
||||||
).withNonCodeElementsFrom(element)
|
).withNonCodeElementsFrom(element)
|
||||||
return recurse(JKExpressionStatementImpl(synchronizedCall))
|
return recurse(JKExpressionStatement(synchronizedCall))
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -6,17 +6,12 @@
|
|||||||
package org.jetbrains.kotlin.nj2k.conversions
|
package org.jetbrains.kotlin.nj2k.conversions
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKJavaThrowStatement
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.detached
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKExpressionStatementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtThrowExpressionImpl
|
|
||||||
|
|
||||||
|
class ThrowStatementConversion(context: NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
||||||
class ThrowStatementConversion(context : NewJ2kConverterContext) : RecursiveApplicableConversionBase(context) {
|
|
||||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||||
if (element !is JKJavaThrowStatement) return recurse(element)
|
if (element !is JKJavaThrowStatement) return recurse(element)
|
||||||
val throwExpression = JKKtThrowExpressionImpl(element::exception.detached())
|
val throwExpression = JKKtThrowExpression(element::exception.detached())
|
||||||
return recurse(JKExpressionStatementImpl(throwExpression))
|
return recurse(JKExpressionStatement(throwExpression))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,10 +7,10 @@ package org.jetbrains.kotlin.nj2k.conversions
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||||
import org.jetbrains.kotlin.nj2k.copyTreeAndDetach
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaDisjunctionType
|
import org.jetbrains.kotlin.nj2k.types.JKJavaDisjunctionType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.updateNullability
|
||||||
import org.jetbrains.kotlin.nj2k.useExpression
|
import org.jetbrains.kotlin.nj2k.useExpression
|
||||||
|
|
||||||
|
|
||||||
@@ -23,8 +23,8 @@ class TryStatementConversion(context: NewJ2kConverterContext) : RecursiveApplica
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun convertNoResourcesTryStatement(tryStatement: JKJavaTryStatement): JKStatement =
|
private fun convertNoResourcesTryStatement(tryStatement: JKJavaTryStatement): JKStatement =
|
||||||
JKExpressionStatementImpl(
|
JKExpressionStatement(
|
||||||
JKKtTryExpressionImpl(
|
JKKtTryExpression(
|
||||||
tryStatement::tryBlock.detached(),
|
tryStatement::tryBlock.detached(),
|
||||||
tryStatement::finallyBlock.detached(),
|
tryStatement::finallyBlock.detached(),
|
||||||
tryStatement.catchSections.flatMap(::convertCatchSection)
|
tryStatement.catchSections.flatMap(::convertCatchSection)
|
||||||
@@ -35,11 +35,11 @@ class TryStatementConversion(context: NewJ2kConverterContext) : RecursiveApplica
|
|||||||
val body =
|
val body =
|
||||||
resourceDeclarationsToUseExpression(
|
resourceDeclarationsToUseExpression(
|
||||||
tryStatement.resourceDeclarations,
|
tryStatement.resourceDeclarations,
|
||||||
JKBlockStatementImpl(tryStatement::tryBlock.detached())
|
JKBlockStatement(tryStatement::tryBlock.detached())
|
||||||
)
|
)
|
||||||
return if (tryStatement.finallyBlock !is JKBodyStub || tryStatement.catchSections.isNotEmpty()) {
|
return if (tryStatement.finallyBlock !is JKBodyStub || tryStatement.catchSections.isNotEmpty()) {
|
||||||
JKExpressionStatementImpl(
|
JKExpressionStatement(
|
||||||
JKKtTryExpressionImpl(
|
JKKtTryExpression(
|
||||||
JKBlockImpl(listOf(body)),
|
JKBlockImpl(listOf(body)),
|
||||||
tryStatement::finallyBlock.detached(),
|
tryStatement::finallyBlock.detached(),
|
||||||
tryStatement.catchSections.flatMap(::convertCatchSection)
|
tryStatement.catchSections.flatMap(::convertCatchSection)
|
||||||
@@ -55,7 +55,7 @@ class TryStatementConversion(context: NewJ2kConverterContext) : RecursiveApplica
|
|||||||
resourceDeclarations
|
resourceDeclarations
|
||||||
.reversed()
|
.reversed()
|
||||||
.fold(innerStatement) { inner, variable ->
|
.fold(innerStatement) { inner, variable ->
|
||||||
JKExpressionStatementImpl(
|
JKExpressionStatement(
|
||||||
useExpression(
|
useExpression(
|
||||||
receiver = (variable as JKLocalVariable)::initializer.detached(),
|
receiver = (variable as JKLocalVariable)::initializer.detached(),
|
||||||
variableIdentifier = variable::name.detached(),
|
variableIdentifier = variable::name.detached(),
|
||||||
@@ -70,11 +70,11 @@ class TryStatementConversion(context: NewJ2kConverterContext) : RecursiveApplica
|
|||||||
return javaCatchSection.parameter.type.type.let {
|
return javaCatchSection.parameter.type.type.let {
|
||||||
(it as? JKJavaDisjunctionType)?.disjunctions ?: listOf(it)
|
(it as? JKJavaDisjunctionType)?.disjunctions ?: listOf(it)
|
||||||
}.map {
|
}.map {
|
||||||
val parameter = JKParameterImpl(
|
val parameter = JKParameter(
|
||||||
JKTypeElementImpl(it.updateNullability(Nullability.NotNull)),
|
JKTypeElement(it.updateNullability(Nullability.NotNull)),
|
||||||
javaCatchSection.parameter.name.copyTreeAndDetach()
|
javaCatchSection.parameter.name.copyTreeAndDetach()
|
||||||
)
|
)
|
||||||
JKKtTryCatchSectionImpl(
|
JKKtTryCatchSection(
|
||||||
parameter,
|
parameter,
|
||||||
javaCatchSection.block.copyTreeAndDetach()
|
javaCatchSection.block.copyTreeAndDetach()
|
||||||
).withNonCodeElementsFrom(javaCatchSection)
|
).withNonCodeElementsFrom(javaCatchSection)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
|||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKUniverseClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.*
|
import org.jetbrains.kotlin.nj2k.types.*
|
||||||
import org.jetbrains.kotlin.psi.KtClass
|
import org.jetbrains.kotlin.psi.KtClass
|
||||||
|
|
||||||
@@ -24,14 +23,15 @@ class TypeMappingConversion(context: NewJ2kConverterContext) : RecursiveApplicab
|
|||||||
is JKTypeElement -> {
|
is JKTypeElement -> {
|
||||||
element.type = element.type.mapType(element)
|
element.type = element.type.mapType(element)
|
||||||
}
|
}
|
||||||
is JKJavaNewExpression -> {
|
is JKNewExpression -> {
|
||||||
val newClassSymbol = element.classSymbol.mapClassSymbol()
|
val newClassSymbol = element.classSymbol.mapClassSymbol()
|
||||||
return recurse(
|
return recurse(
|
||||||
JKJavaNewExpressionImpl(
|
JKNewExpression(
|
||||||
newClassSymbol,
|
newClassSymbol,
|
||||||
element::arguments.detached(),
|
element::arguments.detached(),
|
||||||
element::typeArgumentList.detached().fixTypeArguments(newClassSymbol),
|
element::typeArgumentList.detached().fixTypeArguments(newClassSymbol),
|
||||||
element::classBody.detached()
|
element::classBody.detached(),
|
||||||
|
element.isAnonymousClass
|
||||||
).withNonCodeElementsFrom(element)
|
).withNonCodeElementsFrom(element)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -41,16 +41,16 @@ class TypeMappingConversion(context: NewJ2kConverterContext) : RecursiveApplicab
|
|||||||
|
|
||||||
private fun JKTypeArgumentList.fixTypeArguments(classSymbol: JKClassSymbol): JKTypeArgumentList {
|
private fun JKTypeArgumentList.fixTypeArguments(classSymbol: JKClassSymbol): JKTypeArgumentList {
|
||||||
if (typeArguments.isNotEmpty()) {
|
if (typeArguments.isNotEmpty()) {
|
||||||
return JKTypeArgumentListImpl(
|
return JKTypeArgumentList(
|
||||||
typeArguments.map { typeArgument ->
|
typeArguments.map { typeArgument ->
|
||||||
JKTypeElementImpl(typeArgument.type.mapType(null))
|
JKTypeElement(typeArgument.type.mapType(null))
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return when (val typeParametersCount = classSymbol.expectedTypeParametersCount()) {
|
return when (val typeParametersCount = classSymbol.expectedTypeParametersCount()) {
|
||||||
0 -> this
|
0 -> this
|
||||||
else -> JKTypeArgumentListImpl(List(typeParametersCount) {
|
else -> JKTypeArgumentList(List(typeParametersCount) {
|
||||||
JKTypeElementImpl(typeFactory.types.nullableAny)
|
JKTypeElement(typeFactory.types.nullableAny)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ class TypeMappingConversion(context: NewJ2kConverterContext) : RecursiveApplicab
|
|||||||
private fun JKType.fixRawType(typeElement: JKTypeElement?) =
|
private fun JKType.fixRawType(typeElement: JKTypeElement?) =
|
||||||
when (typeElement?.parent) {
|
when (typeElement?.parent) {
|
||||||
is JKClassLiteralExpression -> this
|
is JKClassLiteralExpression -> this
|
||||||
is JKKtIsExpression ->
|
is JKIsExpression ->
|
||||||
addTypeParametersToRawProjectionType(JKStarProjectionTypeImpl)
|
addTypeParametersToRawProjectionType(JKStarProjectionTypeImpl)
|
||||||
.updateNullability(Nullability.NotNull)
|
.updateNullability(Nullability.NotNull)
|
||||||
is JKTypeCastExpression ->
|
is JKTypeCastExpression ->
|
||||||
@@ -80,7 +80,7 @@ class TypeMappingConversion(context: NewJ2kConverterContext) : RecursiveApplicab
|
|||||||
nullability
|
nullability
|
||||||
)
|
)
|
||||||
is JKVarianceTypeParameterType ->
|
is JKVarianceTypeParameterType ->
|
||||||
JKVarianceTypeParameterTypeImpl(
|
JKVarianceTypeParameterType(
|
||||||
variance,
|
variance,
|
||||||
boundType.mapType(null)
|
boundType.mapType(null)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,20 +5,23 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k
|
package org.jetbrains.kotlin.nj2k
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.tree.TokenSet
|
import com.intellij.psi.tree.TokenSet
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.nj2k.conversions.RecursiveApplicableConversionBase
|
import org.jetbrains.kotlin.nj2k.conversions.RecursiveApplicableConversionBase
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedMethod
|
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedMethod
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.types.JKNoType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.replaceJavaClassWithKotlinClassType
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
fun JKOperator.isEquals() =
|
fun JKOperator.isEquals() =
|
||||||
(token as? JKKtSingleValueOperatorToken)?.psiToken in equalsOperators
|
token.safeAs<JKKtSingleValueOperatorToken>()?.psiToken in equalsOperators
|
||||||
|
|
||||||
private val equalsOperators =
|
private val equalsOperators =
|
||||||
TokenSet.create(
|
TokenSet.create(
|
||||||
@@ -52,13 +55,12 @@ fun downToExpression(
|
|||||||
conversionContext
|
conversionContext
|
||||||
)
|
)
|
||||||
|
|
||||||
fun JKExpression.parenthesizeIfBinaryExpression() =
|
fun JKExpression.parenthesizeIfBinaryExpression() = when (this) {
|
||||||
when (this) {
|
is JKBinaryExpression -> JKParenthesizedExpression(this)
|
||||||
is JKBinaryExpression -> JKParenthesizedExpressionImpl(this)
|
else -> this
|
||||||
else -> this
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun JKExpression.parenthesize() = JKParenthesizedExpressionImpl(this)
|
fun JKExpression.parenthesize() = JKParenthesizedExpression(this)
|
||||||
|
|
||||||
fun rangeExpression(
|
fun rangeExpression(
|
||||||
from: JKExpression,
|
from: JKExpression,
|
||||||
@@ -66,7 +68,7 @@ fun rangeExpression(
|
|||||||
operatorName: String,
|
operatorName: String,
|
||||||
conversionContext: NewJ2kConverterContext
|
conversionContext: NewJ2kConverterContext
|
||||||
): JKExpression =
|
): JKExpression =
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
from,
|
from,
|
||||||
to,
|
to,
|
||||||
JKKtOperatorImpl(
|
JKKtOperatorImpl(
|
||||||
@@ -77,10 +79,10 @@ fun rangeExpression(
|
|||||||
|
|
||||||
|
|
||||||
fun blockStatement(vararg statements: JKStatement) =
|
fun blockStatement(vararg statements: JKStatement) =
|
||||||
JKBlockStatementImpl(JKBlockImpl(statements.toList()))
|
JKBlockStatement(JKBlockImpl(statements.toList()))
|
||||||
|
|
||||||
fun blockStatement(statements: List<JKStatement>) =
|
fun blockStatement(statements: List<JKStatement>) =
|
||||||
JKBlockStatementImpl(JKBlockImpl(statements))
|
JKBlockStatement(JKBlockImpl(statements))
|
||||||
|
|
||||||
fun useExpression(
|
fun useExpression(
|
||||||
receiver: JKExpression,
|
receiver: JKExpression,
|
||||||
@@ -90,41 +92,41 @@ fun useExpression(
|
|||||||
): JKExpression {
|
): JKExpression {
|
||||||
val useSymbol = symbolProvider.provideMethodSymbol("kotlin.io.use")
|
val useSymbol = symbolProvider.provideMethodSymbol("kotlin.io.use")
|
||||||
val lambdaParameter =
|
val lambdaParameter =
|
||||||
JKParameterImpl(JKTypeElementImpl(JKNoTypeImpl), variableIdentifier)
|
JKParameter(JKTypeElement(JKNoType), variableIdentifier)
|
||||||
|
|
||||||
val lambda = JKLambdaExpressionImpl(
|
val lambda = JKLambdaExpression(
|
||||||
body,
|
body,
|
||||||
listOf(lambdaParameter)
|
listOf(lambdaParameter)
|
||||||
)
|
)
|
||||||
val methodCall =
|
val methodCall =
|
||||||
JKJavaMethodCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
useSymbol,
|
useSymbol,
|
||||||
listOf(lambda).toArgumentList()
|
listOf(lambda).toArgumentList()
|
||||||
)
|
)
|
||||||
return JKQualifiedExpressionImpl(receiver, JKKtQualifierImpl.DOT, methodCall)
|
return JKQualifiedExpression(receiver, methodCall)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun kotlinAssert(assertion: JKExpression, message: JKExpression?, typeFactory: JKTypeFactory) =
|
fun kotlinAssert(assertion: JKExpression, message: JKExpression?, typeFactory: JKTypeFactory) =
|
||||||
JKKtCallExpressionImpl(
|
JKCallExpressionImpl(
|
||||||
JKUnresolvedMethod(//TODO resolve assert
|
JKUnresolvedMethod(//TODO resolve assert
|
||||||
"assert",
|
"assert",
|
||||||
typeFactory,
|
typeFactory,
|
||||||
typeFactory.types.unit
|
typeFactory.types.unit
|
||||||
),
|
),
|
||||||
(listOfNotNull(assertion, message)).toArgumentList()
|
listOfNotNull(assertion, message).toArgumentList()
|
||||||
)
|
)
|
||||||
|
|
||||||
fun jvmAnnotation(name: String, symbolProvider: JKSymbolProvider) =
|
fun jvmAnnotation(name: String, symbolProvider: JKSymbolProvider) =
|
||||||
JKAnnotationImpl(
|
JKAnnotation(
|
||||||
symbolProvider.provideClassSymbol("kotlin.jvm.$name")
|
symbolProvider.provideClassSymbol("kotlin.jvm.$name")
|
||||||
)
|
)
|
||||||
|
|
||||||
fun throwAnnotation(throws: List<JKType>, symbolProvider: JKSymbolProvider) =
|
fun throwAnnotation(throws: List<JKType>, symbolProvider: JKSymbolProvider) =
|
||||||
JKAnnotationImpl(
|
JKAnnotation(
|
||||||
symbolProvider.provideClassSymbol("kotlin.jvm.Throws"),
|
symbolProvider.provideClassSymbol("kotlin.jvm.Throws"),
|
||||||
throws.map {
|
throws.map {
|
||||||
JKAnnotationParameterImpl(
|
JKAnnotationParameterImpl(
|
||||||
JKClassLiteralExpressionImpl(JKTypeElementImpl(it), JKClassLiteralExpression.LiteralType.KOTLIN_CLASS)
|
JKClassLiteralExpression(JKTypeElement(it), JKClassLiteralExpression.ClassLiteralType.KOTLIN_CLASS)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -136,9 +138,9 @@ fun stringLiteral(content: String, typeFactory: JKTypeFactory): JKExpression {
|
|||||||
val lines = content.split('\n')
|
val lines = content.split('\n')
|
||||||
return lines.mapIndexed { i, line ->
|
return lines.mapIndexed { i, line ->
|
||||||
val newlineSeparator = if (i == lines.size - 1) "" else "\\n"
|
val newlineSeparator = if (i == lines.size - 1) "" else "\\n"
|
||||||
JKKtLiteralExpressionImpl("\"$line$newlineSeparator\"", JKLiteralExpression.LiteralType.STRING)
|
JKLiteralExpression("\"$line$newlineSeparator\"", JKLiteralExpression.LiteralType.STRING)
|
||||||
}.reduce { acc: JKExpression, literalExpression: JKKtLiteralExpression ->
|
}.reduce { acc: JKExpression, literalExpression: JKLiteralExpression ->
|
||||||
JKBinaryExpressionImpl(acc, literalExpression, JKKtOperatorImpl(JKOperatorToken.PLUS, typeFactory.types.string))
|
JKBinaryExpression(acc, literalExpression, JKKtOperatorImpl(JKOperatorToken.PLUS, typeFactory.types.string))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,11 +170,13 @@ fun JKExpression.unboxFieldReference(): JKFieldAccessExpression? = when {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun JKFieldAccessExpression.asAssignmentFromTarget(): JKKtAssignmentStatement? =
|
fun JKFieldAccessExpression.asAssignmentFromTarget(): JKKtAssignmentStatement? =
|
||||||
(parent as? JKKtAssignmentStatement)
|
parent.safeAs<JKKtAssignmentStatement>()?.takeIf { it.field == this }
|
||||||
?.takeIf { it.field == this }
|
|
||||||
|
|
||||||
fun JKFieldAccessExpression.isInDecrementOrIncrement(): Boolean =
|
fun JKFieldAccessExpression.isInDecrementOrIncrement(): Boolean =
|
||||||
(parent as? JKUnaryExpression)?.operator?.token?.text in listOf("++", "--")
|
when (parent.safeAs<JKUnaryExpression>()?.operator?.token) {
|
||||||
|
JKOperatorToken.PLUSPLUS, JKOperatorToken.MINUSMINUS -> true
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
fun JKVariable.hasWritableUsages(scope: JKTreeElement, context: NewJ2kConverterContext): Boolean =
|
fun JKVariable.hasWritableUsages(scope: JKTreeElement, context: NewJ2kConverterContext): Boolean =
|
||||||
findUsages(scope, context).any {
|
findUsages(scope, context).any {
|
||||||
@@ -181,7 +185,7 @@ fun JKVariable.hasWritableUsages(scope: JKTreeElement, context: NewJ2kConverterC
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun equalsExpression(left: JKExpression, right: JKExpression, typeFactory: JKTypeFactory) =
|
fun equalsExpression(left: JKExpression, right: JKExpression, typeFactory: JKTypeFactory) =
|
||||||
JKBinaryExpressionImpl(
|
JKBinaryExpression(
|
||||||
left,
|
left,
|
||||||
right,
|
right,
|
||||||
JKKtOperatorImpl(
|
JKKtOperatorImpl(
|
||||||
@@ -191,16 +195,16 @@ fun equalsExpression(left: JKExpression, right: JKExpression, typeFactory: JKTyp
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun createCompanion(declarations: List<JKDeclaration>): JKClass =
|
fun createCompanion(declarations: List<JKDeclaration>): JKClass =
|
||||||
JKClassImpl(
|
JKClass(
|
||||||
JKNameIdentifierImpl(""),
|
JKNameIdentifier(""),
|
||||||
JKInheritanceInfoImpl(emptyList(), emptyList()),
|
JKInheritanceInfo(emptyList(), emptyList()),
|
||||||
JKClass.ClassKind.COMPANION,
|
JKClass.ClassKind.COMPANION,
|
||||||
JKTypeParameterListImpl(),
|
JKTypeParameterList(),
|
||||||
JKClassBodyImpl(declarations),
|
JKClassBody(declarations),
|
||||||
JKAnnotationListImpl(),
|
JKAnnotationList(),
|
||||||
emptyList(),
|
emptyList(),
|
||||||
JKVisibilityModifierElementImpl(Visibility.PUBLIC),
|
JKVisibilityModifierElement(Visibility.PUBLIC),
|
||||||
JKModalityModifierElementImpl(Modality.FINAL)
|
JKModalityModifierElement(Modality.FINAL)
|
||||||
)
|
)
|
||||||
|
|
||||||
fun JKClass.getCompanion(): JKClass? =
|
fun JKClass.getCompanion(): JKClass? =
|
||||||
@@ -208,26 +212,17 @@ fun JKClass.getCompanion(): JKClass? =
|
|||||||
|
|
||||||
fun JKClass.getOrCreateCompanionObject(): JKClass =
|
fun JKClass.getOrCreateCompanionObject(): JKClass =
|
||||||
getCompanion()
|
getCompanion()
|
||||||
?: JKClassImpl(
|
?: createCompanion(declarations = emptyList())
|
||||||
JKNameIdentifierImpl(""),
|
.also { classBody.declarations += it }
|
||||||
JKInheritanceInfoImpl(emptyList(), emptyList()),
|
|
||||||
JKClass.ClassKind.COMPANION,
|
|
||||||
JKTypeParameterListImpl(),
|
|
||||||
JKClassBodyImpl(),
|
|
||||||
JKAnnotationListImpl(),
|
|
||||||
emptyList(),
|
|
||||||
JKVisibilityModifierElementImpl(Visibility.PUBLIC),
|
|
||||||
JKModalityModifierElementImpl(Modality.FINAL)
|
|
||||||
).also { classBody.declarations += it }
|
|
||||||
|
|
||||||
fun runExpression(body: JKStatement, symbolProvider: JKSymbolProvider): JKExpression {
|
fun runExpression(body: JKStatement, symbolProvider: JKSymbolProvider): JKExpression {
|
||||||
val lambda = JKLambdaExpressionImpl(
|
val lambda = JKLambdaExpression(
|
||||||
body,
|
body,
|
||||||
emptyList()
|
emptyList()
|
||||||
)
|
)
|
||||||
return JKKtCallExpressionImpl(
|
return JKCallExpressionImpl(
|
||||||
symbolProvider.provideMethodSymbol("kotlin.run"),
|
symbolProvider.provideMethodSymbol("kotlin.run"),
|
||||||
(listOf(lambda)).toArgumentList()
|
listOf(lambda).toArgumentList()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,59 +235,57 @@ fun JKAnnotationMemberValue.toExpression(symbolProvider: JKSymbolProvider): JKEx
|
|||||||
when (element) {
|
when (element) {
|
||||||
is JKClassLiteralExpression ->
|
is JKClassLiteralExpression ->
|
||||||
element.also {
|
element.also {
|
||||||
element.literalType = JKClassLiteralExpression.LiteralType.KOTLIN_CLASS
|
element.literalType = JKClassLiteralExpression.ClassLiteralType.KOTLIN_CLASS
|
||||||
}
|
}
|
||||||
is JKTypeElement ->
|
is JKTypeElement ->
|
||||||
JKTypeElementImpl(element.type.replaceJavaClassWithKotlinClassType(symbolProvider))
|
JKTypeElement(element.type.replaceJavaClassWithKotlinClassType(symbolProvider))
|
||||||
else -> applyRecursive(element, ::handleAnnotationParameter)
|
else -> applyRecursive(element, ::handleAnnotationParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleAnnotationParameter(
|
return handleAnnotationParameter(
|
||||||
when {
|
when (this) {
|
||||||
this is JKStubExpression -> this
|
is JKStubExpression -> this
|
||||||
this is JKAnnotation ->
|
is JKAnnotation -> JKNewExpression(
|
||||||
JKJavaNewExpressionImpl(
|
classSymbol,
|
||||||
classSymbol,
|
JKArgumentList(
|
||||||
JKArgumentListImpl(
|
arguments.map { argument ->
|
||||||
arguments.map { argument ->
|
val value = argument.value.copyTreeAndDetach().toExpression(symbolProvider)
|
||||||
val value = argument.value.copyTreeAndDetach().toExpression(symbolProvider)
|
when (argument) {
|
||||||
when (argument) {
|
is JKAnnotationNameParameter ->
|
||||||
is JKAnnotationNameParameter ->
|
JKNamedArgument(value, JKNameIdentifier(argument.name.value))
|
||||||
JKNamedArgumentImpl(value, JKNameIdentifierImpl(argument.name.value))
|
else -> JKArgumentImpl(value)
|
||||||
else -> JKArgumentImpl(value)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
),
|
|
||||||
JKTypeArgumentListImpl()
|
}
|
||||||
)
|
),
|
||||||
this is JKKtAnnotationArrayInitializerExpression ->
|
JKTypeArgumentList()
|
||||||
JKKtAnnotationArrayInitializerExpressionImpl(initializers.map { it.detached(this).toExpression(symbolProvider) })
|
)
|
||||||
this is JKExpression -> this
|
is JKKtAnnotationArrayInitializerExpression ->
|
||||||
|
JKKtAnnotationArrayInitializerExpression(initializers.map { it.detached(this).toExpression(symbolProvider) })
|
||||||
|
is JKExpression -> this
|
||||||
else -> error("Bad initializer")
|
else -> error("Bad initializer")
|
||||||
}
|
}
|
||||||
) as JKExpression
|
) as JKExpression
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun JKExpression.asLiteralTextWithPrefix(): String? =
|
fun JKExpression.asLiteralTextWithPrefix(): String? = when {
|
||||||
when {
|
this is JKPrefixExpression
|
||||||
this is JKPrefixExpression
|
&& (operator.token == JKOperatorToken.MINUS || operator.token == JKOperatorToken.PLUS)
|
||||||
&& (operator.token.text == "+" || operator.token.text == "-")
|
&& expression is JKLiteralExpression
|
||||||
&& expression is JKLiteralExpression
|
-> operator.token.text + expression.cast<JKLiteralExpression>().literal
|
||||||
-> operator.token.text + expression.cast<JKLiteralExpression>().literal
|
this is JKLiteralExpression -> literal
|
||||||
this is JKLiteralExpression -> literal
|
else -> null
|
||||||
else -> null
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun JKClass.primaryConstructor(): JKKtPrimaryConstructor? = classBody.declarations.firstIsInstanceOrNull()
|
fun JKClass.primaryConstructor(): JKKtPrimaryConstructor? = classBody.declarations.firstIsInstanceOrNull()
|
||||||
|
|
||||||
fun List<JKExpression>.toArgumentList(): JKArgumentList =
|
fun List<JKExpression>.toArgumentList(): JKArgumentList =
|
||||||
JKArgumentListImpl(map { JKArgumentImpl(it) })
|
JKArgumentList(map { JKArgumentImpl(it) })
|
||||||
|
|
||||||
|
|
||||||
fun JKExpression.asStatement(): JKExpressionStatement =
|
fun JKExpression.asStatement(): JKExpressionStatement =
|
||||||
JKExpressionStatementImpl(this)
|
JKExpressionStatement(this)
|
||||||
|
|
||||||
fun <T : JKExpression> T.nullIfStubExpression(): T? =
|
fun <T : JKExpression> T.nullIfStubExpression(): T? =
|
||||||
if (this is JKStubExpression) null
|
if (this is JKStubExpression) null
|
||||||
@@ -300,20 +293,47 @@ fun <T : JKExpression> T.nullIfStubExpression(): T? =
|
|||||||
|
|
||||||
fun JKExpression.qualified(qualifier: JKExpression?) =
|
fun JKExpression.qualified(qualifier: JKExpression?) =
|
||||||
if (qualifier != null && qualifier !is JKStubExpression) {
|
if (qualifier != null && qualifier !is JKStubExpression) {
|
||||||
JKQualifiedExpressionImpl(qualifier, JKJavaQualifierImpl.DOT, this)
|
JKQualifiedExpression(qualifier, this)
|
||||||
} else this
|
} else this
|
||||||
|
|
||||||
fun JKExpression.callOn(
|
fun JKExpression.callOn(
|
||||||
symbol: JKMethodSymbol,
|
symbol: JKMethodSymbol,
|
||||||
arguments: List<JKExpression> = emptyList(),
|
arguments: List<JKExpression> = emptyList(),
|
||||||
typeArguments: List<JKTypeElement> = emptyList()
|
typeArguments: List<JKTypeElement> = emptyList()
|
||||||
) = JKQualifiedExpressionImpl(
|
) = JKQualifiedExpression(
|
||||||
this,
|
this,
|
||||||
JKKtQualifierImpl.DOT,
|
JKCallExpressionImpl(
|
||||||
JKKtCallExpressionImpl(
|
|
||||||
symbol,
|
symbol,
|
||||||
JKArgumentListImpl(arguments.map { JKArgumentImpl(it) }),
|
JKArgumentList(arguments.map { JKArgumentImpl(it) }),
|
||||||
JKTypeArgumentListImpl(typeArguments)
|
JKTypeArgumentList(typeArguments)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val JKStatement.statements: List<JKStatement>
|
||||||
|
get() = when (this) {
|
||||||
|
is JKBlockStatement -> block.statements
|
||||||
|
else -> listOf(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
val JKElement.psi: PsiElement?
|
||||||
|
get() = (this as? PsiOwner)?.psi
|
||||||
|
|
||||||
|
inline fun <reified Elem : PsiElement> JKElement.psi(): Elem? = (this as? PsiOwner)?.psi as? Elem
|
||||||
|
|
||||||
|
fun JKTypeElement.present(): Boolean = type != JKNoType
|
||||||
|
|
||||||
|
fun JKStatement.isEmpty(): Boolean = when (this) {
|
||||||
|
is JKEmptyStatement -> true
|
||||||
|
is JKBlockStatement -> block is JKBodyStub
|
||||||
|
is JKExpressionStatement -> expression is JKStubExpression
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun JKInheritanceInfo.present(): Boolean =
|
||||||
|
extends.isNotEmpty() || implements.isNotEmpty()
|
||||||
|
|
||||||
|
fun JKClass.isLocalClass(): Boolean =
|
||||||
|
parent !is JKClassBody && parent !is JKFile
|
||||||
|
|
||||||
|
val JKClass.declarationList: List<JKDeclaration>
|
||||||
|
get() = classBody.declarations
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import com.intellij.psi.util.PsiUtil
|
|||||||
import org.jetbrains.kotlin.j2k.ReferenceSearcher
|
import org.jetbrains.kotlin.j2k.ReferenceSearcher
|
||||||
import org.jetbrains.kotlin.j2k.isNullLiteral
|
import org.jetbrains.kotlin.j2k.isNullLiteral
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKModalityModifierElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKVisibilityModifierElementImpl
|
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
import org.jetbrains.kotlin.psi.psiUtil.parentsWithSelf
|
||||||
|
|
||||||
//copied from old j2k
|
//copied from old j2k
|
||||||
@@ -57,11 +57,11 @@ internal fun PsiMember.visibility(
|
|||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}?.let {
|
}?.let {
|
||||||
JKVisibilityModifierElementImpl(it)
|
JKVisibilityModifierElement(it)
|
||||||
}?.also { modifier ->
|
}?.also { modifier ->
|
||||||
assignNonCodeElements?.also { it(modifier, child) }
|
assignNonCodeElements?.also { it(modifier, child) }
|
||||||
}
|
}
|
||||||
}?.firstOrNull() ?: JKVisibilityModifierElementImpl(Visibility.INTERNAL)
|
}?.firstOrNull() ?: JKVisibilityModifierElement(Visibility.INTERNAL)
|
||||||
|
|
||||||
|
|
||||||
fun PsiMember.modality(assignNonCodeElements: ((JKNonCodeElementsListOwner, PsiElement) -> Unit)?) =
|
fun PsiMember.modality(assignNonCodeElements: ((JKNonCodeElementsListOwner, PsiElement) -> Unit)?) =
|
||||||
@@ -73,11 +73,11 @@ fun PsiMember.modality(assignNonCodeElements: ((JKNonCodeElementsListOwner, PsiE
|
|||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}?.let {
|
}?.let {
|
||||||
JKModalityModifierElementImpl(it)
|
JKModalityModifierElement(it)
|
||||||
}?.also { modifier ->
|
}?.also { modifier ->
|
||||||
assignNonCodeElements?.let { it(modifier, child) }
|
assignNonCodeElements?.let { it(modifier, child) }
|
||||||
}
|
}
|
||||||
}?.firstOrNull() ?: JKModalityModifierElementImpl(Modality.OPEN)
|
}?.firstOrNull() ?: JKModalityModifierElement(Modality.OPEN)
|
||||||
|
|
||||||
|
|
||||||
private fun PsiMember.handleProtectedVisibility(referenceSearcher: ReferenceSearcher): Visibility {
|
private fun PsiMember.handleProtectedVisibility(referenceSearcher: ReferenceSearcher): Visibility {
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ package org.jetbrains.kotlin.nj2k.symbols
|
|||||||
import com.intellij.psi.PsiVariable
|
import com.intellij.psi.PsiVariable
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKType
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKVariable
|
import org.jetbrains.kotlin.nj2k.tree.JKVariable
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKClassTypeImpl
|
import org.jetbrains.kotlin.nj2k.types.toJK
|
||||||
import org.jetbrains.kotlin.nj2k.tree.toJK
|
import org.jetbrains.kotlin.nj2k.types.JKClassTypeImpl
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
||||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||||
import org.jetbrains.kotlin.psi.KtEnumEntry
|
import org.jetbrains.kotlin.psi.KtEnumEntry
|
||||||
|
|||||||
@@ -5,16 +5,20 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.symbols
|
package org.jetbrains.kotlin.nj2k.symbols
|
||||||
|
|
||||||
|
|
||||||
import com.intellij.psi.PsiMethod
|
import com.intellij.psi.PsiMethod
|
||||||
import com.intellij.psi.PsiReference
|
import com.intellij.psi.PsiReference
|
||||||
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
import org.jetbrains.kotlin.asJava.elements.KtLightMethod
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
|
import org.jetbrains.kotlin.nj2k.tree.JKClass
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.JKMethod
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKClassTypeImpl
|
import org.jetbrains.kotlin.nj2k.types.asType
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKNoTypeImpl
|
import org.jetbrains.kotlin.nj2k.types.toJK
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKClassTypeImpl
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKNoTypeImpl
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
import org.jetbrains.kotlin.nj2k.types.JKTypeFactory
|
||||||
import org.jetbrains.kotlin.psi.KtFunction
|
import org.jetbrains.kotlin.psi.KtFunction
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|||||||
@@ -10,8 +10,11 @@ import com.intellij.psi.PsiMethod
|
|||||||
import com.intellij.psi.PsiModifier
|
import com.intellij.psi.PsiModifier
|
||||||
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
||||||
import org.jetbrains.kotlin.idea.search.declarationsSearch.findDeepestSuperMethodsNoWrapping
|
import org.jetbrains.kotlin.idea.search.declarationsSearch.findDeepestSuperMethodsNoWrapping
|
||||||
|
import org.jetbrains.kotlin.nj2k.psi
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.psi
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.arrayInnerType
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
@@ -27,11 +30,10 @@ fun JKSymbol.getDisplayName(): String {
|
|||||||
}.fold(name) { acc, symbol -> "${symbol.name}.$acc" }
|
}.fold(name) { acc, symbol -> "${symbol.name}.$acc" }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun JKSymbol.fqNameToImport(): String? =
|
fun JKSymbol.fqNameToImport(): String? = when {
|
||||||
when {
|
this is JKClassSymbol && this !is JKUniverseClassSymbol -> fqName
|
||||||
this is JKClassSymbol && this !is JKUniverseClassSymbol -> fqName
|
else -> null
|
||||||
else -> null
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fun JKSymbol.deepestFqName(): String? {
|
fun JKSymbol.deepestFqName(): String? {
|
||||||
fun Any.deepestFqNameForTarget(): String? =
|
fun Any.deepestFqNameForTarget(): String? =
|
||||||
@@ -43,32 +45,3 @@ fun JKSymbol.deepestFqName(): String? {
|
|||||||
}
|
}
|
||||||
return target.deepestFqNameForTarget() ?: fqName
|
return target.deepestFqNameForTarget() ?: fqName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
val JKMethodSymbol.parameterNames: List<String>?
|
|
||||||
get() {
|
|
||||||
return when (this) {
|
|
||||||
is JKMultiverseFunctionSymbol -> target.valueParameters.map { it.name ?: return null }
|
|
||||||
is JKMultiverseMethodSymbol -> target.parameters.map { it.name ?: return null }
|
|
||||||
is JKUniverseMethodSymbol -> target.parameters.map { it.name.value }
|
|
||||||
is JKUnresolvedMethod -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val JKMethodSymbol.isStatic: Boolean
|
|
||||||
get() = when (this) {
|
|
||||||
is JKMultiverseFunctionSymbol -> target.parent is KtObjectDeclaration
|
|
||||||
is JKMultiverseMethodSymbol -> target.hasModifierProperty(PsiModifier.STATIC)
|
|
||||||
is JKUniverseMethodSymbol -> target.parent?.parent?.safeAs<JKClass>()?.classKind == JKClass.ClassKind.COMPANION
|
|
||||||
is JKUnresolvedMethod -> false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun JKMethodSymbol.parameterTypesWithUnfoldedVarargs(): Sequence<JKType>? {
|
|
||||||
val realParameterTypes = parameterTypes ?: return null
|
|
||||||
if (realParameterTypes.isEmpty()) return emptySequence()
|
|
||||||
val lastArrayType = realParameterTypes.last().arrayInnerType() ?: return realParameterTypes.asSequence()
|
|
||||||
return realParameterTypes.dropLast(1).asSequence() + generateSequence { lastArrayType }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,137 +5,155 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
import com.intellij.psi.JavaTokenType
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.tree.IElementType
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import kotlin.properties.ReadWriteProperty
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import kotlin.reflect.KProperty
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKJavaOperatorToken
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtSingleValueOperatorToken
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKKtWordOperatorToken
|
|
||||||
|
|
||||||
interface JKOperator {
|
|
||||||
val token: JKOperatorToken
|
|
||||||
val returnType: JKType
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKOperatorToken {
|
|
||||||
val text: String
|
|
||||||
|
|
||||||
@Suppress("MemberVisibilityCanBePrivate", "SpellCheckingInspection")
|
|
||||||
companion object {
|
|
||||||
fun fromElementType(elementType: IElementType) = elementTypeToToken.getValue(elementType)
|
|
||||||
|
|
||||||
val RANGE = JKKtSingleValueOperatorToken(KtTokens.RANGE)
|
|
||||||
|
|
||||||
val DIV = JKKtSingleValueOperatorToken(KtTokens.DIV)
|
|
||||||
val MINUS = JKKtSingleValueOperatorToken(KtTokens.MINUS)
|
|
||||||
val ANDAND = JKKtSingleValueOperatorToken(KtTokens.ANDAND)
|
|
||||||
val OROR = JKKtSingleValueOperatorToken(KtTokens.OROR)
|
|
||||||
val PLUS = JKKtSingleValueOperatorToken(KtTokens.PLUS)
|
|
||||||
val MUL = JKKtSingleValueOperatorToken(KtTokens.MUL)
|
|
||||||
val GT = JKKtSingleValueOperatorToken(KtTokens.GT)
|
|
||||||
val GTEQ = JKKtSingleValueOperatorToken(KtTokens.GTEQ)
|
|
||||||
val LT = JKKtSingleValueOperatorToken(KtTokens.LT)
|
|
||||||
val LTEQ = JKKtSingleValueOperatorToken(KtTokens.LTEQ)
|
|
||||||
val PERC = JKKtSingleValueOperatorToken(KtTokens.PERC)
|
|
||||||
val EQ = JKKtSingleValueOperatorToken(KtTokens.EQ)
|
|
||||||
val EQEQ = JKKtSingleValueOperatorToken(KtTokens.EQEQ)
|
|
||||||
val EXCLEQ = JKKtSingleValueOperatorToken(KtTokens.EXCLEQ)
|
|
||||||
|
|
||||||
val PLUSEQ = JKKtSingleValueOperatorToken(KtTokens.PLUSEQ)
|
|
||||||
val MINUSEQ = JKKtSingleValueOperatorToken(KtTokens.MINUSEQ)
|
|
||||||
val DIVEQ = JKKtSingleValueOperatorToken(KtTokens.DIVEQ)
|
|
||||||
val MULTEQ = JKKtSingleValueOperatorToken(KtTokens.MULTEQ)
|
|
||||||
val PERCEQ = JKKtSingleValueOperatorToken(KtTokens.PERCEQ)
|
|
||||||
|
|
||||||
|
|
||||||
val PLUSPLUS = JKKtSingleValueOperatorToken(KtTokens.PLUSPLUS)
|
|
||||||
val MINUSMINUS = JKKtSingleValueOperatorToken(KtTokens.MINUSMINUS)
|
|
||||||
val EXCL = JKKtSingleValueOperatorToken(KtTokens.EXCL)
|
|
||||||
val EQEQEQ = JKKtSingleValueOperatorToken(KtTokens.EQEQEQ)
|
|
||||||
val EXCLEQEQEQ = JKKtSingleValueOperatorToken(KtTokens.EXCLEQEQEQ)
|
|
||||||
|
|
||||||
val AND = JKKtWordOperatorToken("and")
|
|
||||||
val OR = JKKtWordOperatorToken("or")
|
|
||||||
val XOR = JKKtWordOperatorToken("xor")
|
|
||||||
val USHR = JKKtWordOperatorToken("ushr")
|
|
||||||
val SHR = JKKtWordOperatorToken("shr")
|
|
||||||
val SHL = JKKtWordOperatorToken("shl")
|
|
||||||
|
|
||||||
val ANDEQ = JKJavaOperatorToken(JavaTokenType.ANDEQ)
|
|
||||||
val OREQ = JKJavaOperatorToken(JavaTokenType.OREQ)
|
|
||||||
val XOREQ = JKJavaOperatorToken(JavaTokenType.XOREQ)
|
|
||||||
val LTLTEQ = JKJavaOperatorToken(JavaTokenType.LTLTEQ)
|
|
||||||
val GTGTEQ = JKJavaOperatorToken(JavaTokenType.GTGTEQ)
|
|
||||||
val GTGTGTEQ = JKJavaOperatorToken(JavaTokenType.GTGTGTEQ)
|
|
||||||
|
|
||||||
|
|
||||||
private val elementTypeToToken: Map<IElementType, JKOperatorToken> = mapOf(
|
|
||||||
JavaTokenType.DIV to DIV,
|
|
||||||
JavaTokenType.MINUS to MINUS,
|
|
||||||
JavaTokenType.ANDAND to ANDAND,
|
|
||||||
JavaTokenType.OROR to OROR,
|
|
||||||
JavaTokenType.PLUS to PLUS,
|
|
||||||
JavaTokenType.ASTERISK to MUL,
|
|
||||||
JavaTokenType.GT to GT,
|
|
||||||
JavaTokenType.GE to GTEQ,
|
|
||||||
JavaTokenType.LT to LT,
|
|
||||||
JavaTokenType.LE to LTEQ,
|
|
||||||
JavaTokenType.PERC to PERC,
|
|
||||||
|
|
||||||
JavaTokenType.EQ to EQ,
|
|
||||||
JavaTokenType.EQEQ to EQEQ,
|
|
||||||
JavaTokenType.NE to EXCLEQ,
|
|
||||||
|
|
||||||
JavaTokenType.PLUSEQ to PLUSEQ,
|
|
||||||
JavaTokenType.MINUSEQ to MINUSEQ,
|
|
||||||
JavaTokenType.DIVEQ to DIVEQ,
|
|
||||||
JavaTokenType.ASTERISKEQ to MULTEQ,
|
|
||||||
|
|
||||||
JavaTokenType.PLUSPLUS to PLUSPLUS,
|
|
||||||
JavaTokenType.MINUSMINUS to MINUSMINUS,
|
|
||||||
JavaTokenType.EXCL to EXCL,
|
|
||||||
|
|
||||||
KtTokens.EQEQEQ to EQEQEQ,
|
|
||||||
KtTokens.EXCLEQEQEQ to EXCLEQEQEQ,
|
|
||||||
|
|
||||||
JavaTokenType.AND to AND,
|
|
||||||
JavaTokenType.OR to OR,
|
|
||||||
JavaTokenType.XOR to XOR,
|
|
||||||
JavaTokenType.GTGTGT to USHR,
|
|
||||||
JavaTokenType.GTGT to SHR,
|
|
||||||
JavaTokenType.LTLT to SHL,
|
|
||||||
|
|
||||||
JavaTokenType.ANDEQ to ANDEQ,
|
|
||||||
JavaTokenType.OREQ to OREQ,
|
|
||||||
JavaTokenType.XOREQ to XOREQ,
|
|
||||||
JavaTokenType.PERCEQ to PERCEQ,
|
|
||||||
JavaTokenType.LTLTEQ to LTLTEQ,
|
|
||||||
JavaTokenType.GTGTEQ to GTGTEQ,
|
|
||||||
JavaTokenType.GTGTGTEQ to GTGTGTEQ
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtOperatorToken : JKOperatorToken
|
|
||||||
interface JKQualifier
|
|
||||||
|
|
||||||
interface JKElement {
|
interface JKElement {
|
||||||
val parent: JKElement?
|
val parent: JKElement?
|
||||||
|
|
||||||
fun detach(from: JKElement)
|
fun detach(from: JKElement)
|
||||||
|
|
||||||
fun attach(to: JKElement)
|
fun attach(to: JKElement)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class JKChild<T : JKElement>(val value: Int) : ReadWriteProperty<JKTreeElement, T> {
|
||||||
|
override operator fun getValue(thisRef: JKTreeElement, property: KProperty<*>): T {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return thisRef.children[value] as T
|
||||||
|
}
|
||||||
|
|
||||||
interface JKBranchElement : JKElement {
|
override operator fun setValue(thisRef: JKTreeElement, property: KProperty<*>, value: T) {
|
||||||
val children: List<Any>
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
(thisRef.children[this.value] as T).detach(thisRef)
|
||||||
val valid: Boolean
|
thisRef.children[this.value] = value
|
||||||
fun invalidate()
|
value.attach(thisRef)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class JKListChild<T : JKElement>(val value: Int) : ReadWriteProperty<JKTreeElement, List<T>> {
|
||||||
|
override operator fun getValue(thisRef: JKTreeElement, property: KProperty<*>): List<T> {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
return thisRef.children[value] as List<T>
|
||||||
|
}
|
||||||
|
|
||||||
|
override operator fun setValue(thisRef: JKTreeElement, property: KProperty<*>, value: List<T>) {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
(thisRef.children[this.value] as List<T>).forEach { it.detach(thisRef) }
|
||||||
|
thisRef.children[this.value] = value
|
||||||
|
value.forEach { it.attach(thisRef) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
abstract class JKTreeElement : JKElement, JKNonCodeElementsListOwner, Cloneable {
|
||||||
|
override val leftNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
||||||
|
override val rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
||||||
|
|
||||||
|
override var parent: JKElement? = null
|
||||||
|
|
||||||
|
override fun detach(from: JKElement) {
|
||||||
|
val prevParent = parent
|
||||||
|
require(from == prevParent)
|
||||||
|
parent = null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun attach(to: JKElement) {
|
||||||
|
check(parent == null)
|
||||||
|
parent = to
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun accept(visitor: JKVisitor) = visitor.visitTreeElement(this)
|
||||||
|
|
||||||
|
private var childNum = 0
|
||||||
|
|
||||||
|
protected fun <T : JKTreeElement, U : T> child(v: U): ReadWriteProperty<JKTreeElement, T> {
|
||||||
|
children.add(childNum, v)
|
||||||
|
v.attach(this)
|
||||||
|
return JKChild(childNum++)
|
||||||
|
}
|
||||||
|
|
||||||
|
protected inline fun <reified T : JKTreeElement> children(): ReadWriteProperty<JKTreeElement, List<T>> {
|
||||||
|
return children(emptyList())
|
||||||
|
}
|
||||||
|
|
||||||
|
protected fun <T : JKTreeElement> children(v: List<T>): ReadWriteProperty<JKTreeElement, List<T>> {
|
||||||
|
children.add(childNum, v)
|
||||||
|
v.forEach { it.attach(this) }
|
||||||
|
return JKListChild(childNum++)
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun acceptChildren(visitor: JKVisitor) {
|
||||||
|
forEachChild { it.accept(visitor) }
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun forEachChild(block: (JKTreeElement) -> Unit) {
|
||||||
|
children.forEach {
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
if (it is JKTreeElement)
|
||||||
|
block(it)
|
||||||
|
else
|
||||||
|
(it as? List<JKTreeElement>)?.forEach { block(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private var valid: Boolean = true
|
||||||
|
|
||||||
|
fun invalidate() {
|
||||||
|
forEachChild { it.detach(this) }
|
||||||
|
valid = false
|
||||||
|
}
|
||||||
|
|
||||||
|
fun onAttach() {
|
||||||
|
check(valid)
|
||||||
|
}
|
||||||
|
|
||||||
|
var children: MutableList<Any> = mutableListOf()
|
||||||
|
private set
|
||||||
|
|
||||||
|
@Suppress("UNCHECKED_CAST")
|
||||||
|
open fun copy(): JKTreeElement {
|
||||||
|
val cloned = clone() as JKTreeElement
|
||||||
|
val deepClonedChildren =
|
||||||
|
cloned.children.map {
|
||||||
|
when (it) {
|
||||||
|
is JKTreeElement -> it.copy()
|
||||||
|
is List<*> -> (it as List<JKTreeElement>).map { it.copy() }
|
||||||
|
else -> error("Tree is corrupted")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
deepClonedChildren.forEach { child ->
|
||||||
|
when (child) {
|
||||||
|
is JKTreeElement -> {
|
||||||
|
child.detach(this)
|
||||||
|
child.attach(cloned)
|
||||||
|
}
|
||||||
|
is List<*> -> (child as List<JKTreeElement>).forEach {
|
||||||
|
it.detach(this)
|
||||||
|
it.attach(cloned)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cloned.children = deepClonedChildren.toMutableList()
|
||||||
|
return cloned
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKAnnotationMemberValue : JKTreeElement()
|
||||||
|
|
||||||
|
interface PsiOwner {
|
||||||
|
var psi: PsiElement?
|
||||||
|
}
|
||||||
|
|
||||||
|
class PsiOwnerImpl(override var psi: PsiElement? = null) : PsiOwner
|
||||||
|
|
||||||
|
interface JKTypeArgumentListOwner : JKNonCodeElementsListOwner {
|
||||||
|
var typeArgumentList: JKTypeArgumentList
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JKTypeParameterListOwner : JKNonCodeElementsListOwner {
|
||||||
|
var typeParameterList: JKTypeParameterList
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKType {
|
|
||||||
val nullability: Nullability
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,246 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKNoTypeImpl
|
||||||
|
|
||||||
|
abstract class JKDeclaration : JKTreeElement(), PsiOwner by PsiOwnerImpl() {
|
||||||
|
abstract val name: JKNameIdentifier
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKClass(
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
inheritance: JKInheritanceInfo,
|
||||||
|
var classKind: ClassKind,
|
||||||
|
typeParameterList: JKTypeParameterList,
|
||||||
|
classBody: JKClassBody,
|
||||||
|
annotationList: JKAnnotationList,
|
||||||
|
otherModifierElements: List<JKOtherModifierElement>,
|
||||||
|
visibilityElement: JKVisibilityModifierElement,
|
||||||
|
modalityElement: JKModalityModifierElement
|
||||||
|
) : JKDeclaration(), JKVisibilityOwner, JKOtherModifiersOwner, JKModalityOwner, JKTypeParameterListOwner, JKAnnotationListOwner {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitClass(this)
|
||||||
|
|
||||||
|
override var name by child(name)
|
||||||
|
val inheritance by child(inheritance)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
||||||
|
var classBody: JKClassBody by child(classBody)
|
||||||
|
override var annotationList: JKAnnotationList by child(annotationList)
|
||||||
|
|
||||||
|
override var otherModifierElements by children(otherModifierElements)
|
||||||
|
override var visibilityElement by child(visibilityElement)
|
||||||
|
override var modalityElement by child(modalityElement)
|
||||||
|
|
||||||
|
enum class ClassKind {
|
||||||
|
ANNOTATION, CLASS, ENUM, INTERFACE, OBJECT, COMPANION
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKVariable : JKDeclaration(), JKAnnotationListOwner {
|
||||||
|
abstract var type: JKTypeElement
|
||||||
|
abstract var initializer: JKExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKLocalVariable(
|
||||||
|
type: JKTypeElement,
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
initializer: JKExpression,
|
||||||
|
mutabilityElement: JKMutabilityModifierElement,
|
||||||
|
annotationList: JKAnnotationList = JKAnnotationList()
|
||||||
|
) : JKVariable(), JKMutabilityOwner {
|
||||||
|
override var initializer by child(initializer)
|
||||||
|
override var name by child(name)
|
||||||
|
override var type by child(type)
|
||||||
|
override var annotationList by child(annotationList)
|
||||||
|
override var mutabilityElement by child(mutabilityElement)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitLocalVariable(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKForLoopVariable(
|
||||||
|
type: JKTypeElement,
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
initializer: JKExpression,
|
||||||
|
annotationList: JKAnnotationList = JKAnnotationList()
|
||||||
|
) : JKVariable() {
|
||||||
|
override var initializer by child(initializer)
|
||||||
|
override var name by child(name)
|
||||||
|
override var type by child(type)
|
||||||
|
override var annotationList by child(annotationList)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitForLoopVariable(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKParameter(
|
||||||
|
type: JKTypeElement,
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
var isVarArgs: Boolean = false,
|
||||||
|
initializer: JKExpression = JKStubExpression(),
|
||||||
|
annotationList: JKAnnotationList = JKAnnotationList()
|
||||||
|
) : JKVariable(), JKModifiersListOwner {
|
||||||
|
override var initializer by child(initializer)
|
||||||
|
override var name by child(name)
|
||||||
|
override var type by child(type)
|
||||||
|
override var annotationList by child(annotationList)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitParameter(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKEnumConstant(
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
arguments: JKArgumentList,
|
||||||
|
body: JKClassBody,
|
||||||
|
type: JKTypeElement,
|
||||||
|
annotationList: JKAnnotationList = JKAnnotationList()
|
||||||
|
) : JKVariable() {
|
||||||
|
override var name: JKNameIdentifier by child(name)
|
||||||
|
val arguments: JKArgumentList by child(arguments)
|
||||||
|
val body: JKClassBody by child(body)
|
||||||
|
override var type: JKTypeElement by child(type)
|
||||||
|
override var initializer: JKExpression by child(JKStubExpression())
|
||||||
|
override var annotationList by child(annotationList)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitEnumConstant(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKTypeParameter(name: JKNameIdentifier, upperBounds: List<JKTypeElement>) : JKDeclaration() {
|
||||||
|
override var name: JKNameIdentifier by child(name)
|
||||||
|
var upperBounds: List<JKTypeElement> by children(upperBounds)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitTypeParameter(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKMethod : JKDeclaration(), JKVisibilityOwner, JKModalityOwner, JKOtherModifiersOwner, JKTypeParameterListOwner,
|
||||||
|
JKAnnotationListOwner {
|
||||||
|
abstract var parameters: List<JKParameter>
|
||||||
|
abstract var returnType: JKTypeElement
|
||||||
|
abstract var block: JKBlock
|
||||||
|
|
||||||
|
val leftParen = JKTokenElementImpl("(")
|
||||||
|
val rightParen = JKTokenElementImpl(")")
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKMethodImpl(
|
||||||
|
returnType: JKTypeElement,
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
parameters: List<JKParameter>,
|
||||||
|
block: JKBlock,
|
||||||
|
typeParameterList: JKTypeParameterList,
|
||||||
|
annotationList: JKAnnotationList,
|
||||||
|
throwsList: List<JKTypeElement>,
|
||||||
|
otherModifierElements: List<JKOtherModifierElement>,
|
||||||
|
visibilityElement: JKVisibilityModifierElement,
|
||||||
|
modalityElement: JKModalityModifierElement
|
||||||
|
) : JKMethod() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitMethod(this)
|
||||||
|
|
||||||
|
override var returnType: JKTypeElement by child(returnType)
|
||||||
|
override var name: JKNameIdentifier by child(name)
|
||||||
|
override var parameters: List<JKParameter> by children(parameters)
|
||||||
|
override var block: JKBlock by child(block)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
||||||
|
override var annotationList: JKAnnotationList by child(annotationList)
|
||||||
|
var throwsList: List<JKTypeElement> by children(throwsList)
|
||||||
|
|
||||||
|
override var otherModifierElements by children(otherModifierElements)
|
||||||
|
override var visibilityElement by child(visibilityElement)
|
||||||
|
override var modalityElement by child(modalityElement)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKConstructor : JKMethod() {
|
||||||
|
abstract var delegationCall: JKExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKConstructorImpl(
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
parameters: List<JKParameter>,
|
||||||
|
block: JKBlock,
|
||||||
|
delegationCall: JKExpression,
|
||||||
|
annotationList: JKAnnotationList,
|
||||||
|
otherModifierElements: List<JKOtherModifierElement>,
|
||||||
|
visibilityElement: JKVisibilityModifierElement,
|
||||||
|
modalityElement: JKModalityModifierElement
|
||||||
|
) : JKConstructor() {
|
||||||
|
override var returnType: JKTypeElement by child(JKTypeElement(JKNoTypeImpl))
|
||||||
|
|
||||||
|
override var name: JKNameIdentifier by child(name)
|
||||||
|
override var parameters: List<JKParameter> by children(parameters)
|
||||||
|
override var block: JKBlock by child(block)
|
||||||
|
override var delegationCall: JKExpression by child(delegationCall)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterList())
|
||||||
|
override var annotationList: JKAnnotationList by child(annotationList)
|
||||||
|
|
||||||
|
override var otherModifierElements by children(otherModifierElements)
|
||||||
|
override var visibilityElement by child(visibilityElement)
|
||||||
|
override var modalityElement by child(modalityElement)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitConstructor(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKKtPrimaryConstructor(
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
parameters: List<JKParameter>,
|
||||||
|
delegationCall: JKExpression,
|
||||||
|
annotationList: JKAnnotationList,
|
||||||
|
otherModifierElements: List<JKOtherModifierElement>,
|
||||||
|
visibilityElement: JKVisibilityModifierElement,
|
||||||
|
modalityElement: JKModalityModifierElement
|
||||||
|
) : JKConstructor() {
|
||||||
|
override var returnType: JKTypeElement by child(JKTypeElement(JKNoTypeImpl))
|
||||||
|
|
||||||
|
override var name: JKNameIdentifier by child(name)
|
||||||
|
override var parameters: List<JKParameter> by children(parameters)
|
||||||
|
override var block: JKBlock by child(JKBodyStub)
|
||||||
|
override var delegationCall: JKExpression by child(delegationCall)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterList())
|
||||||
|
override var annotationList: JKAnnotationList by child(annotationList)
|
||||||
|
override var otherModifierElements by children(otherModifierElements)
|
||||||
|
override var visibilityElement by child(visibilityElement)
|
||||||
|
override var modalityElement by child(modalityElement)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtPrimaryConstructor(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKField(
|
||||||
|
type: JKTypeElement,
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
initializer: JKExpression,
|
||||||
|
annotationList: JKAnnotationList,
|
||||||
|
otherModifierElements: List<JKOtherModifierElement>,
|
||||||
|
visibilityElement: JKVisibilityModifierElement,
|
||||||
|
modalityElement: JKModalityModifierElement,
|
||||||
|
mutabilityElement: JKMutabilityModifierElement
|
||||||
|
) : JKVariable(), JKVisibilityOwner, JKMutabilityOwner, JKModalityOwner, JKOtherModifiersOwner, JKAnnotationListOwner {
|
||||||
|
override var annotationList: JKAnnotationList by child(annotationList)
|
||||||
|
override var initializer: JKExpression by child(initializer)
|
||||||
|
override var type by child(type)
|
||||||
|
override var name: JKNameIdentifier by child(name)
|
||||||
|
override var otherModifierElements by children(otherModifierElements)
|
||||||
|
override var visibilityElement by child(visibilityElement)
|
||||||
|
override var modalityElement by child(modalityElement)
|
||||||
|
override var mutabilityElement by child(mutabilityElement)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitField(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKKtInitDeclaration(block: JKBlock) : JKDeclaration() {
|
||||||
|
var block: JKBlock by child(block)
|
||||||
|
override val name: JKNameIdentifier by child(JKNameIdentifier("<init>"))
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtInitDeclaration(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKJavaStaticInitDeclaration(block: JKBlock) : JKDeclaration() {
|
||||||
|
var block: JKBlock by child(block)
|
||||||
|
override var name: JKNameIdentifier by child(JKNameIdentifier("<init>"))
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaStaticInitDeclaration(this)
|
||||||
|
}
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
|
|
||||||
|
class JKTreeRoot(element: JKTreeElement) : JKTreeElement() {
|
||||||
|
var element by child(element)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitTreeRoot(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKFile(
|
||||||
|
packageDeclaration: JKPackageDeclaration,
|
||||||
|
importList: JKImportList,
|
||||||
|
declarationList: List<JKDeclaration>
|
||||||
|
) : JKTreeElement(), PsiOwner by PsiOwnerImpl() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitFile(this)
|
||||||
|
|
||||||
|
var packageDeclaration: JKPackageDeclaration by child(packageDeclaration)
|
||||||
|
var importList: JKImportList by child(importList)
|
||||||
|
var declarationList by children(declarationList)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKTypeElement(var type: JKType) : JKTreeElement() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitTypeElement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKBlock : JKTreeElement() {
|
||||||
|
abstract var statements: List<JKStatement>
|
||||||
|
|
||||||
|
val leftBrace = JKTokenElementImpl("{")
|
||||||
|
val rightBrace = JKTokenElementImpl("}")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
object JKBodyStub : JKBlock() {
|
||||||
|
override val leftNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
||||||
|
override val rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
||||||
|
|
||||||
|
override fun copy(): JKTreeElement = this
|
||||||
|
|
||||||
|
override var statements: List<JKStatement>
|
||||||
|
get() = emptyList()
|
||||||
|
set(_) {}
|
||||||
|
|
||||||
|
override fun acceptChildren(visitor: JKVisitor) {}
|
||||||
|
|
||||||
|
override var parent: JKElement?
|
||||||
|
get() = null
|
||||||
|
set(_) {}
|
||||||
|
|
||||||
|
override fun detach(from: JKElement) {}
|
||||||
|
override fun attach(to: JKElement) {}
|
||||||
|
override fun accept(visitor: JKVisitor) = Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKInheritanceInfo(
|
||||||
|
extends: List<JKTypeElement>,
|
||||||
|
implements: List<JKTypeElement>
|
||||||
|
) : JKTreeElement() {
|
||||||
|
var extends: List<JKTypeElement> by children(extends)
|
||||||
|
var implements: List<JKTypeElement> by children(implements)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitInheritanceInfo(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKPackageDeclaration(name: JKNameIdentifier) : JKTreeElement() {
|
||||||
|
var name: JKNameIdentifier by child(name)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitPackageDeclaration(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKLabel : JKTreeElement()
|
||||||
|
|
||||||
|
class JKLabelEmpty : JKLabel() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitLabelEmpty(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKLabelText(label: JKNameIdentifier) : JKLabel() {
|
||||||
|
val label: JKNameIdentifier by child(label)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitLabelText(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKImportStatement(name: JKNameIdentifier) : JKTreeElement() {
|
||||||
|
val name: JKNameIdentifier by child(name)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitImportStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKImportList(imports: List<JKImportStatement>) : JKTreeElement() {
|
||||||
|
var imports by children(imports)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitImportList(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKAnnotationParameter : JKTreeElement() {
|
||||||
|
abstract var value: JKAnnotationMemberValue
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKAnnotationParameterImpl(value: JKAnnotationMemberValue) : JKAnnotationParameter() {
|
||||||
|
override var value: JKAnnotationMemberValue by child(value)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitAnnotationParameter(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKAnnotationNameParameter(
|
||||||
|
value: JKAnnotationMemberValue,
|
||||||
|
name: JKNameIdentifier
|
||||||
|
) : JKAnnotationParameter() {
|
||||||
|
override var value: JKAnnotationMemberValue by child(value)
|
||||||
|
val name: JKNameIdentifier by child(name)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitAnnotationNameParameter(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKArgument : JKTreeElement() {
|
||||||
|
abstract var value: JKExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKNamedArgument(
|
||||||
|
value: JKExpression,
|
||||||
|
name: JKNameIdentifier
|
||||||
|
) : JKArgument() {
|
||||||
|
override var value by child(value)
|
||||||
|
val name by child(name)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitNamedArgument(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKArgumentImpl(value: JKExpression) : JKArgument() {
|
||||||
|
override var value by child(value)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitArgument(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKArgumentList(arguments: List<JKArgument> = emptyList()) : JKTreeElement() {
|
||||||
|
constructor(vararg arguments: JKArgument) : this(arguments.toList())
|
||||||
|
constructor(vararg values: JKExpression) : this(values.map { JKArgumentImpl(it) })
|
||||||
|
|
||||||
|
var arguments by children(arguments)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitArgumentList(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKTypeParameterList(typeParameters: List<JKTypeParameter> = emptyList()) : JKTreeElement() {
|
||||||
|
var typeParameters by children(typeParameters)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitTypeParameterList(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKAnnotationList(annotations: List<JKAnnotation> = emptyList()) : JKTreeElement() {
|
||||||
|
var annotations: List<JKAnnotation> by children(annotations)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitAnnotationList(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKAnnotation(
|
||||||
|
var classSymbol: JKClassSymbol,
|
||||||
|
arguments: List<JKAnnotationParameter> = emptyList()
|
||||||
|
) : JKAnnotationMemberValue() {
|
||||||
|
var arguments: List<JKAnnotationParameter> by children(arguments)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitAnnotation(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKTypeArgumentList(typeArguments: List<JKTypeElement> = emptyList()) : JKTreeElement(), PsiOwner by PsiOwnerImpl() {
|
||||||
|
var typeArguments: List<JKTypeElement> by children(typeArguments)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitTypeArgumentList(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKNameIdentifier(val value: String) : JKTreeElement() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitNameIdentifier(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface JKAnnotationListOwner : JKNonCodeElementsListOwner {
|
||||||
|
var annotationList: JKAnnotationList
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKBlockImpl(statements: List<JKStatement> = emptyList()) : JKBlock() {
|
||||||
|
constructor(vararg statements: JKStatement) : this(statements.toList())
|
||||||
|
|
||||||
|
override var statements by children(statements)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitBlock(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtWhenCase(labels: List<JKKtWhenLabel>, statement: JKStatement) : JKTreeElement() {
|
||||||
|
var labels: List<JKKtWhenLabel> by children(labels)
|
||||||
|
var statement: JKStatement by child(statement)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtWhenCase(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKKtWhenLabel : JKTreeElement()
|
||||||
|
|
||||||
|
class JKKtElseWhenLabel : JKKtWhenLabel() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtElseWhenLabel(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtValueWhenLabel(expression: JKExpression) : JKKtWhenLabel() {
|
||||||
|
var expression: JKExpression by child(expression)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtValueWhenLabel(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKClassBody(declarations: List<JKDeclaration> = emptyList()) : JKTreeElement() {
|
||||||
|
var declarations: List<JKDeclaration> by children(declarations)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitClassBody(this)
|
||||||
|
|
||||||
|
val leftBrace = JKTokenElementImpl("{")
|
||||||
|
val rightBrace = JKTokenElementImpl("}")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKJavaTryCatchSection(
|
||||||
|
parameter: JKParameter,
|
||||||
|
block: JKBlock
|
||||||
|
) : JKStatement() {
|
||||||
|
var parameter: JKParameter by child(parameter)
|
||||||
|
var block: JKBlock by child(block)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaTryCatchSection(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKJavaSwitchCase : JKTreeElement() {
|
||||||
|
abstract fun isDefault(): Boolean
|
||||||
|
abstract var statements: List<JKStatement>
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaDefaultSwitchCase(statements: List<JKStatement>) : JKJavaSwitchCase(), PsiOwner by PsiOwnerImpl() {
|
||||||
|
override var statements: List<JKStatement> by children(statements)
|
||||||
|
override fun isDefault(): Boolean = true
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaDefaultSwitchCase(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaLabelSwitchCase(
|
||||||
|
label: JKExpression,
|
||||||
|
statements: List<JKStatement>
|
||||||
|
) : JKJavaSwitchCase(), PsiOwner by PsiOwnerImpl() {
|
||||||
|
override var statements: List<JKStatement> by children(statements)
|
||||||
|
var label: JKExpression by child(label)
|
||||||
|
override fun isDefault(): Boolean = false
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaLabelSwitchCase(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtTryCatchSection(
|
||||||
|
parameter: JKParameter,
|
||||||
|
block: JKBlock
|
||||||
|
) : JKTreeElement() {
|
||||||
|
var parameter: JKParameter by child(parameter)
|
||||||
|
var block: JKBlock by child(block)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtTryCatchSection(this)
|
||||||
|
}
|
||||||
@@ -0,0 +1,315 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.symbols.*
|
||||||
|
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKContextType
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKNoTypeImpl
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
|
|
||||||
|
abstract class JKExpression : JKAnnotationMemberValue(), PsiOwner by PsiOwnerImpl()
|
||||||
|
|
||||||
|
abstract class JKOperatorExpression : JKExpression() {
|
||||||
|
abstract var operator: JKOperator
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKBinaryExpression(
|
||||||
|
left: JKExpression,
|
||||||
|
right: JKExpression,
|
||||||
|
override var operator: JKOperator
|
||||||
|
) : JKOperatorExpression() {
|
||||||
|
var right by child(right)
|
||||||
|
var left by child(left)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitBinaryExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKUnaryExpression : JKOperatorExpression() {
|
||||||
|
abstract var expression: JKExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKPrefixExpression(expression: JKExpression, override var operator: JKOperator) : JKUnaryExpression() {
|
||||||
|
override var expression by child(expression)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitPrefixExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKPostfixExpression(expression: JKExpression, override var operator: JKOperator) : JKUnaryExpression() {
|
||||||
|
override var expression by child(expression)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitPostfixExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKQualifiedExpression(
|
||||||
|
receiver: JKExpression,
|
||||||
|
selector: JKExpression
|
||||||
|
) : JKExpression() {
|
||||||
|
var receiver: JKExpression by child(receiver)
|
||||||
|
var selector: JKExpression by child(selector)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitQualifiedExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKArrayAccessExpression(
|
||||||
|
expression: JKExpression,
|
||||||
|
indexExpression: JKExpression
|
||||||
|
) : JKExpression() {
|
||||||
|
var expression: JKExpression by child(expression)
|
||||||
|
var indexExpression: JKExpression by child(indexExpression)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitArrayAccessExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKParenthesizedExpression(expression: JKExpression) : JKExpression() {
|
||||||
|
var expression: JKExpression by child(expression)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitParenthesizedExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKTypeCastExpression(expression: JKExpression, type: JKTypeElement) : JKExpression() {
|
||||||
|
var expression by child(expression)
|
||||||
|
var type by child(type)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitTypeCastExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKLiteralExpression(
|
||||||
|
var literal: String,
|
||||||
|
val type: LiteralType
|
||||||
|
) : JKExpression() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitLiteralExpression(this)
|
||||||
|
|
||||||
|
enum class LiteralType {
|
||||||
|
STRING, CHAR, BOOLEAN, NULL, INT, LONG, FLOAT, DOUBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKStubExpression : JKExpression() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitStubExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKThisExpression(qualifierLabel: JKLabel) : JKExpression() {
|
||||||
|
var qualifierLabel: JKLabel by child(qualifierLabel)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitThisExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKSuperExpression(qualifierLabel: JKLabel = JKLabelEmpty()) : JKExpression() {
|
||||||
|
var qualifierLabel: JKLabel by child(qualifierLabel)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitSuperExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKIfElseExpression(condition: JKExpression, thenBranch: JKExpression, elseBranch: JKExpression) : JKExpression() {
|
||||||
|
var condition by child(condition)
|
||||||
|
var thenBranch by child(thenBranch)
|
||||||
|
var elseBranch by child(elseBranch)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitIfElseExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKLambdaExpression(
|
||||||
|
statement: JKStatement,
|
||||||
|
parameters: List<JKParameter>,
|
||||||
|
functionalType: JKTypeElement = JKTypeElement(JKNoTypeImpl),
|
||||||
|
returnType: JKTypeElement = JKTypeElement(JKContextType)
|
||||||
|
) : JKExpression() {
|
||||||
|
var statement by child(statement)
|
||||||
|
var parameters by children(parameters)
|
||||||
|
var functionalType by child(functionalType)
|
||||||
|
val returnType by child(returnType)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitLambdaExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
abstract class JKCallExpression : JKExpression(), JKTypeArgumentListOwner {
|
||||||
|
abstract val identifier: JKMethodSymbol
|
||||||
|
abstract var arguments: JKArgumentList
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKDelegationConstructorCall(
|
||||||
|
override val identifier: JKMethodSymbol,
|
||||||
|
expression: JKExpression,
|
||||||
|
arguments: JKArgumentList
|
||||||
|
) : JKCallExpression() {
|
||||||
|
override var typeArgumentList: JKTypeArgumentList by child(JKTypeArgumentList())
|
||||||
|
val expression: JKExpression by child(expression)
|
||||||
|
override var arguments: JKArgumentList by child(arguments)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitDelegationConstructorCall(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKCallExpressionImpl(
|
||||||
|
override val identifier: JKMethodSymbol,
|
||||||
|
arguments: JKArgumentList,
|
||||||
|
typeArgumentList: JKTypeArgumentList = JKTypeArgumentList()
|
||||||
|
) : JKCallExpression() {
|
||||||
|
override var typeArgumentList by child(typeArgumentList)
|
||||||
|
override var arguments by child(arguments)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitCallExpressionImpl(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKNewExpression(
|
||||||
|
val classSymbol: JKClassSymbol,
|
||||||
|
arguments: JKArgumentList,
|
||||||
|
typeArgumentList: JKTypeArgumentList,
|
||||||
|
classBody: JKClassBody = JKClassBody(),
|
||||||
|
val isAnonymousClass: Boolean = false
|
||||||
|
) : JKExpression() {
|
||||||
|
var typeArgumentList by child(typeArgumentList)
|
||||||
|
var arguments by child(arguments)
|
||||||
|
var classBody by child(classBody)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitNewExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKFieldAccessExpression(var identifier: JKFieldSymbol) : JKExpression() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitFieldAccessExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKPackageAccessExpression(var identifier: JKPackageSymbol) : JKExpression() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitPackageAccessExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKClassAccessExpression(var identifier: JKClassSymbol) : JKExpression() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitClassAccessExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKMethodReferenceExpression(
|
||||||
|
qualifier: JKExpression,
|
||||||
|
val identifier: JKSymbol,
|
||||||
|
functionalType: JKTypeElement,
|
||||||
|
val isConstructorCall: Boolean
|
||||||
|
) : JKExpression() {
|
||||||
|
val qualifier by child(qualifier)
|
||||||
|
val functionalType by child(functionalType)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitMethodReferenceExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKLabeledExpression(statement: JKStatement, labels: List<JKNameIdentifier>) : JKExpression() {
|
||||||
|
var statement: JKStatement by child(statement)
|
||||||
|
val labels: List<JKNameIdentifier> by children(labels)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitLabeledExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKClassLiteralExpression(
|
||||||
|
classType: JKTypeElement,
|
||||||
|
var literalType: ClassLiteralType
|
||||||
|
) : JKExpression() {
|
||||||
|
val classType: JKTypeElement by child(classType)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitClassLiteralExpression(this)
|
||||||
|
|
||||||
|
enum class ClassLiteralType {
|
||||||
|
KOTLIN_CLASS,
|
||||||
|
JAVA_CLASS,
|
||||||
|
JAVA_PRIMITIVE_CLASS,
|
||||||
|
JAVA_VOID_TYPE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
abstract class JKKtAssignmentChainLink : JKExpression() {
|
||||||
|
abstract val receiver: JKExpression
|
||||||
|
abstract val assignmentStatement: JKKtAssignmentStatement
|
||||||
|
abstract val field: JKExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKAssignmentChainAlsoLink(
|
||||||
|
receiver: JKExpression,
|
||||||
|
assignmentStatement: JKKtAssignmentStatement,
|
||||||
|
field: JKExpression
|
||||||
|
) : JKKtAssignmentChainLink() {
|
||||||
|
override val receiver by child(receiver)
|
||||||
|
override val assignmentStatement by child(assignmentStatement)
|
||||||
|
override val field by child(field)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitAssignmentChainAlsoLink(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKAssignmentChainLetLink(
|
||||||
|
receiver: JKExpression,
|
||||||
|
assignmentStatement: JKKtAssignmentStatement,
|
||||||
|
field: JKExpression
|
||||||
|
) : JKKtAssignmentChainLink() {
|
||||||
|
override val receiver by child(receiver)
|
||||||
|
override val assignmentStatement by child(assignmentStatement)
|
||||||
|
override val field by child(field)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitAssignmentChainLetLink(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKIsExpression(expression: JKExpression, type: JKTypeElement) : JKExpression() {
|
||||||
|
var type by child(type)
|
||||||
|
var expression by child(expression)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitIsExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtThrowExpression(exception: JKExpression) : JKExpression() {
|
||||||
|
var exception: JKExpression by child(exception)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtThrowExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtItExpression(val type: JKType) : JKExpression() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtItExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtAnnotationArrayInitializerExpression(initializers: List<JKAnnotationMemberValue>) : JKExpression() {
|
||||||
|
constructor(vararg initializers: JKAnnotationMemberValue) : this(initializers.toList())
|
||||||
|
|
||||||
|
val initializers: List<JKAnnotationMemberValue> by children(initializers)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtAnnotationArrayInitializerExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtTryExpression(
|
||||||
|
tryBlock: JKBlock,
|
||||||
|
finallyBlock: JKBlock,
|
||||||
|
catchSections: List<JKKtTryCatchSection>
|
||||||
|
) : JKExpression() {
|
||||||
|
var tryBlock: JKBlock by child(tryBlock)
|
||||||
|
var finallyBlock: JKBlock by child(finallyBlock)
|
||||||
|
var catchSections: List<JKKtTryCatchSection> by children(catchSections)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtTryExpression(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtTryCatchSection(
|
||||||
|
parameter: JKParameter,
|
||||||
|
block: JKBlock
|
||||||
|
) : JKTreeElement() {
|
||||||
|
var parameter: JKParameter by child(parameter)
|
||||||
|
var block: JKBlock by child(block)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtTryCatchSection(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaNewEmptyArray(initializer: List<JKExpression>, type: JKTypeElement) : JKExpression() {
|
||||||
|
val type by child(type)
|
||||||
|
var initializer by children(initializer)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaNewEmptyArray(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaNewArray(initializer: List<JKExpression>, type: JKTypeElement) : JKExpression() {
|
||||||
|
val type by child(type)
|
||||||
|
var initializer by children(initializer)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaNewArray(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKJavaAssignmentExpression(
|
||||||
|
field: JKExpression,
|
||||||
|
expression: JKExpression,
|
||||||
|
var operator: JKOperator
|
||||||
|
) : JKExpression() {
|
||||||
|
var field by child(field)
|
||||||
|
var expression by child(expression)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaAssignmentExpression(this)
|
||||||
|
}
|
||||||
@@ -1,157 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree.impl
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKBranchElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKNonCodeElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTreeElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
|
||||||
import kotlin.properties.ReadWriteProperty
|
|
||||||
import kotlin.reflect.KProperty
|
|
||||||
|
|
||||||
|
|
||||||
private class JKChild<T : JKElement>(val value: Int) : ReadWriteProperty<JKBranchElementBase, T> {
|
|
||||||
override operator fun getValue(thisRef: JKBranchElementBase, property: KProperty<*>): T {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
return thisRef.children[value] as T
|
|
||||||
}
|
|
||||||
|
|
||||||
override operator fun setValue(thisRef: JKBranchElementBase, property: KProperty<*>, value: T) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
(thisRef.children[this.value] as T).detach(thisRef)
|
|
||||||
thisRef.children[this.value] = value
|
|
||||||
value.attach(thisRef)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JKListChild<T : JKElement>(val value: Int) : ReadWriteProperty<JKBranchElementBase, List<T>> {
|
|
||||||
override operator fun getValue(thisRef: JKBranchElementBase, property: KProperty<*>): List<T> {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
return thisRef.children[value] as List<T>
|
|
||||||
}
|
|
||||||
|
|
||||||
override operator fun setValue(thisRef: JKBranchElementBase, property: KProperty<*>, value: List<T>) {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
(thisRef.children[this.value] as List<T>).forEach { it.detach(thisRef) }
|
|
||||||
thisRef.children[this.value] = value
|
|
||||||
value.forEach { it.attach(thisRef) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKElementBase : JKTreeElement, Cloneable {
|
|
||||||
override val leftNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
|
||||||
override val rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
|
||||||
|
|
||||||
override var parent: JKElement? = null
|
|
||||||
|
|
||||||
override fun detach(from: JKElement) {
|
|
||||||
val prevParent = parent
|
|
||||||
require(from == prevParent)
|
|
||||||
parent = null
|
|
||||||
onDetach(prevParent)
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun onDetach(from: JKElement) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun attach(to: JKElement) {
|
|
||||||
check(parent == null)
|
|
||||||
parent = to
|
|
||||||
onAttach()
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun onAttach() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitTreeElement(this)
|
|
||||||
|
|
||||||
override fun acceptChildren(visitor: JKVisitor) {}
|
|
||||||
|
|
||||||
override fun copy(): JKTreeElement =
|
|
||||||
clone() as JKTreeElement
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKBranchElementBase : JKElementBase(), JKBranchElement {
|
|
||||||
private var childNum = 0
|
|
||||||
|
|
||||||
protected fun <T : JKTreeElement, U : T> child(v: U): ReadWriteProperty<JKBranchElementBase, T> {
|
|
||||||
children.add(childNum, v)
|
|
||||||
v.attach(this)
|
|
||||||
return JKChild(childNum++)
|
|
||||||
}
|
|
||||||
|
|
||||||
protected inline fun <reified T : JKTreeElement> children(): ReadWriteProperty<JKBranchElementBase, List<T>> {
|
|
||||||
return children(emptyList())
|
|
||||||
}
|
|
||||||
|
|
||||||
protected fun <T : JKTreeElement> children(v: List<T>): ReadWriteProperty<JKBranchElementBase, List<T>> {
|
|
||||||
children.add(childNum, v)
|
|
||||||
v.forEach { it.attach(this) }
|
|
||||||
return JKListChild(childNum++)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun acceptChildren(visitor: JKVisitor) {
|
|
||||||
forEachChild { it.accept(visitor) }
|
|
||||||
}
|
|
||||||
|
|
||||||
protected inline fun forEachChild(block: (JKTreeElement) -> Unit) {
|
|
||||||
children.forEach {
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
if (it is JKTreeElement)
|
|
||||||
block(it)
|
|
||||||
else
|
|
||||||
(it as? List<JKTreeElement>)?.forEach { block(it) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
final override var valid: Boolean = true
|
|
||||||
|
|
||||||
final override fun invalidate() {
|
|
||||||
forEachChild { it.detach(this) }
|
|
||||||
valid = false
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAttach() {
|
|
||||||
check(valid)
|
|
||||||
}
|
|
||||||
|
|
||||||
final override var children: MutableList<Any> = mutableListOf()
|
|
||||||
private set
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
|
||||||
override fun copy(): JKTreeElement {
|
|
||||||
val cloned = super.copy() as JKBranchElementBase
|
|
||||||
val deepClonedChildren =
|
|
||||||
cloned.children.map {
|
|
||||||
when (it) {
|
|
||||||
is JKElementBase -> it.copy()
|
|
||||||
is List<*> -> (it as List<JKTreeElement>).map { it.copy() }
|
|
||||||
else -> error("Tree is corrupted")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
deepClonedChildren.forEach { child ->
|
|
||||||
when (child) {
|
|
||||||
is JKElementBase -> {
|
|
||||||
child.detach(this)
|
|
||||||
child.attach(cloned)
|
|
||||||
}
|
|
||||||
is List<*> -> (child as List<JKTreeElement>).forEach {
|
|
||||||
it.detach(this)
|
|
||||||
it.attach(cloned)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cloned.children = deepClonedChildren.toMutableList()
|
|
||||||
return cloned
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,639 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree.impl
|
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKLiteralExpression.LiteralType
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.*
|
|
||||||
|
|
||||||
class JKTreeRootImpl(element: JKTreeElement) : JKTreeRoot, JKBranchElementBase() {
|
|
||||||
override var element by child(element)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitTreeRoot(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKFileImpl(
|
|
||||||
packageDeclaration: JKPackageDeclaration,
|
|
||||||
importList: JKImportList,
|
|
||||||
declarationList: List<JKDeclaration>
|
|
||||||
) : JKFile, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitFile(this)
|
|
||||||
|
|
||||||
override var packageDeclaration: JKPackageDeclaration by child(packageDeclaration)
|
|
||||||
override var importList: JKImportList by child(importList)
|
|
||||||
override var declarationList by children(declarationList)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKClassImpl(
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
inheritance: JKInheritanceInfo,
|
|
||||||
override var classKind: JKClass.ClassKind,
|
|
||||||
typeParameterList: JKTypeParameterList,
|
|
||||||
classBody: JKClassBody,
|
|
||||||
annotationList: JKAnnotationList,
|
|
||||||
otherModifierElements: List<JKOtherModifierElement>,
|
|
||||||
visibilityElement: JKVisibilityModifierElement,
|
|
||||||
modalityElement: JKModalityModifierElement
|
|
||||||
) : JKClass(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitClass(this)
|
|
||||||
|
|
||||||
override var name by child(name)
|
|
||||||
override val inheritance by child(inheritance)
|
|
||||||
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
|
||||||
override var classBody: JKClassBody by child(classBody)
|
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
|
||||||
|
|
||||||
override var otherModifierElements by children(otherModifierElements)
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
override var modalityElement by child(modalityElement)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKNameIdentifierImpl(override val value: String) : JKNameIdentifier, JKElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitNameIdentifier(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKForLoopVariableImpl(
|
|
||||||
type: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
initializer: JKExpression,
|
|
||||||
annotationList: JKAnnotationList = JKAnnotationListImpl()
|
|
||||||
) : JKForLoopVariable() {
|
|
||||||
override var initializer by child(initializer)
|
|
||||||
override var name by child(name)
|
|
||||||
override var type by child(type)
|
|
||||||
override var annotationList by child(annotationList)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitForLoopVariable(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKParameterImpl(
|
|
||||||
type: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
override var isVarArgs: Boolean = false,
|
|
||||||
initializer: JKExpression = JKStubExpressionImpl(),
|
|
||||||
annotationList: JKAnnotationList = JKAnnotationListImpl()
|
|
||||||
) : JKParameter(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitParameter(this)
|
|
||||||
|
|
||||||
override var initializer by child(initializer)
|
|
||||||
override var name by child(name)
|
|
||||||
override var type by child(type)
|
|
||||||
override var annotationList by child(annotationList)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKBlockImpl(statements: List<JKStatement> = emptyList()) : JKBlock(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
constructor(vararg statements: JKStatement) : this(statements.toList())
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitBlock(this)
|
|
||||||
|
|
||||||
override var statements by children(statements)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKBinaryExpressionImpl(
|
|
||||||
left: JKExpression,
|
|
||||||
right: JKExpression,
|
|
||||||
override var operator: JKOperator
|
|
||||||
) : JKBinaryExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitBinaryExpression(this)
|
|
||||||
override var right by child(right)
|
|
||||||
override var left by child(left)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKPrefixExpressionImpl(expression: JKExpression, override var operator: JKOperator) : JKPrefixExpression, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitPrefixExpression(this)
|
|
||||||
|
|
||||||
override var expression by child(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKPostfixExpressionImpl(expression: JKExpression, override var operator: JKOperator) : JKPostfixExpression, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitPostfixExpression(this)
|
|
||||||
|
|
||||||
override var expression by child(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKExpressionListImpl(expressions: List<JKExpression> = emptyList()) : JKExpressionList, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
constructor(vararg expresions: JKExpression) : this(expresions.asList())
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitExpressionList(this)
|
|
||||||
|
|
||||||
override var expressions by children(expressions)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKQualifiedExpressionImpl(
|
|
||||||
receiver: JKExpression,
|
|
||||||
override var operator: JKQualifier,
|
|
||||||
selector: JKExpression
|
|
||||||
) : JKQualifiedExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitQualifiedExpression(this)
|
|
||||||
|
|
||||||
override var receiver: JKExpression by child(receiver)
|
|
||||||
override var selector: JKExpression by child(selector)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKExpressionStatementImpl(expression: JKExpression) : JKExpressionStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitExpressionStatement(this)
|
|
||||||
|
|
||||||
override var expression: JKExpression by child(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKDeclarationStatementImpl(declaredStatements: List<JKDeclaration>) : JKDeclarationStatement(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val declaredStatements by children(declaredStatements)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitDeclarationStatement(this)
|
|
||||||
|
|
||||||
override var rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf(JKSpaceElementImpl("\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKArrayAccessExpressionImpl(
|
|
||||||
expression: JKExpression,
|
|
||||||
indexExpression: JKExpression
|
|
||||||
) : JKArrayAccessExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitArrayAccessExpression(this)
|
|
||||||
|
|
||||||
override var expression: JKExpression by child(expression)
|
|
||||||
override var indexExpression: JKExpression by child(indexExpression)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKParenthesizedExpressionImpl(expression: JKExpression) : JKParenthesizedExpression, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitParenthesizedExpression(this)
|
|
||||||
|
|
||||||
override var expression: JKExpression by child(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKTypeCastExpressionImpl(expression: JKExpression, type: JKTypeElement) : JKTypeCastExpression, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitTypeCastExpression(this)
|
|
||||||
|
|
||||||
override var expression by child(expression)
|
|
||||||
override var type by child(type)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKTypeElementImpl(override var type: JKType) : JKTypeElement, JKElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitTypeElement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
data class JKClassTypeImpl(
|
|
||||||
override val classReference: JKClassSymbol,
|
|
||||||
override val parameters: List<JKType> = emptyList(),
|
|
||||||
override val nullability: Nullability = Nullability.Default
|
|
||||||
) : JKClassType
|
|
||||||
|
|
||||||
object JKNoTypeImpl : JKNoType {
|
|
||||||
override val nullability: Nullability = Nullability.NotNull
|
|
||||||
}
|
|
||||||
|
|
||||||
object JKStarProjectionTypeImpl : JKStarProjectionType
|
|
||||||
|
|
||||||
val JKType.fqName: String?
|
|
||||||
get() = when (this) {
|
|
||||||
is JKClassType -> classReference.fqName
|
|
||||||
is JKJavaPrimitiveType -> jvmPrimitiveType.name
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKNullLiteral : JKLiteralExpression, JKElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val literal: String
|
|
||||||
get() = "null"
|
|
||||||
override val type: LiteralType
|
|
||||||
get() = LiteralType.NULL
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitLiteralExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKBooleanLiteral(val value: Boolean) : JKLiteralExpression, JKElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val literal: String
|
|
||||||
get() = value.toString()
|
|
||||||
override val type: LiteralType
|
|
||||||
get() = LiteralType.BOOLEAN
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitLiteralExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun LiteralType.toJkType(typeFactory: JKTypeFactory): JKType = when (this) {
|
|
||||||
LiteralType.CHAR -> typeFactory.types.char
|
|
||||||
LiteralType.BOOLEAN -> typeFactory.types.boolean
|
|
||||||
LiteralType.INT -> typeFactory.types.int
|
|
||||||
LiteralType.LONG -> typeFactory.types.long
|
|
||||||
LiteralType.FLOAT -> typeFactory.types.float
|
|
||||||
LiteralType.DOUBLE -> typeFactory.types.double
|
|
||||||
LiteralType.NULL -> typeFactory.types.nullableAny
|
|
||||||
LiteralType.STRING -> typeFactory.types.string
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKLocalVariableImpl(
|
|
||||||
type: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
initializer: JKExpression,
|
|
||||||
mutabilityElement: JKMutabilityModifierElement,
|
|
||||||
annotationList: JKAnnotationList = JKAnnotationListImpl()
|
|
||||||
) : JKLocalVariable(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var initializer by child(initializer)
|
|
||||||
override var name by child(name)
|
|
||||||
override var type by child(type)
|
|
||||||
override var annotationList by child(annotationList)
|
|
||||||
|
|
||||||
override var mutabilityElement by child(mutabilityElement)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitLocalVariable(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKStubExpressionImpl : JKStubExpression, JKElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitStubExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
object JKBodyStubImpl : JKBodyStub() {
|
|
||||||
override val leftNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
|
||||||
override val rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
|
||||||
|
|
||||||
override fun copy(): JKTreeElement = this
|
|
||||||
|
|
||||||
override var statements: List<JKStatement>
|
|
||||||
get() = emptyList()
|
|
||||||
set(value) {}
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitBodyStub(this)
|
|
||||||
|
|
||||||
override fun acceptChildren(visitor: JKVisitor) {}
|
|
||||||
|
|
||||||
override var parent: JKElement?
|
|
||||||
get() = null
|
|
||||||
set(it) {}
|
|
||||||
|
|
||||||
override fun detach(from: JKElement) {
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun attach(to: JKElement) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKBlockStatementImpl(block: JKBlock) : JKBlockStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var block by child(block)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitBlockStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKBlockStatementWithoutBracketsImpl(statements: List<JKStatement>) : JKBlockStatementWithoutBrackets(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var statements by children(statements)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitBlockStatementWithoutBrackets(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKThisExpressionImpl(qualifierLabel: JKLabel) : JKThisExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var qualifierLabel: JKLabel by child(qualifierLabel)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitThisExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKSuperExpressionImpl(qualifierLabel: JKLabel = JKLabelEmptyImpl()) : JKSuperExpression, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var qualifierLabel: JKLabel by child(qualifierLabel)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitSuperExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKWhileStatementImpl(condition: JKExpression, body: JKStatement) : JKWhileStatement(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var condition by child(condition)
|
|
||||||
override var body by child(body)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitWhileStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKDoWhileStatementImpl(body: JKStatement, condition: JKExpression) : JKDoWhileStatement(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var condition by child(condition)
|
|
||||||
override var body by child(body)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitDoWhileStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKBreakStatementImpl : JKBreakStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitBreakStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKBreakWithLabelStatementImpl(override var label: JKNameIdentifier) : JKBreakWithLabelStatement(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitBreakWithLabelStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKIfStatementImpl(condition: JKExpression, thenBranch: JKStatement) : JKIfStatement(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var thenBranch by child(thenBranch)
|
|
||||||
override var condition by child(condition)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitIfStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKIfElseStatementImpl(condition: JKExpression, thenBranch: JKStatement, elseBranch: JKStatement) : JKIfElseStatement(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var elseBranch by child(elseBranch)
|
|
||||||
override var thenBranch by child(thenBranch)
|
|
||||||
override var condition by child(condition)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitIfElseStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKIfElseExpressionImpl(condition: JKExpression, thenBranch: JKExpression, elseBranch: JKExpression) : JKIfElseExpression,
|
|
||||||
JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var elseBranch by child(elseBranch)
|
|
||||||
override var thenBranch by child(thenBranch)
|
|
||||||
override var condition by child(condition)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitIfElseExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKClassAccessExpressionImpl(override var identifier: JKClassSymbol) : JKClassAccessExpression, JKElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitClassAccessExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKLambdaExpressionImpl(
|
|
||||||
statement: JKStatement,
|
|
||||||
parameters: List<JKParameter>,
|
|
||||||
functionalType: JKTypeElement = JKTypeElementImpl(JKNoTypeImpl),
|
|
||||||
returnType: JKTypeElement = JKTypeElementImpl(JKContextType)//TODO use function type
|
|
||||||
) : JKLambdaExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var statement by child(statement)
|
|
||||||
override val returnType by child(returnType)
|
|
||||||
override var parameters by children(parameters)
|
|
||||||
override var functionalType by child(functionalType)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitLambdaExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKInheritanceInfoImpl(
|
|
||||||
extends: List<JKTypeElement>,
|
|
||||||
implements: List<JKTypeElement>
|
|
||||||
) : JKInheritanceInfo, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var extends: List<JKTypeElement> by children(extends)
|
|
||||||
override var implements: List<JKTypeElement> by children(implements)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitInheritanceInfo(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKDelegationConstructorCallImpl(
|
|
||||||
override val identifier: JKMethodSymbol,
|
|
||||||
expression: JKExpression,
|
|
||||||
arguments: JKArgumentList
|
|
||||||
) : JKBranchElementBase(), JKDelegationConstructorCall, PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var typeArgumentList: JKTypeArgumentList by child(JKTypeArgumentListImpl())
|
|
||||||
override val expression: JKExpression by child(expression)
|
|
||||||
override var arguments: JKArgumentList by child(arguments)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitDelegationConstructorCall(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKFieldAccessExpressionImpl(override var identifier: JKFieldSymbol) : JKFieldAccessExpression, JKElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitFieldAccessExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKPackageAccessExpressionImpl(override var identifier: JKPackageSymbol) : JKPackageAccessExpression, JKElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitPackageAccessExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
val JKStatement.statements: List<JKStatement>
|
|
||||||
get() =
|
|
||||||
when (this) {
|
|
||||||
is JKBlockStatement -> block.statements
|
|
||||||
else -> listOf(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKLabelEmptyImpl : JKLabelEmpty, JKElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitLabelEmpty(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKLabelTextImpl(label: JKNameIdentifier) : JKLabelText, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val label: JKNameIdentifier by child(label)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitLabelText(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKContinueStatementImpl(label: JKLabel) : JKContinueStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var label: JKLabel by child(label)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitContinueStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKLabeledStatementImpl(statement: JKStatement, labels: List<JKNameIdentifier>) : JKLabeledStatement, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var statement: JKStatement by child(statement)
|
|
||||||
override val labels: List<JKNameIdentifier> by children(labels)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitLabeledStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKEmptyStatementImpl : JKEmptyStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitEmptyStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class PsiOwnerImpl(override var psi: PsiElement? = null) : PsiOwner
|
|
||||||
|
|
||||||
val JKElement.psi: PsiElement?
|
|
||||||
get() = (this as? PsiOwner)?.psi
|
|
||||||
|
|
||||||
inline fun <reified Elem : PsiElement> JKElement.psi(): Elem? = (this as? PsiOwner)?.psi as? Elem
|
|
||||||
|
|
||||||
class JKTypeParameterListImpl(typeParameters: List<JKTypeParameter> = emptyList()) : JKTypeParameterList, JKBranchElementBase() {
|
|
||||||
override var typeParameters by children(typeParameters)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitTypeParameterList(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKTypeParameterImpl(name: JKNameIdentifier, upperBounds: List<JKTypeElement>) : JKTypeParameter() {
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override var upperBounds: List<JKTypeElement> by children(upperBounds)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitTypeParameter(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
data class JKVarianceTypeParameterTypeImpl(
|
|
||||||
override val variance: JKVarianceTypeParameterType.Variance,
|
|
||||||
override val boundType: JKType
|
|
||||||
) : JKVarianceTypeParameterType
|
|
||||||
|
|
||||||
data class JKTypeParameterTypeImpl(
|
|
||||||
override val identifier: JKTypeParameterSymbol,
|
|
||||||
override val nullability: Nullability = Nullability.Default
|
|
||||||
) : JKTypeParameterType
|
|
||||||
|
|
||||||
data class JKCapturedType(
|
|
||||||
val wildcardType: JKWildCardType,
|
|
||||||
override val nullability: Nullability = Nullability.Default
|
|
||||||
) : JKType
|
|
||||||
|
|
||||||
class JKEnumConstantImpl(
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
arguments: JKArgumentList,
|
|
||||||
body: JKClassBody,
|
|
||||||
type: JKTypeElement,
|
|
||||||
annotationList: JKAnnotationList = JKAnnotationListImpl()
|
|
||||||
) : JKEnumConstant(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override val arguments: JKArgumentList by child(arguments)
|
|
||||||
override val body: JKClassBody by child(body)
|
|
||||||
override var type: JKTypeElement by child(type)
|
|
||||||
override var initializer: JKExpression by child(JKStubExpressionImpl())
|
|
||||||
override var annotationList by child(annotationList)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitEnumConstant(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JKTypeElement.present(): Boolean =
|
|
||||||
type != JKNoTypeImpl
|
|
||||||
|
|
||||||
class JKForInStatementImpl(declaration: JKDeclaration, iterationExpression: JKExpression, body: JKStatement) :
|
|
||||||
JKForInStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var declaration: JKDeclaration by child(declaration)
|
|
||||||
override var iterationExpression: JKExpression by child(iterationExpression)
|
|
||||||
override var body: JKStatement by child(body)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitForInStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JKStatement.isEmpty(): Boolean =
|
|
||||||
when (this) {
|
|
||||||
is JKEmptyStatement -> true
|
|
||||||
is JKBlockStatement -> block is JKBodyStubImpl
|
|
||||||
is JKExpressionStatement -> expression is JKStubExpression
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKPackageDeclarationImpl(name: JKNameIdentifier) : JKPackageDeclaration() {
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitPackageDeclaration(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKAnnotationListImpl(annotations: List<JKAnnotation> = emptyList()) : JKAnnotationList, JKBranchElementBase() {
|
|
||||||
override var annotations: List<JKAnnotation> by children(annotations)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitAnnotationList(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKAnnotationImpl(
|
|
||||||
override var classSymbol: JKClassSymbol,
|
|
||||||
arguments: List<JKAnnotationParameter> = emptyList()
|
|
||||||
) : JKAnnotation, JKBranchElementBase() {
|
|
||||||
override var arguments: List<JKAnnotationParameter> by children(arguments)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitAnnotation(this)
|
|
||||||
|
|
||||||
override var rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf(JKSpaceElementImpl("\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKTypeArgumentListImpl(typeArguments: List<JKTypeElement> = emptyList()) : JKTypeArgumentList, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var typeArguments: List<JKTypeElement> by children(typeArguments)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitTypeArgumentList(this)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKClassLiteralExpressionImpl(
|
|
||||||
classType: JKTypeElement,
|
|
||||||
override var literalType: JKClassLiteralExpression.LiteralType
|
|
||||||
) : JKClassLiteralExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val classType: JKTypeElement by child(classType)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitClassLiteralExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKImportStatementImpl(name: JKNameIdentifier) : JKImportStatement, JKBranchElementBase() {
|
|
||||||
override val name: JKNameIdentifier by child(name)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitImportStatement(this)
|
|
||||||
|
|
||||||
override var rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf(JKSpaceElementImpl("\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKImportListImpl(imports: List<JKImportStatement>) : JKImportList, JKBranchElementBase() {
|
|
||||||
override var imports by children(imports)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitImportList(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKAnnotationParameterImpl(value: JKAnnotationMemberValue) : JKAnnotationParameter, JKBranchElementBase() {
|
|
||||||
override var value: JKAnnotationMemberValue by child(value)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitAnnotationParameter(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKAnnotationNameParameterImpl(
|
|
||||||
value: JKAnnotationMemberValue,
|
|
||||||
name: JKNameIdentifier
|
|
||||||
) : JKAnnotationNameParameter, JKBranchElementBase() {
|
|
||||||
override var value: JKAnnotationMemberValue by child(value)
|
|
||||||
override val name: JKNameIdentifier by child(name)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitAnnotationNameParameter(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKNamedArgumentImpl(
|
|
||||||
value: JKExpression,
|
|
||||||
name: JKNameIdentifier
|
|
||||||
) : JKNamedArgument, JKBranchElementBase() {
|
|
||||||
override var value by child(value)
|
|
||||||
override val name by child(name)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitNamedArgument(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKArgumentImpl(value: JKExpression) : JKArgument, JKBranchElementBase() {
|
|
||||||
override var value by child(value)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitArgument(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKArgumentListImpl(arguments: List<JKArgument> = emptyList()) : JKArgumentList, JKBranchElementBase() {
|
|
||||||
constructor(vararg arguments: JKArgument) : this(arguments.toList())
|
|
||||||
constructor(vararg values: JKExpression) : this(values.map { JKArgumentImpl(it) })
|
|
||||||
|
|
||||||
override var arguments by children(arguments)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitArgumentList(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKMutabilityModifierElementImpl(override var mutability: Mutability) : JKMutabilityModifierElement() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitMutabilityModifierElement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKModalityModifierElementImpl(override var modality: Modality) : JKModalityModifierElement() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitModalityModifierElement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKVisibilityModifierElementImpl(override var visibility: Visibility) : JKVisibilityModifierElement() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitVisibilityModifierElement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKOtherModifierElementImpl(override var otherModifier: OtherModifier) : JKOtherModifierElement() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitOtherModifierElement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKMethodReferenceExpressionImpl(
|
|
||||||
qualifier: JKExpression,
|
|
||||||
override val identifier: JKSymbol,
|
|
||||||
functionalType: JKTypeElement,
|
|
||||||
override val isConstructorCall: Boolean
|
|
||||||
) : JKMethodReferenceExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val qualifier by child(qualifier)
|
|
||||||
override val functionalType by child(functionalType)
|
|
||||||
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitMethodReferenceExpression(this)
|
|
||||||
}
|
|
||||||
@@ -1,327 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree.impl
|
|
||||||
|
|
||||||
import com.intellij.psi.JavaTokenType
|
|
||||||
import com.intellij.psi.impl.source.tree.ElementType.OPERATION_BIT_SET
|
|
||||||
import com.intellij.psi.tree.IElementType
|
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKLiteralExpression.LiteralType.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaArrayType
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaDisjunctionType
|
|
||||||
import org.jetbrains.kotlin.nj2k.types.JKJavaPrimitiveType
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
|
||||||
|
|
||||||
class JKJavaFieldImpl(
|
|
||||||
type: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
initializer: JKExpression,
|
|
||||||
annotationList: JKAnnotationList,
|
|
||||||
otherModifierElements: List<JKOtherModifierElement>,
|
|
||||||
visibilityElement: JKVisibilityModifierElement,
|
|
||||||
modalityElement: JKModalityModifierElement,
|
|
||||||
mutabilityElement: JKMutabilityModifierElement
|
|
||||||
) : JKJavaField(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaField(this)
|
|
||||||
|
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
|
||||||
override var initializer: JKExpression by child(initializer)
|
|
||||||
override var type by child(type)
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
|
|
||||||
override var otherModifierElements by children(otherModifierElements)
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
override var modalityElement by child(modalityElement)
|
|
||||||
override var mutabilityElement by child(mutabilityElement)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaMethodImpl(
|
|
||||||
returnType: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
parameters: List<JKParameter>,
|
|
||||||
block: JKBlock,
|
|
||||||
typeParameterList: JKTypeParameterList,
|
|
||||||
annotationList: JKAnnotationList,
|
|
||||||
throwsList: List<JKTypeElement>,
|
|
||||||
otherModifierElements: List<JKOtherModifierElement>,
|
|
||||||
visibilityElement: JKVisibilityModifierElement,
|
|
||||||
modalityElement: JKModalityModifierElement
|
|
||||||
) : JKJavaMethod(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaMethod(this)
|
|
||||||
|
|
||||||
override var returnType: JKTypeElement by child(returnType)
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override var parameters: List<JKParameter> by children(parameters)
|
|
||||||
override var block: JKBlock by child(block)
|
|
||||||
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
|
||||||
override var throwsList: List<JKTypeElement> by children(throwsList)
|
|
||||||
|
|
||||||
override var otherModifierElements by children(otherModifierElements)
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
override var modalityElement by child(modalityElement)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaLiteralExpressionImpl(
|
|
||||||
override val literal: String,
|
|
||||||
override val type: JKLiteralExpression.LiteralType
|
|
||||||
) : JKJavaLiteralExpression, JKElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaLiteralExpression(this)
|
|
||||||
|
|
||||||
init {
|
|
||||||
require(type in setOf(STRING, CHAR, INT, LONG, FLOAT, DOUBLE))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaOperatorToken(val psiToken: IElementType) : JKOperatorToken {
|
|
||||||
override val text: String
|
|
||||||
get() = error("Java token should not be printed, it should be replaces with corresponding Kotlin one")
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class JKJavaQualifierImpl : JKQualifier {
|
|
||||||
object DOT : JKJavaQualifierImpl()
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaMethodCallExpressionImpl(
|
|
||||||
override var identifier: JKMethodSymbol,
|
|
||||||
arguments: JKArgumentList,
|
|
||||||
typeArgumentList: JKTypeArgumentList = JKTypeArgumentListImpl()
|
|
||||||
) : JKJavaMethodCallExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaMethodCallExpression(this)
|
|
||||||
|
|
||||||
override var arguments: JKArgumentList by child(arguments)
|
|
||||||
override var typeArgumentList: JKTypeArgumentList by child(typeArgumentList)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKClassBodyImpl(declarations: List<JKDeclaration> = emptyList()) : JKClassBody() {
|
|
||||||
override var declarations: List<JKDeclaration> by children(declarations)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitClassBody(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKEmptyClassBodyImpl : JKEmptyClassBody() {
|
|
||||||
override var declarations: List<JKDeclaration> by children(emptyList())
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitEmptyClassBody(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaNewExpressionImpl(
|
|
||||||
override var classSymbol: JKClassSymbol,
|
|
||||||
arguments: JKArgumentList,
|
|
||||||
typeArgumentList: JKTypeArgumentList,
|
|
||||||
classBody: JKClassBody = JKEmptyClassBodyImpl()
|
|
||||||
) : JKJavaNewExpression, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var arguments: JKArgumentList by child(arguments)
|
|
||||||
override var typeArgumentList: JKTypeArgumentList by child(typeArgumentList)
|
|
||||||
override var classBody: JKClassBody by child(classBody)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaNewExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaNewEmptyArrayImpl(initializer: List<JKExpression>, type: JKTypeElement) : JKJavaNewEmptyArray, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val type by child(type)
|
|
||||||
override var initializer by children(initializer)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaNewEmptyArray(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaNewArrayImpl(initializer: List<JKExpression>, type: JKTypeElement) : JKJavaNewArray, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val type by child(type)
|
|
||||||
override var initializer by children(initializer)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaNewArray(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaPrimitiveTypeImpl(override val jvmPrimitiveType: JvmPrimitiveType) : JKJavaPrimitiveType {
|
|
||||||
companion object {
|
|
||||||
val BOOLEAN = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.BOOLEAN)
|
|
||||||
val CHAR = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.CHAR)
|
|
||||||
val BYTE = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.BYTE)
|
|
||||||
val SHORT = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.SHORT)
|
|
||||||
val INT = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.INT)
|
|
||||||
val FLOAT = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.FLOAT)
|
|
||||||
val LONG = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.LONG)
|
|
||||||
val DOUBLE = JKJavaPrimitiveTypeImpl(JvmPrimitiveType.DOUBLE)
|
|
||||||
|
|
||||||
val KEYWORD_TO_INSTANCE = listOf(
|
|
||||||
BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE
|
|
||||||
).associate {
|
|
||||||
it.jvmPrimitiveType.javaKeywordName to it
|
|
||||||
} + ("void" to JKJavaVoidType)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object JKJavaVoidType : JKType {
|
|
||||||
override var nullability: Nullability
|
|
||||||
get() = Nullability.NotNull
|
|
||||||
set(it) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
data class JKJavaArrayTypeImpl(override val type: JKType, override var nullability: Nullability = Nullability.Default) :
|
|
||||||
JKJavaArrayType {
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaDisjunctionTypeImpl(
|
|
||||||
override val disjunctions: List<JKType>,
|
|
||||||
override val nullability: Nullability = Nullability.Default
|
|
||||||
) : JKJavaDisjunctionType
|
|
||||||
|
|
||||||
class JKReturnStatementImpl(
|
|
||||||
expression: JKExpression,
|
|
||||||
label: JKLabel = JKLabelEmptyImpl()
|
|
||||||
) : JKReturnStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitReturnStatement(this)
|
|
||||||
|
|
||||||
override val expression by child(expression)
|
|
||||||
override var label by child(label)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaAssertStatementImpl(condition: JKExpression, description: JKExpression) : JKJavaAssertStatement(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val description by child(description)
|
|
||||||
override val condition by child(condition)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaAssertStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaForLoopStatementImpl(initializer: JKStatement, condition: JKExpression, updaters: List<JKStatement>, body: JKStatement) :
|
|
||||||
JKJavaForLoopStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var body by child(body)
|
|
||||||
override var updaters by children(updaters)
|
|
||||||
override var condition by child(condition)
|
|
||||||
override var initializer by child(initializer)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaForLoopStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKJavaPolyadicExpressionImpl(operands: List<JKExpression>, override var tokens: List<JKOperator>) : JKJavaPolyadicExpression,
|
|
||||||
JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var operands by children(operands)
|
|
||||||
|
|
||||||
override fun getTokenBeforeOperand(operand: JKExpression): JKOperator? {
|
|
||||||
val index = operands.indexOf(operand)
|
|
||||||
return if (index < 1 || index > tokens.size) null else tokens[index - 1]
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaPolyadicExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaAssignmentExpressionImpl(
|
|
||||||
field: JKExpression,
|
|
||||||
expression: JKExpression,
|
|
||||||
override var operator: JKOperator
|
|
||||||
) : JKBranchElementBase(), JKJavaAssignmentExpression, PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaAssignmentExpression(this)
|
|
||||||
override var field by child(field)
|
|
||||||
override var expression by child(expression)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaSwitchStatementImpl(
|
|
||||||
expression: JKExpression,
|
|
||||||
cases: List<JKJavaSwitchCase>
|
|
||||||
) : JKJavaSwitchStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var expression: JKExpression by child(expression)
|
|
||||||
override var cases: List<JKJavaSwitchCase> by children(cases)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaSwitchStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaDefaultSwitchCaseImpl(statements: List<JKStatement>) : JKJavaDefaultSwitchCase, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var statements: List<JKStatement> by children(statements)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaDefaultSwitchCase(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaLabelSwitchCaseImpl(
|
|
||||||
label: JKExpression,
|
|
||||||
statements: List<JKStatement>
|
|
||||||
) : JKJavaLabelSwitchCase, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var statements: List<JKStatement> by children(statements)
|
|
||||||
override var label: JKExpression by child(label)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaLabelSwitchCase(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaThrowStatementImpl(exception: JKExpression) : JKJavaThrowStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var exception: JKExpression by child(exception)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaThrowStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaTryStatementImpl(
|
|
||||||
resourceDeclarations: List<JKDeclaration>,
|
|
||||||
tryBlock: JKBlock,
|
|
||||||
finallyBlock: JKBlock,
|
|
||||||
catchSections: List<JKJavaTryCatchSection>
|
|
||||||
) : JKJavaTryStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var resourceDeclarations: List<JKDeclaration> by children(resourceDeclarations)
|
|
||||||
override var tryBlock: JKBlock by child(tryBlock)
|
|
||||||
override var finallyBlock: JKBlock by child(finallyBlock)
|
|
||||||
override var catchSections: List<JKJavaTryCatchSection> by children(catchSections)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaTryStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaTryCatchSectionImpl(
|
|
||||||
parameter: JKParameter,
|
|
||||||
block: JKBlock
|
|
||||||
) : JKJavaTryCatchSection, JKBranchElementBase(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var parameter: JKParameter by child(parameter)
|
|
||||||
override var block: JKBlock by child(block)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaTryCatchSection(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaSynchronizedStatementImpl(
|
|
||||||
lockExpression: JKExpression,
|
|
||||||
body: JKBlock
|
|
||||||
) : JKJavaSynchronizedStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override val lockExpression: JKExpression by child(lockExpression)
|
|
||||||
override val body: JKBlock by child(body)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaSynchronizedStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaAnnotationMethodImpl(
|
|
||||||
returnType: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
defaultValue: JKAnnotationMemberValue
|
|
||||||
) : JKJavaAnnotationMethod(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var returnType: JKTypeElement by child(returnType)
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override var parameters: List<JKParameter> by children()
|
|
||||||
override var defaultValue: JKAnnotationMemberValue by child(defaultValue)
|
|
||||||
override var block: JKBlock by child(JKBodyStubImpl)
|
|
||||||
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterListImpl())
|
|
||||||
override var annotationList: JKAnnotationList by child(JKAnnotationListImpl())
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaAnnotationMethod(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtAnnotationArrayInitializerExpressionImpl(initializers: List<JKAnnotationMemberValue>) : JKKtAnnotationArrayInitializerExpression,
|
|
||||||
JKBranchElementBase() {
|
|
||||||
constructor(vararg initializers: JKAnnotationMemberValue) : this(initializers.toList())
|
|
||||||
|
|
||||||
override val initializers: List<JKAnnotationMemberValue> by children(initializers)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtAnnotationArrayInitializerExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKJavaStaticInitDeclarationImpl(block: JKBlock) : JKJavaStaticInitDeclaration() {
|
|
||||||
override var block: JKBlock by child(block)
|
|
||||||
override var name: JKNameIdentifier by child(JKNameIdentifierImpl("<init>"))
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitJavaStaticInitDeclaration(this)
|
|
||||||
}
|
|
||||||
@@ -1,312 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree.impl
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
|
||||||
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKMethodSymbol
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
|
||||||
|
|
||||||
class JKKtPropertyImpl(
|
|
||||||
type: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
initializer: JKExpression,
|
|
||||||
getter: JKKtGetterOrSetter,
|
|
||||||
setter: JKKtGetterOrSetter,
|
|
||||||
annotationList: JKAnnotationList,
|
|
||||||
otherModifierElements: List<JKOtherModifierElement>,
|
|
||||||
visibilityElement: JKVisibilityModifierElement,
|
|
||||||
modalityElement: JKModalityModifierElement,
|
|
||||||
mutabilityElement: JKMutabilityModifierElement
|
|
||||||
) : JKKtProperty(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtProperty(this)
|
|
||||||
|
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
|
||||||
override var type by child(type)
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override var initializer: JKExpression by child(initializer)
|
|
||||||
override var getter: JKKtGetterOrSetter by child(getter)
|
|
||||||
override var setter: JKKtGetterOrSetter by child(setter)
|
|
||||||
|
|
||||||
override var otherModifierElements by children(otherModifierElements)
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
override var modalityElement by child(modalityElement)
|
|
||||||
override var mutabilityElement by child(mutabilityElement)
|
|
||||||
|
|
||||||
override var rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf(JKSpaceElementImpl("\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtFunctionImpl(
|
|
||||||
returnType: JKTypeElement,
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
parameters: List<JKParameter>,
|
|
||||||
block: JKBlock,
|
|
||||||
typeParameterList: JKTypeParameterList,
|
|
||||||
annotationList: JKAnnotationList,
|
|
||||||
otherModifierElements: List<JKOtherModifierElement>,
|
|
||||||
visibilityElement: JKVisibilityModifierElement,
|
|
||||||
modalityElement: JKModalityModifierElement
|
|
||||||
) : JKKtFunction(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtFunction(this)
|
|
||||||
|
|
||||||
override var returnType: JKTypeElement by child(returnType)
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override var parameters: List<JKParameter> by children(parameters)
|
|
||||||
override var block: JKBlock by child(block)
|
|
||||||
override var typeParameterList: JKTypeParameterList by child(typeParameterList)
|
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
|
||||||
|
|
||||||
|
|
||||||
override var otherModifierElements by children(otherModifierElements)
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
override var modalityElement by child(modalityElement)
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class JKKtQualifierImpl : JKQualifier, JKElementBase() {
|
|
||||||
object DOT : JKKtQualifierImpl()
|
|
||||||
object SAFE : JKKtQualifierImpl()
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtCallExpressionImpl(
|
|
||||||
override val identifier: JKMethodSymbol,
|
|
||||||
arguments: JKArgumentList,
|
|
||||||
typeArgumentList: JKTypeArgumentList = JKTypeArgumentListImpl()
|
|
||||||
) : JKKtMethodCallExpression, JKBranchElementBase() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtMethodCallExpression(this)
|
|
||||||
|
|
||||||
override var arguments: JKArgumentList by child(arguments)
|
|
||||||
override var typeArgumentList: JKTypeArgumentList by child(typeArgumentList)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtLiteralExpressionImpl(
|
|
||||||
override val literal: String,
|
|
||||||
override val type: JKLiteralExpression.LiteralType
|
|
||||||
) : JKKtLiteralExpression,
|
|
||||||
JKElementBase() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtLiteralExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtSingleValueOperatorToken(val psiToken: KtSingleValueToken) : JKKtOperatorToken {
|
|
||||||
override val text: String = psiToken.value
|
|
||||||
}
|
|
||||||
|
|
||||||
object JKKtSpreadOperatorToken : JKKtOperatorToken {
|
|
||||||
override val text: String = "*"
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtSpreadOperator(override val returnType: JKType) : JKOperator {
|
|
||||||
override val token: JKOperatorToken = JKKtSpreadOperatorToken
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtWordOperatorToken(override val text: String) : JKKtOperatorToken
|
|
||||||
|
|
||||||
class JKKtOperatorImpl(override val token: JKOperatorToken, override val returnType: JKType) : JKOperator
|
|
||||||
|
|
||||||
class JKAssignmentChainAlsoLinkImpl(
|
|
||||||
receiver: JKExpression,
|
|
||||||
assignmentStatement: JKKtAssignmentStatement,
|
|
||||||
field: JKExpression
|
|
||||||
) : JKAssignmentChainAlsoLink, JKBranchElementBase() {
|
|
||||||
override val receiver by child(receiver)
|
|
||||||
override val assignmentStatement by child(assignmentStatement)
|
|
||||||
override val field by child(field)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitAssignmentChainAlsoLink(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKAssignmentChainLetLinkImpl(
|
|
||||||
receiver: JKExpression,
|
|
||||||
assignmentStatement: JKKtAssignmentStatement,
|
|
||||||
field: JKExpression
|
|
||||||
) : JKAssignmentChainLetLink, JKBranchElementBase() {
|
|
||||||
override val receiver by child(receiver)
|
|
||||||
override val assignmentStatement by child(assignmentStatement)
|
|
||||||
override val field by child(field)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitAssignmentChainLetLink(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtAssignmentStatementImpl(
|
|
||||||
field: JKExpression,
|
|
||||||
expression: JKExpression,
|
|
||||||
override var token: JKOperatorToken
|
|
||||||
) : JKKtAssignmentStatement() {
|
|
||||||
override var field: JKExpression by child(field)
|
|
||||||
override var expression by child(expression)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtAssignmentStatement(this)
|
|
||||||
|
|
||||||
override var rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf(JKSpaceElementImpl("\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
object JKContextType : JKType {
|
|
||||||
override val nullability: Nullability
|
|
||||||
get() = Nullability.Default
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtConstructorImpl(
|
|
||||||
name: JKNameIdentifier,
|
|
||||||
parameters: List<JKParameter>,
|
|
||||||
block: JKBlock,
|
|
||||||
delegationCall: JKExpression,
|
|
||||||
annotationList: JKAnnotationList,
|
|
||||||
otherModifierElements: List<JKOtherModifierElement>,
|
|
||||||
visibilityElement: JKVisibilityModifierElement,
|
|
||||||
modalityElement: JKModalityModifierElement
|
|
||||||
) : JKKtConstructor() {
|
|
||||||
override var returnType: JKTypeElement by child(JKTypeElementImpl(JKNoTypeImpl))
|
|
||||||
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override var parameters: List<JKParameter> by children(parameters)
|
|
||||||
override var block: JKBlock by child(block)
|
|
||||||
override var delegationCall: JKExpression by child(delegationCall)
|
|
||||||
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterListImpl())
|
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
|
||||||
|
|
||||||
override var otherModifierElements by children(otherModifierElements)
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
override var modalityElement by child(modalityElement)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtConstructor(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtPrimaryConstructorImpl(
|
|
||||||
name: JKNameIdentifier,//TODO not needed
|
|
||||||
parameters: List<JKParameter>,
|
|
||||||
delegationCall: JKExpression,
|
|
||||||
annotationList: JKAnnotationList,
|
|
||||||
otherModifierElements: List<JKOtherModifierElement>,
|
|
||||||
visibilityElement: JKVisibilityModifierElement,
|
|
||||||
modalityElement: JKModalityModifierElement
|
|
||||||
) : JKKtPrimaryConstructor() {
|
|
||||||
override var returnType: JKTypeElement by child(JKTypeElementImpl(JKNoTypeImpl))
|
|
||||||
|
|
||||||
override var name: JKNameIdentifier by child(name)
|
|
||||||
override var parameters: List<JKParameter> by children(parameters)
|
|
||||||
override var block: JKBlock by child(JKBodyStubImpl)
|
|
||||||
override var delegationCall: JKExpression by child(delegationCall)
|
|
||||||
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterListImpl())
|
|
||||||
override var annotationList: JKAnnotationList by child(annotationList)
|
|
||||||
|
|
||||||
override var otherModifierElements by children(otherModifierElements)
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
override var modalityElement by child(modalityElement)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtPrimaryConstructor(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtWhenStatementImpl(
|
|
||||||
expression: JKExpression,
|
|
||||||
cases: List<JKKtWhenCase>
|
|
||||||
) : JKKtWhenStatement() {
|
|
||||||
override var expression: JKExpression by child(expression)
|
|
||||||
override var cases: List<JKKtWhenCase> by children(cases)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtWhenStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtWhenCaseImpl(labels: List<JKKtWhenLabel>, statement: JKStatement) : JKKtWhenCase, JKBranchElementBase() {
|
|
||||||
override var labels: List<JKKtWhenLabel> by children(labels)
|
|
||||||
override var statement: JKStatement by child(statement)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtWhenCase(this)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtElseWhenLabelImpl : JKKtElseWhenLabel, JKElementBase() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtElseWhenLabel(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtValueWhenLabelImpl(expression: JKExpression) : JKKtValueWhenLabel, JKBranchElementBase() {
|
|
||||||
override var expression: JKExpression by child(expression)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtValueWhenLabel(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKKtIsExpressionImpl(expression: JKExpression, type: JKTypeElement) : JKKtIsExpression, JKBranchElementBase(),
|
|
||||||
PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var type by child(type)
|
|
||||||
override var expression by child(expression)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtIsExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtInitDeclarationImpl(block: JKBlock) : JKKtInitDeclaration() {
|
|
||||||
override var block: JKBlock by child(block)
|
|
||||||
override val name: JKNameIdentifier by child(JKNameIdentifierImpl("<name>"))
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtInitDeclaration(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class JKKtConvertedFromForLoopSyntheticWhileStatementImpl(
|
|
||||||
variableDeclaration: JKStatement,
|
|
||||||
whileStatement: JKWhileStatement
|
|
||||||
) : JKKtConvertedFromForLoopSyntheticWhileStatement(), PsiOwner by PsiOwnerImpl() {
|
|
||||||
override var variableDeclaration: JKStatement by child(variableDeclaration)
|
|
||||||
override var whileStatement: JKWhileStatement by child(whileStatement)
|
|
||||||
override fun accept(visitor: JKVisitor) =
|
|
||||||
visitor.visitKtConvertedFromForLoopSyntheticWhileStatement(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtThrowExpressionImpl(exception: JKExpression) : JKKtThrowExpression, JKBranchElementBase() {
|
|
||||||
override var exception: JKExpression by child(exception)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtThrowExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtTryExpressionImpl(
|
|
||||||
tryBlock: JKBlock,
|
|
||||||
finallyBlock: JKBlock,
|
|
||||||
catchSections: List<JKKtTryCatchSection>
|
|
||||||
) : JKKtTryExpression, JKBranchElementBase() {
|
|
||||||
override var tryBlock: JKBlock by child(tryBlock)
|
|
||||||
override var finallyBlock: JKBlock by child(finallyBlock)
|
|
||||||
override var catchSections: List<JKKtTryCatchSection> by children(catchSections)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtTryExpression(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtTryCatchSectionImpl(
|
|
||||||
parameter: JKParameter,
|
|
||||||
block: JKBlock
|
|
||||||
) : JKKtTryCatchSection, JKBranchElementBase() {
|
|
||||||
override var parameter: JKParameter by child(parameter)
|
|
||||||
override var block: JKBlock by child(block)
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtTryCatchSection(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtGetterOrSetterImpl(
|
|
||||||
body: JKStatement,
|
|
||||||
override val kind: JKKtGetterOrSetter.Kind,
|
|
||||||
visibilityElement: JKVisibilityModifierElement
|
|
||||||
) : JKKtGetterOrSetter, JKBranchElementBase() {
|
|
||||||
override var body: JKStatement by child(body)
|
|
||||||
|
|
||||||
override var visibilityElement by child(visibilityElement)
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtGetterOrSetter(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtEmptyGetterOrSetterImpl : JKKtEmptyGetterOrSetter, JKBranchElementBase() {
|
|
||||||
override var body: JKStatement by child(JKEmptyStatementImpl())
|
|
||||||
override val kind: JKKtGetterOrSetter.Kind
|
|
||||||
get() = error("Cannot get kind of JKKtEmptyGetterOrSetter")
|
|
||||||
|
|
||||||
override var visibilityElement by child(JKVisibilityModifierElementImpl(Visibility.PUBLIC))
|
|
||||||
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtEmptyGetterOrSetter(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
class JKKtItExpressionImpl(override val type: JKType) : JKKtItExpression, JKBranchElementBase() {
|
|
||||||
override fun accept(visitor: JKVisitor) = visitor.visitKtItExpression(this)
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree.impl
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKCommentElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKNonCodeElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKSpaceElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKTokenElement
|
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
|
||||||
|
|
||||||
|
|
||||||
class JKSpaceElementImpl(override val text: String) : JKSpaceElement
|
|
||||||
|
|
||||||
class JKCommentElementImpl(override val text: String) : JKCommentElement
|
|
||||||
|
|
||||||
class JKTokenElementImpl(override val text: String) : JKTokenElement {
|
|
||||||
override val leftNonCodeElements: MutableList<JKNonCodeElement> = SmartList()
|
|
||||||
override val rightNonCodeElements: MutableList<JKNonCodeElement> = SmartList()
|
|
||||||
}
|
|
||||||
@@ -1,519 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree
|
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement
|
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.*
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBranchElementBase
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKSpaceElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKTokenElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
|
||||||
|
|
||||||
interface JKTreeElement : JKElement, JKNonCodeElementsListOwner {
|
|
||||||
fun accept(visitor: JKVisitor)
|
|
||||||
fun acceptChildren(visitor: JKVisitor)
|
|
||||||
fun copy(): JKTreeElement
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKTreeRoot : JKTreeElement {
|
|
||||||
var element: JKTreeElement
|
|
||||||
}
|
|
||||||
|
|
||||||
interface PsiOwner {
|
|
||||||
var psi: PsiElement?
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKDeclaration : JKTreeElement, JKBranchElementBase() {
|
|
||||||
override val rightNonCodeElements = mutableListOf<JKNonCodeElement>(JKSpaceElementImpl("\n"))
|
|
||||||
abstract val name: JKNameIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKImportStatement : JKTreeElement {
|
|
||||||
val name: JKNameIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKImportList : JKTreeElement {
|
|
||||||
var imports: List<JKImportStatement>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKFile : JKTreeElement, JKBranchElement {
|
|
||||||
var packageDeclaration: JKPackageDeclaration
|
|
||||||
var importList: JKImportList
|
|
||||||
var declarationList: List<JKDeclaration>
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKClass : JKDeclaration(), JKVisibilityOwner, JKOtherModifiersOwner, JKModalityOwner, JKTypeParameterListOwner,
|
|
||||||
JKAnnotationListOwner,
|
|
||||||
JKBranchElement {
|
|
||||||
abstract val inheritance: JKInheritanceInfo
|
|
||||||
abstract var classBody: JKClassBody
|
|
||||||
abstract var classKind: ClassKind
|
|
||||||
|
|
||||||
enum class ClassKind {
|
|
||||||
ANNOTATION, CLASS, ENUM, INTERFACE, OBJECT, COMPANION
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JKClass.isLocalClass(): Boolean =
|
|
||||||
parent !is JKClassBody && parent !is JKFile
|
|
||||||
|
|
||||||
val JKClass.declarationList: List<JKDeclaration>
|
|
||||||
get() = classBody.declarations
|
|
||||||
|
|
||||||
|
|
||||||
interface JKInheritanceInfo : JKTreeElement, JKBranchElement {
|
|
||||||
var extends: List<JKTypeElement>
|
|
||||||
var implements: List<JKTypeElement>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JKInheritanceInfo.present(): Boolean =
|
|
||||||
extends.isNotEmpty() || implements.isNotEmpty()
|
|
||||||
|
|
||||||
interface JKAnnotationList : JKTreeElement {
|
|
||||||
var annotations: List<JKAnnotation>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKAnnotation : JKAnnotationMemberValue {
|
|
||||||
var classSymbol: JKClassSymbol
|
|
||||||
var arguments: List<JKAnnotationParameter>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKAnnotationParameter : JKTreeElement {
|
|
||||||
var value: JKAnnotationMemberValue
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKAnnotationNameParameter : JKAnnotationParameter {
|
|
||||||
val name: JKNameIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKAnnotationListOwner : JKTreeElement {
|
|
||||||
var annotationList: JKAnnotationList
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKMethod : JKDeclaration(), JKVisibilityOwner, JKModalityOwner, JKOtherModifiersOwner, JKTypeParameterListOwner,
|
|
||||||
JKAnnotationListOwner {
|
|
||||||
abstract var parameters: List<JKParameter>
|
|
||||||
abstract var returnType: JKTypeElement
|
|
||||||
abstract var block: JKBlock
|
|
||||||
|
|
||||||
val leftParen = JKTokenElementImpl("(")
|
|
||||||
val rightParen = JKTokenElementImpl(")")
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKVariable : JKDeclaration(), JKAnnotationListOwner {
|
|
||||||
abstract var type: JKTypeElement
|
|
||||||
abstract var initializer: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKForLoopVariable : JKVariable()
|
|
||||||
|
|
||||||
abstract class JKLocalVariable : JKVariable(), JKMutabilityOwner
|
|
||||||
|
|
||||||
|
|
||||||
abstract class JKModifierElement : JKTreeElement, JKBranchElementBase(), JKNonCodeElementsListOwner
|
|
||||||
|
|
||||||
val JKModifierElement.modifier: Modifier
|
|
||||||
get() = when (this) {
|
|
||||||
is JKMutabilityModifierElement -> mutability
|
|
||||||
is JKModalityModifierElement -> modality
|
|
||||||
is JKVisibilityModifierElement -> visibility
|
|
||||||
is JKOtherModifierElement -> otherModifier
|
|
||||||
else -> error("")
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKMutabilityModifierElement : JKModifierElement() {
|
|
||||||
abstract var mutability: Mutability
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKModalityModifierElement : JKModifierElement() {
|
|
||||||
abstract var modality: Modality
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKVisibilityModifierElement : JKModifierElement() {
|
|
||||||
abstract var visibility: Visibility
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKOtherModifierElement : JKModifierElement() {
|
|
||||||
abstract var otherModifier: OtherModifier
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Modifier {
|
|
||||||
val text: String
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKOtherModifiersOwner : JKModifiersListOwner {
|
|
||||||
var otherModifierElements: List<JKOtherModifierElement>
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JKOtherModifiersOwner.elementByModifier(modifier: OtherModifier): JKOtherModifierElement? =
|
|
||||||
otherModifierElements.firstOrNull { it.otherModifier == modifier }
|
|
||||||
|
|
||||||
fun JKOtherModifiersOwner.hasOtherModifier(modifier: OtherModifier): Boolean =
|
|
||||||
otherModifierElements.any { it.otherModifier == modifier }
|
|
||||||
|
|
||||||
enum class OtherModifier(override val text: String) : Modifier {
|
|
||||||
OVERRIDE("override"),
|
|
||||||
ACTUAL("actual"),
|
|
||||||
ANNOTATION("annotation"),
|
|
||||||
COMPANION("companion"),
|
|
||||||
CONST("const"),
|
|
||||||
CROSSINLINE("crossinline"),
|
|
||||||
DATA("data"),
|
|
||||||
EXPECT("expect"),
|
|
||||||
EXTERNAL("external"),
|
|
||||||
INFIX("infix"),
|
|
||||||
INLINE("inline"),
|
|
||||||
INNER("inner"),
|
|
||||||
LATEINIT("lateinit"),
|
|
||||||
NOINLINE("noinline"),
|
|
||||||
OPERATOR("operator"),
|
|
||||||
OUT("out"),
|
|
||||||
REIFIED("reified"),
|
|
||||||
SEALED("sealed"),
|
|
||||||
SUSPEND("suspend"),
|
|
||||||
TAILREC("tailrec"),
|
|
||||||
VARARG("vararg"),
|
|
||||||
|
|
||||||
NATIVE("native"),
|
|
||||||
STATIC("static"),
|
|
||||||
STRICTFP("strictfp"),
|
|
||||||
SYNCHRONIZED("synchronized"),
|
|
||||||
TRANSIENT("transient"),
|
|
||||||
VOLATILE("volatile")
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKVisibilityOwner : JKModifiersListOwner {
|
|
||||||
val visibilityElement: JKVisibilityModifierElement
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Visibility(override val text: String) : Modifier {
|
|
||||||
PUBLIC("public"),
|
|
||||||
INTERNAL("internal"),
|
|
||||||
PROTECTED("protected"),
|
|
||||||
PRIVATE("private")
|
|
||||||
}
|
|
||||||
|
|
||||||
var JKVisibilityOwner.visibility: Visibility
|
|
||||||
get() = visibilityElement.visibility
|
|
||||||
set(value) {
|
|
||||||
visibilityElement.visibility = value
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKModalityOwner : JKModifiersListOwner {
|
|
||||||
val modalityElement: JKModalityModifierElement
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum class Modality(override val text: String) : Modifier {
|
|
||||||
OPEN("open"),
|
|
||||||
FINAL("final"),
|
|
||||||
ABSTRACT("abstract"),
|
|
||||||
}
|
|
||||||
|
|
||||||
var JKModalityOwner.modality: Modality
|
|
||||||
get() = modalityElement.modality
|
|
||||||
set(value) {
|
|
||||||
modalityElement.modality = value
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKMutabilityOwner : JKModifiersListOwner {
|
|
||||||
val mutabilityElement: JKMutabilityModifierElement
|
|
||||||
}
|
|
||||||
|
|
||||||
enum class Mutability(override val text: String) : Modifier {
|
|
||||||
MUTABLE("var"),
|
|
||||||
IMMUTABLE("val"),
|
|
||||||
UNKNOWN("var")//TODO ???
|
|
||||||
}
|
|
||||||
|
|
||||||
var JKMutabilityOwner.mutability: Mutability
|
|
||||||
get() = mutabilityElement.mutability
|
|
||||||
set(value) {
|
|
||||||
mutabilityElement.mutability = value
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKModifiersListOwner : JKTreeElement
|
|
||||||
|
|
||||||
fun JKModifiersListOwner.modifierElements(): List<JKModifierElement> =
|
|
||||||
listOfNotNull((this as? JKVisibilityOwner)?.visibilityElement) +
|
|
||||||
(this as? JKOtherModifiersOwner)?.otherModifierElements.orEmpty() +
|
|
||||||
listOfNotNull((this as? JKModalityOwner)?.modalityElement) +
|
|
||||||
listOfNotNull((this as? JKMutabilityOwner)?.mutabilityElement)
|
|
||||||
|
|
||||||
|
|
||||||
interface JKTypeElement : JKTreeElement {
|
|
||||||
var type: JKType
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKStatement : JKTreeElement, JKBranchElementBase() {
|
|
||||||
override var rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf(JKSpaceElementImpl("\n"))
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKBlock : JKTreeElement, JKBranchElementBase() {
|
|
||||||
abstract var statements: List<JKStatement>
|
|
||||||
|
|
||||||
val leftBrace = JKTokenElementImpl("{")
|
|
||||||
val rightBrace = JKTokenElementImpl("}")
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKBodyStub : JKBlock() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKIdentifier : JKTreeElement
|
|
||||||
|
|
||||||
interface JKNameIdentifier : JKIdentifier {
|
|
||||||
val value: String
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKExpression : JKTreeElement, JKAnnotationMemberValue
|
|
||||||
|
|
||||||
interface JKMethodReferenceExpression : JKExpression, PsiOwner {
|
|
||||||
val qualifier: JKExpression
|
|
||||||
val identifier: JKSymbol
|
|
||||||
val functionalType: JKTypeElement
|
|
||||||
val isConstructorCall: Boolean
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKExpressionStatement : JKStatement() {
|
|
||||||
abstract var expression: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKDeclarationStatement : JKStatement() {
|
|
||||||
abstract val declaredStatements: List<JKDeclaration>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKOperatorExpression : JKExpression {
|
|
||||||
var operator: JKOperator
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO make left & right to be immutable
|
|
||||||
interface JKBinaryExpression : JKOperatorExpression {
|
|
||||||
var left: JKExpression
|
|
||||||
var right: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKUnaryExpression : JKOperatorExpression {
|
|
||||||
var expression: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKPrefixExpression : JKUnaryExpression
|
|
||||||
|
|
||||||
interface JKPostfixExpression : JKUnaryExpression
|
|
||||||
|
|
||||||
interface JKQualifiedExpression : JKExpression {
|
|
||||||
var receiver: JKExpression
|
|
||||||
var operator: JKQualifier
|
|
||||||
var selector: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKTypeArgumentList : JKTreeElement {
|
|
||||||
var typeArguments: List<JKTypeElement>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKTypeArgumentListOwner : JKTreeElement {
|
|
||||||
var typeArgumentList: JKTypeArgumentList
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKMethodCallExpression : JKExpression, JKTypeArgumentListOwner, JKBranchElement {
|
|
||||||
val identifier: JKMethodSymbol
|
|
||||||
var arguments: JKArgumentList
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKFieldAccessExpression : JKExpression {
|
|
||||||
val identifier: JKFieldSymbol
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKPackageAccessExpression : JKExpression {
|
|
||||||
val identifier: JKPackageSymbol
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKClassAccessExpression : JKExpression {
|
|
||||||
val identifier: JKClassSymbol
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKArrayAccessExpression : JKExpression {
|
|
||||||
var expression: JKExpression
|
|
||||||
var indexExpression: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKParenthesizedExpression : JKExpression {
|
|
||||||
val expression: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKTypeCastExpression : JKExpression {
|
|
||||||
val expression: JKExpression
|
|
||||||
val type: JKTypeElement
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKExpressionList : JKTreeElement, JKBranchElement {
|
|
||||||
var expressions: List<JKExpression>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKArgument : JKTreeElement, JKBranchElement {
|
|
||||||
var value: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKNamedArgument : JKArgument {
|
|
||||||
val name: JKNameIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKArgumentList : JKTreeElement, JKBranchElement {
|
|
||||||
var arguments: List<JKArgument>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface JKLiteralExpression : JKExpression {
|
|
||||||
val literal: String
|
|
||||||
val type: LiteralType
|
|
||||||
|
|
||||||
enum class LiteralType {
|
|
||||||
STRING, CHAR, BOOLEAN, NULL, INT, LONG, FLOAT, DOUBLE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKParameter : JKVariable(), JKModifiersListOwner {
|
|
||||||
abstract var isVarArgs: Boolean
|
|
||||||
|
|
||||||
override val rightNonCodeElements: MutableList<JKNonCodeElement> = mutableListOf()
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKStringLiteralExpression : JKLiteralExpression {
|
|
||||||
val text: String
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKStubExpression : JKExpression
|
|
||||||
|
|
||||||
abstract class JKLoopStatement : JKStatement() {
|
|
||||||
abstract var body: JKStatement
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKBlockStatement : JKStatement() {
|
|
||||||
abstract var block: JKBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKBlockStatementWithoutBrackets : JKStatement() {
|
|
||||||
abstract var statements: List<JKStatement>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKThisExpression : JKExpression {
|
|
||||||
var qualifierLabel: JKLabel
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKSuperExpression : JKExpression {
|
|
||||||
var qualifierLabel: JKLabel
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKWhileStatement : JKLoopStatement() {
|
|
||||||
abstract var condition: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKDoWhileStatement : JKLoopStatement() {
|
|
||||||
abstract var condition: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKBreakStatement : JKStatement()
|
|
||||||
|
|
||||||
abstract class JKBreakWithLabelStatement : JKBreakStatement() {
|
|
||||||
abstract var label: JKNameIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKIfStatement : JKStatement() {
|
|
||||||
abstract var condition: JKExpression
|
|
||||||
abstract var thenBranch: JKStatement
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKIfElseStatement : JKIfStatement() {
|
|
||||||
abstract var elseBranch: JKStatement
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKIfElseExpression : JKExpression {
|
|
||||||
var condition: JKExpression
|
|
||||||
var thenBranch: JKExpression
|
|
||||||
var elseBranch: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKLambdaExpression : JKExpression {
|
|
||||||
var parameters: List<JKParameter>
|
|
||||||
val returnType: JKTypeElement
|
|
||||||
var statement: JKStatement
|
|
||||||
val functionalType: JKTypeElement
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKDelegationConstructorCall : JKMethodCallExpression {
|
|
||||||
override val identifier: JKMethodSymbol
|
|
||||||
val expression: JKExpression
|
|
||||||
override var arguments: JKArgumentList
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKLabel : JKTreeElement
|
|
||||||
|
|
||||||
interface JKLabelEmpty : JKLabel
|
|
||||||
|
|
||||||
interface JKLabelText : JKLabel {
|
|
||||||
val label: JKNameIdentifier
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKContinueStatement : JKStatement() {
|
|
||||||
abstract var label: JKLabel
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKLabeledStatement : JKExpression {
|
|
||||||
var statement: JKStatement
|
|
||||||
val labels: List<JKNameIdentifier>
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKEmptyStatement : JKStatement()
|
|
||||||
|
|
||||||
interface JKTypeParameterList : JKTreeElement {
|
|
||||||
var typeParameters: List<JKTypeParameter>
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKTypeParameter : JKDeclaration() {
|
|
||||||
abstract var upperBounds: List<JKTypeElement>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKTypeParameterListOwner : JKTreeElement {
|
|
||||||
var typeParameterList: JKTypeParameterList
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKEnumConstant : JKVariable() {
|
|
||||||
abstract val arguments: JKArgumentList
|
|
||||||
abstract val body: JKClassBody
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKForInStatement : JKStatement() {
|
|
||||||
abstract var declaration: JKDeclaration
|
|
||||||
abstract var iterationExpression: JKExpression
|
|
||||||
abstract var body: JKStatement
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKPackageDeclaration : JKDeclaration()
|
|
||||||
|
|
||||||
interface JKClassLiteralExpression : JKExpression {
|
|
||||||
val classType: JKTypeElement
|
|
||||||
var literalType: LiteralType
|
|
||||||
|
|
||||||
enum class LiteralType {
|
|
||||||
KOTLIN_CLASS,
|
|
||||||
JAVA_CLASS,
|
|
||||||
JAVA_PRIMITIVE_CLASS,
|
|
||||||
JAVA_VOID_TYPE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKAnnotationMemberValue : JKTreeElement
|
|
||||||
@@ -1,156 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBranchElementBase
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKModalityModifierElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKTokenElementImpl
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKVisibilityModifierElementImpl
|
|
||||||
|
|
||||||
abstract class JKField : JKVariable(), JKVisibilityOwner, JKMutabilityOwner, JKModalityOwner, JKOtherModifiersOwner, JKAnnotationListOwner
|
|
||||||
|
|
||||||
abstract class JKJavaField : JKField()
|
|
||||||
|
|
||||||
abstract class JKJavaMethod : JKMethod(), JKBranchElement {
|
|
||||||
abstract var throwsList: List<JKTypeElement>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaMethodCallExpression : JKMethodCallExpression
|
|
||||||
|
|
||||||
abstract class JKClassBody : JKTreeElement, JKBranchElementBase() {
|
|
||||||
abstract var declarations: List<JKDeclaration>
|
|
||||||
|
|
||||||
val leftBrace = JKTokenElementImpl("{")
|
|
||||||
val rightBrace = JKTokenElementImpl("}")
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKEmptyClassBody : JKClassBody() {
|
|
||||||
override var declarations: List<JKDeclaration> = emptyList()
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaNewExpression : JKExpression, JKTypeArgumentListOwner, PsiOwner {
|
|
||||||
var classSymbol: JKClassSymbol
|
|
||||||
var arguments: JKArgumentList
|
|
||||||
var classBody: JKClassBody
|
|
||||||
}
|
|
||||||
|
|
||||||
fun JKJavaNewExpression.isAnonymousClass() =
|
|
||||||
classBody !is JKEmptyClassBody
|
|
||||||
|
|
||||||
|
|
||||||
interface JKJavaDefaultNewExpression : JKExpression {
|
|
||||||
val classSymbol: JKClassSymbol
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface JKJavaNewEmptyArray : JKExpression {
|
|
||||||
val type: JKTypeElement
|
|
||||||
var initializer: List<JKExpression>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaNewArray : JKExpression {
|
|
||||||
val type: JKTypeElement
|
|
||||||
var initializer: List<JKExpression>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaLiteralExpression : JKLiteralExpression
|
|
||||||
|
|
||||||
abstract class JKReturnStatement : JKStatement() {
|
|
||||||
abstract val expression: JKExpression
|
|
||||||
abstract var label: JKLabel
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKJavaAssertStatement : JKStatement() {
|
|
||||||
abstract val condition: JKExpression
|
|
||||||
abstract val description: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKJavaForLoopStatement : JKLoopStatement() {
|
|
||||||
abstract var initializer: JKStatement
|
|
||||||
abstract var condition: JKExpression
|
|
||||||
abstract var updaters: List<JKStatement>
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface JKJavaPolyadicExpression : JKExpression {
|
|
||||||
var operands: List<JKExpression>
|
|
||||||
var tokens: List<JKOperator>
|
|
||||||
|
|
||||||
fun getTokenBeforeOperand(operand: JKExpression): JKOperator?
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaAssignmentExpression : JKExpression, JKBranchElement {
|
|
||||||
var field: JKExpression
|
|
||||||
var expression: JKExpression
|
|
||||||
var operator: JKOperator
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKJavaThrowStatement : JKStatement() {
|
|
||||||
abstract var exception: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKJavaTryStatement : JKStatement() {
|
|
||||||
abstract var resourceDeclarations: List<JKDeclaration>
|
|
||||||
abstract var tryBlock: JKBlock
|
|
||||||
abstract var finallyBlock: JKBlock
|
|
||||||
abstract var catchSections: List<JKJavaTryCatchSection>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaTryCatchSection : JKTreeElement {
|
|
||||||
var parameter: JKParameter
|
|
||||||
var block: JKBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
abstract class JKJavaSwitchStatement : JKStatement() {
|
|
||||||
abstract var expression: JKExpression
|
|
||||||
abstract var cases: List<JKJavaSwitchCase>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaSwitchCase : JKTreeElement {
|
|
||||||
fun isDefault(): Boolean
|
|
||||||
var statements: List<JKStatement>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaDefaultSwitchCase : JKJavaSwitchCase {
|
|
||||||
override fun isDefault(): Boolean = true
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaLabelSwitchCase : JKJavaSwitchCase {
|
|
||||||
override fun isDefault(): Boolean = false
|
|
||||||
var label: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKJavaContinueStatement : JKStatement()
|
|
||||||
|
|
||||||
abstract class JKJavaSynchronizedStatement : JKStatement(), JKBranchElement {
|
|
||||||
abstract val lockExpression: JKExpression
|
|
||||||
abstract val body: JKBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKJavaAnnotationMethod : JKMethod(), JKBranchElement {
|
|
||||||
abstract val defaultValue: JKAnnotationMemberValue
|
|
||||||
|
|
||||||
override var otherModifierElements by children<JKOtherModifierElement>()
|
|
||||||
override var visibilityElement by child(JKVisibilityModifierElementImpl(Visibility.PUBLIC))
|
|
||||||
override var modalityElement by child(JKModalityModifierElementImpl(Modality.FINAL))
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKJavaStaticInitDeclaration : JKDeclaration(), JKBranchElement {
|
|
||||||
abstract var block: JKBlock
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2017 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree
|
|
||||||
|
|
||||||
interface JKKtGetterOrSetter : JKTreeElement, JKVisibilityOwner, JKBranchElement {
|
|
||||||
var body: JKStatement
|
|
||||||
val kind: Kind
|
|
||||||
|
|
||||||
enum class Kind {
|
|
||||||
GETTER, SETTER
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtEmptyGetterOrSetter : JKKtGetterOrSetter
|
|
||||||
|
|
||||||
abstract class JKKtProperty : JKField(), PsiOwner {
|
|
||||||
abstract var getter: JKKtGetterOrSetter
|
|
||||||
abstract var setter: JKKtGetterOrSetter
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
abstract class JKKtFunction : JKMethod(), PsiOwner
|
|
||||||
|
|
||||||
abstract class JKKtConstructor : JKMethod(), JKOtherModifiersOwner {
|
|
||||||
abstract var delegationCall: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKKtPrimaryConstructor : JKKtConstructor()
|
|
||||||
|
|
||||||
abstract class JKKtAssignmentStatement : JKStatement() {
|
|
||||||
abstract var field: JKExpression
|
|
||||||
abstract var expression: JKExpression
|
|
||||||
abstract var token: JKOperatorToken
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtCall : JKMethodCallExpression
|
|
||||||
|
|
||||||
interface JKKtMethodCallExpression : JKMethodCallExpression
|
|
||||||
|
|
||||||
interface JKKtAssignmentChainLink : JKExpression {
|
|
||||||
val receiver: JKExpression
|
|
||||||
val assignmentStatement: JKKtAssignmentStatement
|
|
||||||
val field: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKAssignmentChainAlsoLink : JKKtAssignmentChainLink
|
|
||||||
interface JKAssignmentChainLetLink : JKKtAssignmentChainLink
|
|
||||||
|
|
||||||
interface JKKtLiteralExpression : JKLiteralExpression
|
|
||||||
|
|
||||||
abstract class JKKtWhenStatement : JKStatement() {
|
|
||||||
abstract var expression: JKExpression
|
|
||||||
abstract var cases: List<JKKtWhenCase>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtWhenCase : JKTreeElement {
|
|
||||||
var labels: List<JKKtWhenLabel>
|
|
||||||
var statement: JKStatement
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtWhenLabel : JKTreeElement
|
|
||||||
|
|
||||||
interface JKKtElseWhenLabel : JKKtWhenLabel
|
|
||||||
|
|
||||||
interface JKKtValueWhenLabel : JKKtWhenLabel {
|
|
||||||
var expression: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtIsExpression : JKExpression, PsiOwner {
|
|
||||||
var expression: JKExpression
|
|
||||||
var type: JKTypeElement
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class JKKtInitDeclaration : JKDeclaration() {
|
|
||||||
abstract var block: JKBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
abstract class JKKtConvertedFromForLoopSyntheticWhileStatement : JKStatement() {
|
|
||||||
abstract var variableDeclaration: JKStatement
|
|
||||||
abstract var whileStatement: JKWhileStatement
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
interface JKKtThrowExpression : JKExpression {
|
|
||||||
var exception: JKExpression
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtTryExpression : JKExpression {
|
|
||||||
var tryBlock: JKBlock
|
|
||||||
var finallyBlock: JKBlock
|
|
||||||
var catchSections: List<JKKtTryCatchSection>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtTryCatchSection : JKTreeElement {
|
|
||||||
var parameter: JKParameter
|
|
||||||
var block: JKBlock
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtAnnotationArrayInitializerExpression : JKExpression, JKBranchElement {
|
|
||||||
val initializers: List<JKAnnotationMemberValue>
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKKtItExpression : JKExpression {
|
|
||||||
val type: JKType
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||||
|
|
||||||
|
interface Modifier {
|
||||||
|
val text: String
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class OtherModifier(override val text: String) : Modifier {
|
||||||
|
OVERRIDE("override"),
|
||||||
|
ACTUAL("actual"),
|
||||||
|
ANNOTATION("annotation"),
|
||||||
|
COMPANION("companion"),
|
||||||
|
CONST("const"),
|
||||||
|
CROSSINLINE("crossinline"),
|
||||||
|
DATA("data"),
|
||||||
|
EXPECT("expect"),
|
||||||
|
EXTERNAL("external"),
|
||||||
|
INFIX("infix"),
|
||||||
|
INLINE("inline"),
|
||||||
|
INNER("inner"),
|
||||||
|
LATEINIT("lateinit"),
|
||||||
|
NOINLINE("noinline"),
|
||||||
|
OPERATOR("operator"),
|
||||||
|
OUT("out"),
|
||||||
|
REIFIED("reified"),
|
||||||
|
SEALED("sealed"),
|
||||||
|
SUSPEND("suspend"),
|
||||||
|
TAILREC("tailrec"),
|
||||||
|
VARARG("vararg"),
|
||||||
|
|
||||||
|
NATIVE("native"),
|
||||||
|
STATIC("static"),
|
||||||
|
STRICTFP("strictfp"),
|
||||||
|
SYNCHRONIZED("synchronized"),
|
||||||
|
TRANSIENT("transient"),
|
||||||
|
VOLATILE("volatile")
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKModifierElement : JKTreeElement()
|
||||||
|
|
||||||
|
|
||||||
|
interface JKOtherModifiersOwner : JKModifiersListOwner {
|
||||||
|
var otherModifierElements: List<JKOtherModifierElement>
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKMutabilityModifierElement(var mutability: Mutability) : JKModifierElement() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitMutabilityModifierElement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKModalityModifierElement(var modality: Modality) : JKModifierElement() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitModalityModifierElement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKVisibilityModifierElement(var visibility: Visibility) : JKModifierElement() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitVisibilityModifierElement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKOtherModifierElement(var otherModifier: OtherModifier) : JKModifierElement() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitOtherModifierElement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
interface JKVisibilityOwner : JKModifiersListOwner {
|
||||||
|
val visibilityElement: JKVisibilityModifierElement
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Visibility(override val text: String) : Modifier {
|
||||||
|
PUBLIC("public"),
|
||||||
|
INTERNAL("internal"),
|
||||||
|
PROTECTED("protected"),
|
||||||
|
PRIVATE("private")
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JKModalityOwner : JKModifiersListOwner {
|
||||||
|
val modalityElement: JKModalityModifierElement
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Modality(override val text: String) : Modifier {
|
||||||
|
OPEN("open"),
|
||||||
|
FINAL("final"),
|
||||||
|
ABSTRACT("abstract"),
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JKMutabilityOwner : JKModifiersListOwner {
|
||||||
|
val mutabilityElement: JKMutabilityModifierElement
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Mutability(override val text: String) : Modifier {
|
||||||
|
MUTABLE("var"),
|
||||||
|
IMMUTABLE("val"),
|
||||||
|
UNKNOWN("var")
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JKModifiersListOwner : JKNonCodeElementsListOwner
|
||||||
|
|
||||||
|
fun JKOtherModifiersOwner.elementByModifier(modifier: OtherModifier): JKOtherModifierElement? =
|
||||||
|
otherModifierElements.firstOrNull { it.otherModifier == modifier }
|
||||||
|
|
||||||
|
fun JKOtherModifiersOwner.hasOtherModifier(modifier: OtherModifier): Boolean =
|
||||||
|
otherModifierElements.any { it.otherModifier == modifier }
|
||||||
|
|
||||||
|
var JKVisibilityOwner.visibility: Visibility
|
||||||
|
get() = visibilityElement.visibility
|
||||||
|
set(value) {
|
||||||
|
visibilityElement.visibility = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var JKMutabilityOwner.mutability: Mutability
|
||||||
|
get() = mutabilityElement.mutability
|
||||||
|
set(value) {
|
||||||
|
mutabilityElement.mutability = value
|
||||||
|
}
|
||||||
|
|
||||||
|
var JKModalityOwner.modality: Modality
|
||||||
|
get() = modalityElement.modality
|
||||||
|
set(value) {
|
||||||
|
modalityElement.modality = value
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
val JKModifierElement.modifier: Modifier
|
||||||
|
get() = when (this) {
|
||||||
|
is JKMutabilityModifierElement -> mutability
|
||||||
|
is JKModalityModifierElement -> modality
|
||||||
|
is JKVisibilityModifierElement -> visibility
|
||||||
|
is JKOtherModifierElement -> otherModifier
|
||||||
|
else -> error("")
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline fun JKModifiersListOwner.forEachModifier(action: (JKModifierElement) -> Unit) {
|
||||||
|
safeAs<JKVisibilityOwner>()?.visibilityElement?.let(action)
|
||||||
|
safeAs<JKOtherModifiersOwner>()?.otherModifierElements?.forEach(action)
|
||||||
|
safeAs<JKModalityOwner>()?.modalityElement?.let(action)
|
||||||
|
safeAs<JKMutabilityOwner>()?.mutabilityElement?.let(action)
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
|
import com.intellij.psi.JavaTokenType
|
||||||
|
import com.intellij.psi.tree.IElementType
|
||||||
|
import org.jetbrains.kotlin.lexer.KtSingleValueToken
|
||||||
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
|
import org.jetbrains.kotlin.nj2k.types.JKType
|
||||||
|
|
||||||
|
interface JKOperator {
|
||||||
|
val token: JKOperatorToken
|
||||||
|
val returnType: JKType
|
||||||
|
}
|
||||||
|
|
||||||
|
interface JKOperatorToken {
|
||||||
|
val text: String
|
||||||
|
|
||||||
|
@Suppress("MemberVisibilityCanBePrivate", "SpellCheckingInspection")
|
||||||
|
companion object {
|
||||||
|
fun fromElementType(elementType: IElementType) = elementTypeToToken.getValue(elementType)
|
||||||
|
|
||||||
|
val RANGE = JKKtSingleValueOperatorToken(KtTokens.RANGE)
|
||||||
|
|
||||||
|
val DIV = JKKtSingleValueOperatorToken(KtTokens.DIV)
|
||||||
|
val MINUS = JKKtSingleValueOperatorToken(KtTokens.MINUS)
|
||||||
|
val ANDAND = JKKtSingleValueOperatorToken(KtTokens.ANDAND)
|
||||||
|
val OROR = JKKtSingleValueOperatorToken(KtTokens.OROR)
|
||||||
|
val PLUS = JKKtSingleValueOperatorToken(KtTokens.PLUS)
|
||||||
|
val MUL = JKKtSingleValueOperatorToken(KtTokens.MUL)
|
||||||
|
val GT = JKKtSingleValueOperatorToken(KtTokens.GT)
|
||||||
|
val GTEQ = JKKtSingleValueOperatorToken(KtTokens.GTEQ)
|
||||||
|
val LT = JKKtSingleValueOperatorToken(KtTokens.LT)
|
||||||
|
val LTEQ = JKKtSingleValueOperatorToken(KtTokens.LTEQ)
|
||||||
|
val PERC = JKKtSingleValueOperatorToken(KtTokens.PERC)
|
||||||
|
val EQ = JKKtSingleValueOperatorToken(KtTokens.EQ)
|
||||||
|
val EQEQ = JKKtSingleValueOperatorToken(KtTokens.EQEQ)
|
||||||
|
val EXCLEQ = JKKtSingleValueOperatorToken(KtTokens.EXCLEQ)
|
||||||
|
|
||||||
|
val PLUSEQ = JKKtSingleValueOperatorToken(KtTokens.PLUSEQ)
|
||||||
|
val MINUSEQ = JKKtSingleValueOperatorToken(KtTokens.MINUSEQ)
|
||||||
|
val DIVEQ = JKKtSingleValueOperatorToken(KtTokens.DIVEQ)
|
||||||
|
val MULTEQ = JKKtSingleValueOperatorToken(KtTokens.MULTEQ)
|
||||||
|
val PERCEQ = JKKtSingleValueOperatorToken(KtTokens.PERCEQ)
|
||||||
|
|
||||||
|
val PLUSPLUS = JKKtSingleValueOperatorToken(KtTokens.PLUSPLUS)
|
||||||
|
val MINUSMINUS = JKKtSingleValueOperatorToken(KtTokens.MINUSMINUS)
|
||||||
|
val EXCL = JKKtSingleValueOperatorToken(KtTokens.EXCL)
|
||||||
|
val EQEQEQ = JKKtSingleValueOperatorToken(KtTokens.EQEQEQ)
|
||||||
|
val EXCLEQEQEQ = JKKtSingleValueOperatorToken(KtTokens.EXCLEQEQEQ)
|
||||||
|
|
||||||
|
val AND = JKKtWordOperatorToken("and")
|
||||||
|
val OR = JKKtWordOperatorToken("or")
|
||||||
|
val XOR = JKKtWordOperatorToken("xor")
|
||||||
|
val USHR = JKKtWordOperatorToken("ushr")
|
||||||
|
val SHR = JKKtWordOperatorToken("shr")
|
||||||
|
val SHL = JKKtWordOperatorToken("shl")
|
||||||
|
|
||||||
|
val ANDEQ = JKJavaOperatorToken(JavaTokenType.ANDEQ)
|
||||||
|
val OREQ = JKJavaOperatorToken(JavaTokenType.OREQ)
|
||||||
|
val XOREQ = JKJavaOperatorToken(JavaTokenType.XOREQ)
|
||||||
|
val LTLTEQ = JKJavaOperatorToken(JavaTokenType.LTLTEQ)
|
||||||
|
val GTGTEQ = JKJavaOperatorToken(JavaTokenType.GTGTEQ)
|
||||||
|
val GTGTGTEQ = JKJavaOperatorToken(JavaTokenType.GTGTGTEQ)
|
||||||
|
|
||||||
|
private val elementTypeToToken: Map<IElementType, JKOperatorToken> = mapOf(
|
||||||
|
JavaTokenType.DIV to DIV,
|
||||||
|
JavaTokenType.MINUS to MINUS,
|
||||||
|
JavaTokenType.ANDAND to ANDAND,
|
||||||
|
JavaTokenType.OROR to OROR,
|
||||||
|
JavaTokenType.PLUS to PLUS,
|
||||||
|
JavaTokenType.ASTERISK to MUL,
|
||||||
|
JavaTokenType.GT to GT,
|
||||||
|
JavaTokenType.GE to GTEQ,
|
||||||
|
JavaTokenType.LT to LT,
|
||||||
|
JavaTokenType.LE to LTEQ,
|
||||||
|
JavaTokenType.PERC to PERC,
|
||||||
|
|
||||||
|
JavaTokenType.EQ to EQ,
|
||||||
|
JavaTokenType.EQEQ to EQEQ,
|
||||||
|
JavaTokenType.NE to EXCLEQ,
|
||||||
|
|
||||||
|
JavaTokenType.PLUSEQ to PLUSEQ,
|
||||||
|
JavaTokenType.MINUSEQ to MINUSEQ,
|
||||||
|
JavaTokenType.DIVEQ to DIVEQ,
|
||||||
|
JavaTokenType.ASTERISKEQ to MULTEQ,
|
||||||
|
|
||||||
|
JavaTokenType.PLUSPLUS to PLUSPLUS,
|
||||||
|
JavaTokenType.MINUSMINUS to MINUSMINUS,
|
||||||
|
JavaTokenType.EXCL to EXCL,
|
||||||
|
|
||||||
|
KtTokens.EQEQEQ to EQEQEQ,
|
||||||
|
KtTokens.EXCLEQEQEQ to EXCLEQEQEQ,
|
||||||
|
|
||||||
|
JavaTokenType.AND to AND,
|
||||||
|
JavaTokenType.OR to OR,
|
||||||
|
JavaTokenType.XOR to XOR,
|
||||||
|
JavaTokenType.GTGTGT to USHR,
|
||||||
|
JavaTokenType.GTGT to SHR,
|
||||||
|
JavaTokenType.LTLT to SHL,
|
||||||
|
|
||||||
|
JavaTokenType.ANDEQ to ANDEQ,
|
||||||
|
JavaTokenType.OREQ to OREQ,
|
||||||
|
JavaTokenType.XOREQ to XOREQ,
|
||||||
|
JavaTokenType.PERCEQ to PERCEQ,
|
||||||
|
JavaTokenType.LTLTEQ to LTLTEQ,
|
||||||
|
JavaTokenType.GTGTEQ to GTGTEQ,
|
||||||
|
JavaTokenType.GTGTGTEQ to GTGTGTEQ
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtWordOperatorToken(override val text: String) : JKKtOperatorToken
|
||||||
|
|
||||||
|
class JKKtOperatorImpl(override val token: JKOperatorToken, override val returnType: JKType) : JKOperator
|
||||||
|
|
||||||
|
interface JKKtOperatorToken : JKOperatorToken
|
||||||
|
|
||||||
|
class JKJavaOperatorToken(val psiToken: IElementType) : JKOperatorToken {
|
||||||
|
override val text: String
|
||||||
|
get() = error("Java token should not be printed, it should be replaces with corresponding Kotlin one")
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtSingleValueOperatorToken(val psiToken: KtSingleValueToken) : JKKtOperatorToken {
|
||||||
|
override val text: String = psiToken.value
|
||||||
|
}
|
||||||
|
|
||||||
|
object JKKtSpreadOperatorToken : JKKtOperatorToken {
|
||||||
|
override val text: String = "*"
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtSpreadOperator(override val returnType: JKType) : JKOperator {
|
||||||
|
override val token: JKOperatorToken = JKKtSpreadOperatorToken
|
||||||
|
}
|
||||||
@@ -0,0 +1,191 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.nj2k.tree.visitors.JKVisitor
|
||||||
|
|
||||||
|
abstract class JKStatement : JKTreeElement(), PsiOwner by PsiOwnerImpl()
|
||||||
|
|
||||||
|
class JKEmptyStatement : JKStatement() {
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitEmptyStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class JKLoopStatement : JKStatement() {
|
||||||
|
abstract var body: JKStatement
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKWhileStatement(condition: JKExpression, body: JKStatement) : JKLoopStatement() {
|
||||||
|
var condition by child(condition)
|
||||||
|
override var body by child(body)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitWhileStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKDoWhileStatement(body: JKStatement, condition: JKExpression) : JKLoopStatement() {
|
||||||
|
var condition by child(condition)
|
||||||
|
override var body by child(body)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitDoWhileStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKForInStatement(declaration: JKDeclaration, iterationExpression: JKExpression, body: JKStatement) : JKStatement() {
|
||||||
|
var declaration: JKDeclaration by child(declaration)
|
||||||
|
var iterationExpression: JKExpression by child(iterationExpression)
|
||||||
|
var body: JKStatement by child(body)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitForInStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKIfElseStatement(condition: JKExpression, thenBranch: JKStatement, elseBranch: JKStatement) : JKStatement() {
|
||||||
|
var condition by child(condition)
|
||||||
|
var thenBranch by child(thenBranch)
|
||||||
|
var elseBranch by child(elseBranch)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitIfElseStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKBreakStatement(label: JKLabel) : JKStatement() {
|
||||||
|
val label: JKLabel by child(label)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitBreakStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKContinueStatement(label: JKLabel) : JKStatement() {
|
||||||
|
var label: JKLabel by child(label)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitContinueStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKBlockStatement(block: JKBlock) : JKStatement() {
|
||||||
|
var block by child(block)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitBlockStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKBlockStatementWithoutBrackets(statements: List<JKStatement>) : JKStatement() {
|
||||||
|
var statements by children(statements)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitBlockStatementWithoutBrackets(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKExpressionStatement(expression: JKExpression) : JKStatement() {
|
||||||
|
var expression: JKExpression by child(expression)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitExpressionStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKDeclarationStatement(declaredStatements: List<JKDeclaration>) : JKStatement() {
|
||||||
|
val declaredStatements by children(declaredStatements)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitDeclarationStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtWhenStatement(
|
||||||
|
expression: JKExpression,
|
||||||
|
cases: List<JKKtWhenCase>
|
||||||
|
) : JKStatement() {
|
||||||
|
var expression: JKExpression by child(expression)
|
||||||
|
var cases: List<JKKtWhenCase> by children(cases)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtWhenStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtConvertedFromForLoopSyntheticWhileStatement(
|
||||||
|
variableDeclaration: JKStatement,
|
||||||
|
whileStatement: JKWhileStatement
|
||||||
|
) : JKStatement() {
|
||||||
|
var variableDeclaration: JKStatement by child(variableDeclaration)
|
||||||
|
var whileStatement: JKWhileStatement by child(whileStatement)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtConvertedFromForLoopSyntheticWhileStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKKtAssignmentStatement(
|
||||||
|
field: JKExpression,
|
||||||
|
expression: JKExpression,
|
||||||
|
var token: JKOperatorToken
|
||||||
|
) : JKStatement() {
|
||||||
|
var field: JKExpression by child(field)
|
||||||
|
var expression by child(expression)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitKtAssignmentStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKReturnStatement(
|
||||||
|
expression: JKExpression,
|
||||||
|
label: JKLabel = JKLabelEmpty()
|
||||||
|
) : JKStatement() {
|
||||||
|
val expression by child(expression)
|
||||||
|
var label by child(label)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitReturnStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaSwitchStatement(
|
||||||
|
expression: JKExpression,
|
||||||
|
cases: List<JKJavaSwitchCase>
|
||||||
|
) : JKStatement() {
|
||||||
|
var expression: JKExpression by child(expression)
|
||||||
|
var cases: List<JKJavaSwitchCase> by children(cases)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaSwitchStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaThrowStatement(exception: JKExpression) : JKStatement() {
|
||||||
|
var exception: JKExpression by child(exception)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaThrowStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaTryStatement(
|
||||||
|
resourceDeclarations: List<JKDeclaration>,
|
||||||
|
tryBlock: JKBlock,
|
||||||
|
finallyBlock: JKBlock,
|
||||||
|
catchSections: List<JKJavaTryCatchSection>
|
||||||
|
) : JKStatement() {
|
||||||
|
var resourceDeclarations: List<JKDeclaration> by children(resourceDeclarations)
|
||||||
|
var tryBlock: JKBlock by child(tryBlock)
|
||||||
|
var finallyBlock: JKBlock by child(finallyBlock)
|
||||||
|
var catchSections: List<JKJavaTryCatchSection> by children(catchSections)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaTryStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaSynchronizedStatement(
|
||||||
|
lockExpression: JKExpression,
|
||||||
|
body: JKBlock
|
||||||
|
) : JKStatement() {
|
||||||
|
val lockExpression: JKExpression by child(lockExpression)
|
||||||
|
val body: JKBlock by child(body)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaSynchronizedStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class JKJavaAssertStatement(condition: JKExpression, description: JKExpression) : JKStatement() {
|
||||||
|
val description by child(description)
|
||||||
|
val condition by child(condition)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaAssertStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaForLoopStatement(
|
||||||
|
initializer: JKStatement,
|
||||||
|
condition: JKExpression,
|
||||||
|
updaters: List<JKStatement>,
|
||||||
|
body: JKStatement
|
||||||
|
) : JKLoopStatement() {
|
||||||
|
override var body by child(body)
|
||||||
|
var updaters by children(updaters)
|
||||||
|
var condition by child(condition)
|
||||||
|
var initializer by child(initializer)
|
||||||
|
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaForLoopStatement(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
class JKJavaAnnotationMethod(
|
||||||
|
returnType: JKTypeElement,
|
||||||
|
name: JKNameIdentifier,
|
||||||
|
defaultValue: JKAnnotationMemberValue,
|
||||||
|
otherModifierElements: List<JKOtherModifierElement>,
|
||||||
|
visibilityElement: JKVisibilityModifierElement,
|
||||||
|
modalityElement: JKModalityModifierElement
|
||||||
|
) : JKMethod(), JKAnnotationListOwner, JKTypeParameterListOwner {
|
||||||
|
override var returnType: JKTypeElement by child(returnType)
|
||||||
|
override var name: JKNameIdentifier by child(name)
|
||||||
|
override var parameters: List<JKParameter> by children()
|
||||||
|
var defaultValue: JKAnnotationMemberValue by child(defaultValue)
|
||||||
|
override var block: JKBlock by child(JKBodyStub)
|
||||||
|
override var typeParameterList: JKTypeParameterList by child(JKTypeParameterList())
|
||||||
|
override var annotationList: JKAnnotationList by child(JKAnnotationList())
|
||||||
|
override var otherModifierElements by children(otherModifierElements)
|
||||||
|
override var visibilityElement by child(visibilityElement)
|
||||||
|
override var modalityElement by child(modalityElement)
|
||||||
|
override fun accept(visitor: JKVisitor) = visitor.visitJavaAnnotationMethod(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
+8
-23
@@ -5,21 +5,20 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.utils.SmartList
|
||||||
|
|
||||||
|
|
||||||
interface JKNonCodeElement {
|
interface JKNonCodeElement {
|
||||||
val text: String
|
val text: String
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKSpaceElement : JKNonCodeElement
|
class JKSpaceElement(override val text: String) : JKNonCodeElement
|
||||||
|
class JKCommentElement(override val text: String) : JKNonCodeElement
|
||||||
interface JKCommentElement : JKNonCodeElement
|
|
||||||
|
|
||||||
fun JKCommentElement.isMultiline() =
|
|
||||||
text.startsWith("/*")
|
|
||||||
|
|
||||||
fun JKCommentElement.isSingleline() =
|
|
||||||
text.startsWith("//")
|
|
||||||
|
|
||||||
|
class JKTokenElementImpl(override val text: String) : JKTokenElement {
|
||||||
|
override val leftNonCodeElements: MutableList<JKNonCodeElement> = SmartList()
|
||||||
|
override val rightNonCodeElements: MutableList<JKNonCodeElement> = SmartList()
|
||||||
|
}
|
||||||
|
|
||||||
interface JKNonCodeElementsListOwner {
|
interface JKNonCodeElementsListOwner {
|
||||||
val leftNonCodeElements: MutableList<JKNonCodeElement>
|
val leftNonCodeElements: MutableList<JKNonCodeElement>
|
||||||
@@ -31,20 +30,6 @@ fun JKNonCodeElementsListOwner.takeNonCodeElementsFrom(other: JKNonCodeElementsL
|
|||||||
rightNonCodeElements += other.rightNonCodeElements
|
rightNonCodeElements += other.rightNonCodeElements
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun List<JKNonCodeElement>.dropSpacesAtBeginning() =
|
|
||||||
dropWhile { it is JKSpaceElement }
|
|
||||||
|
|
||||||
fun JKTreeElement.commentsFromInside(): List<JKCommentElement> {
|
|
||||||
val comments = mutableListOf<JKCommentElement>()
|
|
||||||
fun recurse(element: JKTreeElement): JKTreeElement {
|
|
||||||
comments += (element.leftNonCodeElements + element.rightNonCodeElements).filterIsInstance<JKCommentElement>()
|
|
||||||
return applyRecursive(element, ::recurse)
|
|
||||||
}
|
|
||||||
applyRecursive(this, ::recurse)
|
|
||||||
return comments
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <reified T : JKNonCodeElementsListOwner> T.withNonCodeElementsFrom(other: JKNonCodeElementsListOwner): T =
|
inline fun <reified T : JKNonCodeElementsListOwner> T.withNonCodeElementsFrom(other: JKNonCodeElementsListOwner): T =
|
||||||
also { it.takeNonCodeElementsFrom(other) }
|
also { it.takeNonCodeElementsFrom(other) }
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree
|
package org.jetbrains.kotlin.nj2k.tree
|
||||||
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.JKBranchElementBase
|
|
||||||
import kotlin.jvm.internal.CallableReference
|
import kotlin.jvm.internal.CallableReference
|
||||||
import kotlin.reflect.KProperty0
|
import kotlin.reflect.KProperty0
|
||||||
|
|
||||||
@@ -44,9 +44,6 @@ fun <T : JKElement> KProperty0<List<T>>.detached(): List<T> =
|
|||||||
fun <T : JKElement> T.detached(from: JKElement): T =
|
fun <T : JKElement> T.detached(from: JKElement): T =
|
||||||
also { it.detach(from) }
|
also { it.detach(from) }
|
||||||
|
|
||||||
fun <T : JKBranchElement> T.invalidated(): T =
|
|
||||||
also { it.invalidate() }
|
|
||||||
|
|
||||||
fun <R : JKTreeElement, T> applyRecursive(
|
fun <R : JKTreeElement, T> applyRecursive(
|
||||||
element: R,
|
element: R,
|
||||||
data: T,
|
data: T,
|
||||||
@@ -76,25 +73,23 @@ fun <R : JKTreeElement, T> applyRecursive(
|
|||||||
return newChild
|
return newChild
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element is JKBranchElementBase) {
|
val iter = element.children.listIterator()
|
||||||
val iter = element.children.listIterator()
|
while (iter.hasNext()) {
|
||||||
while (iter.hasNext()) {
|
val child = iter.next()
|
||||||
val child = iter.next()
|
|
||||||
|
|
||||||
if (child is List<*>) {
|
if (child is List<*>) {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
iter.set(applyRecursiveToList(element, child as List<JKTreeElement>, iter, data, func))
|
iter.set(applyRecursiveToList(element, child as List<JKTreeElement>, iter, data, func))
|
||||||
} else if (child is JKTreeElement) {
|
} else if (child is JKTreeElement) {
|
||||||
val newChild = func(child, data)
|
val newChild = func(child, data)
|
||||||
if (child !== newChild) {
|
if (child !== newChild) {
|
||||||
child.detach(element)
|
child.detach(element)
|
||||||
iter.set(newChild)
|
iter.set(newChild)
|
||||||
newChild.attach(element)
|
newChild.attach(element)
|
||||||
onElementChanged(newChild, child)
|
onElementChanged(newChild, child)
|
||||||
}
|
|
||||||
} else {
|
|
||||||
error("unsupported child type: ${child::class}")
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
error("unsupported child type: ${child::class}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return element
|
return element
|
||||||
@@ -106,4 +101,11 @@ fun <R : JKTreeElement> applyRecursive(
|
|||||||
): R = applyRecursive(element, null, { _, _ -> }) { it, _ -> func(it) }
|
): R = applyRecursive(element, null, { _, _ -> }) { it, _ -> func(it) }
|
||||||
|
|
||||||
|
|
||||||
|
inline fun <reified T : JKTreeElement> T.copyTree(): T =
|
||||||
|
copy().withNonCodeElementsFrom(this) as T
|
||||||
|
|
||||||
|
inline fun <reified T : JKTreeElement> T.copyTreeAndDetach(): T =
|
||||||
|
copyTree().also {
|
||||||
|
if (it.parent != null) it.detach(it.parent!!)
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,146 +3,146 @@ package org.jetbrains.kotlin.nj2k.tree.visitors
|
|||||||
import org.jetbrains.kotlin.nj2k.tree.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
|
|
||||||
abstract class JKVisitor {
|
abstract class JKVisitor {
|
||||||
abstract fun visitTreeElement(treeElement: JKTreeElement)
|
abstract fun visitTreeElement(treeElement: JKTreeElement)
|
||||||
open fun visitTreeRoot(treeRoot: JKTreeRoot) = visitTreeElement(treeRoot)
|
|
||||||
open fun visitDeclaration(declaration: JKDeclaration) = visitTreeElement(declaration)
|
open fun visitDeclaration(declaration: JKDeclaration) = visitTreeElement(declaration)
|
||||||
|
open fun visitClass(klass: JKClass) = visitDeclaration(klass)
|
||||||
|
open fun visitVariable(variable: JKVariable) = visitDeclaration(variable)
|
||||||
|
open fun visitLocalVariable(localVariable: JKLocalVariable) = visitVariable(localVariable)
|
||||||
|
open fun visitForLoopVariable(forLoopVariable: JKForLoopVariable) = visitVariable(forLoopVariable)
|
||||||
|
open fun visitParameter(parameter: JKParameter) = visitVariable(parameter)
|
||||||
|
open fun visitEnumConstant(enumConstant: JKEnumConstant) = visitVariable(enumConstant)
|
||||||
|
open fun visitTypeParameter(typeParameter: JKTypeParameter) = visitDeclaration(typeParameter)
|
||||||
|
open fun visitMethod(method: JKMethod) = visitDeclaration(method)
|
||||||
|
open fun visitMethodImpl(methodImpl: JKMethodImpl) = visitMethod(methodImpl)
|
||||||
|
open fun visitConstructor(constructor: JKConstructor) = visitMethod(constructor)
|
||||||
|
open fun visitConstructorImpl(constructorImpl: JKConstructorImpl) = visitConstructor(constructorImpl)
|
||||||
|
open fun visitKtPrimaryConstructor(ktPrimaryConstructor: JKKtPrimaryConstructor) = visitConstructor(ktPrimaryConstructor)
|
||||||
|
open fun visitField(field: JKField) = visitVariable(field)
|
||||||
|
open fun visitKtInitDeclaration(ktInitDeclaration: JKKtInitDeclaration) = visitDeclaration(ktInitDeclaration)
|
||||||
|
open fun visitJavaStaticInitDeclaration(javaStaticInitDeclaration: JKJavaStaticInitDeclaration) =
|
||||||
|
visitDeclaration(javaStaticInitDeclaration)
|
||||||
|
|
||||||
|
open fun visitTreeRoot(treeRoot: JKTreeRoot) = visitTreeElement(treeRoot)
|
||||||
|
open fun visitFile(file: JKFile) = visitTreeElement(file)
|
||||||
|
open fun visitTypeElement(typeElement: JKTypeElement) = visitTreeElement(typeElement)
|
||||||
|
open fun visitBlock(block: JKBlock) = visitTreeElement(block)
|
||||||
|
open fun visitInheritanceInfo(inheritanceInfo: JKInheritanceInfo) = visitTreeElement(inheritanceInfo)
|
||||||
|
open fun visitPackageDeclaration(packageDeclaration: JKPackageDeclaration) = visitTreeElement(packageDeclaration)
|
||||||
|
open fun visitLabel(label: JKLabel) = visitTreeElement(label)
|
||||||
|
open fun visitLabelEmpty(labelEmpty: JKLabelEmpty) = visitLabel(labelEmpty)
|
||||||
|
open fun visitLabelText(labelText: JKLabelText) = visitLabel(labelText)
|
||||||
open fun visitImportStatement(importStatement: JKImportStatement) = visitTreeElement(importStatement)
|
open fun visitImportStatement(importStatement: JKImportStatement) = visitTreeElement(importStatement)
|
||||||
open fun visitImportList(importList: JKImportList) = visitTreeElement(importList)
|
open fun visitImportList(importList: JKImportList) = visitTreeElement(importList)
|
||||||
open fun visitFile(file: JKFile) = visitTreeElement(file)
|
|
||||||
open fun visitClass(klass: JKClass) = visitDeclaration(klass)
|
|
||||||
open fun visitInheritanceInfo(inheritanceInfo: JKInheritanceInfo) = visitTreeElement(inheritanceInfo)
|
|
||||||
open fun visitAnnotationList(annotationList: JKAnnotationList) = visitTreeElement(annotationList)
|
|
||||||
open fun visitAnnotation(annotation: JKAnnotation) = visitAnnotationMemberValue(annotation)
|
|
||||||
open fun visitAnnotationParameter(annotationParameter: JKAnnotationParameter) = visitTreeElement(annotationParameter)
|
open fun visitAnnotationParameter(annotationParameter: JKAnnotationParameter) = visitTreeElement(annotationParameter)
|
||||||
open fun visitAnnotationNameParameter(annotationNameParameter: JKAnnotationNameParameter) = visitAnnotationParameter(annotationNameParameter)
|
open fun visitAnnotationParameterImpl(annotationParameterImpl: JKAnnotationParameterImpl) =
|
||||||
open fun visitAnnotationListOwner(annotationListOwner: JKAnnotationListOwner) = visitTreeElement(annotationListOwner)
|
visitAnnotationParameter(annotationParameterImpl)
|
||||||
open fun visitMethod(method: JKMethod) = visitDeclaration(method)
|
|
||||||
open fun visitVariable(variable: JKVariable) = visitDeclaration(variable)
|
open fun visitAnnotationNameParameter(annotationNameParameter: JKAnnotationNameParameter) =
|
||||||
open fun visitForLoopVariable(forLoopVariable: JKForLoopVariable) = visitVariable(forLoopVariable)
|
visitAnnotationParameter(annotationNameParameter)
|
||||||
open fun visitLocalVariable(localVariable: JKLocalVariable) = visitVariable(localVariable)
|
|
||||||
open fun visitModifierElement(modifierElement: JKModifierElement) = visitTreeElement(modifierElement)
|
open fun visitArgument(argument: JKArgument) = visitTreeElement(argument)
|
||||||
open fun visitMutabilityModifierElement(mutabilityModifierElement: JKMutabilityModifierElement) = visitModifierElement(mutabilityModifierElement)
|
open fun visitNamedArgument(namedArgument: JKNamedArgument) = visitArgument(namedArgument)
|
||||||
open fun visitModalityModifierElement(modalityModifierElement: JKModalityModifierElement) = visitModifierElement(modalityModifierElement)
|
open fun visitArgumentImpl(argumentImpl: JKArgumentImpl) = visitArgument(argumentImpl)
|
||||||
open fun visitVisibilityModifierElement(visibilityModifierElement: JKVisibilityModifierElement) = visitModifierElement(visibilityModifierElement)
|
open fun visitArgumentList(argumentList: JKArgumentList) = visitTreeElement(argumentList)
|
||||||
open fun visitOtherModifierElement(otherModifierElement: JKOtherModifierElement) = visitModifierElement(otherModifierElement)
|
open fun visitTypeParameterList(typeParameterList: JKTypeParameterList) = visitTreeElement(typeParameterList)
|
||||||
open fun visitOtherModifiersOwner(otherModifiersOwner: JKOtherModifiersOwner) = visitModifiersListOwner(otherModifiersOwner)
|
open fun visitAnnotationList(annotationList: JKAnnotationList) = visitTreeElement(annotationList)
|
||||||
open fun visitVisibilityOwner(visibilityOwner: JKVisibilityOwner) = visitModifiersListOwner(visibilityOwner)
|
open fun visitAnnotation(annotation: JKAnnotation) = visitTreeElement(annotation)
|
||||||
open fun visitModalityOwner(modalityOwner: JKModalityOwner) = visitModifiersListOwner(modalityOwner)
|
open fun visitTypeArgumentList(typeArgumentList: JKTypeArgumentList) = visitTreeElement(typeArgumentList)
|
||||||
open fun visitMutabilityOwner(mutabilityOwner: JKMutabilityOwner) = visitModifiersListOwner(mutabilityOwner)
|
open fun visitNameIdentifier(nameIdentifier: JKNameIdentifier) = visitTreeElement(nameIdentifier)
|
||||||
open fun visitModifiersListOwner(modifiersListOwner: JKModifiersListOwner) = visitTreeElement(modifiersListOwner)
|
open fun visitBlockImpl(blockImpl: JKBlockImpl) = visitBlock(blockImpl)
|
||||||
open fun visitTypeElement(typeElement: JKTypeElement) = visitTreeElement(typeElement)
|
open fun visitKtWhenCase(ktWhenCase: JKKtWhenCase) = visitTreeElement(ktWhenCase)
|
||||||
open fun visitStatement(statement: JKStatement) = visitTreeElement(statement)
|
open fun visitKtWhenLabel(ktWhenLabel: JKKtWhenLabel) = visitTreeElement(ktWhenLabel)
|
||||||
open fun visitBlock(block: JKBlock) = visitTreeElement(block)
|
open fun visitKtElseWhenLabel(ktElseWhenLabel: JKKtElseWhenLabel) = visitKtWhenLabel(ktElseWhenLabel)
|
||||||
open fun visitBodyStub(bodyStub: JKBodyStub) = visitBlock(bodyStub)
|
open fun visitKtValueWhenLabel(ktValueWhenLabel: JKKtValueWhenLabel) = visitKtWhenLabel(ktValueWhenLabel)
|
||||||
open fun visitIdentifier(identifier: JKIdentifier) = visitTreeElement(identifier)
|
open fun visitClassBody(classBody: JKClassBody) = visitTreeElement(classBody)
|
||||||
open fun visitNameIdentifier(nameIdentifier: JKNameIdentifier) = visitIdentifier(nameIdentifier)
|
open fun visitJavaTryCatchSection(javaTryCatchSection: JKJavaTryCatchSection) = visitStatement(javaTryCatchSection)
|
||||||
|
open fun visitJavaSwitchCase(javaSwitchCase: JKJavaSwitchCase) = visitTreeElement(javaSwitchCase)
|
||||||
|
open fun visitJavaDefaultSwitchCase(javaDefaultSwitchCase: JKJavaDefaultSwitchCase) = visitJavaSwitchCase(javaDefaultSwitchCase)
|
||||||
|
open fun visitJavaLabelSwitchCase(javaLabelSwitchCase: JKJavaLabelSwitchCase) = visitJavaSwitchCase(javaLabelSwitchCase)
|
||||||
open fun visitExpression(expression: JKExpression) = visitTreeElement(expression)
|
open fun visitExpression(expression: JKExpression) = visitTreeElement(expression)
|
||||||
open fun visitMethodReferenceExpression(methodReferenceExpression: JKMethodReferenceExpression) = visitExpression(methodReferenceExpression)
|
|
||||||
open fun visitExpressionStatement(expressionStatement: JKExpressionStatement) = visitStatement(expressionStatement)
|
|
||||||
open fun visitDeclarationStatement(declarationStatement: JKDeclarationStatement) = visitStatement(declarationStatement)
|
|
||||||
open fun visitOperatorExpression(operatorExpression: JKOperatorExpression) = visitExpression(operatorExpression)
|
open fun visitOperatorExpression(operatorExpression: JKOperatorExpression) = visitExpression(operatorExpression)
|
||||||
open fun visitBinaryExpression(binaryExpression: JKBinaryExpression) = visitOperatorExpression(binaryExpression)
|
open fun visitBinaryExpression(binaryExpression: JKBinaryExpression) = visitOperatorExpression(binaryExpression)
|
||||||
open fun visitUnaryExpression(unaryExpression: JKUnaryExpression) = visitOperatorExpression(unaryExpression)
|
open fun visitUnaryExpression(unaryExpression: JKUnaryExpression) = visitOperatorExpression(unaryExpression)
|
||||||
open fun visitPrefixExpression(prefixExpression: JKPrefixExpression) = visitUnaryExpression(prefixExpression)
|
open fun visitPrefixExpression(prefixExpression: JKPrefixExpression) = visitUnaryExpression(prefixExpression)
|
||||||
open fun visitPostfixExpression(postfixExpression: JKPostfixExpression) = visitUnaryExpression(postfixExpression)
|
open fun visitPostfixExpression(postfixExpression: JKPostfixExpression) = visitUnaryExpression(postfixExpression)
|
||||||
open fun visitQualifiedExpression(qualifiedExpression: JKQualifiedExpression) = visitExpression(qualifiedExpression)
|
open fun visitQualifiedExpression(qualifiedExpression: JKQualifiedExpression) = visitExpression(qualifiedExpression)
|
||||||
open fun visitTypeArgumentList(typeArgumentList: JKTypeArgumentList) = visitTreeElement(typeArgumentList)
|
|
||||||
open fun visitTypeArgumentListOwner(typeArgumentListOwner: JKTypeArgumentListOwner) = visitTreeElement(typeArgumentListOwner)
|
|
||||||
open fun visitMethodCallExpression(methodCallExpression: JKMethodCallExpression) = visitExpression(methodCallExpression)
|
|
||||||
open fun visitFieldAccessExpression(fieldAccessExpression: JKFieldAccessExpression) = visitAssignableExpression(fieldAccessExpression)
|
|
||||||
open fun visitPackageAccessExpression(packageAccessExpression: JKPackageAccessExpression) = visitAssignableExpression(packageAccessExpression)
|
|
||||||
open fun visitClassAccessExpression(classAccessExpression: JKClassAccessExpression) = visitExpression(classAccessExpression)
|
|
||||||
open fun visitArrayAccessExpression(arrayAccessExpression: JKArrayAccessExpression) = visitAssignableExpression(arrayAccessExpression)
|
|
||||||
open fun visitParenthesizedExpression(parenthesizedExpression: JKParenthesizedExpression) = visitExpression(parenthesizedExpression)
|
open fun visitParenthesizedExpression(parenthesizedExpression: JKParenthesizedExpression) = visitExpression(parenthesizedExpression)
|
||||||
open fun visitTypeCastExpression(typeCastExpression: JKTypeCastExpression) = visitExpression(typeCastExpression)
|
open fun visitTypeCastExpression(typeCastExpression: JKTypeCastExpression) = visitExpression(typeCastExpression)
|
||||||
open fun visitExpressionList(expressionList: JKExpressionList) = visitTreeElement(expressionList)
|
|
||||||
open fun visitArgument(argument: JKArgument) = visitTreeElement(argument)
|
|
||||||
open fun visitNamedArgument(namedArgument: JKNamedArgument) = visitArgument(namedArgument)
|
|
||||||
open fun visitArgumentList(argumentList: JKArgumentList) = visitTreeElement(argumentList)
|
|
||||||
open fun visitLiteralExpression(literalExpression: JKLiteralExpression) = visitExpression(literalExpression)
|
open fun visitLiteralExpression(literalExpression: JKLiteralExpression) = visitExpression(literalExpression)
|
||||||
open fun visitParameter(parameter: JKParameter) = visitVariable(parameter)
|
|
||||||
open fun visitStringLiteralExpression(stringLiteralExpression: JKStringLiteralExpression) = visitLiteralExpression(stringLiteralExpression)
|
|
||||||
open fun visitStubExpression(stubExpression: JKStubExpression) = visitExpression(stubExpression)
|
open fun visitStubExpression(stubExpression: JKStubExpression) = visitExpression(stubExpression)
|
||||||
open fun visitLoopStatement(loopStatement: JKLoopStatement) = visitStatement(loopStatement)
|
|
||||||
open fun visitBlockStatement(blockStatement: JKBlockStatement) = visitStatement(blockStatement)
|
|
||||||
open fun visitBlockStatementWithoutBrackets(blockStatementWithoutBrackets: JKBlockStatementWithoutBrackets) = visitStatement(blockStatementWithoutBrackets)
|
|
||||||
open fun visitThisExpression(thisExpression: JKThisExpression) = visitExpression(thisExpression)
|
open fun visitThisExpression(thisExpression: JKThisExpression) = visitExpression(thisExpression)
|
||||||
open fun visitSuperExpression(superExpression: JKSuperExpression) = visitExpression(superExpression)
|
open fun visitSuperExpression(superExpression: JKSuperExpression) = visitExpression(superExpression)
|
||||||
open fun visitWhileStatement(whileStatement: JKWhileStatement) = visitLoopStatement(whileStatement)
|
|
||||||
open fun visitDoWhileStatement(doWhileStatement: JKDoWhileStatement) = visitLoopStatement(doWhileStatement)
|
|
||||||
open fun visitBreakStatement(breakStatement: JKBreakStatement) = visitStatement(breakStatement)
|
|
||||||
open fun visitBreakWithLabelStatement(breakWithLabelStatement: JKBreakWithLabelStatement) = visitBreakStatement(breakWithLabelStatement)
|
|
||||||
open fun visitIfStatement(ifStatement: JKIfStatement) = visitStatement(ifStatement)
|
|
||||||
open fun visitIfElseStatement(ifElseStatement: JKIfElseStatement) = visitIfStatement(ifElseStatement)
|
|
||||||
open fun visitIfElseExpression(ifElseExpression: JKIfElseExpression) = visitExpression(ifElseExpression)
|
open fun visitIfElseExpression(ifElseExpression: JKIfElseExpression) = visitExpression(ifElseExpression)
|
||||||
open fun visitAssignableExpression(assignableExpression: JKExpression) = visitExpression(assignableExpression)
|
|
||||||
open fun visitLambdaExpression(lambdaExpression: JKLambdaExpression) = visitExpression(lambdaExpression)
|
open fun visitLambdaExpression(lambdaExpression: JKLambdaExpression) = visitExpression(lambdaExpression)
|
||||||
open fun visitDelegationConstructorCall(delegationConstructorCall: JKDelegationConstructorCall) = visitMethodCallExpression(delegationConstructorCall)
|
open fun visitCallExpression(callExpression: JKCallExpression) = visitExpression(callExpression)
|
||||||
open fun visitLabel(label: JKLabel) = visitTreeElement(label)
|
open fun visitDelegationConstructorCall(delegationConstructorCall: JKDelegationConstructorCall) =
|
||||||
open fun visitLabelEmpty(labelEmpty: JKLabelEmpty) = visitLabel(labelEmpty)
|
visitCallExpression(delegationConstructorCall)
|
||||||
open fun visitLabelText(labelText: JKLabelText) = visitLabel(labelText)
|
|
||||||
open fun visitContinueStatement(continueStatement: JKContinueStatement) = visitStatement(continueStatement)
|
open fun visitCallExpressionImpl(callExpressionImpl: JKCallExpressionImpl) = visitCallExpression(callExpressionImpl)
|
||||||
open fun visitLabeledStatement(labeledStatement: JKLabeledStatement) = visitExpression(labeledStatement)
|
open fun visitNewExpression(newExpression: JKNewExpression) = visitExpression(newExpression)
|
||||||
open fun visitEmptyStatement(emptyStatement: JKEmptyStatement) = visitStatement(emptyStatement)
|
open fun visitFieldAccessExpression(fieldAccessExpression: JKFieldAccessExpression) = visitExpression(fieldAccessExpression)
|
||||||
open fun visitTypeParameterList(typeParameterList: JKTypeParameterList) = visitTreeElement(typeParameterList)
|
open fun visitPackageAccessExpression(packageAccessExpression: JKPackageAccessExpression) = visitExpression(packageAccessExpression)
|
||||||
open fun visitTypeParameter(typeParameter: JKTypeParameter) = visitDeclaration(typeParameter)
|
open fun visitClassAccessExpression(classAccessExpression: JKClassAccessExpression) = visitExpression(classAccessExpression)
|
||||||
open fun visitTypeParameterListOwner(typeParameterListOwner: JKTypeParameterListOwner) = visitTreeElement(typeParameterListOwner)
|
open fun visitMethodReferenceExpression(methodReferenceExpression: JKMethodReferenceExpression) =
|
||||||
open fun visitEnumConstant(enumConstant: JKEnumConstant) = visitVariable(enumConstant)
|
visitExpression(methodReferenceExpression)
|
||||||
open fun visitForInStatement(forInStatement: JKForInStatement) = visitStatement(forInStatement)
|
|
||||||
open fun visitPackageDeclaration(packageDeclaration: JKPackageDeclaration) = visitDeclaration(packageDeclaration)
|
open fun visitLabeledExpression(labeledExpression: JKLabeledExpression) = visitExpression(labeledExpression)
|
||||||
open fun visitClassLiteralExpression(classLiteralExpression: JKClassLiteralExpression) = visitExpression(classLiteralExpression)
|
open fun visitClassLiteralExpression(classLiteralExpression: JKClassLiteralExpression) = visitExpression(classLiteralExpression)
|
||||||
open fun visitAnnotationMemberValue(annotationMemberValue: JKAnnotationMemberValue) = visitTreeElement(annotationMemberValue)
|
|
||||||
open fun visitField(field: JKField) = visitVariable(field)
|
|
||||||
open fun visitJavaField(javaField: JKJavaField) = visitField(javaField)
|
|
||||||
open fun visitJavaMethod(javaMethod: JKJavaMethod) = visitMethod(javaMethod)
|
|
||||||
open fun visitJavaMethodCallExpression(javaMethodCallExpression: JKJavaMethodCallExpression) = visitMethodCallExpression(javaMethodCallExpression)
|
|
||||||
open fun visitClassBody(classBody: JKClassBody) = visitTreeElement(classBody)
|
|
||||||
open fun visitEmptyClassBody(emptyClassBody: JKEmptyClassBody) = visitClassBody(emptyClassBody)
|
|
||||||
open fun visitJavaNewExpression(javaNewExpression: JKJavaNewExpression) = visitExpression(javaNewExpression)
|
|
||||||
open fun visitJavaDefaultNewExpression(javaDefaultNewExpression: JKJavaDefaultNewExpression) = visitExpression(javaDefaultNewExpression)
|
|
||||||
open fun visitJavaNewEmptyArray(javaNewEmptyArray: JKJavaNewEmptyArray) = visitExpression(javaNewEmptyArray)
|
|
||||||
open fun visitJavaNewArray(javaNewArray: JKJavaNewArray) = visitExpression(javaNewArray)
|
|
||||||
open fun visitJavaLiteralExpression(javaLiteralExpression: JKJavaLiteralExpression) = visitLiteralExpression(javaLiteralExpression)
|
|
||||||
open fun visitReturnStatement(returnStatement: JKReturnStatement) = visitStatement(returnStatement)
|
|
||||||
open fun visitJavaAssertStatement(javaAssertStatement: JKJavaAssertStatement) = visitStatement(javaAssertStatement)
|
|
||||||
open fun visitJavaForLoopStatement(javaForLoopStatement: JKJavaForLoopStatement) = visitLoopStatement(javaForLoopStatement)
|
|
||||||
open fun visitJavaPolyadicExpression(javaPolyadicExpression: JKJavaPolyadicExpression) = visitExpression(javaPolyadicExpression)
|
|
||||||
open fun visitJavaAssignmentExpression(javaAssignmentExpression: JKJavaAssignmentExpression) = visitExpression(javaAssignmentExpression)
|
|
||||||
open fun visitJavaThrowStatement(javaThrowStatement: JKJavaThrowStatement) = visitStatement(javaThrowStatement)
|
|
||||||
open fun visitJavaTryStatement(javaTryStatement: JKJavaTryStatement) = visitStatement(javaTryStatement)
|
|
||||||
open fun visitJavaTryCatchSection(javaTryCatchSection: JKJavaTryCatchSection) = visitTreeElement(javaTryCatchSection)
|
|
||||||
open fun visitJavaSwitchStatement(javaSwitchStatement: JKJavaSwitchStatement) = visitStatement(javaSwitchStatement)
|
|
||||||
open fun visitJavaSwitchCase(javaSwitchCase: JKJavaSwitchCase) = visitTreeElement(javaSwitchCase)
|
|
||||||
open fun visitJavaDefaultSwitchCase(javaDefaultSwitchCase: JKJavaDefaultSwitchCase) = visitJavaSwitchCase(javaDefaultSwitchCase)
|
|
||||||
open fun visitJavaLabelSwitchCase(javaLabelSwitchCase: JKJavaLabelSwitchCase) = visitJavaSwitchCase(javaLabelSwitchCase)
|
|
||||||
open fun visitJavaContinueStatement(javaContinueStatement: JKJavaContinueStatement) = visitStatement(javaContinueStatement)
|
|
||||||
open fun visitJavaSynchronizedStatement(javaSynchronizedStatement: JKJavaSynchronizedStatement) = visitStatement(javaSynchronizedStatement)
|
|
||||||
open fun visitJavaAnnotationMethod(javaAnnotationMethod: JKJavaAnnotationMethod) = visitMethod(javaAnnotationMethod)
|
|
||||||
open fun visitJavaStaticInitDeclaration(javaStaticInitDeclaration: JKJavaStaticInitDeclaration) = visitDeclaration(javaStaticInitDeclaration)
|
|
||||||
open fun visitKtGetterOrSetter(ktGetterOrSetter: JKKtGetterOrSetter) = visitTreeElement(ktGetterOrSetter)
|
|
||||||
open fun visitKtEmptyGetterOrSetter(ktEmptyGetterOrSetter: JKKtEmptyGetterOrSetter) = visitKtGetterOrSetter(ktEmptyGetterOrSetter)
|
|
||||||
open fun visitKtProperty(ktProperty: JKKtProperty) = visitField(ktProperty)
|
|
||||||
open fun visitKtFunction(ktFunction: JKKtFunction) = visitMethod(ktFunction)
|
|
||||||
open fun visitKtConstructor(ktConstructor: JKKtConstructor) = visitMethod(ktConstructor)
|
|
||||||
open fun visitKtPrimaryConstructor(ktPrimaryConstructor: JKKtPrimaryConstructor) = visitKtConstructor(ktPrimaryConstructor)
|
|
||||||
open fun visitKtAssignmentStatement(ktAssignmentStatement: JKKtAssignmentStatement) = visitStatement(ktAssignmentStatement)
|
|
||||||
open fun visitKtCall(ktCall: JKKtCall) = visitMethodCallExpression(ktCall)
|
|
||||||
open fun visitKtMethodCallExpression(ktMethodCallExpression: JKKtMethodCallExpression) = visitMethodCallExpression(ktMethodCallExpression)
|
|
||||||
open fun visitKtAssignmentChainLink(ktAssignmentChainLink: JKKtAssignmentChainLink) = visitExpression(ktAssignmentChainLink)
|
open fun visitKtAssignmentChainLink(ktAssignmentChainLink: JKKtAssignmentChainLink) = visitExpression(ktAssignmentChainLink)
|
||||||
open fun visitAssignmentChainAlsoLink(assignmentChainAlsoLink: JKAssignmentChainAlsoLink) = visitKtAssignmentChainLink(assignmentChainAlsoLink)
|
open fun visitAssignmentChainAlsoLink(assignmentChainAlsoLink: JKAssignmentChainAlsoLink) =
|
||||||
open fun visitAssignmentChainLetLink(assignmentChainLetLink: JKAssignmentChainLetLink) = visitKtAssignmentChainLink(assignmentChainLetLink)
|
visitKtAssignmentChainLink(assignmentChainAlsoLink)
|
||||||
open fun visitKtLiteralExpression(ktLiteralExpression: JKKtLiteralExpression) = visitLiteralExpression(ktLiteralExpression)
|
|
||||||
open fun visitKtWhenStatement(ktWhenStatement: JKKtWhenStatement) = visitStatement(ktWhenStatement)
|
open fun visitAssignmentChainLetLink(assignmentChainLetLink: JKAssignmentChainLetLink) =
|
||||||
open fun visitKtWhenCase(ktWhenCase: JKKtWhenCase) = visitTreeElement(ktWhenCase)
|
visitKtAssignmentChainLink(assignmentChainLetLink)
|
||||||
open fun visitKtWhenLabel(ktWhenLabel: JKKtWhenLabel) = visitTreeElement(ktWhenLabel)
|
|
||||||
open fun visitKtElseWhenLabel(ktElseWhenLabel: JKKtElseWhenLabel) = visitKtWhenLabel(ktElseWhenLabel)
|
open fun visitIsExpression(isExpression: JKIsExpression) = visitExpression(isExpression)
|
||||||
open fun visitKtValueWhenLabel(ktValueWhenLabel: JKKtValueWhenLabel) = visitKtWhenLabel(ktValueWhenLabel)
|
|
||||||
open fun visitKtIsExpression(ktIsExpression: JKKtIsExpression) = visitExpression(ktIsExpression)
|
|
||||||
open fun visitKtInitDeclaration(ktInitDeclaration: JKKtInitDeclaration) = visitDeclaration(ktInitDeclaration)
|
|
||||||
open fun visitKtConvertedFromForLoopSyntheticWhileStatement(ktConvertedFromForLoopSyntheticWhileStatement: JKKtConvertedFromForLoopSyntheticWhileStatement) = visitStatement(ktConvertedFromForLoopSyntheticWhileStatement)
|
|
||||||
open fun visitKtThrowExpression(ktThrowExpression: JKKtThrowExpression) = visitExpression(ktThrowExpression)
|
open fun visitKtThrowExpression(ktThrowExpression: JKKtThrowExpression) = visitExpression(ktThrowExpression)
|
||||||
|
open fun visitKtItExpression(ktItExpression: JKKtItExpression) = visitExpression(ktItExpression)
|
||||||
|
open fun visitKtAnnotationArrayInitializerExpression(ktAnnotationArrayInitializerExpression: JKKtAnnotationArrayInitializerExpression) =
|
||||||
|
visitExpression(ktAnnotationArrayInitializerExpression)
|
||||||
|
|
||||||
open fun visitKtTryExpression(ktTryExpression: JKKtTryExpression) = visitExpression(ktTryExpression)
|
open fun visitKtTryExpression(ktTryExpression: JKKtTryExpression) = visitExpression(ktTryExpression)
|
||||||
open fun visitKtTryCatchSection(ktTryCatchSection: JKKtTryCatchSection) = visitTreeElement(ktTryCatchSection)
|
open fun visitKtTryCatchSection(ktTryCatchSection: JKKtTryCatchSection) = visitTreeElement(ktTryCatchSection)
|
||||||
open fun visitKtAnnotationArrayInitializerExpression(ktAnnotationArrayInitializerExpression: JKKtAnnotationArrayInitializerExpression) = visitExpression(ktAnnotationArrayInitializerExpression)
|
open fun visitJavaNewEmptyArray(javaNewEmptyArray: JKJavaNewEmptyArray) = visitExpression(javaNewEmptyArray)
|
||||||
open fun visitKtItExpression(ktItExpression: JKKtItExpression) = visitExpression(ktItExpression)
|
open fun visitJavaNewArray(javaNewArray: JKJavaNewArray) = visitExpression(javaNewArray)
|
||||||
|
open fun visitJavaAssignmentExpression(javaAssignmentExpression: JKJavaAssignmentExpression) = visitExpression(javaAssignmentExpression)
|
||||||
|
open fun visitModifierElement(modifierElement: JKModifierElement) = visitTreeElement(modifierElement)
|
||||||
|
open fun visitMutabilityModifierElement(mutabilityModifierElement: JKMutabilityModifierElement) =
|
||||||
|
visitModifierElement(mutabilityModifierElement)
|
||||||
|
|
||||||
|
open fun visitModalityModifierElement(modalityModifierElement: JKModalityModifierElement) =
|
||||||
|
visitModifierElement(modalityModifierElement)
|
||||||
|
|
||||||
|
open fun visitVisibilityModifierElement(visibilityModifierElement: JKVisibilityModifierElement) =
|
||||||
|
visitModifierElement(visibilityModifierElement)
|
||||||
|
|
||||||
|
open fun visitOtherModifierElement(otherModifierElement: JKOtherModifierElement) = visitModifierElement(otherModifierElement)
|
||||||
|
open fun visitStatement(statement: JKStatement) = visitTreeElement(statement)
|
||||||
|
open fun visitEmptyStatement(emptyStatement: JKEmptyStatement) = visitStatement(emptyStatement)
|
||||||
|
open fun visitLoopStatement(loopStatement: JKLoopStatement) = visitStatement(loopStatement)
|
||||||
|
open fun visitWhileStatement(whileStatement: JKWhileStatement) = visitLoopStatement(whileStatement)
|
||||||
|
open fun visitDoWhileStatement(doWhileStatement: JKDoWhileStatement) = visitLoopStatement(doWhileStatement)
|
||||||
|
open fun visitForInStatement(forInStatement: JKForInStatement) = visitStatement(forInStatement)
|
||||||
|
open fun visitIfElseStatement(ifElseStatement: JKIfElseStatement) = visitStatement(ifElseStatement)
|
||||||
|
open fun visitBreakStatement(breakStatement: JKBreakStatement) = visitStatement(breakStatement)
|
||||||
|
open fun visitContinueStatement(continueStatement: JKContinueStatement) = visitStatement(continueStatement)
|
||||||
|
open fun visitBlockStatement(blockStatement: JKBlockStatement) = visitStatement(blockStatement)
|
||||||
|
open fun visitBlockStatementWithoutBrackets(blockStatementWithoutBrackets: JKBlockStatementWithoutBrackets) =
|
||||||
|
visitStatement(blockStatementWithoutBrackets)
|
||||||
|
|
||||||
|
open fun visitExpressionStatement(expressionStatement: JKExpressionStatement) = visitStatement(expressionStatement)
|
||||||
|
open fun visitDeclarationStatement(declarationStatement: JKDeclarationStatement) = visitStatement(declarationStatement)
|
||||||
|
open fun visitKtWhenStatement(ktWhenStatement: JKKtWhenStatement) = visitStatement(ktWhenStatement)
|
||||||
|
open fun visitKtConvertedFromForLoopSyntheticWhileStatement(ktConvertedFromForLoopSyntheticWhileStatement: JKKtConvertedFromForLoopSyntheticWhileStatement) =
|
||||||
|
visitStatement(ktConvertedFromForLoopSyntheticWhileStatement)
|
||||||
|
|
||||||
|
open fun visitKtAssignmentStatement(ktAssignmentStatement: JKKtAssignmentStatement) = visitStatement(ktAssignmentStatement)
|
||||||
|
open fun visitReturnStatement(returnStatement: JKReturnStatement) = visitStatement(returnStatement)
|
||||||
|
open fun visitJavaSwitchStatement(javaSwitchStatement: JKJavaSwitchStatement) = visitStatement(javaSwitchStatement)
|
||||||
|
open fun visitJavaThrowStatement(javaThrowStatement: JKJavaThrowStatement) = visitStatement(javaThrowStatement)
|
||||||
|
open fun visitJavaTryStatement(javaTryStatement: JKJavaTryStatement) = visitStatement(javaTryStatement)
|
||||||
|
open fun visitJavaSynchronizedStatement(javaSynchronizedStatement: JKJavaSynchronizedStatement) = visitStatement(javaSynchronizedStatement)
|
||||||
|
open fun visitJavaAssertStatement(javaAssertStatement: JKJavaAssertStatement) = visitStatement(javaAssertStatement)
|
||||||
|
open fun visitJavaForLoopStatement(javaForLoopStatement: JKJavaForLoopStatement) = visitLoopStatement(javaForLoopStatement)
|
||||||
|
open fun visitJavaAnnotationMethod(javaAnnotationMethod: JKJavaAnnotationMethod) = visitMethod(javaAnnotationMethod)
|
||||||
}
|
}
|
||||||
|
|||||||
+663
-857
File diff suppressed because it is too large
Load Diff
@@ -11,15 +11,11 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
|||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
||||||
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
|
import org.jetbrains.kotlin.js.resolve.diagnostics.findPsi
|
||||||
import org.jetbrains.kotlin.name.FqName
|
|
||||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||||
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
|
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKTypeParameterSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKUnresolvedClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKClass
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKType
|
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
|
||||||
import org.jetbrains.kotlin.psi.KtTypeParameter
|
import org.jetbrains.kotlin.psi.KtTypeParameter
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
import org.jetbrains.kotlin.types.KotlinType
|
||||||
|
|||||||
@@ -8,26 +8,14 @@ package org.jetbrains.kotlin.nj2k.types
|
|||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKTypeParameterSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.JKType
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType
|
||||||
|
|
||||||
|
interface JKType {
|
||||||
|
val nullability: Nullability
|
||||||
|
}
|
||||||
|
|
||||||
interface JKWildCardType : JKType
|
interface JKWildCardType : JKType
|
||||||
|
|
||||||
interface JKVarianceTypeParameterType : JKWildCardType {
|
|
||||||
val variance: Variance
|
|
||||||
val boundType: JKType
|
|
||||||
override val nullability: Nullability
|
|
||||||
get() = Nullability.Default
|
|
||||||
|
|
||||||
enum class Variance {
|
|
||||||
IN, OUT
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKTypeParameterType : JKType {
|
|
||||||
val identifier: JKTypeParameterSymbol
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKNoType : JKType
|
interface JKNoType : JKType
|
||||||
|
|
||||||
interface JKParametrizedType : JKType {
|
interface JKParametrizedType : JKType {
|
||||||
@@ -39,21 +27,82 @@ interface JKClassType : JKParametrizedType {
|
|||||||
override val nullability: Nullability
|
override val nullability: Nullability
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKJavaPrimitiveType : JKType {
|
|
||||||
val jvmPrimitiveType: JvmPrimitiveType
|
|
||||||
override val nullability: Nullability
|
|
||||||
get() = Nullability.NotNull
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKJavaArrayType : JKType {
|
|
||||||
val type: JKType
|
|
||||||
}
|
|
||||||
|
|
||||||
interface JKStarProjectionType : JKWildCardType {
|
interface JKStarProjectionType : JKWildCardType {
|
||||||
override val nullability: Nullability
|
override val nullability: Nullability
|
||||||
get() = Nullability.NotNull
|
get() = Nullability.NotNull
|
||||||
}
|
}
|
||||||
|
|
||||||
interface JKJavaDisjunctionType : JKType {
|
object JKNoTypeImpl : JKNoType {
|
||||||
val disjunctions: List<JKType>
|
override val nullability: Nullability = Nullability.NotNull
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data class JKClassTypeImpl(
|
||||||
|
override val classReference: JKClassSymbol,
|
||||||
|
override val parameters: List<JKType> = emptyList(),
|
||||||
|
override val nullability: Nullability = Nullability.Default
|
||||||
|
) : JKClassType
|
||||||
|
|
||||||
|
|
||||||
|
object JKStarProjectionTypeImpl : JKStarProjectionType
|
||||||
|
|
||||||
|
object JKContextType : JKType {
|
||||||
|
override val nullability: Nullability
|
||||||
|
get() = Nullability.Default
|
||||||
|
}
|
||||||
|
|
||||||
|
data class JKVarianceTypeParameterType(
|
||||||
|
val variance: Variance,
|
||||||
|
val boundType: JKType
|
||||||
|
) : JKWildCardType {
|
||||||
|
override val nullability: Nullability
|
||||||
|
get() = Nullability.Default
|
||||||
|
|
||||||
|
enum class Variance {
|
||||||
|
IN, OUT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class JKTypeParameterType(
|
||||||
|
val identifier: JKTypeParameterSymbol,
|
||||||
|
override val nullability: Nullability = Nullability.Default
|
||||||
|
) : JKType
|
||||||
|
|
||||||
|
data class JKCapturedType(
|
||||||
|
val wildcardType: JKWildCardType,
|
||||||
|
override val nullability: Nullability = Nullability.Default
|
||||||
|
) : JKType
|
||||||
|
|
||||||
|
class JKJavaPrimitiveType(val jvmPrimitiveType: JvmPrimitiveType) : JKType {
|
||||||
|
override val nullability: Nullability
|
||||||
|
get() = Nullability.NotNull
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
val BOOLEAN = JKJavaPrimitiveType(JvmPrimitiveType.BOOLEAN)
|
||||||
|
val CHAR = JKJavaPrimitiveType(JvmPrimitiveType.CHAR)
|
||||||
|
val BYTE = JKJavaPrimitiveType(JvmPrimitiveType.BYTE)
|
||||||
|
val SHORT = JKJavaPrimitiveType(JvmPrimitiveType.SHORT)
|
||||||
|
val INT = JKJavaPrimitiveType(JvmPrimitiveType.INT)
|
||||||
|
val FLOAT = JKJavaPrimitiveType(JvmPrimitiveType.FLOAT)
|
||||||
|
val LONG = JKJavaPrimitiveType(JvmPrimitiveType.LONG)
|
||||||
|
val DOUBLE = JKJavaPrimitiveType(JvmPrimitiveType.DOUBLE)
|
||||||
|
|
||||||
|
val KEYWORD_TO_INSTANCE = listOf(
|
||||||
|
BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE
|
||||||
|
).associateBy { it.jvmPrimitiveType.javaKeywordName } + ("void" to JKJavaVoidType)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class JKJavaArrayType(
|
||||||
|
val type: JKType,
|
||||||
|
override var nullability: Nullability = Nullability.Default
|
||||||
|
) : JKType
|
||||||
|
|
||||||
|
data class JKJavaDisjunctionType(
|
||||||
|
val disjunctions: List<JKType>,
|
||||||
|
override val nullability: Nullability = Nullability.Default
|
||||||
|
) : JKType
|
||||||
|
|
||||||
|
object JKJavaVoidType : JKType {
|
||||||
|
override val nullability: Nullability
|
||||||
|
get() = Nullability.NotNull
|
||||||
|
}
|
||||||
|
|||||||
+31
-32
@@ -1,9 +1,9 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.jetbrains.kotlin.nj2k.tree
|
package org.jetbrains.kotlin.nj2k.types
|
||||||
|
|
||||||
import com.intellij.psi.CommonClassNames
|
import com.intellij.psi.CommonClassNames
|
||||||
import com.intellij.psi.PsiClass
|
import com.intellij.psi.PsiClass
|
||||||
@@ -16,8 +16,9 @@ import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
|
|||||||
import org.jetbrains.kotlin.j2k.ast.Nullability
|
import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||||
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
|
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
|
||||||
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
import org.jetbrains.kotlin.nj2k.symbols.JKClassSymbol
|
||||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
import org.jetbrains.kotlin.nj2k.toJkType
|
||||||
import org.jetbrains.kotlin.nj2k.types.*
|
import org.jetbrains.kotlin.nj2k.tree.*
|
||||||
|
|
||||||
import org.jetbrains.kotlin.psi.KtClass
|
import org.jetbrains.kotlin.psi.KtClass
|
||||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
@@ -35,14 +36,13 @@ fun JKExpression.type(typeFactory: JKTypeFactory): JKType? =
|
|||||||
else -> error("Cannot get type of ${operator::class}, it should be first converted to KtOperator")
|
else -> error("Cannot get type of ${operator::class}, it should be first converted to KtOperator")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is JKMethodCallExpression -> identifier.returnType
|
is JKCallExpression -> identifier.returnType
|
||||||
is JKFieldAccessExpressionImpl -> identifier.fieldType
|
is JKFieldAccessExpression -> identifier.fieldType
|
||||||
is JKQualifiedExpressionImpl -> selector.type(typeFactory)
|
is JKQualifiedExpression -> selector.type(typeFactory)
|
||||||
is JKKtThrowExpression -> typeFactory.types.nothing
|
is JKKtThrowExpression -> typeFactory.types.nothing
|
||||||
is JKClassAccessExpression ->
|
is JKClassAccessExpression ->
|
||||||
JKClassTypeImpl(identifier, emptyList(), Nullability.NotNull)
|
JKClassTypeImpl(identifier, emptyList(), Nullability.NotNull)
|
||||||
is JKJavaNewExpression -> JKClassTypeImpl(classSymbol)
|
is JKIsExpression -> typeFactory.types.boolean
|
||||||
is JKKtIsExpression -> typeFactory.types.boolean
|
|
||||||
is JKParenthesizedExpression -> expression.type(typeFactory)
|
is JKParenthesizedExpression -> expression.type(typeFactory)
|
||||||
is JKTypeCastExpression -> type.type
|
is JKTypeCastExpression -> type.type
|
||||||
is JKThisExpression -> null// TODO return actual type
|
is JKThisExpression -> null// TODO return actual type
|
||||||
@@ -53,28 +53,27 @@ fun JKExpression.type(typeFactory: JKTypeFactory): JKType? =
|
|||||||
(expression.type(typeFactory) as? JKParametrizedType)?.parameters?.lastOrNull()
|
(expression.type(typeFactory) as? JKParametrizedType)?.parameters?.lastOrNull()
|
||||||
is JKClassLiteralExpression -> {
|
is JKClassLiteralExpression -> {
|
||||||
val symbol = when (literalType) {
|
val symbol = when (literalType) {
|
||||||
JKClassLiteralExpression.LiteralType.KOTLIN_CLASS ->
|
JKClassLiteralExpression.ClassLiteralType.KOTLIN_CLASS ->
|
||||||
typeFactory.symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.kClass.toSafe())
|
typeFactory.symbolProvider.provideClassSymbol(KotlinBuiltIns.FQ_NAMES.kClass.toSafe())
|
||||||
JKClassLiteralExpression.LiteralType.JAVA_CLASS,
|
JKClassLiteralExpression.ClassLiteralType.JAVA_CLASS,
|
||||||
JKClassLiteralExpression.LiteralType.JAVA_PRIMITIVE_CLASS, JKClassLiteralExpression.LiteralType.JAVA_VOID_TYPE ->
|
JKClassLiteralExpression.ClassLiteralType.JAVA_PRIMITIVE_CLASS, JKClassLiteralExpression.ClassLiteralType.JAVA_VOID_TYPE ->
|
||||||
typeFactory.symbolProvider.provideClassSymbol("java.lang.Class")
|
typeFactory.symbolProvider.provideClassSymbol("java.lang.Class")
|
||||||
}
|
}
|
||||||
JKClassTypeImpl(symbol, listOf(classType.type), Nullability.NotNull)
|
JKClassTypeImpl(symbol, listOf(classType.type), Nullability.NotNull)
|
||||||
}
|
}
|
||||||
is JKKtAnnotationArrayInitializerExpression -> JKNoTypeImpl //TODO
|
is JKKtAnnotationArrayInitializerExpression -> JKNoTypeImpl //TODO
|
||||||
is JKLambdaExpression -> returnType.type
|
is JKLambdaExpression -> returnType.type
|
||||||
is JKLabeledStatement ->
|
is JKLabeledExpression -> typeFactory.types.unit
|
||||||
statement.safeAs<JKExpressionStatement>()?.expression?.type(typeFactory)
|
|
||||||
is JKMethodReferenceExpression -> JKNoTypeImpl //TODO
|
is JKMethodReferenceExpression -> JKNoTypeImpl //TODO
|
||||||
is JKAssignmentChainAlsoLink -> receiver.type(typeFactory)
|
is JKAssignmentChainAlsoLink -> receiver.type(typeFactory)
|
||||||
is JKAssignmentChainLetLink -> field.type(typeFactory)
|
is JKAssignmentChainLetLink -> field.type(typeFactory)
|
||||||
is JKKtAssignmentStatement -> typeFactory.types.unit
|
|
||||||
is JKKtItExpression -> type
|
is JKKtItExpression -> type
|
||||||
|
is JKNewExpression -> JKClassTypeImpl(classSymbol)
|
||||||
else -> TODO(this::class.java.toString())
|
else -> TODO(this::class.java.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun JKType.asTypeElement() =
|
fun JKType.asTypeElement() =
|
||||||
JKTypeElementImpl(this)
|
JKTypeElement(this)
|
||||||
|
|
||||||
fun JKClassSymbol.asType(nullability: Nullability = Nullability.Default): JKClassType =
|
fun JKClassSymbol.asType(nullability: Nullability = Nullability.Default): JKClassType =
|
||||||
JKClassTypeImpl(this, emptyList(), nullability)
|
JKClassTypeImpl(this, emptyList(), nullability)
|
||||||
@@ -112,7 +111,7 @@ private val jvmPrimitiveTypesPriority =
|
|||||||
|
|
||||||
fun JKType.applyRecursive(transform: (JKType) -> JKType?): JKType =
|
fun JKType.applyRecursive(transform: (JKType) -> JKType?): JKType =
|
||||||
transform(this) ?: when (this) {
|
transform(this) ?: when (this) {
|
||||||
is JKTypeParameterTypeImpl -> this
|
is JKTypeParameterType -> this
|
||||||
is JKClassTypeImpl ->
|
is JKClassTypeImpl ->
|
||||||
JKClassTypeImpl(
|
JKClassTypeImpl(
|
||||||
classReference,
|
classReference,
|
||||||
@@ -122,10 +121,10 @@ fun JKType.applyRecursive(transform: (JKType) -> JKType?): JKType =
|
|||||||
is JKNoType -> this
|
is JKNoType -> this
|
||||||
is JKJavaVoidType -> this
|
is JKJavaVoidType -> this
|
||||||
is JKJavaPrimitiveType -> this
|
is JKJavaPrimitiveType -> this
|
||||||
is JKJavaArrayType -> JKJavaArrayTypeImpl(type.applyRecursive(transform), nullability)
|
is JKJavaArrayType -> JKJavaArrayType(type.applyRecursive(transform), nullability)
|
||||||
is JKContextType -> JKContextType
|
is JKContextType -> JKContextType
|
||||||
is JKJavaDisjunctionType ->
|
is JKJavaDisjunctionType ->
|
||||||
JKJavaDisjunctionTypeImpl(disjunctions.map { it.applyRecursive(transform) }, nullability)
|
JKJavaDisjunctionType(disjunctions.map { it.applyRecursive(transform) }, nullability)
|
||||||
is JKStarProjectionType -> this
|
is JKStarProjectionType -> this
|
||||||
else -> TODO(this::class.toString())
|
else -> TODO(this::class.toString())
|
||||||
}
|
}
|
||||||
@@ -133,12 +132,12 @@ fun JKType.applyRecursive(transform: (JKType) -> JKType?): JKType =
|
|||||||
inline fun <reified T : JKType> T.updateNullability(newNullability: Nullability): T =
|
inline fun <reified T : JKType> T.updateNullability(newNullability: Nullability): T =
|
||||||
if (nullability == newNullability) this
|
if (nullability == newNullability) this
|
||||||
else when (this) {
|
else when (this) {
|
||||||
is JKTypeParameterTypeImpl -> JKTypeParameterTypeImpl(identifier, newNullability)
|
is JKTypeParameterType -> JKTypeParameterType(identifier, newNullability)
|
||||||
is JKClassTypeImpl -> JKClassTypeImpl(classReference, parameters, newNullability)
|
is JKClassTypeImpl -> JKClassTypeImpl(classReference, parameters, newNullability)
|
||||||
is JKNoType -> this
|
is JKNoType -> this
|
||||||
is JKJavaVoidType -> this
|
is JKJavaVoidType -> this
|
||||||
is JKJavaPrimitiveType -> this
|
is JKJavaPrimitiveType -> this
|
||||||
is JKJavaArrayType -> JKJavaArrayTypeImpl(type, newNullability)
|
is JKJavaArrayType -> JKJavaArrayType(type, newNullability)
|
||||||
is JKContextType -> JKContextType
|
is JKContextType -> JKContextType
|
||||||
is JKJavaDisjunctionType -> this
|
is JKJavaDisjunctionType -> this
|
||||||
else -> TODO(this::class.toString())
|
else -> TODO(this::class.toString())
|
||||||
@@ -148,14 +147,14 @@ inline fun <reified T : JKType> T.updateNullability(newNullability: Nullability)
|
|||||||
fun <T : JKType> T.updateNullabilityRecursively(newNullability: Nullability): T =
|
fun <T : JKType> T.updateNullabilityRecursively(newNullability: Nullability): T =
|
||||||
applyRecursive {
|
applyRecursive {
|
||||||
when (it) {
|
when (it) {
|
||||||
is JKTypeParameterTypeImpl -> JKTypeParameterTypeImpl(it.identifier, newNullability)
|
is JKTypeParameterType -> JKTypeParameterType(it.identifier, newNullability)
|
||||||
is JKClassTypeImpl ->
|
is JKClassTypeImpl ->
|
||||||
JKClassTypeImpl(
|
JKClassTypeImpl(
|
||||||
it.classReference,
|
it.classReference,
|
||||||
it.parameters.map { it.updateNullabilityRecursively(newNullability) },
|
it.parameters.map { it.updateNullabilityRecursively(newNullability) },
|
||||||
newNullability
|
newNullability
|
||||||
)
|
)
|
||||||
is JKJavaArrayType -> JKJavaArrayTypeImpl(it.type.updateNullabilityRecursively(newNullability), newNullability)
|
is JKJavaArrayType -> JKJavaArrayType(it.type.updateNullabilityRecursively(newNullability), newNullability)
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
} as T
|
} as T
|
||||||
@@ -183,14 +182,14 @@ fun JKJavaPrimitiveType.toLiteralType(): JKLiteralExpression.LiteralType? =
|
|||||||
fun JKType.asPrimitiveType(): JKJavaPrimitiveType? =
|
fun JKType.asPrimitiveType(): JKJavaPrimitiveType? =
|
||||||
if (this is JKJavaPrimitiveType) this
|
if (this is JKJavaPrimitiveType) this
|
||||||
else when ((this as? JKClassType)?.classReference?.fqName) {
|
else when ((this as? JKClassType)?.classReference?.fqName) {
|
||||||
KotlinBuiltIns.FQ_NAMES._char.asString(), CommonClassNames.JAVA_LANG_CHARACTER -> JKJavaPrimitiveTypeImpl.CHAR
|
KotlinBuiltIns.FQ_NAMES._char.asString(), CommonClassNames.JAVA_LANG_CHARACTER -> JKJavaPrimitiveType.CHAR
|
||||||
KotlinBuiltIns.FQ_NAMES._boolean.asString(), CommonClassNames.JAVA_LANG_BOOLEAN -> JKJavaPrimitiveTypeImpl.BOOLEAN
|
KotlinBuiltIns.FQ_NAMES._boolean.asString(), CommonClassNames.JAVA_LANG_BOOLEAN -> JKJavaPrimitiveType.BOOLEAN
|
||||||
KotlinBuiltIns.FQ_NAMES._int.asString(), CommonClassNames.JAVA_LANG_INTEGER -> JKJavaPrimitiveTypeImpl.INT
|
KotlinBuiltIns.FQ_NAMES._int.asString(), CommonClassNames.JAVA_LANG_INTEGER -> JKJavaPrimitiveType.INT
|
||||||
KotlinBuiltIns.FQ_NAMES._long.asString(), CommonClassNames.JAVA_LANG_LONG -> JKJavaPrimitiveTypeImpl.LONG
|
KotlinBuiltIns.FQ_NAMES._long.asString(), CommonClassNames.JAVA_LANG_LONG -> JKJavaPrimitiveType.LONG
|
||||||
KotlinBuiltIns.FQ_NAMES._float.asString(), CommonClassNames.JAVA_LANG_FLOAT -> JKJavaPrimitiveTypeImpl.FLOAT
|
KotlinBuiltIns.FQ_NAMES._float.asString(), CommonClassNames.JAVA_LANG_FLOAT -> JKJavaPrimitiveType.FLOAT
|
||||||
KotlinBuiltIns.FQ_NAMES._double.asString(), CommonClassNames.JAVA_LANG_DOUBLE -> JKJavaPrimitiveTypeImpl.DOUBLE
|
KotlinBuiltIns.FQ_NAMES._double.asString(), CommonClassNames.JAVA_LANG_DOUBLE -> JKJavaPrimitiveType.DOUBLE
|
||||||
KotlinBuiltIns.FQ_NAMES._byte.asString(), CommonClassNames.JAVA_LANG_BYTE -> JKJavaPrimitiveTypeImpl.BYTE
|
KotlinBuiltIns.FQ_NAMES._byte.asString(), CommonClassNames.JAVA_LANG_BYTE -> JKJavaPrimitiveType.BYTE
|
||||||
KotlinBuiltIns.FQ_NAMES._short.asString(), CommonClassNames.JAVA_LANG_SHORT -> JKJavaPrimitiveTypeImpl.SHORT
|
KotlinBuiltIns.FQ_NAMES._short.asString(), CommonClassNames.JAVA_LANG_SHORT -> JKJavaPrimitiveType.SHORT
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -221,7 +220,7 @@ fun JKType.arrayFqName(): String =
|
|||||||
fun JKClassSymbol.isArrayType(): Boolean =
|
fun JKClassSymbol.isArrayType(): Boolean =
|
||||||
fqName in arrayFqNames
|
fqName in arrayFqNames
|
||||||
|
|
||||||
private val arrayFqNames = JKJavaPrimitiveTypeImpl.KEYWORD_TO_INSTANCE.values
|
private val arrayFqNames = JKJavaPrimitiveType.KEYWORD_TO_INSTANCE.values
|
||||||
.filterIsInstance<JKJavaPrimitiveType>()
|
.filterIsInstance<JKJavaPrimitiveType>()
|
||||||
.map { PrimitiveType.valueOf(it.jvmPrimitiveType.name).arrayTypeFqName.asString() } +
|
.map { PrimitiveType.valueOf(it.jvmPrimitiveType.name).arrayTypeFqName.asString() } +
|
||||||
KotlinBuiltIns.FQ_NAMES.array.asString()
|
KotlinBuiltIns.FQ_NAMES.array.asString()
|
||||||
+1
-1
@@ -29,6 +29,6 @@ internal class A {
|
|||||||
fun foo(param1: String?, param2: String?, param3: String?) {}
|
fun foo(param1: String?, param2: String?, param3: String?) {}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
/*it's public*/ /*and static*/ const val/*and final*/ C = 1
|
/*it's public*/ /*and static*/ /*and final*/ const val C = 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user