diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt index 8b962bd5bba..4e15e6e43bf 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/psiUtil/psiUtils.kt @@ -431,6 +431,9 @@ fun PsiElement.before(element: PsiElement) = textRange.endOffset <= element.text inline fun PsiElement.getLastParentOfTypeInRow() = parents.takeWhile { it is T }.lastOrNull() as? T +inline fun 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) diff --git a/idea/resources/META-INF/plugin-common.xml b/idea/resources/META-INF/plugin-common.xml index 2a337f41a78..2120f34ecf7 100644 --- a/idea/resources/META-INF/plugin-common.xml +++ b/idea/resources/META-INF/plugin-common.xml @@ -2699,6 +2699,14 @@ level="WARNING" language="kotlin"/> + + + +This inspection reports redundant qualifier name in references. For example: +
+package my.simple.name
+class Foo
+
+fun test() {
+    val s = my.simple.name.Foo() // redundant qualifier name
+}
+
+ + \ No newline at end of file diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt new file mode 100644 index 00000000000..cd13d9b372c --- /dev/null +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/RemoveRedundantQualifierNameInspection.kt @@ -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.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()?.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) + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/.inspection b/idea/testData/inspectionsLocal/removeRedundantQualifierName/.inspection new file mode 100644 index 00000000000..f8663880192 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/.inspection @@ -0,0 +1 @@ +org.jetbrains.kotlin.idea.inspections.RemoveRedundantQualifierNameInspection \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt new file mode 100644 index 00000000000..3b356c50d38 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt @@ -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.Foo.check() + } + + companion object { + fun check() {} + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt.after new file mode 100644 index 00000000000..7136ad1230a --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionCollision.kt.after @@ -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() {} + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnClass.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnClass.kt new file mode 100644 index 00000000000..2da9653a1ae --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnClass.kt @@ -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.Foo() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnClass.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnClass.kt.after new file mode 100644 index 00000000000..c453aa398a2 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnClass.kt.after @@ -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() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnVariable.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnVariable.kt new file mode 100644 index 00000000000..24c2b3f0d3d --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnVariable.kt @@ -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.Foo() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnVariable.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnVariable.kt.after new file mode 100644 index 00000000000..2762a02a7f9 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionOnVariable.kt.after @@ -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() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType.kt new file mode 100644 index 00000000000..105e4365635 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType.kt @@ -0,0 +1,15 @@ +package my.simple.name + + +class Bar { + class Foo { + companion object { + class CheckClass + } + } +} + + +fun foo(a: my.simple.name.Bar.Foo.Companion.CheckClass) { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType.kt.after new file mode 100644 index 00000000000..abe3132c8aa --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType.kt.after @@ -0,0 +1,15 @@ +package my.simple.name + + +class Bar { + class Foo { + companion object { + class CheckClass + } + } +} + + +fun foo(a: Bar.Foo.Companion.CheckClass) { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType2.kt new file mode 100644 index 00000000000..65ef44a57e9 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType2.kt @@ -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.Bar.Foo.Companion.CheckClass) { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType2.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType2.kt.after new file mode 100644 index 00000000000..fe06ac0e953 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType2.kt.after @@ -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) { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType3.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType3.kt new file mode 100644 index 00000000000..504224b8ee8 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType3.kt @@ -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.Bar.Foo.Companion.CheckClass) { + + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType3.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType3.kt.after new file mode 100644 index 00000000000..8289502a6ad --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType3.kt.after @@ -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) { + + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType4.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType4.kt new file mode 100644 index 00000000000..b26a317a1ed --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType4.kt @@ -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.Bar.Foo.Companion.CheckClass) {} + + companion object { + class CheckClass + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType4.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType4.kt.after new file mode 100644 index 00000000000..34dc88c955c --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType4.kt.after @@ -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 + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType5.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType5.kt new file mode 100644 index 00000000000..882a9b68b2c --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType5.kt @@ -0,0 +1,11 @@ +package my.simple.name + +class F { + class CheckClass + + fun foo(a: F.CheckClass) {} + + companion object { + class CheckClass + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType5.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType5.kt.after new file mode 100644 index 00000000000..be30035a79f --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionType5.kt.after @@ -0,0 +1,11 @@ +package my.simple.name + +class F { + class CheckClass + + fun foo(a: CheckClass) {} + + companion object { + class CheckClass + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionWithOuterName.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionWithOuterName.kt new file mode 100644 index 00000000000..cd6c5bf5158 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionWithOuterName.kt @@ -0,0 +1,11 @@ +package my.sample + +class Inner { + fun a() { + my.sample.Inner.say() + } + + companion object Inner { + fun say() {} + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionWithOuterName.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionWithOuterName.kt.after new file mode 100644 index 00000000000..3f42ba3b622 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/companionWithOuterName.kt.after @@ -0,0 +1,11 @@ +package my.sample + +class Inner { + fun a() { + say() + } + + companion object Inner { + fun say() {} + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression.kt new file mode 100644 index 00000000000..ca1ba51a944 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression.kt @@ -0,0 +1,10 @@ +package my.simple.name + +class Foo +class Bar + +fun main() { + val a = my.simple.name.Foo() + val b = my.simple.name.Bar() + val c = my.simple.name.Foo() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression.kt.after new file mode 100644 index 00000000000..a69bf0b15e8 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression.kt.after @@ -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() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression2.kt new file mode 100644 index 00000000000..e61b6f2cd93 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression2.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +package my.simple.name + +fun main() { + val a = kotlin.Int.MAX_VALUE + val b = kotlin.Int.Companion.MAX_VALUE + val c = kotlin.Int.Companion::MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression2.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression2.kt.after new file mode 100644 index 00000000000..8639f180cbb --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression2.kt.after @@ -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 +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression3.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression3.kt new file mode 100644 index 00000000000..9b93279d817 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression3.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +package my.simple.name + +fun main() { + val a = kotlin.Int.MAX_VALUE + val b = kotlin.Int.Companion.MAX_VALUE + val c = kotlin.Int.Companion::MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression3.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression3.kt.after new file mode 100644 index 00000000000..e77b672f347 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression3.kt.after @@ -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 +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression4.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression4.kt new file mode 100644 index 00000000000..0c90c425531 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression4.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +package my.simple.name + +import kotlin.Int.Companion.MAX_VALUE + +fun main() { + val a = kotlin.Int.Companion.MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression4.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression4.kt.after new file mode 100644 index 00000000000..6bb4270ffcd --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression4.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +package my.simple.name + +import kotlin.Int.Companion.MAX_VALUE + +fun main() { + val a = MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression5.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression5.kt new file mode 100644 index 00000000000..21aa0e69811 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression5.kt @@ -0,0 +1,8 @@ +// WITH_RUNTIME +package my.simple.name + +import kotlin.Int.Companion.MAX_VALUE + +fun main() { + val a = kotlin.Int.MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression5.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression5.kt.after new file mode 100644 index 00000000000..6bb4270ffcd --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expression5.kt.after @@ -0,0 +1,8 @@ +// WITH_RUNTIME +package my.simple.name + +import kotlin.Int.Companion.MAX_VALUE + +fun main() { + val a = MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expressionWithParameter.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expressionWithParameter.kt new file mode 100644 index 00000000000..67c4e486053 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expressionWithParameter.kt @@ -0,0 +1,11 @@ +package my.simple.name + +fun run() {} +fun go(check: () -> Unit) = check() + +fun main() { + val a = my.simple.name.go { + run() + } + val b = my.simple.name.go(::run) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/expressionWithParameter.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expressionWithParameter.kt.after new file mode 100644 index 00000000000..8d49938803f --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/expressionWithParameter.kt.after @@ -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) +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass.kt new file mode 100644 index 00000000000..157e14fae83 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass.kt @@ -0,0 +1,16 @@ +package my.simple.name + +class Outer { + class Middle { + class Inner { + companion object { + fun check() {} + } + } + } +} + +fun main() { + my.simple.name.Outer.Middle.Inner.check() + Outer.Middle.Inner.check() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass.kt.after new file mode 100644 index 00000000000..dc545cf6e4b --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass.kt.after @@ -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() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass2.kt new file mode 100644 index 00000000000..544e62da611 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass2.kt @@ -0,0 +1,15 @@ +package my.simple.name + +class Outer { + class Middle { + class Inner { + fun check() { + Outer.Middle.Inner.Companion.check() + } + + companion object { + fun check() {} + } + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass2.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass2.kt.after new file mode 100644 index 00000000000..e83acdddc5d --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass2.kt.after @@ -0,0 +1,15 @@ +package my.simple.name + +class Outer { + class Middle { + class Inner { + fun check() { + Companion.check() + } + + companion object { + fun check() {} + } + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass3.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass3.kt new file mode 100644 index 00000000000..2fa89533a25 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass3.kt @@ -0,0 +1,15 @@ +package my.simple.name + +class Outer { + class Middle { + class Inner { + fun otherCheck() { + Outer.Middle.Inner.Companion.check() + } + + companion object { + fun check() {} + } + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass3.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass3.kt.after new file mode 100644 index 00000000000..22e51ca7672 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass3.kt.after @@ -0,0 +1,15 @@ +package my.simple.name + +class Outer { + class Middle { + class Inner { + fun otherCheck() { + check() + } + + companion object { + fun check() {} + } + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass4.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass4.kt new file mode 100644 index 00000000000..cba7f10b7a8 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass4.kt @@ -0,0 +1,16 @@ +package my.simple.name + +fun check() {} +class Outer { + class Middle { + class Inner { + fun foo() { + Middle.Inner.Companion.check() + my.simple.name.check() + } + companion object { + fun check() {} + } + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass4.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass4.kt.after new file mode 100644 index 00000000000..0606fe38d24 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass4.kt.after @@ -0,0 +1,16 @@ +package my.simple.name + +fun check() {} +class Outer { + class Middle { + class Inner { + fun foo() { + Middle.Inner.Companion.check() + check() + } + companion object { + fun check() {} + } + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass5.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass5.kt new file mode 100644 index 00000000000..6859a197cca --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass5.kt @@ -0,0 +1,16 @@ +package my.simple.name + +fun check() {} +class Outer { + class Middle { + class Inner { + fun foo() { + Middle.Inner.Companion.check() + my.simple.name.check() + } + companion object { + fun check() {} + } + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass5.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass5.kt.after new file mode 100644 index 00000000000..beffeb68aa9 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClass5.kt.after @@ -0,0 +1,16 @@ +package my.simple.name + +fun check() {} +class Outer { + class Middle { + class Inner { + fun foo() { + check() + my.simple.name.check() + } + companion object { + fun check() {} + } + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport.kt new file mode 100644 index 00000000000..a1a54d75b5d --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport.kt @@ -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.check() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport.kt.after new file mode 100644 index 00000000000..dc0ca112239 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport.kt.after @@ -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() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt new file mode 100644 index 00000000000..155cf59672d --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt @@ -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.check() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt.after new file mode 100644 index 00000000000..a0130bb8a1c --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt.after @@ -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() +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt new file mode 100644 index 00000000000..f85f3134e32 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt @@ -0,0 +1,12 @@ +package my.simple.name + +class Inner { + fun a() { + fun Inner() {} + Inner.say() + } + + companion object { + fun say() {} + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt.after new file mode 100644 index 00000000000..273e7d659c1 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt.after @@ -0,0 +1,12 @@ +package my.simple.name + +class Inner { + fun a() { + fun Inner() {} + say() + } + + companion object { + fun say() {} + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun2.kt new file mode 100644 index 00000000000..0ba1e6b3100 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun2.kt @@ -0,0 +1,12 @@ +package my.simple.name + +class Inner { + fun a() { + fun say(i: Inner) {} + Inner.say() + } + + companion object { + fun say() {} + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun2.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun2.kt.after new file mode 100644 index 00000000000..fec0bfd2b13 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun2.kt.after @@ -0,0 +1,12 @@ +package my.simple.name + +class Inner { + fun a() { + fun say(i: Inner) {} + say() + } + + companion object { + fun say() {} + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCollisionTopLevelClass.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCollisionTopLevelClass.kt new file mode 100644 index 00000000000..8a6fec6e2a8 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCollisionTopLevelClass.kt @@ -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.SuperClass.check() + } + + companion object { + fun check() {} + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanion.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanion.kt new file mode 100644 index 00000000000..7573202907f --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanion.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +package my.simple.name + +class Child { + fun f() { + Companion.value + } + + companion object { + val value = 1 + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionOtherName.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionOtherName.kt new file mode 100644 index 00000000000..52a7d790351 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionOtherName.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +package my.simple.name + +class Child { + fun f() { + Helper.value + } + + companion object Helper { + val value = 1 + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType.kt new file mode 100644 index 00000000000..383b1c383ea --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType.kt @@ -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.Foo.Companion.CheckClass) {} + + companion object { + class CheckClass + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType2.kt new file mode 100644 index 00000000000..6aa658d9920 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableCompanionType2.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +package my.simple.name + +class F { + class CheckClass + + fun foo(a: Companion.CheckClass) {} + + companion object { + class CheckClass + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression.kt new file mode 100644 index 00000000000..d2a74e15130 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +// PROBLEM: none +package my.simple.name + +fun main() { + val a = kotlin.Int.Companion.MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression2.kt new file mode 100644 index 00000000000..a5adf329d15 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression2.kt @@ -0,0 +1,7 @@ +// WITH_RUNTIME +// PROBLEM: none +package my.simple.name + +fun main() { + val a = kotlin.Int.Companion::MAX_VALUE +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression3.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression3.kt new file mode 100644 index 00000000000..1491da2bc73 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableExpression3.kt @@ -0,0 +1,9 @@ +// PROBLEM: none +package my.simple.name + +class Foo { + val f = this + fun check() { + f.f.f.f.f.f.f.f.f + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalFun.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalFun.kt new file mode 100644 index 00000000000..95ad588c6bd --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalFun.kt @@ -0,0 +1,13 @@ +// PROBLEM: none +package my.simple.name + +class Inner { + fun a() { + fun say() {} + Inner.say() + } + + companion object { + fun say() {} + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable.kt new file mode 100644 index 00000000000..ab38de559bf --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable.kt @@ -0,0 +1,13 @@ +// PROBLEM: none +package my.simple.name + +class Inner { + fun a() { + val MAX = 2 + val a = Member.MAX + } + + companion object Member { + val MAX = 1 + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable2.kt new file mode 100644 index 00000000000..66d6a61bab9 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableLocalVariable2.kt @@ -0,0 +1,12 @@ +// PROBLEM: none +package my.simple.name + +class Inner { + fun a() { + val a = Member.MAX + } + + companion object Member { + val MAX = 1 + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableOuterClass.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableOuterClass.kt new file mode 100644 index 00000000000..065b0c2018e --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableOuterClass.kt @@ -0,0 +1,18 @@ +// PROBLEM: none +package my.simple.name + +class Foo { + companion object { + fun say(){} + } +} + +class Bar { + class Inner { + fun a() { + my.simple.name.Foo.say() + } + + class Foo + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableThis.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableThis.kt new file mode 100644 index 00000000000..9b7922c7b79 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableThis.kt @@ -0,0 +1,10 @@ +// PROBLEM: none +package my.simple.name + +class Inner { + fun a() { + this.say() + } + + fun say() {} +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime.kt new file mode 100644 index 00000000000..b46e6bdced2 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +// PROBLEM: none +package my.simple.name + +class Int + +fun foo(a: kotlin.Int) { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime2.kt new file mode 100644 index 00000000000..1684830bccf --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/notApplicableTypeWithRuntime2.kt @@ -0,0 +1,9 @@ +// WITH_RUNTIME +// PROBLEM: none +package my.simple.name + +typealias Int = Long + +fun foo(a: kotlin.Int) { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/secondaryConstructor.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/secondaryConstructor.kt new file mode 100644 index 00000000000..d7c76e07210 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/secondaryConstructor.kt @@ -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.Foo(1) + val b = Outer.Foo() + } + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/secondaryConstructor.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/secondaryConstructor.kt.after new file mode 100644 index 00000000000..5ff4602cd33 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/secondaryConstructor.kt.after @@ -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() + } + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass.kt new file mode 100644 index 00000000000..0db9cb23407 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass.kt @@ -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.check() + } + + companion object { + fun check() {} + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass.kt.after new file mode 100644 index 00000000000..a6507c26c79 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass.kt.after @@ -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() {} + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass2.kt new file mode 100644 index 00000000000..77ab064a2b1 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass2.kt @@ -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.check() + } + + companion object { + fun check() {} + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass2.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass2.kt.after new file mode 100644 index 00000000000..01d14a4bd5c --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/superClass2.kt.after @@ -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() {} + } + } +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/type.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type.kt new file mode 100644 index 00000000000..b57a949fad5 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type.kt @@ -0,0 +1,9 @@ +package my.simple.name + +class Foo +class Bar + +fun foo(a: my.simple.name.Foo) { + val b: my.simple.name.Bar + val c: my.simple.name.Foo +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/type.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type.kt.after new file mode 100644 index 00000000000..99a95136b79 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type.kt.after @@ -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 +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/type2.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type2.kt new file mode 100644 index 00000000000..9bbbf4a2b7d --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type2.kt @@ -0,0 +1,13 @@ +// WITH_RUNTIME +package my.simple.name + +class Outer { + fun goo(i: Outer.Middle.Inner.Int) { + + } + class Middle { + class Inner { + class Int + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/type2.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type2.kt.after new file mode 100644 index 00000000000..5f3a588690b --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/type2.kt.after @@ -0,0 +1,13 @@ +// WITH_RUNTIME +package my.simple.name + +class Outer { + fun goo(i: Middle.Inner.Int) { + + } + class Middle { + class Inner { + class Int + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithAlias.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithAlias.kt new file mode 100644 index 00000000000..5d86d29c656 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithAlias.kt @@ -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.Int) { + + } + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithAlias.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithAlias.kt.after new file mode 100644 index 00000000000..77364e1d0d3 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithAlias.kt.after @@ -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) { + + } + } + } +} diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithRuntime.kt b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithRuntime.kt new file mode 100644 index 00000000000..362cf6abde7 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithRuntime.kt @@ -0,0 +1,6 @@ +// WITH_RUNTIME +package my.simple.name + +fun foo(a: kotlin.Int) { + +} \ No newline at end of file diff --git a/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithRuntime.kt.after b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithRuntime.kt.after new file mode 100644 index 00000000000..dc3786cbd92 --- /dev/null +++ b/idea/testData/inspectionsLocal/removeRedundantQualifierName/typeWithRuntime.kt.after @@ -0,0 +1,6 @@ +// WITH_RUNTIME +package my.simple.name + +fun foo(a: Int) { + +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index 6b2ff6adebe..bc8e39d576a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -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)