Track lookups for conventions

Original commit: 27a196b25b
This commit is contained in:
Zalim Bashorov
2015-09-16 23:12:01 +03:00
parent e3aa1fa4cb
commit 62dcbf8aab
7 changed files with 144 additions and 4 deletions
@@ -21,9 +21,11 @@ import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.test.JetTestUtils
import org.jetbrains.kotlin.utils.join
import java.io.File
import java.util.ArrayList
import java.util.*
import kotlin.test.fail
private val DECLARATION_KEYWORDS = listOf("interface", "class", "enum class", "object", "fun", "val", "var")
abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
allowNoFilesWithSuffixInTestData = true,
allowNoBuildLogFileInTestData = true
@@ -48,14 +50,13 @@ abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
val matchResult = COMMENT_WITH_LOOKUP_INFO.match(text)
if (matchResult != null) {
matchResult.groups
fail("File $file unexpectedly contains multiline comments. In range ${matchResult.range} found: ${matchResult.value} in $text")
}
val lines = text.lines().toArrayList()
for ((line, lookupsFromLine) in lookupsFromFile.groupBy { it.lookupLine!! }) {
val columnToLookups = lookupsFromLine.groupBy { it.lookupColumn!! }.toList().sortBy { it.first }
val columnToLookups = lookupsFromLine.groupBy { it.lookupColumn!! }.toList().sortedBy { it.first }
val lineContent = lines[line - 1]
val parts = ArrayList<CharSequence>(columnToLookups.size() * 2)
@@ -67,8 +68,20 @@ abstract class AbstractLookupTrackerTest : AbstractIncrementalJpsTest(
parts.add(lineContent.subSequence(start, end))
val lookups = lookupsFromColumn.distinct().joinToString(separator = " ", prefix = "/*", postfix = "*/") {
it.scopeKind.toString()[0].toLowerCase().toString() + ":" + it.scopeFqName
val rest = lineContent.substring(end)
val name =
when {
rest.startsWith(it.name) || // same name
rest.startsWith("$" + it.name) || // backing field
DECLARATION_KEYWORDS.any { w -> rest.startsWith(w) } // it's declaration
-> ""
else -> "(" + it.name + ")"
}
it.scopeKind.toString()[0].toLowerCase().toString() + ":" + it.scopeFqName + name
}
parts.add(lookups)
start = end
@@ -41,6 +41,12 @@ public class LookupTrackerTestGenerated extends AbstractLookupTrackerTest {
doTest(fileName);
}
@TestMetadata("conventions")
public void testConventions() throws Exception {
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/lookupTracker/conventions/");
doTest(fileName);
}
@TestMetadata("localDeclarations")
public void testLocalDeclarations() throws Exception {
String fileName = JetTestUtils.navigationMetadata("jps-plugin/testData/incremental/lookupTracker/localDeclarations/");
@@ -0,0 +1,18 @@
package foo.bar
/*p:foo.bar*/fun testComparisons(a: /*p:foo.bar*/A, b: /*p:foo.bar*/Int, c: /*p:foo.bar*/Any, na: /*p:foo.bar*/A?) {
a /*c:foo.bar.A(equals)*/== c
a /*c:foo.bar.A(equals)*/!= c
na /*c:foo.bar.A(equals)*/== a
na /*c:foo.bar.A(equals)*/== null
a /*c:foo.bar.A(compareTo)*/> b
a /*c:foo.bar.A(compareTo)*/< b
a /*c:foo.bar.A(compareTo)*/>= b
a /*c:foo.bar.A(compareTo)*/<= b
a /*c:foo.bar.A(compareTo) p:foo.bar(compareTo)*/> c
a /*c:foo.bar.A(compareTo) p:foo.bar(compareTo)*/< c
a /*c:foo.bar.A(compareTo) p:foo.bar(compareTo)*/>= c
a /*c:foo.bar.A(compareTo) p:foo.bar(compareTo)*/<= c
}
@@ -0,0 +1,35 @@
package foo.bar
/*p:foo.bar*/class A {
fun plus(a: /*c:foo.bar.A p:foo.bar*/Int) = this
fun timesAssign(a: /*c:foo.bar.A p:foo.bar*/Any?) {}
fun inc(): /*c:foo.bar.A p:foo.bar*/A = this
fun get(i: /*c:foo.bar.A p:foo.bar*/Int) = 1
fun contains(a: /*c:foo.bar.A p:foo.bar*/Int): /*c:foo.bar.A p:foo.bar*/Boolean = false
fun invoke() {}
fun compareTo(a: /*c:foo.bar.A p:foo.bar*/Int) = 0
fun component1() = this
fun iterator() = this
fun next() = this
}
/*p:foo.bar*/fun /*p:foo.bar*/A.minus(a: /*p:foo.bar*/Int) = this
/*p:foo.bar*/fun /*p:foo.bar*/A.divAssign(a: /*p:foo.bar*/Any?) {}
/*p:foo.bar*/fun /*p:foo.bar*/A.dec(): /*p:foo.bar*/A = this
/*p:foo.bar*/fun /*p:foo.bar*/A.not() {}
/*p:foo.bar*/fun /*p:foo.bar*/A.set(i: /*p:foo.bar*/Int, v: /*p:foo.bar*/Int) {}
/*p:foo.bar*/fun /*p:foo.bar*/A.contains(a: /*p:foo.bar*/Any): /*p:foo.bar*/Boolean = true
/*p:foo.bar*/fun /*p:foo.bar*/A.invoke(i: /*p:foo.bar*/Int) {}
/*p:foo.bar*/fun /*p:foo.bar*/A.compareTo(a: /*p:foo.bar*/Any) = 0
/*p:foo.bar*/fun /*p:foo.bar*/A.component2() = this
/*p:foo.bar*/fun /*p:foo.bar*/A?.iterator() = this!!
/*p:foo.bar*/fun /*p:foo.bar*/A.hasNext(): /*p:foo.bar*/Boolean = false
@@ -0,0 +1,28 @@
package foo.bar
/*p:foo.bar*/class D1 {
fun get(t: /*c:foo.bar.D1 p:foo.bar*/Any?, p: /*c:foo.bar.D1 p:foo.bar*/PropertyMetadata) = 1
}
/*p:foo.bar*/fun /*p:foo.bar*/D1.set(t: /*p:foo.bar*/Any?, p: /*p:foo.bar*/PropertyMetadata, v: /*p:foo.bar*/Int) {}
/*p:foo.bar(D2)*/open class D2 {
fun set(t: /*c:foo.bar.D2 p:foo.bar*/Any?, p: /*c:foo.bar.D2 p:foo.bar*/PropertyMetadata, v: /*c:foo.bar.D2 p:foo.bar*/Int) {}
}
/*p:foo.bar*/fun /*p:foo.bar*/D2.get(t: /*p:foo.bar*/Any?, p: /*p:foo.bar*/PropertyMetadata) = 1
/*p:foo.bar*/fun /*p:foo.bar*/D2.propertyDelegated(p: /*p:foo.bar*/Any?) {}
/*p:foo.bar*/class D3 : /*p:foo.bar*/D2() {
fun propertyDelegated(p: /*c:foo.bar.D3 p:foo.bar*/Any?) {}
}
/*p:foo.bar*/val x1 by /*p:foo.bar c:foo.bar.D1(get) c:foo.bar.D1(propertyDelegated) p:foo.bar(propertyDelegated)*/D1()
/*p:foo.bar*/var y1 by /*p:foo.bar c:foo.bar.D1(get) c:foo.bar.D1(set) p:foo.bar(set) c:foo.bar.D1(propertyDelegated) p:foo.bar(propertyDelegated)*/D1()
/*p:foo.bar*/val x2 by /*p:foo.bar c:foo.bar.D2(get) p:foo.bar(get) c:foo.bar.D2(propertyDelegated) p:foo.bar(propertyDelegated)*/D2()
/*p:foo.bar*/var y2 by /*p:foo.bar c:foo.bar.D2(get) p:foo.bar(get) c:foo.bar.D2(set) c:foo.bar.D2(propertyDelegated) p:foo.bar(propertyDelegated)*/D2()
/*p:foo.bar*/val x3 by /*p:foo.bar c:foo.bar.D3(get) p:foo.bar(get) c:foo.bar.D3(propertyDelegated)*/D3()
/*p:foo.bar*/var y3 by /*p:foo.bar c:foo.bar.D3(get) p:foo.bar(get) c:foo.bar.D3(set) c:foo.bar.D3(propertyDelegated)*/D3()
@@ -0,0 +1,24 @@
package foo.bar
/*p:foo.bar*/fun testOperators(a: /*p:foo.bar*/A, b: /*p:foo.bar*/Int) {
var d = a
d/*c:foo.bar.A(inc)*/++
/*c:foo.bar.A(inc)*/++d
d/*c:foo.bar.A(dec) p:foo.bar(dec)*/--
/*c:foo.bar.A(dec) p:foo.bar(dec)*/--d
a /*c:foo.bar.A(plus)*/+ b
a /*c:foo.bar.A(minus) p:foo.bar(minus)*/- b
/*c:foo.bar.A(not) p:foo.bar(not)*/!a
// for val
a /*c:foo.bar.A(timesAssign)*/*= b
a /*c:foo.bar.A(divAssign) p:foo.bar(divAssign)*//= b
// for var
d /*c:foo.bar.A(plusAssign) p:foo.bar(plusAssign) c:foo.bar.A(plus)*/+= b
d /*c:foo.bar.A(minusAssign) p:foo.bar(minusAssign) c:foo.bar.A(minus) p:foo.bar(minus)*/-= b
d /*c:foo.bar.A(timesAssign) c:foo.bar.A(times) p:foo.bar(times)*/*= b
d /*c:foo.bar.A(divAssign) p:foo.bar(divAssign) c:foo.bar.A(div) p:foo.bar(div)*//= b
}
@@ -0,0 +1,16 @@
package foo.bar
/*p:foo.bar*/fun testOther(a: /*p:foo.bar*/A, b: /*p:foo.bar*/Int, c: /*p:foo.bar*/Any, na: /*p:foo.bar*/A?) {
/*c:foo.bar.A(set) p:foo.bar(set)*/a[1] = /*c:foo.bar.A(get)*/a[2]
b /*c:foo.bar.A(contains)*/in a
"s" /*c:foo.bar.A(contains) p:foo.bar(contains)*/!in a
/*p:foo.bar c:foo.bar.A(invoke)*/a()
/*p:foo.bar c:foo.bar.A(invoke) p:foo.bar(invoke)*/a(1)
val (/*c:foo.bar.A(component1)*/h, /*c:foo.bar.A(component2) p:foo.bar(component2)*/t) = a;
for ((/*c:foo.bar.A(component1)*/f, /*c:foo.bar.A(component2) p:foo.bar(component2)*/s) in /*c:foo.bar.A(iterator) c:foo.bar.A(hasNext) p:foo.bar(hasNext) c:foo.bar.A(next)*/a);
for ((/*c:foo.bar.A(component1)*/f, /*c:foo.bar.A(component2) p:foo.bar(component2)*/s) in /*c:foo.bar.A(iterator) p:foo.bar(iterator) c:foo.bar.A(hasNext) p:foo.bar(hasNext) c:foo.bar.A(next)*/na);
}