Fix bug in ShortenReferences visitor (do not skip PSI elements after modication)

This commit is contained in:
Alexey Sedunov
2014-04-17 13:26:47 +04:00
parent 95b4ec2058
commit cceaa3b66f
4 changed files with 42 additions and 1 deletions
@@ -107,13 +107,17 @@ public object ShortenReferences {
}
}
private class ShortenQualifiedExpressionsVisitor(val file: JetFile, val resolveMap: Map<JetReferenceExpression, BindingContext>) : JetTreeVisitorVoid() {
private class ShortenQualifiedExpressionsVisitor(val file: JetFile, val resolveMap: Map<JetReferenceExpression, BindingContext>) : JetVisitorVoid() {
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)
+16
View File
@@ -0,0 +1,16 @@
package p.q
<selection>fun foo(): Int {
p.q.MyClass.foo()
return p.q.MyClass.coProp + 10
}</selection>
class MyClass {
class object {
val coProp = 1
fun foo() {
}
}
}
@@ -0,0 +1,16 @@
package p.q
fun foo(): Int {
MyClass.foo()
return MyClass.coProp + 10
}
class MyClass {
class object {
val coProp = 1
fun foo() {
}
}
}
@@ -37,6 +37,11 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/shortenRefs"), Pattern.compile("^([^\\.]+)\\.kt$"), true);
}
@TestMetadata("classObject.kt")
public void testClassObject() throws Exception {
doTest("idea/testData/shortenRefs/classObject.kt");
}
@TestMetadata("JavaStaticMethod.kt")
public void testJavaStaticMethod() throws Exception {
doTest("idea/testData/shortenRefs/JavaStaticMethod.kt");