LightClassTest: test corner cases related to inherited visiblity

EA-99155
 #KT-16899 Fixed
This commit is contained in:
Pavel V. Talanov
2017-03-24 15:08:15 +03:00
parent 4b85fd9fbe
commit a81bac0b50
18 changed files with 184 additions and 45 deletions
@@ -0,0 +1,6 @@
package p
abstract class A {
internal val ap: Int = 4
internal fun af(): Int
}
@@ -0,0 +1,7 @@
public final class C extends p.A {
public int getAp$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
public int af$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
public C() { /* compiled code */ }
}
@@ -0,0 +1,13 @@
// p.C
package p
class C : A() {
override val ap: Int
get() = super.c
override fun af(): Int {
return super.foo()
}
}
// LAZINESS:NoConsistency
@@ -0,0 +1,11 @@
package p
abstract class A {
open internal val ap: Int = 4
abstract internal fun af(): Int
}
interface I {
internal val ip: Int
internal fun if(): Int
}
@@ -0,0 +1,13 @@
public final class C extends p.A implements p.I {
private final int ip = 5;
public int getAp$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
public int af$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
public int getIp$production_sources_for_module_light_idea_test_case() { /* compiled code */ }
public int $$<no name provided>$production_sources_for_module_light_idea_test_case /* Real name is '<no name provided>$production_sources_for_module_light_idea_test_case' */() { /* compiled code */ }
public C() { /* compiled code */ }
}
@@ -0,0 +1,16 @@
// p.C
package p
class C : A(), I {
override val ap: Int
get() = super.c
override fun af(): Int {
return super.foo()
}
override val ip = 5
override fun if() = 5
}
// LAZINESS:NoLaziness
@@ -0,0 +1,6 @@
package p
abstract class A {
protected val ap: Int = 4
abstract protected fun af(): Int
}
@@ -0,0 +1,7 @@
public final class C extends p.A {
protected int getAp() { /* compiled code */ }
protected int af() { /* compiled code */ }
public C() { /* compiled code */ }
}
@@ -0,0 +1,13 @@
// p.C
package p
class C : A() {
override val ap: Int
get() = super.c
override fun af(): Int {
return super.foo()
}
}
// LAZINESS:NoLaziness
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
@RunWith(JUnit3RunnerWithInners.class)
public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassTest {
public void testAllFilesPresentInLightClasses() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true, "local");
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true, "local", "ideRegression");
}
@TestMetadata("AnnotationClass.kt")
@@ -98,6 +98,12 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
doTest(fileName);
}
@TestMetadata("PrivateInTrait.kt")
public void testPrivateInTrait() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/PrivateInTrait.kt");
doTest(fileName);
}
@TestMetadata("SameName.kt")
public void testSameName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/SameName.kt");
@@ -110,6 +116,12 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
doTest(fileName);
}
@TestMetadata("TraitClassObjectField.kt")
public void testTraitClassObjectField() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/TraitClassObjectField.kt");
doTest(fileName);
}
@TestMetadata("WrongAnnotations.kt")
public void testWrongAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/WrongAnnotations.kt");
@@ -263,12 +275,6 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
doTest(fileName);
}
@TestMetadata("PrivateInTrait.NoCompile.kt")
public void testPrivateInTrait_NoCompile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInTrait.NoCompile.kt");
doTest(fileName);
}
@TestMetadata("Synthetic.kt")
public void testSynthetic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Synthetic.kt");
@@ -281,12 +287,6 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
doTest(fileName);
}
@TestMetadata("TraitClassObjectField.NoCompile.kt")
public void testTraitClassObjectField_NoCompile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/TraitClassObjectField.NoCompile.kt");
doTest(fileName);
}
@TestMetadata("UnitAsGenericArgument.kt")
public void testUnitAsGenericArgument() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/UnitAsGenericArgument.kt");
@@ -380,7 +380,7 @@ fun main(args: Array<String>) {
}
testClass<AbstractCompilerLightClassTest> {
model("asJava/lightClasses", excludeDirs = listOf("local"))
model("asJava/lightClasses", excludeDirs = listOf("local", "ideRegression"))
}
testClass<AbstractTypeBindingTest> {
@@ -965,11 +965,11 @@ fun main(args: Array<String>) {
testGroup("idea/tests", "compiler/testData") {
testClass<AbstractIdeLightClassTest> {
model("asJava/lightClasses", excludeDirs = listOf("delegation"))
model("asJava/lightClasses", excludeDirs = listOf("delegation"), pattern = KT_WITHOUT_DOTS_IN_NAME)
}
testClass<AbstractIdeCompiledLightClassTest> {
model("asJava/lightClasses", excludeDirs = listOf("local", "compilationErrors"), pattern = KT_WITHOUT_DOTS_IN_NAME)
model("asJava/lightClasses", excludeDirs = listOf("local", "compilationErrors", "ideRegression"), pattern = KT_WITHOUT_DOTS_IN_NAME)
}
}
@@ -48,13 +48,19 @@ import kotlin.test.assertEquals
abstract class AbstractIdeLightClassTest : KotlinLightCodeInsightFixtureTestCase() {
fun doTest(testDataPath: String) {
myFixture.configureByFile(testDataPath)
val extraFilePath = testDataPath.replace(".kt", ".extra.kt")
val testFiles = if (File(extraFilePath).isFile) listOf(testDataPath, extraFilePath) else listOf(testDataPath)
val lazinessMode = lazinessModeByFileText(testDataPath)
myFixture.configureByFiles(*testFiles.toTypedArray())
val ktFile = myFixture.file as KtFile
testLightClass(testDataPath, { LightClassTestCommon.removeEmptyDefaultImpls(it) }) { fqName ->
val tracker = LightClassLazinessChecker.Tracker(fqName)
project.withServiceRegistered<StubComputationTracker, PsiClass?>(tracker) {
findClass(fqName, ktFile, project)?.apply {
LightClassLazinessChecker.check(this as KtLightClass, tracker)
LightClassLazinessChecker.check(this as KtLightClass, tracker, lazinessMode)
tracker.allowLevel(EXACT)
PsiElementChecker.checkPsiElementStructure(this)
}
@@ -62,6 +68,13 @@ abstract class AbstractIdeLightClassTest : KotlinLightCodeInsightFixtureTestCase
}
}
private fun lazinessModeByFileText(testDataPath: String): LightClassLazinessChecker.Mode {
return File(testDataPath).readText().run {
val argument = substringAfter("LAZINESS:", "").substringBefore(" ")
LightClassLazinessChecker.Mode.values().firstOrNull { it.name == argument } ?: LightClassLazinessChecker.Mode.AllChecks
}
}
override fun getProjectDescriptor() = KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
}
@@ -118,6 +131,12 @@ private fun findClass(fqName: String, ktFile: KtFile?, project: Project): PsiCla
object LightClassLazinessChecker {
enum class Mode {
AllChecks,
NoLaziness,
NoConsistency
}
class Tracker(private val fqName: String) : StubComputationTracker {
private var level = NONE
@@ -157,12 +176,16 @@ object LightClassLazinessChecker {
}
}
fun check(lightClass: KtLightClass, tracker: Tracker) {
fun check(lightClass: KtLightClass, tracker: Tracker, lazinessMode: Mode) {
// lighter classes not implemented for locals
if (lightClass.kotlinOrigin?.isLocal ?: false) return
tracker.allowLevel(LIGHT)
if (lazinessMode != Mode.AllChecks) {
tracker.allowLevel(EXACT)
}
// collect method class results on light members that should not trigger exact context evaluation
val fieldsToInfo = lightClass.fields.asList().keysToMap { fieldInfo(it) }
val methodsToInfo = lightClass.methods.asList().keysToMap { methodInfo(it) }
@@ -173,6 +196,9 @@ object LightClassLazinessChecker {
tracker.checkLevel(EXACT)
// still running code above to catch possible exceptions
if (lazinessMode == Mode.NoConsistency) return
// check collected data against delegates which should contain correct data
for ((field, lightFieldInfo) in fieldsToInfo) {
val delegate = (field as KtLightField).clsDelegate
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
@RunWith(JUnit3RunnerWithInners.class)
public class IdeCompiledLightClassTestGenerated extends AbstractIdeCompiledLightClassTest {
public void testAllFilesPresentInLightClasses() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true, "local", "compilationErrors");
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true, "local", "compilationErrors", "ideRegression");
}
@TestMetadata("AnnotationClass.kt")
@@ -33,7 +33,7 @@ import java.util.regex.Pattern;
@RunWith(JUnit3RunnerWithInners.class)
public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
public void testAllFilesPresentInLightClasses() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true, "delegation");
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true, "delegation");
}
@TestMetadata("AnnotationClass.kt")
@@ -89,7 +89,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
@RunWith(JUnit3RunnerWithInners.class)
public static class CompilationErrors extends AbstractIdeLightClassTest {
public void testAllFilesPresentInCompilationErrors() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/compilationErrors"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/compilationErrors"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("AnnotationModifiers.kt")
@@ -98,6 +98,12 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
doTest(fileName);
}
@TestMetadata("PrivateInTrait.kt")
public void testPrivateInTrait() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/PrivateInTrait.kt");
doTest(fileName);
}
@TestMetadata("SameName.kt")
public void testSameName() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/SameName.kt");
@@ -110,6 +116,12 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
doTest(fileName);
}
@TestMetadata("TraitClassObjectField.kt")
public void testTraitClassObjectField() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/TraitClassObjectField.kt");
doTest(fileName);
}
@TestMetadata("WrongAnnotations.kt")
public void testWrongAnnotations() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/compilationErrors/WrongAnnotations.kt");
@@ -122,13 +134,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
@RunWith(JUnit3RunnerWithInners.class)
public static class Facades extends AbstractIdeLightClassTest {
public void testAllFilesPresentInFacades() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("EmptyFile.NoCompile.kt")
public void testEmptyFile_NoCompile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/facades/EmptyFile.NoCompile.kt");
doTest(fileName);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/facades"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("MultiFile.kt")
@@ -150,12 +156,39 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
}
}
@TestMetadata("compiler/testData/asJava/lightClasses/ideRegression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class IdeRegression extends AbstractIdeLightClassTest {
public void testAllFilesPresentInIdeRegression() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/ideRegression"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("OverridingFinalInternal.kt")
public void testOverridingFinalInternal() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/ideRegression/OverridingFinalInternal.kt");
doTest(fileName);
}
@TestMetadata("OverridingInternal.kt")
public void testOverridingInternal() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/ideRegression/OverridingInternal.kt");
doTest(fileName);
}
@TestMetadata("OverridingProtected.kt")
public void testOverridingProtected() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/ideRegression/OverridingProtected.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/asJava/lightClasses/local")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Local extends AbstractIdeLightClassTest {
public void testAllFilesPresentInLocal() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/local"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/local"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("DollarsInNameLocal.kt")
@@ -170,7 +203,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
@RunWith(JUnit3RunnerWithInners.class)
public static class NullabilityAnnotations extends AbstractIdeLightClassTest {
public void testAllFilesPresentInNullabilityAnnotations() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/nullabilityAnnotations"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("Class.kt")
@@ -251,12 +284,6 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
doTest(fileName);
}
@TestMetadata("PrivateInTrait.NoCompile.kt")
public void testPrivateInTrait_NoCompile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInTrait.NoCompile.kt");
doTest(fileName);
}
@TestMetadata("Synthetic.kt")
public void testSynthetic() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/Synthetic.kt");
@@ -269,12 +296,6 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
doTest(fileName);
}
@TestMetadata("TraitClassObjectField.NoCompile.kt")
public void testTraitClassObjectField_NoCompile() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/TraitClassObjectField.NoCompile.kt");
doTest(fileName);
}
@TestMetadata("UnitAsGenericArgument.kt")
public void testUnitAsGenericArgument() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/asJava/lightClasses/nullabilityAnnotations/UnitAsGenericArgument.kt");
@@ -299,7 +320,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
@RunWith(JUnit3RunnerWithInners.class)
public static class Object extends AbstractIdeLightClassTest {
public void testAllFilesPresentInObject() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/object"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("SimpleObject.kt")
@@ -314,7 +335,7 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
@RunWith(JUnit3RunnerWithInners.class)
public static class PublicField extends AbstractIdeLightClassTest {
public void testAllFilesPresentInPublicField() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/asJava/lightClasses/publicField"), Pattern.compile("^([^.]+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("CompanionObject.kt")