Teach index working with source roots with package prefix
#KT-9167 Fixed
This commit is contained in:
committed by
Nikolay Krasko
parent
c0739ef53c
commit
23e35ab112
@@ -59,7 +59,8 @@ public class JvmDependenciesIndex(_roots: List<JavaRoot>) {
|
||||
val rootIndices = IntArrayList()
|
||||
}
|
||||
|
||||
// root "Cache" object corresponds to DefaultPackage which exists in every root
|
||||
// root "Cache" object corresponds to DefaultPackage which exists in every root. Roots with non-default fqname are also listed here but
|
||||
// they will be ignored on requests with invalid fqname prefix.
|
||||
private val rootCache: Cache by lazy {
|
||||
with(Cache()) {
|
||||
roots.indices.forEach {
|
||||
@@ -208,10 +209,23 @@ public class JvmDependenciesIndex(_roots: List<JavaRoot>) {
|
||||
return null
|
||||
}
|
||||
|
||||
var currentFile = roots[rootIndex].file
|
||||
val pathRoot = roots[rootIndex]
|
||||
val prefixPathSegments = pathRoot.prefixFqName?.pathSegments()
|
||||
|
||||
var currentFile = pathRoot.file
|
||||
|
||||
for (pathIndex in packagesPath.indices) {
|
||||
val subPackageName = packagesPath[pathIndex]
|
||||
currentFile = currentFile.findChild(subPackageName) ?: return null
|
||||
if (prefixPathSegments != null && pathIndex < prefixPathSegments.size) {
|
||||
// Traverse prefix first instead of traversing real directories
|
||||
if (prefixPathSegments[pathIndex].identifier != subPackageName) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
else {
|
||||
currentFile = currentFile.findChild(subPackageName) ?: return null
|
||||
}
|
||||
|
||||
val correspondingCacheIndex = pathIndex + 1
|
||||
if (correspondingCacheIndex > fillCachesAfter) {
|
||||
// subPackageName exists in this root
|
||||
|
||||
@@ -225,6 +225,19 @@ public class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() {
|
||||
checkWhen(touch("src/test1.kt"), null, packageClasses("kotlinProject", "src/test1.kt", "Test1Kt"))
|
||||
}
|
||||
|
||||
public fun testSourcePackagePrefix() {
|
||||
doTest()
|
||||
}
|
||||
|
||||
public fun testSourcePackageLongPrefix() {
|
||||
initProject()
|
||||
val buildResult = makeAll()
|
||||
buildResult.assertSuccessful()
|
||||
val warnings = buildResult.getMessages(BuildMessage.Kind.WARNING)
|
||||
assertEquals("Warning about invalid package prefix in module 2 is expected: $warnings", 2, warnings.size)
|
||||
assertEquals("Invalid package prefix name is ignored: invalid-prefix.test", warnings.first().messageText)
|
||||
}
|
||||
|
||||
public fun testKotlinJavaScriptProject() {
|
||||
initProject()
|
||||
addKotlinJavaScriptStdlibDependency()
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
<resourceExtensions />
|
||||
<annotationProcessing>
|
||||
<profile default="true" name="Default" enabled="false">
|
||||
<processorPath useClasspath="true" />
|
||||
</profile>
|
||||
</annotationProcessing>
|
||||
</component>
|
||||
<component name="CopyrightManager" default="">
|
||||
<module2copyright />
|
||||
</component>
|
||||
<component name="DependencyValidationManager">
|
||||
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
|
||||
</component>
|
||||
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/module1/module1.iml" filepath="$PROJECT_DIR$/module1/module1.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/module2/module2.iml" filepath="$PROJECT_DIR$/module2/module2.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="" />
|
||||
</component>
|
||||
</project>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="good.prefix" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
package good.prefix;
|
||||
|
||||
public class JavaDependency {
|
||||
public void bar() {}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package good.prefix;
|
||||
|
||||
public class JavaTest extends JavaDependency {
|
||||
|
||||
}
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package bad.prefix
|
||||
|
||||
class KotlinTestInBadPrefix
|
||||
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package good.prefix
|
||||
|
||||
class KotlinTestInGoodPrefix
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package test.other
|
||||
|
||||
import bad.prefix.KotlinTestInBadPrefix
|
||||
import good.prefix.KotlinTestInGoodPrefix
|
||||
import good.prefix.JavaTest;
|
||||
|
||||
val goodTest = KotlinTestInGoodPrefix()
|
||||
val badTest = KotlinTestInBadPrefix()
|
||||
val javaTest = JavaTest().bar()
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="invalid-prefix.test"/>
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="module1" />
|
||||
<orderEntry type="library" name="KotlinRuntime" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package some
|
||||
|
||||
import bad.prefix.KotlinTestInBadPrefix
|
||||
import good.prefix.KotlinTestInGoodPrefix
|
||||
import good.prefix.JavaTest;
|
||||
import test.JavaRef
|
||||
|
||||
val goodTest = KotlinTestInGoodPrefix()
|
||||
val badTest = KotlinTestInBadPrefix()
|
||||
val javaTest = JavaTest().bar()
|
||||
val javaRef = JavaRef().foo(null)
|
||||
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package test;
|
||||
|
||||
import good.prefix.JavaTest;
|
||||
|
||||
public class JavaRef {
|
||||
public void foo(JavaTest javaTest) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" packagePrefix="xxx"/>
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="IDEA_JDK" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="module" module-name="kotlinProject" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||
</component>
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/kotlinProject.iml" filepath="$PROJECT_DIR$/kotlinProject.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="IDEA_JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,4 @@
|
||||
package xxx;
|
||||
|
||||
public class OtherJava {
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package xxx;
|
||||
|
||||
public class Test {
|
||||
String test(OtherJava otherJava) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package xxx
|
||||
|
||||
val test = Test().test(null)
|
||||
Reference in New Issue
Block a user