Shorten references: Do not lookup packages when searching for conflicting declarations
Minor: use JetTreeVisitor
This commit is contained in:
@@ -442,7 +442,7 @@ fun main(args: Array<String>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractShortenRefsTest>()) {
|
testClass(javaClass<AbstractShortenRefsTest>()) {
|
||||||
model("shortenRefs")
|
model("shortenRefs", pattern = """^([^\.]+)\.kt$""")
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractCompiledKotlinInJavaCompletionTest>()) {
|
testClass(javaClass<AbstractCompiledKotlinInJavaCompletionTest>()) {
|
||||||
|
|||||||
@@ -44,16 +44,12 @@ public object ShortenReferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ResolveAllReferencesVisitor(file: JetFile) : JetVisitorVoid() {
|
private class ResolveAllReferencesVisitor(file: JetFile) : JetTreeVisitorVoid() {
|
||||||
private val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file)
|
private val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file)
|
||||||
private val resolveMap = HashMap<JetReferenceExpression, BindingContext>()
|
private val resolveMap = HashMap<JetReferenceExpression, BindingContext>()
|
||||||
|
|
||||||
public val result: Map<JetReferenceExpression, BindingContext> = resolveMap
|
public val result: Map<JetReferenceExpression, BindingContext> = resolveMap
|
||||||
|
|
||||||
override fun visitJetElement(element : JetElement) {
|
|
||||||
element.acceptChildren(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitUserType(userType: JetUserType) {
|
override fun visitUserType(userType: JetUserType) {
|
||||||
userType.acceptChildren(this)
|
userType.acceptChildren(this)
|
||||||
|
|
||||||
@@ -75,7 +71,7 @@ public object ShortenReferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ShortenTypesVisitor(val file: JetFile, val resolveMap: Map<JetReferenceExpression, BindingContext>) : JetVisitorVoid() {
|
private class ShortenTypesVisitor(val file: JetFile, val resolveMap: Map<JetReferenceExpression, BindingContext>) : JetTreeVisitorVoid() {
|
||||||
private val resolveSession : ResolveSessionForBodies
|
private val resolveSession : ResolveSessionForBodies
|
||||||
get() = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file)
|
get() = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file)
|
||||||
|
|
||||||
@@ -89,10 +85,6 @@ public object ShortenReferences {
|
|||||||
|
|
||||||
private fun bindingContext(expression: JetReferenceExpression): BindingContext = resolveMap[expression]!!
|
private fun bindingContext(expression: JetReferenceExpression): BindingContext = resolveMap[expression]!!
|
||||||
|
|
||||||
override fun visitJetElement(element : JetElement) {
|
|
||||||
element.acceptChildren(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitUserType(userType: JetUserType) {
|
override fun visitUserType(userType: JetUserType) {
|
||||||
userType.getTypeArgumentList()?.accept(this)
|
userType.getTypeArgumentList()?.accept(this)
|
||||||
|
|
||||||
@@ -117,7 +109,7 @@ public object ShortenReferences {
|
|||||||
val typeReference = PsiTreeUtil.getParentOfType(userType, javaClass<JetTypeReference>())!!
|
val typeReference = PsiTreeUtil.getParentOfType(userType, javaClass<JetTypeReference>())!!
|
||||||
val scope = resolveSession.resolveToElement(typeReference).get(BindingContext.TYPE_RESOLUTION_SCOPE, typeReference)!!
|
val scope = resolveSession.resolveToElement(typeReference).get(BindingContext.TYPE_RESOLUTION_SCOPE, typeReference)!!
|
||||||
val name = target.getName()
|
val name = target.getName()
|
||||||
val targetByName = scope.getClassifier(name) ?: scope.getPackage(name)
|
val targetByName = scope.getClassifier(name)
|
||||||
if (targetByName == null) {
|
if (targetByName == null) {
|
||||||
addImportIfNeeded(target, file)
|
addImportIfNeeded(target, file)
|
||||||
return true
|
return true
|
||||||
@@ -141,17 +133,13 @@ public object ShortenReferences {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class ShortenQualifiedExpressionsVisitor(val file: JetFile, val resolveMap: Map<JetReferenceExpression, BindingContext>) : JetVisitorVoid() {
|
private class ShortenQualifiedExpressionsVisitor(val file: JetFile, val resolveMap: Map<JetReferenceExpression, BindingContext>) : JetTreeVisitorVoid() {
|
||||||
private val resolveSession : ResolveSessionForBodies
|
private val resolveSession : ResolveSessionForBodies
|
||||||
get() = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file)
|
get() = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file)
|
||||||
|
|
||||||
private fun bindingContext(expression: JetReferenceExpression): BindingContext
|
private fun bindingContext(expression: JetReferenceExpression): BindingContext
|
||||||
= resolveMap[expression] ?: resolveSession.resolveToElement(expression) // binding context can be absent in the map if some references have been shortened already
|
= resolveMap[expression] ?: resolveSession.resolveToElement(expression) // binding context can be absent in the map if some references have been shortened already
|
||||||
|
|
||||||
override fun visitJetElement(element : JetElement) {
|
|
||||||
acceptChildren(element)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun visitDotQualifiedExpression(expression: JetDotQualifiedExpression) {
|
override fun visitDotQualifiedExpression(expression: JetDotQualifiedExpression) {
|
||||||
val resultElement = processDotQualifiedExpression(expression)
|
val resultElement = processDotQualifiedExpression(expression)
|
||||||
acceptChildren(resultElement)
|
acceptChildren(resultElement)
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package same
|
||||||
|
|
||||||
|
class same() {}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun f(s: <selection>same.same</selection>) {
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
import same.same
|
||||||
|
|
||||||
|
fun f(s: same) {
|
||||||
|
}
|
||||||
@@ -32,6 +32,11 @@ abstract class AbstractShortenRefsTest : LightCodeInsightFixtureTestCase() {
|
|||||||
|
|
||||||
protected fun doTest(testPath: String) {
|
protected fun doTest(testPath: String) {
|
||||||
val fixture = myFixture!!
|
val fixture = myFixture!!
|
||||||
|
val dependencyPath = testPath.replace(".kt", ".dependency.kt")
|
||||||
|
if (File(dependencyPath).exists()) {
|
||||||
|
fixture.configureByFile(dependencyPath)
|
||||||
|
}
|
||||||
|
|
||||||
fixture.configureByFile(testPath)
|
fixture.configureByFile(testPath)
|
||||||
|
|
||||||
val file = fixture.getFile() as JetFile
|
val file = fixture.getFile() as JetFile
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import org.jetbrains.jet.shortenRefs.AbstractShortenRefsTest;
|
|||||||
@InnerTestClasses({ShortenRefsTestGenerated.Constructor.class, ShortenRefsTestGenerated.Type.class})
|
@InnerTestClasses({ShortenRefsTestGenerated.Constructor.class, ShortenRefsTestGenerated.Type.class})
|
||||||
public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
||||||
public void testAllFilesPresentInShortenRefs() throws Exception {
|
public void testAllFilesPresentInShortenRefs() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("JavaStaticMethod.kt")
|
@TestMetadata("JavaStaticMethod.kt")
|
||||||
@@ -45,7 +45,7 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
|||||||
@TestMetadata("idea/testData/shortenRefs/constructor")
|
@TestMetadata("idea/testData/shortenRefs/constructor")
|
||||||
public static class Constructor extends AbstractShortenRefsTest {
|
public static class Constructor extends AbstractShortenRefsTest {
|
||||||
public void testAllFilesPresentInConstructor() throws Exception {
|
public void testAllFilesPresentInConstructor() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs/constructor"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs/constructor"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("Ambiguous.kt")
|
@TestMetadata("Ambiguous.kt")
|
||||||
@@ -108,7 +108,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
|||||||
@TestMetadata("idea/testData/shortenRefs/type")
|
@TestMetadata("idea/testData/shortenRefs/type")
|
||||||
public static class Type extends AbstractShortenRefsTest {
|
public static class Type extends AbstractShortenRefsTest {
|
||||||
public void testAllFilesPresentInType() throws Exception {
|
public void testAllFilesPresentInType() throws Exception {
|
||||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs/type"), Pattern.compile("^(.+)\\.kt$"), true);
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs/type"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ClassSameNameAsPackage.kt")
|
||||||
|
public void testClassSameNameAsPackage() throws Exception {
|
||||||
|
doTest("idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("FunctionType.kt")
|
@TestMetadata("FunctionType.kt")
|
||||||
|
|||||||
Reference in New Issue
Block a user