Delete quick fix which was needed to migrate users to the version of Kotlin which was the latest in 2014 (EA-93982 - assert: PsiModificationTrackerImpl.fireEvent)

This commit is contained in:
Dmitry Jemerov
2017-01-26 20:39:04 +01:00
parent 6cbb2a4491
commit 731aeac04f
6 changed files with 1 additions and 128 deletions
@@ -1,60 +0,0 @@
/*
* Copyright 2010-2015 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.idea.quickfix
import com.intellij.codeInsight.FileModificationService
import com.intellij.codeInsight.intention.IntentionAction
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.lexer.KtTokens.OVERRIDE_KEYWORD
import org.jetbrains.kotlin.lexer.KtTokens.PUBLIC_KEYWORD
import org.jetbrains.kotlin.psi.KtNamedFunction
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
object AddOverrideToEqualsHashCodeToStringActionFactory : KotlinSingleIntentionActionFactory() {
private val NAME = "Add 'override' to equals, hashCode, toString in project"
private fun isEqualsHashCodeOrToString(element: KtNamedFunction): Boolean {
return when (element.name) {
"equals" -> {
val paramTypeRef = element.valueParameters.singleOrNull()?.typeReference ?: return false
val paramType = paramTypeRef.analyze(BodyResolveMode.PARTIAL)[BindingContext.TYPE, paramTypeRef] ?: return false
KotlinBuiltIns.isNullableAny(paramType)
}
"hashCode", "toString" -> element.valueParameters.isEmpty()
else -> false
}
}
private fun KtNamedFunction.doInvoke() {
if (!FileModificationService.getInstance().preparePsiElementForWrite(this)) return
addModifier(OVERRIDE_KEYWORD)
removeModifier(PUBLIC_KEYWORD)
}
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
return WholeProjectForEachElementOfTypeFix.createByPredicate<KtNamedFunction>(
predicate = { isEqualsHashCodeOrToString(it) },
taskProcessor = { it.doInvoke() },
name = NAME
)
}
}
@@ -202,8 +202,6 @@ class QuickFixRegistrar : QuickFixContributor {
VAL_OR_VAR_ON_CATCH_PARAMETER.registerFactory(RemoveValVarFromParameterFix)
VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER.registerFactory(RemoveValVarFromParameterFix)
VIRTUAL_MEMBER_HIDDEN.registerFactory(AddOverrideToEqualsHashCodeToStringActionFactory)
UNUSED_VARIABLE.registerFactory(RemovePsiElementSimpleFix.RemoveVariableFactory)
UNUSED_VARIABLE.registerFactory(RenameToUnderscoreFix.Factory)
@@ -1,29 +0,0 @@
// "Add 'override' to equals, hashCode, toString in project" "true"
class A {
fun <caret>equals(other: Any?) = false
fun hashCode() = 0
fun toString(): String {
return "A"
}
}
class B {
open fun equals(other: Any?) = false
open fun hashCode(): Int {
return 42
}
open fun toString() = ""
}
class C {
public fun equals(other: Any?): Boolean = true
public fun hashCode() = 0
public fun toString() = ""
}
class D {
public open fun equals(o: Any?) = false
public open fun hashCode(): Int = 239
public open fun toString() = ""
}
@@ -1,29 +0,0 @@
// "Add 'override' to equals, hashCode, toString in project" "true"
class A {
override fun equals(other: Any?) = false
override fun hashCode() = 0
override fun toString(): String {
return "A"
}
}
class B {
override fun equals(other: Any?) = false
override fun hashCode(): Int {
return 42
}
override fun toString() = ""
}
class C {
override fun equals(other: Any?): Boolean = true
override fun hashCode() = 0
override fun toString() = ""
}
class D {
override fun equals(o: Any?) = false
override fun hashCode(): Int = 239
override fun toString() = ""
}
@@ -6109,12 +6109,6 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Migration extends AbstractQuickFixTest {
@TestMetadata("addOverrideToEqualsHashCodeToString.kt")
public void testAddOverrideToEqualsHashCodeToString() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/addOverrideToEqualsHashCodeToString.kt");
doTest(fileName);
}
public void testAllFilesPresentInMigration() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
}
@@ -4117,8 +4117,7 @@ public class JavaToKotlinConverterForWebDemoTestGenerated extends AbstractJavaTo
@TestMetadata("RedunduntTypeCastAndProhibitedInline.java")
public void testRedunduntTypeCastAndProhibitedInline() throws Exception {
String fileName = KotlinTestUtils
.navigationMetadata("j2k/testData/fileOrElement/postProcessing/RedunduntTypeCastAndProhibitedInline.java");
String fileName = KotlinTestUtils.navigationMetadata("j2k/testData/fileOrElement/postProcessing/RedunduntTypeCastAndProhibitedInline.java");
doTest(fileName);
}