RemoveRedundantQualifierNameInspection: fix false negative for java constructor

#KT-32506 Fixed
This commit is contained in:
Dmitry Gridin
2019-07-10 16:23:35 +03:00
parent bd50454a73
commit 694c231689
4 changed files with 22 additions and 1 deletions
@@ -11,6 +11,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElementVisitor import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiMember import com.intellij.psi.PsiMember
import com.intellij.psi.PsiMethod
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement import org.jetbrains.kotlin.idea.analysis.analyzeAsReplacement
import org.jetbrains.kotlin.idea.caches.resolve.analyze import org.jetbrains.kotlin.idea.caches.resolve.analyze
@@ -72,7 +73,8 @@ private tailrec fun KtDotQualifiedExpression.firstExpressionWithoutReceiver(): K
val element = getQualifiedElementSelector()?.mainReference?.resolve() ?: return null val element = getQualifiedElementSelector()?.mainReference?.resolve() ?: return null
return if (element is KtClassOrObject || return if (element is KtClassOrObject ||
element is KtCallableDeclaration && element.receiverTypeReference == null || element is KtCallableDeclaration && element.receiverTypeReference == null ||
element is PsiMember && element.hasModifier(JvmModifier.STATIC) element is PsiMember && element.hasModifier(JvmModifier.STATIC) ||
element is PsiMethod && element.isConstructor
) this else (receiverExpression as? KtDotQualifiedExpression)?.firstExpressionWithoutReceiver() ) this else (receiverExpression as? KtDotQualifiedExpression)?.firstExpressionWithoutReceiver()
} }
@@ -0,0 +1,7 @@
// WITH_RUNTIME
import java.util.ArrayList
fun test() {
val a = java.<caret>util.ArrayList<Int>()
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
import java.util.ArrayList
fun test() {
val a = ArrayList<Int>()
}
@@ -8139,6 +8139,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt"); runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/innerClassWithImport2.kt");
} }
@TestMetadata("javaConstructor.kt")
public void testJavaConstructor() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/javaConstructor.kt");
}
@TestMetadata("localFun.kt") @TestMetadata("localFun.kt")
public void testLocalFun() throws Exception { public void testLocalFun() throws Exception {
runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt"); runTest("idea/testData/inspectionsLocal/removeRedundantQualifierName/localFun.kt");