New J2K: Move equals operator conversion from post processing to AST conversion

This commit is contained in:
Ilya Kirillov
2019-01-17 14:34:53 +03:00
committed by Ilya Kirillov
parent 70c700f07a
commit fbcf2e1bcd
3 changed files with 45 additions and 3 deletions
@@ -37,7 +37,6 @@ import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.core.setVisibility
import org.jetbrains.kotlin.idea.inspections.*
import org.jetbrains.kotlin.idea.inspections.branchedTransformations.IfThenToSafeAccessInspection
import org.jetbrains.kotlin.idea.inspections.conventionNameCalls.ReplaceCallWithBinaryOperatorInspection
import org.jetbrains.kotlin.idea.inspections.conventionNameCalls.ReplaceGetOrSetInspection
import org.jetbrains.kotlin.idea.intentions.*
import org.jetbrains.kotlin.idea.intentions.branchedTransformations.intentions.FoldIfToReturnAsymmetricallyIntention
@@ -138,7 +137,6 @@ object NewJ2KPostProcessingRegistrarImpl : J2KPostProcessingRegistrar {
registerInspectionBasedProcessing(SimplifyAssertNotNullInspection()),
registerIntentionBasedProcessing(RemoveRedundantCallsOfConversionMethodsIntention()),
registerGeneralInspectionBasedProcessing(LiftReturnOrAssignmentInspection()),
registerGeneralInspectionBasedProcessing(ReplaceCallWithBinaryOperatorInspection()),
registerGeneralInspectionBasedProcessing(MayBeConstantInspection()),
registerIntentionBasedProcessing(RemoveEmptyPrimaryConstructorIntention()),
registerDiagnosticBasedProcessing(Errors.PLATFORM_CLASS_MAPPED_TO_KOTLIN) { element: KtDotQualifiedExpression, diagnostic ->
@@ -0,0 +1,36 @@
/*
* Copyright 2010-2019 JetBrains s.r.o. 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.j2k.conversions
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.refactoring.fqName.getKotlinFqName
import org.jetbrains.kotlin.j2k.ConversionContext
import org.jetbrains.kotlin.j2k.ast.Nullability
import org.jetbrains.kotlin.j2k.equalsExpression
import org.jetbrains.kotlin.j2k.tree.*
import org.jetbrains.kotlin.j2k.tree.impl.*
import org.jetbrains.kotlin.lexer.KtTokens
class EqualsOperatorConversion(private val context: ConversionContext) : RecursiveApplicableConversionBase() {
override fun applyToElement(element: JKTreeElement): JKTreeElement {
if (element !is JKQualifiedExpression) return recurse(element)
if (element.receiver is JKSuperExpression) return recurse(element)
val selector = element.selector as? JKMethodCallExpression ?: return (element)
val argument = selector.arguments.expressions.singleOrNull() ?: return recurse(element)
if (selector.identifier.deepestFqName() == "java.lang.Object.equals") {
return recurse(
JKParenthesizedExpressionImpl(
equalsExpression(
element::receiver.detached(),
argument.detached(selector.arguments),
context.symbolProvider
)
)
)
}
return recurse(element)
}
}
@@ -394,4 +394,12 @@ private fun convertIntegerLiteral(element: JKLiteralExpression): JKKtLiteralExpr
text,
element.type
)
}
}
fun equalsExpression(left: JKExpression, right: JKExpression, symbolProvider: JKSymbolProvider) =
kotlinBinaryExpression(
left,
right,
KtTokens.EQEQ,
symbolProvider
)