From c9eb313ec4c8f9fd7da4dd7577474bae81d16a30 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Tue, 22 Apr 2014 18:27:46 +0400 Subject: [PATCH] Add MultiFileHighlightingTest which checks that other files are not parsed during highlighting --- .../jet/generators/tests/GenerateTests.kt | 5 ++ .../delegatesReference.kt | 11 +++ .../dependencies/delegates.kt | 12 +++ .../dependencies/enums.kt | 18 ++++ .../dependencies/util.kt | 49 ++++++++++ .../multiFileHighlighting/enumReference.kt | 17 ++++ .../referencesFunWithUnspecifiedType.kt | 8 ++ .../topLevelMembersReference.kt | 23 +++++ .../AbstractMultiFileHighlightingTest.java | 89 +++++++++++++++++++ .../MultiFileHighlightingTestGenerated.java | 59 ++++++++++++ 10 files changed, 291 insertions(+) create mode 100644 idea/testData/multiFileHighlighting/delegatesReference.kt create mode 100644 idea/testData/multiFileHighlighting/dependencies/delegates.kt create mode 100644 idea/testData/multiFileHighlighting/dependencies/enums.kt create mode 100644 idea/testData/multiFileHighlighting/dependencies/util.kt create mode 100644 idea/testData/multiFileHighlighting/enumReference.kt create mode 100644 idea/testData/multiFileHighlighting/referencesFunWithUnspecifiedType.kt create mode 100644 idea/testData/multiFileHighlighting/topLevelMembersReference.kt create mode 100644 idea/tests/org/jetbrains/jet/plugin/stubs/AbstractMultiFileHighlightingTest.java create mode 100644 idea/tests/org/jetbrains/jet/plugin/stubs/MultiFileHighlightingTestGenerated.java diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index e413254329c..19db2ae90c8 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -111,6 +111,7 @@ import org.jetbrains.jet.plugin.debugger.evaluate.AbstractSelectExpressionForDeb import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentCompletionTest import org.jetbrains.jet.plugin.debugger.evaluate.AbstractCodeFragmentHighlightingTest import org.jetbrains.jet.plugin.stubs.AbstractLazyResolveByStubTest +import org.jetbrains.jet.plugin.stubs.AbstractMultiFileHighlightingTest fun main(args: Array) { System.setProperty("java.awt.headless", "true") @@ -602,6 +603,10 @@ fun main(args: Array) { model("completion/basic/multifile", extension = null, recursive = false) } + testClass(javaClass()) { + model("multiFileHighlighting", recursive = false) + } + testClass(javaClass()) { model("refactoring/introduceVariable", extension = "kt", testMethod = "doIntroduceVariableTest") model("refactoring/extractFunction", extension = "kt", testMethod = "doExtractFunctionTest") diff --git a/idea/testData/multiFileHighlighting/delegatesReference.kt b/idea/testData/multiFileHighlighting/delegatesReference.kt new file mode 100644 index 00000000000..ef90d294c8f --- /dev/null +++ b/idea/testData/multiFileHighlighting/delegatesReference.kt @@ -0,0 +1,11 @@ +package test + +import delegates.* +import util.* + +fun f() { + val d = D(C("", 0), object : T2 {}) + d.anotherFun() + d.invalidFun() + WithDelegatedProperty().i +} \ No newline at end of file diff --git a/idea/testData/multiFileHighlighting/dependencies/delegates.kt b/idea/testData/multiFileHighlighting/dependencies/delegates.kt new file mode 100644 index 00000000000..57a0b32097a --- /dev/null +++ b/idea/testData/multiFileHighlighting/dependencies/delegates.kt @@ -0,0 +1,12 @@ +package delegates + +import util.* + +class D(val t: T, val t2: T2): T by t, T2 by t2 { + fun anotherFun() { + } +} + +class WithDelegatedProperty() { + val i: Int by someInvalidCode +} \ No newline at end of file diff --git a/idea/testData/multiFileHighlighting/dependencies/enums.kt b/idea/testData/multiFileHighlighting/dependencies/enums.kt new file mode 100644 index 00000000000..a49758fc378 --- /dev/null +++ b/idea/testData/multiFileHighlighting/dependencies/enums.kt @@ -0,0 +1,18 @@ +package enums + +trait Base { + fun f() { + } +} + +enum class E(val i: Int = 0): Base { + E1: E() { + override fun f() { + } + } + E2: E(3) { + override fun f() { + } + } + E3 +} \ No newline at end of file diff --git a/idea/testData/multiFileHighlighting/dependencies/util.kt b/idea/testData/multiFileHighlighting/dependencies/util.kt new file mode 100644 index 00000000000..bd6a258f167 --- /dev/null +++ b/idea/testData/multiFileHighlighting/dependencies/util.kt @@ -0,0 +1,49 @@ +public package util + +trait T { + fun f() +} + +trait T2 { + fun g() { + } +} + +suppress("UNRESOLVED_REFERENCE") +class Invalid: I + +class A(val i: Int) + +suppress("FINAL_SUPERTYPE") +class B: A(1) { +} + +open class C(val s: String, i: Int): A(i), T { + override fun f() {} +} + +fun topLevelFun(u: A): A { + return A(u.i) +} + +val topLevelVal: A = C("", 0) +var topLevelVar: A = B() + +object topLevelObject: T { + override fun f() { + + } + + fun g() { + } +} + +fun funWithUnspecifiedType() = 3 + +fun funWithVararg(vararg i: Int): IntArray { + return i +} + +fun funWithWhere(a: G, b: T) where T: Collection { + +} \ No newline at end of file diff --git a/idea/testData/multiFileHighlighting/enumReference.kt b/idea/testData/multiFileHighlighting/enumReference.kt new file mode 100644 index 00000000000..88b5b780ec6 --- /dev/null +++ b/idea/testData/multiFileHighlighting/enumReference.kt @@ -0,0 +1,17 @@ +package some + +import enums.E +import enums.Base + +fun f(e: Base) { + +} + +fun test() { + f(E.E1) + f(E.E2) + f(E.E3) + f(E.E4) + f(E.Invalid) + E.E1.f() +} \ No newline at end of file diff --git a/idea/testData/multiFileHighlighting/referencesFunWithUnspecifiedType.kt b/idea/testData/multiFileHighlighting/referencesFunWithUnspecifiedType.kt new file mode 100644 index 00000000000..6c73bf3c8bd --- /dev/null +++ b/idea/testData/multiFileHighlighting/referencesFunWithUnspecifiedType.kt @@ -0,0 +1,8 @@ +package shouldFail + +import util.* + +fun f() { + val c = funWithUnspecifiedType() + c + 3 +} diff --git a/idea/testData/multiFileHighlighting/topLevelMembersReference.kt b/idea/testData/multiFileHighlighting/topLevelMembersReference.kt new file mode 100644 index 00000000000..00177ed4500 --- /dev/null +++ b/idea/testData/multiFileHighlighting/topLevelMembersReference.kt @@ -0,0 +1,23 @@ +package first + +import util.* + +fun test() { + topLevelFun(topLevelVar) + topLevelFun(topLevelVal) + val c = C("ff", 1) + c.s.invalid + val b = B() + funWithVararg(1, 2, 3) + val i = Invalid() + topLevelObject.f() + topLevelObject.g() + } + +fun testWhere(list: List) { + funWithWhere(1, list) + funWithWhere(1, 2) +} + +class Example : C("foo", 0) +class Example2 : A(2) diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/AbstractMultiFileHighlightingTest.java b/idea/tests/org/jetbrains/jet/plugin/stubs/AbstractMultiFileHighlightingTest.java new file mode 100644 index 00000000000..baee7409d91 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/AbstractMultiFileHighlightingTest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.stubs; + +import com.intellij.codeInsight.completion.CompletionTestCase; +import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl; +import com.intellij.codeInsight.daemon.impl.HighlightInfo; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.project.DumbService; +import com.intellij.psi.PsiDocumentManager; +import com.intellij.psi.impl.cache.CacheManager; +import com.intellij.psi.impl.source.tree.TreeElement; +import com.intellij.psi.impl.source.tree.TreeUtil; +import com.intellij.psi.search.GlobalSearchScope; +import com.intellij.psi.search.UsageSearchContext; +import com.intellij.testFramework.ExpectedHighlightingData; +import kotlin.Function0; +import kotlin.Unit; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.jet.plugin.PluginTestCaseBase; + +import java.io.File; +import java.util.Collection; + +public abstract class AbstractMultiFileHighlightingTest extends CompletionTestCase { + + public void doTest(@NotNull String filePath) throws Exception { + configureByFile(new File(filePath).getName(), ""); + boolean shouldFail = getName().contains("UnspecifiedType"); + AstAccessControl.instance$.testWithControlledAccessToAst( + shouldFail, getFile().getVirtualFile(), getProject(), getTestRootDisposable(), + new Function0() { + @Override + public Unit invoke() { + checkHighlighting(myEditor, true, false); + return Unit.VALUE; + } + } + ); + } + + @Override + protected String getTestDataPath() { + return PluginTestCaseBase.getTestDataPathBase() + "/multiFileHighlighting/"; + } + + //NOTE: partially copied from DaemonAnalyzerTestCase#checkHighlighting + @Override + @NotNull + protected Collection checkHighlighting(@NotNull ExpectedHighlightingData data) { + data.init(); + PsiDocumentManager.getInstance(myProject).commitAllDocuments(); + + //to load text + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + TreeUtil.clearCaches((TreeElement) myFile.getNode()); + } + }); + + //to initialize caches + if (!DumbService.isDumb(getProject())) { + CacheManager.SERVICE.getInstance(myProject) + .getFilesWithWord("XXX", UsageSearchContext.IN_COMMENTS, GlobalSearchScope.allScope(myProject), true); + } + + Collection infos = doHighlighting(); + + String text = myEditor.getDocument().getText(); + data.checkLineMarkers(DaemonCodeAnalyzerImpl.getLineMarkers(getDocument(getFile()), getProject()), text); + data.checkResult(infos, text); + return infos; + } +} diff --git a/idea/tests/org/jetbrains/jet/plugin/stubs/MultiFileHighlightingTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/stubs/MultiFileHighlightingTestGenerated.java new file mode 100644 index 00000000000..308ebaab7a5 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/stubs/MultiFileHighlightingTestGenerated.java @@ -0,0 +1,59 @@ +/* + * Copyright 2010-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.jet.plugin.stubs; + +import junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import java.util.regex.Pattern; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.plugin.stubs.AbstractMultiFileHighlightingTest; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/multiFileHighlighting") +public class MultiFileHighlightingTestGenerated extends AbstractMultiFileHighlightingTest { + public void testAllFilesPresentInMultiFileHighlighting() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/multiFileHighlighting"), Pattern.compile("^(.+)\\.kt$"), false); + } + + @TestMetadata("delegatesReference.kt") + public void testDelegatesReference() throws Exception { + doTest("idea/testData/multiFileHighlighting/delegatesReference.kt"); + } + + @TestMetadata("enumReference.kt") + public void testEnumReference() throws Exception { + doTest("idea/testData/multiFileHighlighting/enumReference.kt"); + } + + @TestMetadata("referencesFunWithUnspecifiedType.kt") + public void testReferencesFunWithUnspecifiedType() throws Exception { + doTest("idea/testData/multiFileHighlighting/referencesFunWithUnspecifiedType.kt"); + } + + @TestMetadata("topLevelMembersReference.kt") + public void testTopLevelMembersReference() throws Exception { + doTest("idea/testData/multiFileHighlighting/topLevelMembersReference.kt"); + } + +}