diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index ad8df2c6c9c..d4d3ca1b6c9 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -442,7 +442,7 @@ fun main(args: Array) { } testClass(javaClass()) { - model("shortenRefs") + model("shortenRefs", pattern = """^([^\.]+)\.kt$""") } testClass(javaClass()) { diff --git a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt index a38f81bb9a2..1fb56e7a8a9 100644 --- a/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt +++ b/idea/src/org/jetbrains/jet/plugin/codeInsight/ShortenReferences.kt @@ -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 resolveMap = HashMap() public val result: Map = resolveMap - override fun visitJetElement(element : JetElement) { - element.acceptChildren(this) - } - override fun visitUserType(userType: JetUserType) { userType.acceptChildren(this) @@ -75,7 +71,7 @@ public object ShortenReferences { } } - private class ShortenTypesVisitor(val file: JetFile, val resolveMap: Map) : JetVisitorVoid() { + private class ShortenTypesVisitor(val file: JetFile, val resolveMap: Map) : JetTreeVisitorVoid() { private val resolveSession : ResolveSessionForBodies get() = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file) @@ -89,10 +85,6 @@ public object ShortenReferences { private fun bindingContext(expression: JetReferenceExpression): BindingContext = resolveMap[expression]!! - override fun visitJetElement(element : JetElement) { - element.acceptChildren(this) - } - override fun visitUserType(userType: JetUserType) { userType.getTypeArgumentList()?.accept(this) @@ -117,7 +109,7 @@ public object ShortenReferences { val typeReference = PsiTreeUtil.getParentOfType(userType, javaClass())!! val scope = resolveSession.resolveToElement(typeReference).get(BindingContext.TYPE_RESOLUTION_SCOPE, typeReference)!! val name = target.getName() - val targetByName = scope.getClassifier(name) ?: scope.getPackage(name) + val targetByName = scope.getClassifier(name) if (targetByName == null) { addImportIfNeeded(target, file) return true @@ -141,17 +133,13 @@ public object ShortenReferences { } } - private class ShortenQualifiedExpressionsVisitor(val file: JetFile, val resolveMap: Map) : JetVisitorVoid() { + private class ShortenQualifiedExpressionsVisitor(val file: JetFile, val resolveMap: Map) : JetTreeVisitorVoid() { private val resolveSession : ResolveSessionForBodies get() = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(file) 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 - override fun visitJetElement(element : JetElement) { - acceptChildren(element) - } - override fun visitDotQualifiedExpression(expression: JetDotQualifiedExpression) { val resultElement = processDotQualifiedExpression(expression) acceptChildren(resultElement) diff --git a/idea/testData/shortenRefs/type/ClassSameNameAsPackage.dependency.kt b/idea/testData/shortenRefs/type/ClassSameNameAsPackage.dependency.kt new file mode 100644 index 00000000000..4ea23c543e6 --- /dev/null +++ b/idea/testData/shortenRefs/type/ClassSameNameAsPackage.dependency.kt @@ -0,0 +1,3 @@ +package same + +class same() {} \ No newline at end of file diff --git a/idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt b/idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt new file mode 100644 index 00000000000..7152c0070e2 --- /dev/null +++ b/idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt @@ -0,0 +1,2 @@ +fun f(s: same.same) { +} \ No newline at end of file diff --git a/idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt.after b/idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt.after new file mode 100644 index 00000000000..ec85b599c0a --- /dev/null +++ b/idea/testData/shortenRefs/type/ClassSameNameAsPackage.kt.after @@ -0,0 +1,4 @@ +import same.same + +fun f(s: same) { +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/shortenRefs/AbstractShortenRefsTest.kt b/idea/tests/org/jetbrains/jet/shortenRefs/AbstractShortenRefsTest.kt index 28687fbbdfc..3efb43a91f1 100644 --- a/idea/tests/org/jetbrains/jet/shortenRefs/AbstractShortenRefsTest.kt +++ b/idea/tests/org/jetbrains/jet/shortenRefs/AbstractShortenRefsTest.kt @@ -32,6 +32,11 @@ abstract class AbstractShortenRefsTest : LightCodeInsightFixtureTestCase() { protected fun doTest(testPath: String) { val fixture = myFixture!! + val dependencyPath = testPath.replace(".kt", ".dependency.kt") + if (File(dependencyPath).exists()) { + fixture.configureByFile(dependencyPath) + } + fixture.configureByFile(testPath) val file = fixture.getFile() as JetFile diff --git a/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java b/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java index dd77809f088..9453331986e 100644 --- a/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/shortenRefs/ShortenRefsTestGenerated.java @@ -34,7 +34,7 @@ import org.jetbrains.jet.shortenRefs.AbstractShortenRefsTest; @InnerTestClasses({ShortenRefsTestGenerated.Constructor.class, ShortenRefsTestGenerated.Type.class}) public class ShortenRefsTestGenerated extends AbstractShortenRefsTest { 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") @@ -45,7 +45,7 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest { @TestMetadata("idea/testData/shortenRefs/constructor") public static class Constructor extends AbstractShortenRefsTest { 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") @@ -108,7 +108,12 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest { @TestMetadata("idea/testData/shortenRefs/type") public static class Type extends AbstractShortenRefsTest { 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")