New J2K, minor: remove unused declarations, fix typos
This commit is contained in:
@@ -986,16 +986,6 @@ private fun <T> List<T>.headTail(): Pair<T?, List<T>?> {
|
||||
}
|
||||
|
||||
|
||||
private fun JKDelegationConstructorCall.isCallOfConstructorOf(type: JKType): Boolean {
|
||||
return when (type) {
|
||||
is JKClassType -> {
|
||||
val symbol = type.classReference as? JKClassSymbol ?: return false
|
||||
this.identifier.name == symbol.name && this.identifier.declaredIn == symbol
|
||||
}
|
||||
else -> false
|
||||
}
|
||||
}
|
||||
|
||||
private val mappedToKotlinFqNames =
|
||||
setOf(
|
||||
"java.util.ArrayList",
|
||||
|
||||
@@ -16,16 +16,7 @@ data class NewJ2kConverterContext(
|
||||
val importStorage: ImportStorage,
|
||||
val elementsInfoStorage: JKElementInfoStorage
|
||||
) : ConverterContext {
|
||||
val project: Project get() = converter.project
|
||||
val typeFlavorCalculator = TypeFlavorCalculator(object : TypeFlavorConverterFacade {
|
||||
override val referenceSearcher: ReferenceSearcher
|
||||
get() = converter.converterServices.oldServices.referenceSearcher
|
||||
override val javaDataFlowAnalyzerFacade: JavaDataFlowAnalyzerFacade
|
||||
get() = converter.converterServices.oldServices.javaDataFlowAnalyzerFacade
|
||||
override val resolverForConverter: ResolverForConverter
|
||||
get() = converter.converterServices.oldServices.resolverForConverter
|
||||
|
||||
override fun inConversionScope(element: PsiElement): Boolean = inConversionContext(element)
|
||||
})
|
||||
val project: Project
|
||||
get() = converter.project
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@ class AssignmentStatementOperatorConversion : RecursiveApplicableConversionBase(
|
||||
override fun applyToElement(element: JKTreeElement): JKTreeElement {
|
||||
if (element !is JKKtAssignmentStatement) return recurse(element)
|
||||
val operator = element.operator as? JKJavaOperatorImpl ?: return recurse(element)
|
||||
operator.token.correnspondingBinaryOperation()
|
||||
operator.token.correspondingBinaryOperation()
|
||||
?.apply {
|
||||
val expression = element.expression.copyTreeAndDetach()
|
||||
element.expression =
|
||||
@@ -31,7 +31,7 @@ class AssignmentStatementOperatorConversion : RecursiveApplicableConversionBase(
|
||||
return recurse(element)
|
||||
}
|
||||
|
||||
private fun JKJavaOperatorToken.correnspondingBinaryOperation() =
|
||||
private fun JKJavaOperatorToken.correspondingBinaryOperation() =
|
||||
when (psiToken) {
|
||||
JavaTokenType.OREQ -> JavaTokenType.OR
|
||||
JavaTokenType.ANDEQ -> JavaTokenType.AND
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.nj2k.conversions
|
||||
|
||||
import org.jetbrains.kotlin.nj2k.getOrCreateCompainonObject
|
||||
import org.jetbrains.kotlin.nj2k.getOrCreateCompanionObject
|
||||
import org.jetbrains.kotlin.nj2k.tree.*
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class InterfaceWithFieldConversion : RecursiveApplicableConversionBase() {
|
||||
}
|
||||
if (fieldsToMoveToCompanion.isNotEmpty()) {
|
||||
element.classBody.declarations -= fieldsToMoveToCompanion
|
||||
val companion = element.getOrCreateCompainonObject()
|
||||
val companion = element.getOrCreateCompanionObject()
|
||||
companion.classBody.declarations += fieldsToMoveToCompanion
|
||||
}
|
||||
return recurse(element)
|
||||
|
||||
+2
-2
@@ -5,7 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.nj2k.conversions
|
||||
|
||||
import org.jetbrains.kotlin.nj2k.getOrCreateCompainonObject
|
||||
import org.jetbrains.kotlin.nj2k.getOrCreateCompanionObject
|
||||
import org.jetbrains.kotlin.nj2k.tree.*
|
||||
|
||||
class StaticsToCompanionExtractConversion : RecursiveApplicableConversionBase() {
|
||||
@@ -16,7 +16,7 @@ class StaticsToCompanionExtractConversion : RecursiveApplicableConversionBase()
|
||||
declaration is JKExtraModifiersOwner && declaration.hasExtraModifier(ExtraModifier.STATIC)
|
||||
}
|
||||
if (statics.isEmpty()) return recurse(element)
|
||||
val companion = element.getOrCreateCompainonObject()
|
||||
val companion = element.getOrCreateCompanionObject()
|
||||
|
||||
element.classBody.declarations -= statics
|
||||
companion.classBody.declarations += statics.onEach { declaration ->
|
||||
|
||||
@@ -103,18 +103,9 @@ private fun JKKtOperatorToken.unaryExpressionMethodType(
|
||||
}
|
||||
}
|
||||
|
||||
fun JKOperator.isComparationOperator() =
|
||||
(token as? JKKtSingleValueOperatorToken)?.psiToken in comparationOperators
|
||||
|
||||
fun JKOperator.isEquals() =
|
||||
(token as? JKKtSingleValueOperatorToken)?.psiToken in equalsOperators
|
||||
|
||||
fun JKOperator.isArithmetic() =
|
||||
(token as? JKKtSingleValueOperatorToken)?.psiToken in arithmeticOperators
|
||||
|
||||
fun JKOperator.isLessOrGreater() =
|
||||
(token as? JKKtSingleValueOperatorToken)?.psiToken in lessGreaterOperators
|
||||
|
||||
private val equalsOperators =
|
||||
TokenSet.create(
|
||||
KtTokens.EQEQEQ,
|
||||
@@ -131,7 +122,7 @@ private val lessGreaterOperators =
|
||||
KtTokens.GTEQ
|
||||
)
|
||||
|
||||
private val comparationOperators =
|
||||
private val comparisonOperators =
|
||||
TokenSet.orSet(
|
||||
lessGreaterOperators,
|
||||
equalsOperators
|
||||
@@ -139,7 +130,7 @@ private val comparationOperators =
|
||||
|
||||
private val booleanOperators =
|
||||
TokenSet.orSet(
|
||||
comparationOperators,
|
||||
comparisonOperators,
|
||||
TokenSet.create(
|
||||
KtTokens.ANDAND,
|
||||
KtTokens.OROR
|
||||
@@ -240,9 +231,6 @@ fun downToExpression(
|
||||
conversionContext
|
||||
)
|
||||
|
||||
fun List<JKExpression>.toExpressionList() =
|
||||
JKExpressionListImpl(this)
|
||||
|
||||
fun JKExpression.parenthesizeIfBinaryExpression() =
|
||||
when (this) {
|
||||
is JKBinaryExpression -> JKParenthesizedExpressionImpl(this)
|
||||
@@ -362,12 +350,6 @@ fun JKFieldAccessExpression.asAssignmentFromTarget(): JKKtAssignmentStatement? =
|
||||
fun JKFieldAccessExpression.isInDecrementOrIncrement(): Boolean =
|
||||
(parent as? JKUnaryExpression)?.operator?.token?.text in listOf("++", "--")
|
||||
|
||||
fun JKExpression.bangedBangedExpr(symbolProvider: JKSymbolProvider): JKExpression =
|
||||
JKPostfixExpressionImpl(
|
||||
this,
|
||||
JKKtOperatorImpl(KtTokens.EXCLEXCL, type(symbolProvider)!!)
|
||||
)
|
||||
|
||||
fun JKVariable.hasWritableUsages(scope: JKTreeElement, context: NewJ2kConverterContext): Boolean =
|
||||
findUsages(scope, context).any {
|
||||
it.asAssignmentFromTarget() != null
|
||||
@@ -398,7 +380,7 @@ fun createCompanion(declarations: List<JKDeclaration>): JKClass =
|
||||
fun JKClass.getCompanion(): JKClass? =
|
||||
declarationList.firstOrNull { it is JKClass && it.classKind == JKClass.ClassKind.COMPANION } as? JKClass
|
||||
|
||||
fun JKClass.getOrCreateCompainonObject(): JKClass =
|
||||
fun JKClass.getOrCreateCompanionObject(): JKClass =
|
||||
getCompanion()
|
||||
?: JKClassImpl(
|
||||
JKNameIdentifierImpl(""),
|
||||
|
||||
@@ -172,8 +172,6 @@ fun JKExtraModifiersOwner.elementByModifier(modifier: ExtraModifier): JKExtraMod
|
||||
fun JKExtraModifiersOwner.hasExtraModifier(modifier: ExtraModifier): Boolean =
|
||||
extraModifierElements.any { it.extraModifier == modifier }
|
||||
|
||||
//val JKExtraModifiersOwner.extraModifiers
|
||||
|
||||
enum class ExtraModifier(override val text: String) : Modifier {
|
||||
ACTUAL("actual"),
|
||||
ANNOTATION("annotation"),
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.j2k.ast.Nullability
|
||||
import org.jetbrains.kotlin.js.descriptorUtils.getJetTypeFqName
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.nj2k.JKSymbolProvider
|
||||
import org.jetbrains.kotlin.nj2k.NewJ2kConverterContext
|
||||
import org.jetbrains.kotlin.nj2k.kotlinTypeByName
|
||||
import org.jetbrains.kotlin.nj2k.tree.impl.*
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
@@ -41,7 +40,7 @@ fun JKExpression.type(symbolProvider: JKSymbolProvider): JKType? =
|
||||
}
|
||||
is JKMethodCallExpression -> identifier.returnType
|
||||
is JKFieldAccessExpressionImpl -> identifier.fieldType
|
||||
is JKQualifiedExpressionImpl -> this.selector.type(symbolProvider)
|
||||
is JKQualifiedExpressionImpl -> selector.type(symbolProvider)
|
||||
is JKKtThrowExpression -> kotlinTypeByName(KotlinBuiltIns.FQ_NAMES.nothing.asString(), symbolProvider)
|
||||
is JKClassAccessExpression ->
|
||||
JKClassTypeImpl(identifier, emptyList(), Nullability.NotNull)
|
||||
@@ -157,14 +156,13 @@ fun JKType.toKtType(symbolProvider: JKSymbolProvider): KotlinType? =
|
||||
symbolProvider
|
||||
).toKtType(symbolProvider)
|
||||
else -> null
|
||||
// else -> TODO(this::class.java.toString())
|
||||
}
|
||||
|
||||
infix fun JKJavaPrimitiveType.isStrongerThan(other: JKJavaPrimitiveType) =
|
||||
jvmPrimitivePrioritypriority.getValue(this.jvmPrimitiveType.primitiveType) >
|
||||
jvmPrimitivePrioritypriority.getValue(other.jvmPrimitiveType.primitiveType)
|
||||
jvmPrimitiveTypesPriority.getValue(this.jvmPrimitiveType.primitiveType) >
|
||||
jvmPrimitiveTypesPriority.getValue(other.jvmPrimitiveType.primitiveType)
|
||||
|
||||
private val jvmPrimitivePrioritypriority =
|
||||
private val jvmPrimitiveTypesPriority =
|
||||
mapOf(
|
||||
PrimitiveType.BOOLEAN to -1,
|
||||
PrimitiveType.CHAR to 0,
|
||||
@@ -242,15 +240,6 @@ fun <T : JKType> T.updateNullabilityRecursively(newNullability: Nullability): T
|
||||
}
|
||||
} as T
|
||||
|
||||
fun JKJavaMethod.returnTypeNullability(context: NewJ2kConverterContext): Nullability =
|
||||
context.typeFlavorCalculator.methodNullability(psi()!!)
|
||||
|
||||
fun JKType.isCollectionType(symbolProvider: JKSymbolProvider): Boolean {
|
||||
if (this !is JKClassType) return false
|
||||
val collectionType = JKClassTypeImpl(symbolProvider.provideClassSymbol("java.util.Collection"), emptyList())
|
||||
return this.isSubtypeOf(collectionType, symbolProvider)
|
||||
}
|
||||
|
||||
fun JKType.isStringType(): Boolean =
|
||||
(this as? JKClassType)?.classReference?.isStringType() == true
|
||||
|
||||
@@ -364,10 +353,6 @@ fun JKType.arrayInnerType(): JKType? =
|
||||
else -> null
|
||||
}
|
||||
|
||||
val namesOfPrimitiveTypes by lazy {
|
||||
KotlinBuiltIns.FQ_NAMES.primitiveTypeShortNames.map { it.identifier.decapitalize() }
|
||||
}
|
||||
|
||||
fun JKClassSymbol.isInterface(): Boolean {
|
||||
val target = target
|
||||
return when (target) {
|
||||
|
||||
Reference in New Issue
Block a user