Drop DeprecatedFacadeUsageInspection
(cherry picked from commit f18b95d)
This commit is contained in:
committed by
Dmitry Petrov
parent
93bb010875
commit
bb77890a4e
@@ -1252,14 +1252,6 @@
|
||||
level="WARNING"
|
||||
/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.DeprecatedFacadeUsageInspection"
|
||||
displayName="Usage of deprecated Kotlin package facade"
|
||||
groupName="Kotlin"
|
||||
language="JAVA"
|
||||
enabledByDefault="true"
|
||||
cleanupTool="true"
|
||||
level="WARNING"/>
|
||||
|
||||
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.DeprecatedObjectInstanceFieldReferenceInspection"
|
||||
displayName="Usage of deprecated 'INSTANCE$' field"
|
||||
groupName="Kotlin"
|
||||
|
||||
@@ -1,67 +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 com.intellij.psi.codeStyle.JavaCodeStyleManager
|
||||
import org.jetbrains.kotlin.idea.search.allScope
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
|
||||
public class DeprecatedFacadeUsageInspection : LocalInspectionTool(), CleanupLocalInspectionTool {
|
||||
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean, session: LocalInspectionToolSession): PsiElementVisitor {
|
||||
return object : JavaElementVisitor() {
|
||||
override fun visitReferenceExpression(expression: PsiReferenceExpression) {
|
||||
val resolveResult = expression.reference?.resolve()
|
||||
if (resolveResult is PsiMethod && resolveResult.findDelegatedMethodAnnotation() != null) {
|
||||
holder.registerProblem(expression, "Use of deprecated package facade class",
|
||||
ProblemHighlightType.LIKE_DEPRECATED,
|
||||
DeprecatedFacadeUsageFix())
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
private fun PsiMethod.findDelegatedMethodAnnotation() =
|
||||
modifierList.findAnnotation(JvmAnnotationNames.KOTLIN_DELEGATED_METHOD.asString())
|
||||
|
||||
public class DeprecatedFacadeUsageFix : LocalQuickFix {
|
||||
override fun getName(): String = "Replace with new-style facade class"
|
||||
override fun getFamilyName(): String = name
|
||||
|
||||
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
|
||||
val reference = descriptor.psiElement.reference ?: return
|
||||
val resolveResult = reference.resolve() as? PsiMethod ?: return
|
||||
|
||||
val delegatedMethod = resolveResult.findDelegatedMethodAnnotation() ?: return
|
||||
val attr = delegatedMethod.findAttributeValue(JvmAnnotationNames.IMPLEMENTATION_CLASS_NAME_FIELD_NAME)
|
||||
val targetClassName = (attr as? PsiLiteral)?.value as? String ?: return
|
||||
|
||||
val targetClass = JavaPsiFacade.getInstance(project).findClass(targetClassName, project.allScope()) ?: return
|
||||
val targetMethod = targetClass.findMethodBySignature(resolveResult, false) ?: return
|
||||
|
||||
val newReference = reference.bindToElement(targetMethod)
|
||||
JavaCodeStyleManager.getInstance(project).shortenClassReferences(newReference)
|
||||
|
||||
val javaFile = newReference.containingFile as? PsiJavaFile
|
||||
if (javaFile != null) {
|
||||
JavaCodeStyleManager.getInstance(project).removeRedundantImports(javaFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.inspections.DeprecatedFacadeUsageInspection
|
||||
@@ -1,8 +0,0 @@
|
||||
// "Replace with new-style facade class" "true"
|
||||
import facade.Basic_before_data_facadeKt;
|
||||
|
||||
class A {
|
||||
void bar() {
|
||||
Basic_before_data_facadeKt.foo();
|
||||
}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Replace with new-style facade class" "true"
|
||||
import facade.FacadePackage;
|
||||
|
||||
class A {
|
||||
void bar() {
|
||||
FacadePackage.<caret>foo();
|
||||
}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package facade
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Replace with new-style facade class" "true"
|
||||
import facade.StaticImport_before_data_facadeKt;
|
||||
|
||||
class A {
|
||||
void bar() {
|
||||
StaticImport_before_data_facadeKt.foo();
|
||||
}
|
||||
}
|
||||
-8
@@ -1,8 +0,0 @@
|
||||
// "Replace with new-style facade class" "true"
|
||||
import static facade.FacadePackage.foo;
|
||||
|
||||
class A {
|
||||
void bar() {
|
||||
<caret>foo();
|
||||
}
|
||||
}
|
||||
Vendored
-4
@@ -1,4 +0,0 @@
|
||||
package facade
|
||||
|
||||
fun foo() {
|
||||
}
|
||||
@@ -1090,27 +1090,6 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/migration/deprecatedPackageFacade")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class DeprecatedPackageFacade extends AbstractQuickFixMultiFileTest {
|
||||
public void testAllFilesPresentInDeprecatedPackageFacade() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/migration/deprecatedPackageFacade"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("basic.before.Main.java")
|
||||
public void testBasic() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedPackageFacade/basic.before.Main.java");
|
||||
doTestWithExtraFile(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("staticImport.before.Main.java")
|
||||
public void testStaticImport() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/quickfix/migration/deprecatedPackageFacade/staticImport.before.Main.java");
|
||||
doTestWithExtraFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/migration/deprecatedStaticField")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user