Do not store external dependencies in ScriptModuleInfo

There is a cache from ScriptModuleInfo to ScriptDependenciesInfo.
In case when only script dependencies are changed we won't recreate the facade for them and will obtain external dependencies for ScriptModuleInfo stored in ScriptDependenciesInfo. So we cannot store external dependencies inside ScriptModuleInfo. The same problem is with relatedModuleSourceInfo.
This commit is contained in:
Natalia Selezneva
2018-05-23 09:14:30 +03:00
parent ab743ef759
commit 2b322ecf9c
10 changed files with 175 additions and 93 deletions
@@ -739,6 +739,7 @@ fun main(args: Array<String>) {
testClass<AbstractScriptConfigurationHighlightingTest> { testClass<AbstractScriptConfigurationHighlightingTest> {
model("script/definition/highlighting", extension = null, recursive = false) model("script/definition/highlighting", extension = null, recursive = false)
model("script/definition/complex", extension = null, recursive = false, testMethod = "doComplexTest")
} }
testClass<AbstractScriptConfigurationNavigationTest> { testClass<AbstractScriptConfigurationNavigationTest> {
@@ -737,6 +737,7 @@ fun main(args: Array<String>) {
testClass<AbstractScriptConfigurationHighlightingTest> { testClass<AbstractScriptConfigurationHighlightingTest> {
model("script/definition/highlighting", extension = null, recursive = false) model("script/definition/highlighting", extension = null, recursive = false)
model("script/definition/complex", extension = null, recursive = false, testMethod = "doComplexTest")
} }
testClass<AbstractScriptConfigurationNavigationTest> { testClass<AbstractScriptConfigurationNavigationTest> {
@@ -736,6 +736,7 @@ fun main(args: Array<String>) {
testClass<AbstractScriptConfigurationHighlightingTest> { testClass<AbstractScriptConfigurationHighlightingTest> {
model("script/definition/highlighting", extension = null, recursive = false) model("script/definition/highlighting", extension = null, recursive = false)
model("script/definition/complex", extension = null, recursive = false, testMethod = "doComplexTest")
} }
testClass<AbstractScriptConfigurationNavigationTest> { testClass<AbstractScriptConfigurationNavigationTest> {
@@ -736,6 +736,7 @@ fun main(args: Array<String>) {
testClass<AbstractScriptConfigurationHighlightingTest> { testClass<AbstractScriptConfigurationHighlightingTest> {
model("script/definition/highlighting", extension = null, recursive = false) model("script/definition/highlighting", extension = null, recursive = false)
model("script/definition/complex", extension = null, recursive = false, testMethod = "doComplexTest")
} }
testClass<AbstractScriptConfigurationNavigationTest> { testClass<AbstractScriptConfigurationNavigationTest> {
@@ -35,11 +35,11 @@ data class ScriptModuleInfo(
override val moduleOrigin: ModuleOrigin override val moduleOrigin: ModuleOrigin
get() = ModuleOrigin.OTHER get() = ModuleOrigin.OTHER
val externalDependencies: ScriptDependencies by lazy { val externalDependencies: ScriptDependencies
ScriptDependenciesManager.getInstance(project).getScriptDependencies(scriptFile) get() = ScriptDependenciesManager.getInstance(project).getScriptDependencies(scriptFile)
}
val relatedModuleSourceInfo: ModuleSourceInfo? = getScriptRelatedModuleInfo(project, scriptFile) val relatedModuleSourceInfo: ModuleSourceInfo?
get() = getScriptRelatedModuleInfo(project, scriptFile)
override val name: Name = Name.special("<script ${scriptFile.name} ${scriptDefinition.name}>") override val name: Name = Name.special("<script ${scriptFile.name} ${scriptDefinition.name}>")
@@ -0,0 +1,7 @@
package test
object KObject {
fun foo() {
}
}
@@ -0,0 +1,7 @@
/*
TestDependenciesResolver returns empty dependencies on first request,
so ComparasionFailure should fail because 'test' is unresolved
Than TestDependenciesResolver returns classpath with classes from 'lib' folder
so no errors expected
*/
test.KObject.foo()
@@ -0,0 +1,27 @@
package custom.scriptDefinition
import java.io.File
import kotlin.script.dependencies.*
import kotlin.script.experimental.dependencies.*
import kotlin.script.templates.ScriptTemplateDefinition
import kotlin.script.experimental.location.ScriptExpectedLocation
import kotlin.script.experimental.location.ScriptExpectedLocations
var count = 0
class TestDependenciesResolver : DependenciesResolver {
override fun resolve(
scriptContents: ScriptContents,
environment: Environment
): DependenciesResolver.ResolveResult {
if (count == 0) {
count++
return ScriptDependencies.Empty.asSuccess()
}
return ScriptDependencies(classpath = listOf(environment["lib-classes"] as File)).asSuccess()
}
}
@ScriptExpectedLocations([ScriptExpectedLocation.Everywhere])
@ScriptTemplateDefinition(TestDependenciesResolver::class, scriptFilePattern = "script.kts")
open class Template
@@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.testFramework.PlatformTestCase import com.intellij.testFramework.PlatformTestCase
import com.intellij.testFramework.PlatformTestUtil import com.intellij.testFramework.PlatformTestUtil
import com.intellij.testFramework.PsiTestUtil import com.intellij.testFramework.PsiTestUtil
import com.intellij.testFramework.exceptionCases.AbstractExceptionCase
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.idea.completion.test.KotlinCompletionTestCase import org.jetbrains.kotlin.idea.completion.test.KotlinCompletionTestCase
import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionContributor import org.jetbrains.kotlin.idea.core.script.ScriptDefinitionContributor
@@ -46,6 +47,7 @@ import org.jetbrains.kotlin.test.util.projectLibrary
import org.jetbrains.kotlin.test.util.renderAsGotoImplementation import org.jetbrains.kotlin.test.util.renderAsGotoImplementation
import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.kotlin.utils.PathUtil
import org.junit.Assert import org.junit.Assert
import org.junit.ComparisonFailure
import java.io.File import java.io.File
import java.util.regex.Pattern import java.util.regex.Pattern
import kotlin.script.dependencies.Environment import kotlin.script.dependencies.Environment
@@ -64,6 +66,20 @@ abstract class AbstractScriptConfigurationHighlightingTest : AbstractScriptConfi
InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_INFOS")) InTextDirectivesUtils.isDirectiveDefined(file.text, "// CHECK_INFOS"))
} }
fun doComplexTest(path: String) {
configureScriptFile(path)
assertException(object : AbstractExceptionCase<ComparisonFailure>() {
override fun getExpectedExceptionClass(): Class<ComparisonFailure> = ComparisonFailure::class.java
override fun tryClosure() {
checkHighlighting(editor, false, false)
}
})
updateScriptDependenciesSynchronously(myFile.virtualFile, project)
checkHighlighting(editor, false, false)
}
override fun setUp() { override fun setUp() {
super.setUp() super.setUp()
ApplicationManager.getApplication().isScriptDependenciesUpdaterDisabled = true ApplicationManager.getApplication().isScriptDependenciesUpdaterDisabled = true
@@ -17,100 +17,121 @@ import java.util.regex.Pattern;
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ /** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all") @SuppressWarnings("all")
@TestMetadata("idea/testData/script/definition/highlighting")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
public class ScriptConfigurationHighlightingTestGenerated extends AbstractScriptConfigurationHighlightingTest { public class ScriptConfigurationHighlightingTestGenerated extends AbstractScriptConfigurationHighlightingTest {
private void runTest(String testDataFilePath) throws Exception { @TestMetadata("idea/testData/script/definition/highlighting")
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Highlighting extends AbstractScriptConfigurationHighlightingTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
}
@TestMetadata("acceptedAnnotations")
public void testAcceptedAnnotations() throws Exception {
runTest("idea/testData/script/definition/highlighting/acceptedAnnotations/");
}
@TestMetadata("additionalImports")
public void testAdditionalImports() throws Exception {
runTest("idea/testData/script/definition/highlighting/additionalImports/");
}
public void testAllFilesPresentInHighlighting() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/script/definition/highlighting"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
}
@TestMetadata("asyncResolver")
public void testAsyncResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/asyncResolver/");
}
@TestMetadata("conflictingModule")
public void testConflictingModule() throws Exception {
runTest("idea/testData/script/definition/highlighting/conflictingModule/");
}
@TestMetadata("customBaseClass")
public void testCustomBaseClass() throws Exception {
runTest("idea/testData/script/definition/highlighting/customBaseClass/");
}
@TestMetadata("customLibrary")
public void testCustomLibrary() throws Exception {
runTest("idea/testData/script/definition/highlighting/customLibrary/");
}
@TestMetadata("doNotSpeakAboutJava")
public void testDoNotSpeakAboutJava() throws Exception {
runTest("idea/testData/script/definition/highlighting/doNotSpeakAboutJava/");
}
@TestMetadata("doNotSpeakAboutJavaLegacy")
public void testDoNotSpeakAboutJavaLegacy() throws Exception {
runTest("idea/testData/script/definition/highlighting/doNotSpeakAboutJavaLegacy/");
}
@TestMetadata("emptyAsyncResolver")
public void testEmptyAsyncResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/emptyAsyncResolver/");
}
@TestMetadata("errorResolver")
public void testErrorResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/errorResolver/");
}
@TestMetadata("javaNestedClass")
public void testJavaNestedClass() throws Exception {
runTest("idea/testData/script/definition/highlighting/javaNestedClass/");
}
@TestMetadata("multiModule")
public void testMultiModule() throws Exception {
runTest("idea/testData/script/definition/highlighting/multiModule/");
}
@TestMetadata("noResolver")
public void testNoResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/noResolver/");
}
@TestMetadata("propertyAccessor")
public void testPropertyAccessor() throws Exception {
runTest("idea/testData/script/definition/highlighting/propertyAccessor/");
}
@TestMetadata("propertyAccessorFromModule")
public void testPropertyAccessorFromModule() throws Exception {
runTest("idea/testData/script/definition/highlighting/propertyAccessorFromModule/");
}
@TestMetadata("simple")
public void testSimple() throws Exception {
runTest("idea/testData/script/definition/highlighting/simple/");
}
@TestMetadata("throwingResolver")
public void testThrowingResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/throwingResolver/");
}
} }
@TestMetadata("acceptedAnnotations") @TestMetadata("idea/testData/script/definition/complex")
public void testAcceptedAnnotations() throws Exception { @TestDataPath("$PROJECT_ROOT")
runTest("idea/testData/script/definition/highlighting/acceptedAnnotations/"); @RunWith(JUnit3RunnerWithInners.class)
} public static class Complex extends AbstractScriptConfigurationHighlightingTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doComplexTest, TargetBackend.ANY, testDataFilePath);
}
@TestMetadata("additionalImports") public void testAllFilesPresentInComplex() throws Exception {
public void testAdditionalImports() throws Exception { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/script/definition/complex"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false);
runTest("idea/testData/script/definition/highlighting/additionalImports/"); }
}
public void testAllFilesPresentInHighlighting() throws Exception { @TestMetadata("errorResolver")
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/script/definition/highlighting"), Pattern.compile("^([^\\.]+)$"), TargetBackend.ANY, false); public void testErrorResolver() throws Exception {
} runTest("idea/testData/script/definition/complex/errorResolver/");
}
@TestMetadata("asyncResolver")
public void testAsyncResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/asyncResolver/");
}
@TestMetadata("conflictingModule")
public void testConflictingModule() throws Exception {
runTest("idea/testData/script/definition/highlighting/conflictingModule/");
}
@TestMetadata("customBaseClass")
public void testCustomBaseClass() throws Exception {
runTest("idea/testData/script/definition/highlighting/customBaseClass/");
}
@TestMetadata("customLibrary")
public void testCustomLibrary() throws Exception {
runTest("idea/testData/script/definition/highlighting/customLibrary/");
}
@TestMetadata("doNotSpeakAboutJava")
public void testDoNotSpeakAboutJava() throws Exception {
runTest("idea/testData/script/definition/highlighting/doNotSpeakAboutJava/");
}
@TestMetadata("doNotSpeakAboutJavaLegacy")
public void testDoNotSpeakAboutJavaLegacy() throws Exception {
runTest("idea/testData/script/definition/highlighting/doNotSpeakAboutJavaLegacy/");
}
@TestMetadata("emptyAsyncResolver")
public void testEmptyAsyncResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/emptyAsyncResolver/");
}
@TestMetadata("errorResolver")
public void testErrorResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/errorResolver/");
}
@TestMetadata("javaNestedClass")
public void testJavaNestedClass() throws Exception {
runTest("idea/testData/script/definition/highlighting/javaNestedClass/");
}
@TestMetadata("multiModule")
public void testMultiModule() throws Exception {
runTest("idea/testData/script/definition/highlighting/multiModule/");
}
@TestMetadata("noResolver")
public void testNoResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/noResolver/");
}
@TestMetadata("propertyAccessor")
public void testPropertyAccessor() throws Exception {
runTest("idea/testData/script/definition/highlighting/propertyAccessor/");
}
@TestMetadata("propertyAccessorFromModule")
public void testPropertyAccessorFromModule() throws Exception {
runTest("idea/testData/script/definition/highlighting/propertyAccessorFromModule/");
}
@TestMetadata("simple")
public void testSimple() throws Exception {
runTest("idea/testData/script/definition/highlighting/simple/");
}
@TestMetadata("throwingResolver")
public void testThrowingResolver() throws Exception {
runTest("idea/testData/script/definition/highlighting/throwingResolver/");
} }
} }