Add inspection to remove redundant qualifier name

#KT-12134 Fixed
This commit is contained in:
Dmitry Gridin
2019-02-27 15:54:54 +03:00
parent d0c3a28996
commit 3756b6f54d
83 changed files with 1469 additions and 0 deletions
@@ -431,6 +431,9 @@ fun PsiElement.before(element: PsiElement) = textRange.endOffset <= element.text
inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRow() = parents.takeWhile { it is T }.lastOrNull() as? T
inline fun <reified T : PsiElement> PsiElement.getLastParentOfTypeInRowWithSelf() = parentsWithSelf
.takeWhile { it is T }.lastOrNull() as? T
fun KtModifierListOwner.hasExpectModifier() = hasModifier(KtTokens.HEADER_KEYWORD) || hasModifier(KtTokens.EXPECT_KEYWORD)
fun KtModifierList.hasExpectModifier() = hasModifier(KtTokens.HEADER_KEYWORD) || hasModifier(KtTokens.EXPECT_KEYWORD)
@@ -2699,6 +2699,14 @@
level="WARNING"
language="kotlin"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RemoveRedundantQualifierNameInspection"
displayName="Remove redundant qualifier name"
groupPath="Kotlin"
groupName="Redundant constructs"
enabledByDefault="true"
level="WARNING"
language="kotlin"/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.RedundantSetterInspection"
displayName="Redundant property setter"
groupPath="Kotlin"
@@ -0,0 +1,13 @@
<html>
<body>
This inspection reports redundant qualifier name in references. For example:
<pre>
<b>package</b> my.simple.name
<b>class</b> Foo
<b>fun</b> test() {
<b>val</b> s = my.simple.name.Foo() // redundant qualifier name
}
</pre>
</body>
</html>
@@ -0,0 +1,135 @@
/*
* 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.idea.inspections
import com.intellij.codeInspection.*
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElementVisitor
import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.references.resolveMainReferenceToDescriptors
import org.jetbrains.kotlin.idea.util.getResolutionScope
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.descriptorUtil.isCompanionObject
import org.jetbrains.kotlin.resolve.scopes.utils.findFirstClassifierWithDeprecationStatus
class RemoveRedundantQualifierNameInspection : AbstractKotlinInspection(), CleanupLocalInspectionTool {
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor =
object : KtVisitorVoid() {
override fun visitDotQualifiedExpression(expression: KtDotQualifiedExpression) {
if (expression.parent is KtDotQualifiedExpression? || expression.isInImportDirective()) return
val context = expression.analyze()
val importableFqName = expression.getQualifiedElementSelector()
?.getResolvedCall(context)?.resultingDescriptor
?.importableFqName ?: return
val applicableExpression = expression.firstApplicableExpression(validator = {
applicableExpression(expression, context, importableFqName)
}) {
firstChild as? KtDotQualifiedExpression
} ?: return
reportProblem(holder, applicableExpression)
}
override fun visitUserType(type: KtUserType) {
if (type.parent is KtUserType) return
val applicableExpression = type.firstApplicableExpression(KtUserType::applicableExpression) {
firstChild as? KtUserType
} ?: return
reportProblem(holder, applicableExpression)
}
}
}
private tailrec fun <T : KtElement> T.firstApplicableExpression(validator: T.() -> T?, generator: T.() -> T?): T? =
validator() ?: generator()?.firstApplicableExpression(validator, generator)
private fun KtDotQualifiedExpression.applicableExpression(
originalExpression: KtExpression,
oldContext: BindingContext,
importableFqName: FqName
): KtDotQualifiedExpression? {
if (!receiverExpression.isApplicableReceiver(oldContext) || !ShortenReferences.canBePossibleToDropReceiver(
this,
oldContext
)
) return null
val expressionText = originalExpression.text.substring(lastChild.startOffset - originalExpression.startOffset)
val newExpression = KtPsiFactory(originalExpression).createExpression(expressionText)
val newContext = newExpression.analyzeAsReplacement(originalExpression, oldContext)
val newDescriptor = newExpression.getQualifiedElementSelector()?.getResolvedCall(newContext)?.resultingDescriptor ?: return null
return takeIf {
importableFqName == newDescriptor.importableFqName
}
}
private fun KtExpression.isApplicableReceiver(context: BindingContext): Boolean {
if (this is KtInstanceExpressionWithLabel) return false
val reference = getQualifiedElementSelector()
val descriptor = reference?.mainReference?.resolveToDescriptors(context)?.firstOrNull() ?: return false
return if (!descriptor.isCompanionObject()) true
else descriptor.name.asString() != reference.text
}
private fun KtUserType.applicableExpression(): KtUserType? {
if (firstChild !is KtUserType) return null
val referenceExpression = referenceExpression as? KtNameReferenceExpression ?: return null
val originalDescriptor = referenceExpression.resolveMainReferenceToDescriptors().firstOrNull() ?: return null
val shortName = originalDescriptor.importableFqName?.shortName() ?: return null
val scope = referenceExpression.getResolutionScope()
val descriptor = scope.findFirstClassifierWithDeprecationStatus(shortName, NoLookupLocation.FROM_IDE)?.descriptor ?: return null
return if (descriptor == originalDescriptor) this else null
}
private fun reportProblem(holder: ProblemsHolder, element: KtElement) {
val firstChild = element.firstChild
holder.registerProblem(
element,
"Redundant qualifier name",
ProblemHighlightType.LIKE_UNUSED_SYMBOL,
TextRange.from(firstChild.startOffsetInParent, firstChild.textLength + 1),
RemoveRedundantQualifierNameQuickFix()
)
}
class RemoveRedundantQualifierNameQuickFix : LocalQuickFix {
override fun getName() = "Remove redundant qualifier name"
override fun getFamilyName() = name
override fun applyFix(project: Project, descriptor: ProblemDescriptor) {
val file = descriptor.psiElement.containingFile as KtFile
val range = when (val element = descriptor.psiElement) {
is KtUserType -> IntRange(element.startOffset, element.referenceExpression?.endOffset ?: return)
is KtDotQualifiedExpression -> IntRange(
element.startOffset,
element.getLastParentOfTypeInRowWithSelf<KtDotQualifiedExpression>()?.getQualifiedElementSelector()?.endOffset ?: return
)
else -> IntRange.EMPTY
}
val substring = file.text.substring(range.start, range.endInclusive)
Regex.fromLiteral(substring).findAll(file.text, file.importList?.endOffset ?: 0).toList().reversed().forEach {
ShortenReferences.DEFAULT.process(file, it.range.start, it.range.endInclusive + 1)
}
}
}
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.inspections.RemoveRedundantQualifierNameInspection
@@ -0,0 +1,24 @@
// WITH_RUNTIME
package my.simple.name
open class SuperClass {
companion object {
fun check() {}
}
}
class Child : SuperClass() {
class Foo constructor() {
constructor(i: Int) : this()
fun check() {}
fun foo() {
my.simple.name.SuperClass.check()
Child<caret>.Foo.check()
}
companion object {
fun check() {}
}
}
}
@@ -0,0 +1,24 @@
// WITH_RUNTIME
package my.simple.name
open class SuperClass {
companion object {
fun check() {}
}
}
class Child : SuperClass() {
class Foo constructor() {
constructor(i: Int) : this()
fun check() {}
fun foo() {
my.simple.name.SuperClass.check()
Foo.check()
}
companion object {
fun check() {}
}
}
}
@@ -0,0 +1,14 @@
package my.simple.name
import my.simple.name.Foo.Companion.VARIABLE
class Foo {
companion object {
const val VARIABLE = 1
}
}
fun main() {
val a = my.simple.name.Foo.VARIABLE
val b = my.simple.name.Foo.Companion.VARIABLE
val c = my.simple.name<caret>.Foo()
}
@@ -0,0 +1,14 @@
package my.simple.name
import my.simple.name.Foo.Companion.VARIABLE
class Foo {
companion object {
const val VARIABLE = 1
}
}
fun main() {
val a = Foo.VARIABLE
val b = Foo.Companion.VARIABLE
val c = Foo()
}
@@ -0,0 +1,14 @@
package my.simple.name
import my.simple.name.Foo.Companion.VARIABLE
class Foo {
companion object {
const val VARIABLE = 1
}
}
fun main() {
val a = my.simple.name.Foo<caret>.VARIABLE
val b = my.simple.name.Foo.Companion.VARIABLE
val c = my.simple.name.Foo()
}
@@ -0,0 +1,14 @@
package my.simple.name
import my.simple.name.Foo.Companion.VARIABLE
class Foo {
companion object {
const val VARIABLE = 1
}
}
fun main() {
val a = VARIABLE
val b = my.simple.name.Foo.Companion.VARIABLE
val c = my.simple.name.Foo()
}
@@ -0,0 +1,15 @@
package my.simple.name
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
fun foo(a: my.simple.name<caret>.Bar.Foo.Companion.CheckClass) {
}
@@ -0,0 +1,15 @@
package my.simple.name
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
fun foo(a: Bar.Foo.Companion.CheckClass) {
}
@@ -0,0 +1,16 @@
package my.simple.name
import my.simple.name.Bar.Foo.Companion.CheckClass
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
fun foo(a: my.simple.name<caret>.Bar.Foo.Companion.CheckClass) {
}
@@ -0,0 +1,16 @@
package my.simple.name
import my.simple.name.Bar.Foo.Companion.CheckClass
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
fun foo(a: CheckClass) {
}
@@ -0,0 +1,19 @@
package my.simple.name
import my.simple.name.Bar.Foo.Companion.CheckClass
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
class F {
class CheckClass
fun foo(a: my.simple.name<caret>.Bar.Foo.Companion.CheckClass) {
}
}
@@ -0,0 +1,19 @@
package my.simple.name
import my.simple.name.Bar.Foo.Companion.CheckClass
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
class F {
class CheckClass
fun foo(a: Bar.Foo.Companion.CheckClass) {
}
}
@@ -0,0 +1,19 @@
package my.simple.name
import my.simple.name.Bar.Foo.Companion.CheckClass
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
class F {
fun foo(a: my.simple.name<caret>.Bar.Foo.Companion.CheckClass) {}
companion object {
class CheckClass
}
}
@@ -0,0 +1,19 @@
package my.simple.name
import my.simple.name.Bar.Foo.Companion.CheckClass
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
class F {
fun foo(a: Bar.Foo.Companion.CheckClass) {}
companion object {
class CheckClass
}
}
@@ -0,0 +1,11 @@
package my.simple.name
class F {
class CheckClass
fun foo(a: F<caret>.CheckClass) {}
companion object {
class CheckClass
}
}
@@ -0,0 +1,11 @@
package my.simple.name
class F {
class CheckClass
fun foo(a: CheckClass) {}
companion object {
class CheckClass
}
}
@@ -0,0 +1,11 @@
package my.sample
class Inner {
fun a() {
my.sample<caret>.Inner.say()
}
companion object Inner {
fun say() {}
}
}
@@ -0,0 +1,11 @@
package my.sample
class Inner {
fun a() {
say()
}
companion object Inner {
fun say() {}
}
}
@@ -0,0 +1,10 @@
package my.simple.name
class Foo
class Bar
fun main() {
val a = my.simple.name<caret>.Foo()
val b = my.simple.name.Bar()
val c = my.simple.name.Foo()
}
@@ -0,0 +1,10 @@
package my.simple.name
class Foo
class Bar
fun main() {
val a = Foo()
val b = my.simple.name.Bar()
val c = Foo()
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
fun main() {
val a = kotlin<caret>.Int.MAX_VALUE
val b = kotlin.Int.Companion.MAX_VALUE
val c = kotlin.Int.Companion::MAX_VALUE
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
fun main() {
val a = Int.MAX_VALUE
val b = kotlin.Int.Companion.MAX_VALUE
val c = kotlin.Int.Companion::MAX_VALUE
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
fun main() {
val a = kotlin.Int.MAX_VALUE
val b = kotlin<caret>.Int.Companion.MAX_VALUE
val c = kotlin.Int.Companion::MAX_VALUE
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
fun main() {
val a = kotlin.Int.MAX_VALUE
val b = Int.MAX_VALUE
val c = kotlin.Int.Companion::MAX_VALUE
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
import kotlin.Int.Companion.MAX_VALUE
fun main() {
val a = kotlin<caret>.Int.Companion.MAX_VALUE
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
import kotlin.Int.Companion.MAX_VALUE
fun main() {
val a = MAX_VALUE
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
import kotlin.Int.Companion.MAX_VALUE
fun main() {
val a = kotlin<caret>.Int.MAX_VALUE
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
package my.simple.name
import kotlin.Int.Companion.MAX_VALUE
fun main() {
val a = MAX_VALUE
}
@@ -0,0 +1,11 @@
package my.simple.name
fun run() {}
fun go(check: () -> Unit) = check()
fun main() {
val a = my.simple.name<caret>.go {
run()
}
val b = my.simple.name.go(::run)
}
@@ -0,0 +1,11 @@
package my.simple.name
fun run() {}
fun go(check: () -> Unit) = check()
fun main() {
val a = go {
run()
}
val b = go(::run)
}
@@ -0,0 +1,16 @@
package my.simple.name
class Outer {
class Middle {
class Inner {
companion object {
fun check() {}
}
}
}
}
fun main() {
my.simple.name<caret>.Outer.Middle.Inner.check()
Outer.Middle.Inner.check()
}
@@ -0,0 +1,16 @@
package my.simple.name
class Outer {
class Middle {
class Inner {
companion object {
fun check() {}
}
}
}
}
fun main() {
Outer.Middle.Inner.check()
Outer.Middle.Inner.check()
}
@@ -0,0 +1,15 @@
package my.simple.name
class Outer {
class Middle {
class Inner {
fun check() {
Outer.Middle.Inner<caret>.Companion.check()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,15 @@
package my.simple.name
class Outer {
class Middle {
class Inner {
fun check() {
Companion.check()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,15 @@
package my.simple.name
class Outer {
class Middle {
class Inner {
fun otherCheck() {
Outer.Middle.Inner<caret>.Companion.check()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,15 @@
package my.simple.name
class Outer {
class Middle {
class Inner {
fun otherCheck() {
check()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,16 @@
package my.simple.name
fun <T> check() {}
class Outer {
class Middle {
class Inner {
fun foo() {
Middle.Inner.Companion.check()
my.simple.name<caret>.check<Outer>()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,16 @@
package my.simple.name
fun <T> check() {}
class Outer {
class Middle {
class Inner {
fun foo() {
Middle.Inner.Companion.check()
check<Outer>()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,16 @@
package my.simple.name
fun <T> check() {}
class Outer {
class Middle {
class Inner {
fun foo() {
Middle.Inner<caret>.Companion.check()
my.simple.name.check<Outer>()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,16 @@
package my.simple.name
fun <T> check() {}
class Outer {
class Middle {
class Inner {
fun foo() {
check()
my.simple.name.check<Outer>()
}
companion object {
fun check() {}
}
}
}
}
@@ -0,0 +1,18 @@
package my.simple.name
import my.simple.name.Outer.Middle.Inner.Companion.check
class Outer {
class Middle {
class Inner {
companion object {
fun check() {}
}
}
}
}
fun main() {
my.simple.name<caret>.Outer.Middle.Inner.check()
Outer.Middle.Inner.check()
}
@@ -0,0 +1,18 @@
package my.simple.name
import my.simple.name.Outer.Middle.Inner.Companion.check
class Outer {
class Middle {
class Inner {
companion object {
fun check() {}
}
}
}
}
fun main() {
check()
Outer.Middle.Inner.check()
}
@@ -0,0 +1,18 @@
package my.simple.name
import my.simple.name.Outer.Middle.Inner.Companion.check
class Outer {
class Middle {
class Inner {
companion object {
fun check() {}
}
}
}
}
fun main() {
my.simple.name.Outer.Middle.Inner.check()
Outer.Middle.Inner<caret>.check()
}
@@ -0,0 +1,18 @@
package my.simple.name
import my.simple.name.Outer.Middle.Inner.Companion.check
class Outer {
class Middle {
class Inner {
companion object {
fun check() {}
}
}
}
}
fun main() {
my.simple.name.Outer.Middle.Inner.check()
check()
}
@@ -0,0 +1,12 @@
package my.simple.name
class Inner {
fun a() {
fun Inner() {}
Inner<caret>.say()
}
companion object {
fun say() {}
}
}
@@ -0,0 +1,12 @@
package my.simple.name
class Inner {
fun a() {
fun Inner() {}
say()
}
companion object {
fun say() {}
}
}
@@ -0,0 +1,12 @@
package my.simple.name
class Inner {
fun a() {
fun say(i: Inner) {}
Inner<caret>.say()
}
companion object {
fun say() {}
}
}
@@ -0,0 +1,12 @@
package my.simple.name
class Inner {
fun a() {
fun say(i: Inner) {}
say()
}
companion object {
fun say() {}
}
}
@@ -0,0 +1,27 @@
// WITH_RUNTIME
// PROBLEM: none
package my.simple.name
open class SuperClass {
companion object {
fun check() {}
}
}
class Foo
class Child : SuperClass() {
class Foo constructor() {
constructor(i: Int) : this()
class SuperClass
fun check() {}
fun foo() {
my.simple.name<caret>.SuperClass.check()
}
companion object {
fun check() {}
}
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
package my.simple.name
class Child {
fun f() {
Companion<caret>.value
}
companion object {
val value = 1
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
package my.simple.name
class Child {
fun f() {
Helper<caret>.value
}
companion object Helper {
val value = 1
}
}
@@ -0,0 +1,20 @@
// PROBLEM: none
package my.simple.name
import my.simple.name.Bar.Foo.Companion.CheckClass
class Bar {
class Foo {
companion object {
class CheckClass
}
}
}
class F {
fun foo(a: Bar<caret>.Foo.Companion.CheckClass) {}
companion object {
class CheckClass
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
package my.simple.name
class F {
class CheckClass
fun foo(a: Companion<caret>.CheckClass) {}
companion object {
class CheckClass
}
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// PROBLEM: none
package my.simple.name
fun main() {
val a = kotlin.Int<caret>.Companion.MAX_VALUE
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// PROBLEM: none
package my.simple.name
fun main() {
val a = kotlin.Int<caret>.Companion::MAX_VALUE
}
@@ -0,0 +1,9 @@
// PROBLEM: none
package my.simple.name
class Foo {
val f = this
fun check() {
f<caret>.f.f.f.f.f.f.f.f
}
}
@@ -0,0 +1,13 @@
// PROBLEM: none
package my.simple.name
class Inner {
fun a() {
fun say() {}
Inner<caret>.say()
}
companion object {
fun say() {}
}
}
@@ -0,0 +1,13 @@
// PROBLEM: none
package my.simple.name
class Inner {
fun a() {
val MAX = 2
val a = Member<caret>.MAX
}
companion object Member {
val MAX = 1
}
}
@@ -0,0 +1,12 @@
// PROBLEM: none
package my.simple.name
class Inner {
fun a() {
val a = Member<caret>.MAX
}
companion object Member {
val MAX = 1
}
}
@@ -0,0 +1,18 @@
// PROBLEM: none
package my.simple.name
class Foo {
companion object {
fun say(){}
}
}
class Bar {
class Inner {
fun a() {
my.simple<caret>.name.Foo.say()
}
class Foo
}
}
@@ -0,0 +1,10 @@
// PROBLEM: none
package my.simple.name
class Inner {
fun a() {
this<caret>.say()
}
fun say() {}
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// PROBLEM: none
package my.simple.name
class Int
fun foo(a: kotlin<caret>.Int) {
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// PROBLEM: none
package my.simple.name
typealias Int = Long
fun foo(a: kotlin<caret>.Int) {
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
package my.simple.name
class Outer {
class Foo constructor() {
constructor(i: Int) : this()
companion object {
fun check() {
val a = Outer<caret>.Foo(1)
val b = Outer.Foo()
}
}
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
package my.simple.name
class Outer {
class Foo constructor() {
constructor(i: Int) : this()
companion object {
fun check() {
val a = Foo(1)
val b = Foo()
}
}
}
}
@@ -0,0 +1,23 @@
// WITH_RUNTIME
package my.simple.name
open class SuperClass {
companion object {
fun check() {}
}
}
class Child : SuperClass() {
class Foo constructor() {
constructor(i: Int) : this()
fun foo() {
my.simple.name<caret>.SuperClass.check()
Child.Foo.check()
}
companion object {
fun check() {}
}
}
}
@@ -0,0 +1,23 @@
// WITH_RUNTIME
package my.simple.name
open class SuperClass {
companion object {
fun check() {}
}
}
class Child : SuperClass() {
class Foo constructor() {
constructor(i: Int) : this()
fun foo() {
SuperClass.check()
Child.Foo.check()
}
companion object {
fun check() {}
}
}
}
@@ -0,0 +1,23 @@
// WITH_RUNTIME
package my.simple.name
open class SuperClass {
companion object {
fun check() {}
}
}
class Child : SuperClass() {
class Foo constructor() {
constructor(i: Int) : this()
fun foo() {
my.simple.name.SuperClass.check()
Child.Foo<caret>.check()
}
companion object {
fun check() {}
}
}
}
@@ -0,0 +1,23 @@
// WITH_RUNTIME
package my.simple.name
open class SuperClass {
companion object {
fun check() {}
}
}
class Child : SuperClass() {
class Foo constructor() {
constructor(i: Int) : this()
fun foo() {
my.simple.name.SuperClass.check()
check()
}
companion object {
fun check() {}
}
}
}
@@ -0,0 +1,9 @@
package my.simple.name
class Foo
class Bar
fun foo(a: my.simple.name<caret>.Foo) {
val b: my.simple.name.Bar
val c: my.simple.name.Foo
}
@@ -0,0 +1,9 @@
package my.simple.name
class Foo
class Bar
fun foo(a: Foo) {
val b: my.simple.name.Bar
val c: Foo
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
package my.simple.name
class Outer {
fun goo(i: Outer<caret>.Middle.Inner.Int) {
}
class Middle {
class Inner {
class Int
}
}
}
@@ -0,0 +1,13 @@
// WITH_RUNTIME
package my.simple.name
class Outer {
fun goo(i: Middle.Inner.Int) {
}
class Middle {
class Inner {
class Int
}
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
package my.simple.name
typealias Int = Long
class Outer {
class Middle {
class Int
class Inner {
fun goo(i: Outer.Middle<caret>.Int) {
}
}
}
}
@@ -0,0 +1,15 @@
// WITH_RUNTIME
package my.simple.name
typealias Int = Long
class Outer {
class Middle {
class Int
class Inner {
fun goo(i: Int) {
}
}
}
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
package my.simple.name
fun foo(a: kotlin<caret>.Int) {
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
package my.simple.name
fun foo(a: Int) {
}
@@ -5932,6 +5932,249 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
}
}
@TestMetadata("idea/testData/inspectionsLocal/removeRedundantQualifierName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class RemoveRedundantQualifierName extends AbstractLocalInspectionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
public void testAllFilesPresentInRemoveRedundantQualifierName() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/inspectionsLocal/removeRedundantQualifierName"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
}
@TestMetadata("companionCollision.kt")
public void testCompanionCollision() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt");
}
@TestMetadata("companionOnClass.kt")
public void testCompanionOnClass() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnClass.kt");
}
@TestMetadata("companionOnVariable.kt")
public void testCompanionOnVariable() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnVariable.kt");
}
@TestMetadata("companionType.kt")
public void testCompanionType() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType.kt");
}
@TestMetadata("companionType2.kt")
public void testCompanionType2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType2.kt");
}
@TestMetadata("companionType3.kt")
public void testCompanionType3() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType3.kt");
}
@TestMetadata("companionType4.kt")
public void testCompanionType4() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType4.kt");
}
@TestMetadata("companionType5.kt")
public void testCompanionType5() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType5.kt");
}
@TestMetadata("companionWithOuterName.kt")
public void testCompanionWithOuterName() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/companionWithOuterName.kt");
}
@TestMetadata("expression.kt")
public void testExpression() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/expression.kt");
}
@TestMetadata("expression2.kt")
public void testExpression2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/expression2.kt");
}
@TestMetadata("expression3.kt")
public void testExpression3() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/expression3.kt");
}
@TestMetadata("expression4.kt")
public void testExpression4() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/expression4.kt");
}
@TestMetadata("expression5.kt")
public void testExpression5() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/expression5.kt");
}
@TestMetadata("expressionWithParameter.kt")
public void testExpressionWithParameter() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/expressionWithParameter.kt");
}
@TestMetadata("innerClass.kt")
public void testInnerClass() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass.kt");
}
@TestMetadata("innerClass2.kt")
public void testInnerClass2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass2.kt");
}
@TestMetadata("innerClass3.kt")
public void testInnerClass3() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass3.kt");
}
@TestMetadata("innerClass4.kt")
public void testInnerClass4() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass4.kt");
}
@TestMetadata("innerClass5.kt")
public void testInnerClass5() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass5.kt");
}
@TestMetadata("innerClassWithImport.kt")
public void testInnerClassWithImport() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport.kt");
}
@TestMetadata("innerClassWithImport2.kt")
public void testInnerClassWithImport2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt");
}
@TestMetadata("localFun.kt")
public void testLocalFun() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt");
}
@TestMetadata("localFun2.kt")
public void testLocalFun2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun2.kt");
}
@TestMetadata("notApplicableCollisionTopLevelClass.kt")
public void testNotApplicableCollisionTopLevelClass() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCollisionTopLevelClass.kt");
}
@TestMetadata("notApplicableCompanion.kt")
public void testNotApplicableCompanion() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanion.kt");
}
@TestMetadata("notApplicableCompanionOtherName.kt")
public void testNotApplicableCompanionOtherName() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionOtherName.kt");
}
@TestMetadata("notApplicableCompanionType.kt")
public void testNotApplicableCompanionType() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType.kt");
}
@TestMetadata("notApplicableCompanionType2.kt")
public void testNotApplicableCompanionType2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType2.kt");
}
@TestMetadata("notApplicableExpression.kt")
public void testNotApplicableExpression() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression.kt");
}
@TestMetadata("notApplicableExpression2.kt")
public void testNotApplicableExpression2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression2.kt");
}
@TestMetadata("notApplicableExpression3.kt")
public void testNotApplicableExpression3() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression3.kt");
}
@TestMetadata("notApplicableLocalFun.kt")
public void testNotApplicableLocalFun() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalFun.kt");
}
@TestMetadata("notApplicableLocalVariable.kt")
public void testNotApplicableLocalVariable() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable.kt");
}
@TestMetadata("notApplicableLocalVariable2.kt")
public void testNotApplicableLocalVariable2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable2.kt");
}
@TestMetadata("notApplicableOuterClass.kt")
public void testNotApplicableOuterClass() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableOuterClass.kt");
}
@TestMetadata("notApplicableThis.kt")
public void testNotApplicableThis() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableThis.kt");
}
@TestMetadata("notApplicableTypeWithRuntime.kt")
public void testNotApplicableTypeWithRuntime() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime.kt");
}
@TestMetadata("notApplicableTypeWithRuntime2.kt")
public void testNotApplicableTypeWithRuntime2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime2.kt");
}
@TestMetadata("secondaryConstructor.kt")
public void testSecondaryConstructor() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/secondaryConstructor.kt");
}
@TestMetadata("superClass.kt")
public void testSuperClass() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass.kt");
}
@TestMetadata("superClass2.kt")
public void testSuperClass2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass2.kt");
}
@TestMetadata("type.kt")
public void testType() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/type.kt");
}
@TestMetadata("type2.kt")
public void testType2() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/type2.kt");
}
@TestMetadata("typeWithAlias.kt")
public void testTypeWithAlias() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithAlias.kt");
}
@TestMetadata("typeWithRuntime.kt")
public void testTypeWithRuntime() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithRuntime.kt");
}
}
@TestMetadata("idea/testData/inspectionsLocal/removeRedundantSpreadOperator")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)