Removed obsolete tests

This commit is contained in:
Michael Bogdanov
2015-12-28 13:28:22 +03:00
parent e671d05105
commit bb63bcd520
41 changed files with 0 additions and 625 deletions
-8
View File
@@ -1290,14 +1290,6 @@
level="WARNING"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.DeprecatedUsageOfStaticFieldInspection"
displayName="This field will not be generated in future versions of Kotlin. Use 'const' modifier, '@JvmField' annotation or access data through corresponding object."
groupName="Kotlin"
language="JAVA"
enabledByDefault="true"
cleanupTool="true"
level="WARNING"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.EqualsOrHashCodeInspection"
displayName="equals() and hashCode() not paired"
groupName="Kotlin"
@@ -1,156 +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.inspections
import com.intellij.codeInspection.*
import com.intellij.openapi.project.Project
import com.intellij.psi.*
import org.jetbrains.kotlin.asJava.KtLightClass
import org.jetbrains.kotlin.asJava.KtLightField
import org.jetbrains.kotlin.idea.quickfix.AddConstModifierFix
import org.jetbrains.kotlin.idea.quickfix.AddConstModifierIntention
import org.jetbrains.kotlin.idea.quickfix.replaceReferencesToGetterByReferenceToField
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtObjectDeclaration
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.psi.KtPsiFactory
import java.util.*
class DeprecatedUsageOfStaticFieldInspection : LocalInspectionTool(), CleanupLocalInspectionTool {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
return object : JavaElementVisitor() {
override fun visitReferenceExpression(expression: PsiReferenceExpression) {
val resolvedTo = expression.reference?.resolve() as? PsiField ?: return
if (!resolvedTo.hasModifierProperty(PsiModifier.STATIC) || !resolvedTo.isDeprecated) return
val kotlinProperty = (resolvedTo as? KtLightField)?.getOrigin() as? KtProperty
// NOTE: this is hack to avoid test failing with "action is still available" error
if (kotlinProperty?.hasJvmFieldAnnotationOrConstModifier() ?: false) return
val kotlinClassOrObject = (resolvedTo.containingClass as? KtLightClass)?.getOrigin() ?: return
val containingObject = when (kotlinClassOrObject) {
is KtObjectDeclaration -> kotlinClassOrObject as KtObjectDeclaration // KT-9578
is KtClass -> kotlinClassOrObject.getCompanionObjects().singleOrNull() ?: return
else -> return
}
holder.registerProblem(
expression, "This field will not be generated in future versions of Kotlin. Use 'const' modifier, '@JvmField' annotation or access data through corresponding object.",
ProblemHighlightType.LIKE_DEPRECATED,
*createFixes(containingObject, kotlinProperty).toTypedArray()
)
}
}
}
private fun createFixes(containingObject: KtObjectDeclaration, property: KtProperty?): List<LocalQuickFix> {
if (containingObject.getContainingKtFile().isCompiled) return listOf(ReplaceWithGetterInvocationFix())
// order matters here, 'cleanup' applies fixes in this order
val fixes = ArrayList<LocalQuickFix>()
if (property != null && AddConstModifierIntention.isApplicableTo(property)) {
fixes.add(AddConstModifierLocalFix())
}
if (containingObject.isCompanion()) {
val classWithCompanion = containingObject.parent?.parent as? KtClass ?: return listOf()
if (!classWithCompanion.isInterface()) {
fixes.add(AddJvmFieldAnnotationFix())
}
} else {
fixes.add(AddJvmFieldAnnotationFix())
}
fixes.add(ReplaceWithGetterInvocationFix())
return fixes
}
}
abstract class StaticFieldUsageFix: LocalQuickFix {
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val deprecatedField = descriptor.psiElement.reference?.resolve() as? PsiField ?: return
val kotlinProperty = (deprecatedField as? KtLightField)?.getOrigin() as? KtProperty
if (kotlinProperty != null && kotlinProperty.hasJvmFieldAnnotationOrConstModifier()) return
doFix(deprecatedField, kotlinProperty, descriptor)
}
abstract fun doFix(deprecatedField: PsiField, property: KtProperty?, problemDescriptor: ProblemDescriptor)
}
class AddJvmFieldAnnotationFix : StaticFieldUsageFix() {
override fun doFix(deprecatedField: PsiField, property: KtProperty?, problemDescriptor: ProblemDescriptor) {
replaceReferencesToGetterByReferenceToField(property ?: return)
property.addAnnotationEntry(KtPsiFactory(property).createAnnotationEntry("@JvmField"))
}
override fun getName(): String = "Annotate property with @JvmField"
override fun getFamilyName(): String = name
}
class AddConstModifierLocalFix : StaticFieldUsageFix() {
override fun getName(): String = "Add 'const' modifier to a property"
override fun getFamilyName(): String = name
override fun doFix(deprecatedField: PsiField, property: KtProperty?, problemDescriptor: ProblemDescriptor) {
AddConstModifierFix.addConstModifier(property ?: return)
}
}
class ReplaceWithGetterInvocationFix : StaticFieldUsageFix() {
override fun getName(): String = "Replace with getter invocation"
override fun getFamilyName(): String = name
override fun doFix(deprecatedField: PsiField, property: KtProperty?, problemDescriptor: ProblemDescriptor) {
val lightClass = deprecatedField.containingClass as? KtLightClass ?: return
fun replaceWithGetterInvocation(objectField: PsiField) {
val factory = PsiElementFactory.SERVICE.getInstance(deprecatedField.project)
val elementToReplace = problemDescriptor.psiElement
val getterInvocation = factory.createExpressionFromText(
objectField.containingClass!!.qualifiedName + "." + objectField.name + "." + JvmAbi.getterName(deprecatedField.name!!) + "()",
elementToReplace
)
elementToReplace.replace(getterInvocation)
}
val kotlinClass = lightClass.getOrigin()
when (kotlinClass) {
is KtObjectDeclaration -> {
val instanceField = lightClass.findFieldByName(JvmAbi.INSTANCE_FIELD, false) ?: return
replaceWithGetterInvocation(instanceField)
}
is KtClass -> {
val companionObjectName = kotlinClass.getCompanionObjects().singleOrNull()?.name ?: return
val companionObjectField = lightClass.findFieldByName(companionObjectName, false) ?: return
replaceWithGetterInvocation(companionObjectField)
}
}
}
}
private fun KtProperty.hasJvmFieldAnnotationOrConstModifier(): Boolean {
return hasModifier(KtTokens.CONST_KEYWORD) || annotationEntries.any { it.text == "@JvmField" }
}
@@ -1 +0,0 @@
org.jetbrains.kotlin.idea.inspections.DeprecatedUsageOfStaticFieldInspection
@@ -1,22 +0,0 @@
package a
class A
class Cl {
companion object {
@JvmField val property1 = A()
const val property2 = 2
}
}
interface Int {
companion object {
val property1 = A()
const val property2 = 2
}
}
object Obj {
@JvmField val property1 = A()
const val property2 = 2
}
@@ -1,19 +0,0 @@
// "Cleanup code" "true"
import a.*;
class B {
void bar() {
Cl.property1;
Cl.property2;
Cl.property1;
Cl.property2;
Int.Companion.getProperty1();
Int.property2;
Int.Companion.getProperty1();
Int.property2;
Obj.property1;
Obj.property2;
Obj.property1;
Obj.property2;
}
}
@@ -1,19 +0,0 @@
// "Cleanup code" "true"
import a.*;
class B {
void bar() {
Cl.prope<caret>rty1;
Cl.property2;
Cl.Companion.getProperty1();
Cl.Companion.getProperty2();
Int.property1;
Int.property2;
Int.Companion.getProperty1();
Int.Companion.getProperty2();
Obj.property1;
Obj.property2;
Obj.INSTANCE.getProperty1();
Obj.INSTANCE.getProperty2();
}
}
@@ -1,22 +0,0 @@
package a
class A
class Cl {
companion object {
val property1 = A()
val property2 = 2
}
}
interface Int {
companion object {
val property1 = A()
val property2 = 2
}
}
object Obj {
val property1 = A()
val property2 = 2
}
@@ -1,7 +0,0 @@
package a
class A {
companion object Named {
const val property = 1
}
}
@@ -1,10 +0,0 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.property;
A a2 = a.A.property;
A a3 = A.property;
}
}
@@ -1,10 +0,0 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.pro<caret>perty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -1,7 +0,0 @@
package a
class A {
companion object Named {
val property = 1
}
}
@@ -1,10 +0,0 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = a.A.Named.getProperty();
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -1,10 +0,0 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = A.pro<caret>perty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -1,7 +0,0 @@
package a
class A {
companion object Named {
val property = A()
}
}
@@ -1,7 +0,0 @@
package a
class A {
companion object {
@JvmField val property = A()
}
}
@@ -1,10 +0,0 @@
// "Annotate property with @JvmField" "true"
import a.A;
class B {
void bar() {
A a = A.property;
A a2 = a.A.property;
A a3 = A.property;
}
}
@@ -1,10 +0,0 @@
// "Annotate property with @JvmField" "true"
import a.A;
class B {
void bar() {
A a = A.pro<caret>perty;
A a2 = A.Companion.getProperty();
A a3 = A.property;
}
}
@@ -1,7 +0,0 @@
package a
class A {
companion object {
val property = A()
}
}
@@ -1,7 +0,0 @@
package a
interface A {
companion object Named {
const val property = 1
}
}
@@ -1,10 +0,0 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.property;
A a2 = a.A.property;
A a3 = A.property;
}
}
@@ -1,10 +0,0 @@
// "Add 'const' modifier to a property" "true"
import a.A;
class B {
void bar() {
A a = A.prop<caret>erty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
@@ -1,7 +0,0 @@
package a
interface A {
companion object Named {
val property = 1
}
}
@@ -1,10 +0,0 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = a.A.Companion.getProperty();
A a2 = A.Companion.getProperty();
A a3 = A.property;
}
}
@@ -1,10 +0,0 @@
// "Replace with getter invocation" "true"
import a.A;
class B {
void bar() {
A a = A.prop<caret>erty;
A a2 = A.Companion.getProperty();
A a3 = A.property;
}
}
@@ -1,7 +0,0 @@
package a
interface A {
companion object {
val property = 1
}
}
@@ -1,20 +0,0 @@
// "Annotate property with @JvmField" "false"
import a.A;
class B {
void bar() {
A a = A.prop<caret>erty;
A a2 = A.Named.getProperty();
A a3 = A.property;
}
}
// ACTION: Add 'const' modifier to a property
// ACTION: Add static import for 'a.A.property'
// ACTION: Annotate 'property' as @Deprecated
// ACTION: Annotate 'property' as @NotNull
// ACTION: Annotate 'property' as @Nullable
// ACTION: Change variable 'a' type to 'int'
// ACTION: Migrate 'a' type to 'int'
// ACTION: Replace with getter invocation
// ACTION: Split into declaration and assignment
@@ -1,7 +0,0 @@
package a
interface A {
companion object Named {
val property = 1
}
}
@@ -1,5 +0,0 @@
package a
object Obj {
const val property = 1
}
@@ -1,11 +0,0 @@
// "Add 'const' modifier to a property" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.property;
A a2 = a.Obj.property;
A a3 = Obj.property;
}
}
@@ -1,11 +0,0 @@
// "Add 'const' modifier to a property" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
A a2 = Obj.INSTANCE.getProperty();
A a3 = Obj.property;
}
}
@@ -1,5 +0,0 @@
package a
object Obj {
val property = 1
}
@@ -1,16 +0,0 @@
// "Add 'const' modifier to a property" "false"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
Obj.INSTANCE.getProperty();
}
}
// ACTION: Annotate 'property' as @Deprecated
// ACTION: Add static import for 'a.Obj.property'
// ACTION: Annotate property with @JvmField
// ACTION: Split into declaration and assignment
// ACTION: Replace with getter invocation
@@ -1,7 +0,0 @@
package a
object Obj {
val property = A()
}
class A
@@ -1,11 +0,0 @@
// "Replace with getter invocation" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = a.Obj.INSTANCE.getProperty();
A a2 = Obj.getProperty();
A a3 = Obj.property;
}
}
@@ -1,11 +0,0 @@
// "Replace with getter invocation" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
A a2 = Obj.getProperty();
A a3 = Obj.property;
}
}
@@ -1,7 +0,0 @@
package a
object Obj {
val property = A()
}
class A
@@ -1,7 +0,0 @@
package a
object Obj {
@JvmField val property = A()
}
class A
@@ -1,11 +0,0 @@
// "Annotate property with @JvmField" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.property;
A a2 = a.Obj.property;
A a3 = Obj.property;
}
}
@@ -1,11 +0,0 @@
// "Annotate property with @JvmField" "true"
import a.Obj;
import a.A;
class B {
void bar() {
A a = Obj.pro<caret>perty;
A a2 = Obj.getProperty();
A a3 = Obj.property;
}
}
@@ -1,7 +0,0 @@
package a
object Obj {
val property = A()
}
class A
@@ -1234,81 +1234,6 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
}
}
@TestMetadata("idea/testData/quickfix/migration/deprecatedStaticField")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class DeprecatedStaticField extends AbstractQuickFixMultiFileTest {
public void testAllFilesPresentInDeprecatedStaticField() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/deprecatedStaticField"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), true);
}
@TestMetadata("cleanUp.before.Main.java")
public void testCleanUp() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/cleanUp.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("companionObjectOfClass_const.before.Main.java")
public void testCompanionObjectOfClass_const() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfClass_const.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("companionObjectOfClass_getterReference.before.Main.java")
public void testCompanionObjectOfClass_getterReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfClass_getterReference.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("companionObjectOfClass_jvmField.before.Main.java")
public void testCompanionObjectOfClass_jvmField() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfClass_jvmField.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("companionObjectOfInterface_const.before.Main.java")
public void testCompanionObjectOfInterface_const() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfInterface_const.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("companionObjectOfInterface_getterReference.before.Main.java")
public void testCompanionObjectOfInterface_getterReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfInterface_getterReference.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("companionObjectOfInterface_jvmField_unavailable.before.Main.java")
public void testCompanionObjectOfInterface_jvmField_unavailable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/companionObjectOfInterface_jvmField_unavailable.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("object_const.before.Main.java")
public void testObject_const() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/object_const.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("object_const_unavailable.before.Main.java")
public void testObject_const_unavailable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/object_const_unavailable.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("object_getterReference.before.Main.java")
public void testObject_getterReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/object_getterReference.before.Main.java");
doTestWithExtraFile(fileName);
}
@TestMetadata("object_jvmField.before.Main.java")
public void testObject_jvmField() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedStaticField/object_jvmField.before.Main.java");
doTestWithExtraFile(fileName);
}
}
@TestMetadata("idea/testData/quickfix/migration/javaAnnotationPositionedArguments")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)