Linemarker tests
This commit is contained in:
@@ -41,6 +41,7 @@ import com.intellij.util.Function;
|
|||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
import kotlin.KotlinPackage;
|
||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@@ -629,22 +630,52 @@ public class JetTestUtils {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getLastCommentInFile(JetFile file) {
|
public enum CommentType {
|
||||||
|
ALL,
|
||||||
|
LINE_COMMENT,
|
||||||
|
BLOCK_COMMENT
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static String getLastCommentInFile(@NotNull JetFile file) {
|
||||||
|
return KotlinPackage.first(getLastCommentsInFile(file, CommentType.ALL, true));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static List<String> getLastCommentsInFile(@NotNull JetFile file, CommentType commentType, boolean assertMustExist) {
|
||||||
PsiElement lastChild = file.getLastChild();
|
PsiElement lastChild = file.getLastChild();
|
||||||
if (lastChild != null && lastChild.getNode().getElementType().equals(JetTokens.WHITE_SPACE)) {
|
if (lastChild != null && lastChild.getNode().getElementType().equals(JetTokens.WHITE_SPACE)) {
|
||||||
lastChild = lastChild.getPrevSibling();
|
lastChild = lastChild.getPrevSibling();
|
||||||
}
|
}
|
||||||
assert lastChild != null;
|
assert lastChild != null;
|
||||||
|
|
||||||
if (lastChild.getNode().getElementType().equals(JetTokens.BLOCK_COMMENT)) {
|
List<String> comments = ContainerUtil.newArrayList();
|
||||||
String lastChildText = lastChild.getText();
|
|
||||||
return lastChildText.substring(2, lastChildText.length() - 2).trim();
|
while (true) {
|
||||||
|
if (lastChild.getNode().getElementType().equals(JetTokens.BLOCK_COMMENT)) {
|
||||||
|
if (commentType == CommentType.ALL || commentType == CommentType.BLOCK_COMMENT) {
|
||||||
|
String lastChildText = lastChild.getText();
|
||||||
|
comments.add(lastChildText.substring(2, lastChildText.length() - 2).trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (lastChild.getNode().getElementType().equals(JetTokens.EOL_COMMENT)) {
|
||||||
|
if (commentType == CommentType.ALL || commentType == CommentType.LINE_COMMENT) {
|
||||||
|
comments.add(lastChild.getText().substring(2).trim());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
lastChild = lastChild.getPrevSibling();
|
||||||
}
|
}
|
||||||
else if (lastChild.getNode().getElementType().equals(JetTokens.EOL_COMMENT)) {
|
|
||||||
return lastChild.getText().substring(2).trim();
|
if (comments.isEmpty() && assertMustExist) {
|
||||||
} else {
|
throw new AssertionError(String.format(
|
||||||
throw new AssertionError("Test file '" + file.getName() + "' should end in a comment; last node was: " + lastChild);
|
"Test file '%s' should end in a comment of type %s; last node was: %s", file.getName(), commentType, lastChild));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options) throws IOException {
|
public static void compileJavaFiles(@NotNull Collection<File> files, List<String> options) throws IOException {
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ import org.jetbrains.jet.completion.AbstractCompiledKotlinInJavaCompletionTest
|
|||||||
import org.jetbrains.jet.completion.AbstractKotlinSourceInJavaCompletionTest
|
import org.jetbrains.jet.completion.AbstractKotlinSourceInJavaCompletionTest
|
||||||
import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithStdLib
|
import org.jetbrains.jet.checkers.AbstractJetDiagnosticsTestWithStdLib
|
||||||
import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest
|
import org.jetbrains.jet.plugin.codeInsight.AbstractInsertImportOnPasteTest
|
||||||
|
import org.jetbrains.jet.plugin.codeInsight.AbstractLineMarkersTest
|
||||||
import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest
|
import org.jetbrains.jet.resolve.AbstractReferenceToJavaWithWrongFileStructureTest
|
||||||
import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest
|
import org.jetbrains.jet.plugin.navigation.AbstractKotlinGotoTest
|
||||||
import org.jetbrains.jet.plugin.AbstractExpressionSelectionTest
|
import org.jetbrains.jet.plugin.AbstractExpressionSelectionTest
|
||||||
@@ -534,6 +535,10 @@ fun main(args: Array<String>) {
|
|||||||
model("copyPaste/imports", pattern = """^([^\.]+)\.kt$""", testMethod = "doTestCut", testClassName = "Cut", recursive = false)
|
model("copyPaste/imports", pattern = """^([^\.]+)\.kt$""", testMethod = "doTestCut", testClassName = "Cut", recursive = false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass(javaClass<AbstractLineMarkersTest>()) {
|
||||||
|
model("codeInsight/lineMarker")
|
||||||
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractShortenRefsTest>()) {
|
testClass(javaClass<AbstractShortenRefsTest>()) {
|
||||||
model("shortenRefs", pattern = """^([^\.]+)\.kt$""")
|
model("shortenRefs", pattern = """^([^\.]+)\.kt$""")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package sample
|
||||||
|
|
||||||
|
trait <lineMarker descr="*"></lineMarker>S<T> {
|
||||||
|
fun <lineMarker descr="<html><body>Is implemented in <br> sample.S2</body></html>"></lineMarker>foo(t: T): T
|
||||||
|
|
||||||
|
val <lineMarker descr="<html><body>Is overridden in <br/> sample.S2</body></html>"></lineMarker>some: T? get
|
||||||
|
|
||||||
|
var <lineMarker descr="<html><body>Is overridden in <br/> sample.S2</body></html>"></lineMarker>other: T?
|
||||||
|
get
|
||||||
|
set
|
||||||
|
}
|
||||||
|
|
||||||
|
open abstract class <lineMarker descr="*"></lineMarker>S1 : S<String>
|
||||||
|
|
||||||
|
class S2 : S1() {
|
||||||
|
override val <lineMarker descr="Implements property in 'S<T>'"></lineMarker>some: String = "S"
|
||||||
|
|
||||||
|
override var <lineMarker descr="Implements property in 'S<T>'"></lineMarker>other: String?
|
||||||
|
get() = null
|
||||||
|
set(value) {}
|
||||||
|
|
||||||
|
override fun <lineMarker descr="Implements function in 'S<T>'"></lineMarker>foo(t: String): String {
|
||||||
|
return super<S1>.foo(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
trait <lineMarker descr="*"></lineMarker>A {
|
||||||
|
override fun <lineMarker descr="<html><body>Is implemented in <br> C</body></html>"><lineMarker descr="*"></lineMarker></lineMarker>toString() = "A"
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract class <lineMarker descr="*"></lineMarker>B: A
|
||||||
|
|
||||||
|
class C: B() {
|
||||||
|
override fun <lineMarker descr="Overrides function in 'A'"></lineMarker>toString() = "B"
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
trait <lineMarker descr="*"></lineMarker>A {
|
||||||
|
fun <lineMarker descr="<html><body>Is implemented in <br> C</body></html>"></lineMarker>foo(): String = "A"
|
||||||
|
|
||||||
|
// TODO: B shoudn't be mentioned
|
||||||
|
val <lineMarker descr="<html><body>Is overridden in <br/> B<br> C</body></html>"></lineMarker>some: String? get() = null
|
||||||
|
|
||||||
|
// TODO: B shoudn't be mentioned
|
||||||
|
var <lineMarker descr="<html><body>Is overridden in <br/> B<br> C</body></html>"></lineMarker>other: String?
|
||||||
|
get() = null
|
||||||
|
set(value) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class <lineMarker descr="*"></lineMarker>B: A
|
||||||
|
|
||||||
|
class C: B() {
|
||||||
|
override val <lineMarker descr="Overrides property in 'A'"></lineMarker>some: String = "S"
|
||||||
|
|
||||||
|
override var <lineMarker descr="Overrides property in 'A'"></lineMarker>other: String?
|
||||||
|
get() = null
|
||||||
|
set(value) {}
|
||||||
|
|
||||||
|
override fun <lineMarker descr="Overrides function in 'A'"></lineMarker>foo(): String {
|
||||||
|
return super<S1>.foo()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
trait <lineMarker></lineMarker>A1 {
|
||||||
|
fun <lineMarker></lineMarker>foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
trait <lineMarker></lineMarker>B1 {
|
||||||
|
fun <lineMarker></lineMarker>foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
class C1: A1, B1 {
|
||||||
|
override fun <lineMarker descr="Implements function in 'A1'<br/>Implements function in 'B1'"></lineMarker>foo() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LINEMARKER: Implements function in 'A1'<br/>Implements function in 'B1'
|
||||||
|
TARGETS:
|
||||||
|
NavigateToSeveralSuperElements.kt
|
||||||
|
fun <1>foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
trait B1 {
|
||||||
|
fun <2>foo()
|
||||||
|
*/
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
trait <lineMarker descr="*"></lineMarker>A {
|
||||||
|
fun <lineMarker descr="<html><body>Is implemented in <br> B</body></html>"></lineMarker>foo(str: String)
|
||||||
|
fun <lineMarker descr="<html><body>Is implemented in <br> B</body></html>"></lineMarker>foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
open class B : A {
|
||||||
|
override fun <lineMarker descr="Implements function in 'A'"></lineMarker>foo(str: String) { }
|
||||||
|
override fun <lineMarker descr="Implements function in 'A'"></lineMarker>foo() { }
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
trait <lineMarker descr="*"></lineMarker>SkipSupport {
|
||||||
|
fun <lineMarker descr="<html><body>Is implemented in <br> SkipSupportImpl<br> SkipSupportWithDefaults</body></html>"></lineMarker>skip(why: String)
|
||||||
|
fun <lineMarker descr="<html><body>Is implemented in <br> SkipSupportWithDefaults</body></html>"></lineMarker>skip()
|
||||||
|
}
|
||||||
|
|
||||||
|
public trait <lineMarker descr="*"></lineMarker>SkipSupportWithDefaults : SkipSupport {
|
||||||
|
// TODO: should be "Is overriden in SkipSupportImpl"
|
||||||
|
override fun <lineMarker descr="<html><body>Is implemented in <br> SkipSupportImpl</body></html>"><lineMarker descr="Implements function in 'SkipSupport'"></lineMarker></lineMarker>skip(why: String) {}
|
||||||
|
|
||||||
|
// TODO: fix bug with 'null' marker
|
||||||
|
override fun <lineMarker descr="*"><lineMarker descr="Implements function in 'SkipSupport'"></lineMarker></lineMarker>skip() {
|
||||||
|
skip("not given")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class SkipSupportImpl: SkipSupportWithDefaults {
|
||||||
|
override fun <lineMarker descr="Overrides function in 'SkipSupportWithDefaults'"></lineMarker>skip(why: String) = throw RuntimeException(why)
|
||||||
|
}
|
||||||
|
|
||||||
|
// KT-4428 Incorrect override icon shown for overloaded methods
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
public trait Foo {
|
||||||
|
override fun <lineMarker descr="Overrides function in 'Any'"></lineMarker>toString() = "str"
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
LINEMARKER: Overrides function in 'Any'
|
||||||
|
TARGETS:
|
||||||
|
Any.kt
|
||||||
|
public open fun <1>toString(): String
|
||||||
|
*/
|
||||||
@@ -0,0 +1,172 @@
|
|||||||
|
/*
|
||||||
|
* 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.codeInsight;
|
||||||
|
|
||||||
|
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
|
||||||
|
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||||
|
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||||
|
import com.intellij.openapi.editor.Document;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.Condition;
|
||||||
|
import com.intellij.psi.NavigatablePsiElement;
|
||||||
|
import com.intellij.psi.PsiDocumentManager;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
||||||
|
import com.intellij.testFramework.ExpectedHighlightingData;
|
||||||
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase;
|
||||||
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
|
import org.jetbrains.jet.plugin.highlighter.JetLineMarkerProvider;
|
||||||
|
import org.jetbrains.jet.plugin.navigation.NavigationTestUtils;
|
||||||
|
import org.jetbrains.jet.testing.HighlightTestDataUtil;
|
||||||
|
import org.jetbrains.jet.testing.ReferenceUtils;
|
||||||
|
import org.junit.Assert;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class AbstractLineMarkersTest extends JetLightCodeInsightFixtureTestCase {
|
||||||
|
|
||||||
|
private static final String LINE_MARKER_PREFIX = "LINEMARKER:";
|
||||||
|
private static final String TARGETS_PREFIX = "TARGETS";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getBasePath() {
|
||||||
|
return PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/lineMarker";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doTest(String path) {
|
||||||
|
try {
|
||||||
|
myFixture.configureByFile(path);
|
||||||
|
Project project = myFixture.getProject();
|
||||||
|
Document document = myFixture.getEditor().getDocument();
|
||||||
|
|
||||||
|
ExpectedHighlightingData data = new ExpectedHighlightingData(
|
||||||
|
document, false, false, false, myFixture.getFile());
|
||||||
|
data.init();
|
||||||
|
|
||||||
|
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||||
|
|
||||||
|
myFixture.doHighlighting();
|
||||||
|
|
||||||
|
List<LineMarkerInfo> markers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
|
||||||
|
|
||||||
|
try {
|
||||||
|
data.checkLineMarkers(markers, document.getText());
|
||||||
|
}
|
||||||
|
catch (AssertionError error) {
|
||||||
|
try {
|
||||||
|
String actualTextWithTestData = HighlightTestDataUtil.insertInfoTags(markers, false, myFixture.getFile().getText());
|
||||||
|
JetTestUtils.assertEqualsToFile(new File(getTestDataPath(), fileName()), actualTextWithTestData);
|
||||||
|
}
|
||||||
|
catch (FileComparisonFailure failure) {
|
||||||
|
throw new FileComparisonFailure(error.getMessage() + "\n" + failure.getMessage(),
|
||||||
|
failure.getExpected(),
|
||||||
|
failure.getActual(),
|
||||||
|
failure.getFilePath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNavigationElements(markers);
|
||||||
|
}
|
||||||
|
catch (Exception exc) {
|
||||||
|
throw new RuntimeException(exc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertNavigationElements(List<LineMarkerInfo> markers) {
|
||||||
|
List<String> navigationDataComments = JetTestUtils.getLastCommentsInFile(
|
||||||
|
(JetFile) myFixture.getFile(), JetTestUtils.CommentType.BLOCK_COMMENT, false);
|
||||||
|
if (navigationDataComments.isEmpty()) return;
|
||||||
|
|
||||||
|
for (String navigationComment : navigationDataComments) {
|
||||||
|
final String description = getLineMarkerDescription(navigationComment);
|
||||||
|
LineMarkerInfo navigateMarker = ContainerUtil.find(markers, new Condition<LineMarkerInfo>() {
|
||||||
|
@Override
|
||||||
|
public boolean value(LineMarkerInfo marker) {
|
||||||
|
String tooltip = marker.getLineMarkerTooltip();
|
||||||
|
return tooltip != null && tooltip.startsWith(description);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assertNotNull(
|
||||||
|
String.format("Can't find marker for navigation check with description \"%s\"", description),
|
||||||
|
navigateMarker);
|
||||||
|
|
||||||
|
GutterIconNavigationHandler handler = navigateMarker.getNavigationHandler();
|
||||||
|
if (handler instanceof JetLineMarkerProvider.KotlinSuperNavigationHandler) {
|
||||||
|
PsiElement element = navigateMarker.getElement();
|
||||||
|
|
||||||
|
//noinspection unchecked
|
||||||
|
handler.navigate(null, element);
|
||||||
|
List<NavigatablePsiElement> navigateElements =
|
||||||
|
((JetLineMarkerProvider.KotlinSuperNavigationHandler) handler).getNavigationElements();
|
||||||
|
|
||||||
|
Collections.sort(navigateElements, new Comparator<NavigatablePsiElement>() {
|
||||||
|
@Override
|
||||||
|
public int compare(@NotNull NavigatablePsiElement first, @NotNull NavigatablePsiElement second) {
|
||||||
|
String elementFirstStr = ReferenceUtils.renderAsGotoImplementation(first);
|
||||||
|
String elementSecondStr = ReferenceUtils.renderAsGotoImplementation(second);
|
||||||
|
|
||||||
|
return elementFirstStr.compareTo(elementSecondStr);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
String actualNavigationData =
|
||||||
|
NavigationTestUtils.getNavigateElementsText(myFixture.getProject(), navigateElements);
|
||||||
|
|
||||||
|
assertSameLines(getExpectedNavigationText(navigationComment), actualNavigationData);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Assert.fail("Only JetLineMarkerProvider.KotlinSuperNavigationHandler are supported in navigate check");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getLineMarkerDescription(String navigationComment) {
|
||||||
|
int firstLineEnd = navigationComment.indexOf("\n");
|
||||||
|
assertTrue("The first line in block comment must contain description of marker for navigation check", firstLineEnd != -1);
|
||||||
|
|
||||||
|
String navigationMarkerText = navigationComment.substring(0, firstLineEnd);
|
||||||
|
|
||||||
|
assertTrue(String.format("Add %s directive in first line of comment", LINE_MARKER_PREFIX),
|
||||||
|
navigationMarkerText.startsWith(LINE_MARKER_PREFIX));
|
||||||
|
|
||||||
|
navigationMarkerText = navigationMarkerText.substring(LINE_MARKER_PREFIX.length());
|
||||||
|
|
||||||
|
return navigationMarkerText.trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getExpectedNavigationText(String navigationComment) {
|
||||||
|
int firstLineEnd = navigationComment.indexOf("\n");
|
||||||
|
|
||||||
|
String expectedNavigationText = navigationComment.substring(firstLineEnd + 1);
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
String.format("Marker %s is expected before navigation data", TARGETS_PREFIX),
|
||||||
|
expectedNavigationText.startsWith(TARGETS_PREFIX));
|
||||||
|
|
||||||
|
expectedNavigationText = expectedNavigationText.substring(expectedNavigationText.indexOf("\n") + 1);
|
||||||
|
|
||||||
|
return expectedNavigationText;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,143 @@
|
|||||||
|
/*
|
||||||
|
* 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.codeInsight;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import junit.framework.Test;
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
|
import org.jetbrains.jet.test.InnerTestClasses;
|
||||||
|
import org.jetbrains.jet.test.TestMetadata;
|
||||||
|
import org.jetbrains.jet.JUnit3RunnerWithInners;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("idea/testData/codeInsight/lineMarker")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(org.jetbrains.jet.JUnit3RunnerWithInners.class)
|
||||||
|
public class LineMarkersTestGenerated extends AbstractLineMarkersTest {
|
||||||
|
public void testAllFilesPresentInLineMarker() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/codeInsight/lineMarker"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Class.kt")
|
||||||
|
public void testClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/Class.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ClassObjectInStaticNestedClass.kt")
|
||||||
|
public void testClassObjectInStaticNestedClass() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/ClassObjectInStaticNestedClass.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DelegatedFun.kt")
|
||||||
|
public void testDelegatedFun() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/DelegatedFun.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("DelegatedProperty.kt")
|
||||||
|
public void testDelegatedProperty() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/DelegatedProperty.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FakeOverrideForClasses.kt")
|
||||||
|
public void testFakeOverrideForClasses() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/FakeOverrideForClasses.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FakeOverrideFun.kt")
|
||||||
|
public void testFakeOverrideFun() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/FakeOverrideFun.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FakeOverrideFunWithMostRelevantImplementation.kt")
|
||||||
|
public void testFakeOverrideFunWithMostRelevantImplementation() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/FakeOverrideFunWithMostRelevantImplementation.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FakeOverrideProperty.kt")
|
||||||
|
public void testFakeOverrideProperty() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/FakeOverrideProperty.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FakeOverrideToStringInTrait.kt")
|
||||||
|
public void testFakeOverrideToStringInTrait() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/FakeOverrideToStringInTrait.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("FakeOverridesForTraitFunWithImpl.kt")
|
||||||
|
public void testFakeOverridesForTraitFunWithImpl() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/FakeOverridesForTraitFunWithImpl.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("NavigateToSeveralSuperElements.kt")
|
||||||
|
public void testNavigateToSeveralSuperElements() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/NavigateToSeveralSuperElements.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Overloads.kt")
|
||||||
|
public void testOverloads() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/Overloads.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("OverrideFunction.kt")
|
||||||
|
public void testOverrideFunction() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/OverrideFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("OverrideIconForOverloadMethodBug.kt")
|
||||||
|
public void testOverrideIconForOverloadMethodBug() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/OverrideIconForOverloadMethodBug.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("PropertyOverride.kt")
|
||||||
|
public void testPropertyOverride() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/PropertyOverride.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ToStringInTrait.kt")
|
||||||
|
public void testToStringInTrait() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/ToStringInTrait.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("Trait.kt")
|
||||||
|
public void testTrait() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/codeInsight/lineMarker/Trait.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.codeInsight;
|
|
||||||
|
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
|
||||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
|
||||||
import com.intellij.openapi.editor.Document;
|
|
||||||
import com.intellij.openapi.project.Project;
|
|
||||||
import com.intellij.psi.PsiDocumentManager;
|
|
||||||
import com.intellij.rt.execution.junit.FileComparisonFailure;
|
|
||||||
import com.intellij.testFramework.ExpectedHighlightingData;
|
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
|
||||||
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase;
|
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
|
||||||
import org.jetbrains.jet.testing.HighlightTestDataUtil;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class OverrideImplementLineMarkerTest extends JetLightCodeInsightFixtureTestCase {
|
|
||||||
@Override
|
|
||||||
protected String getBasePath() {
|
|
||||||
return PluginTestCaseBase.TEST_DATA_PROJECT_RELATIVE + "/codeInsight/lineMarker";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testTrait() throws Throwable {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testClass() throws Throwable {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testOverrideFunction() throws Throwable {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPropertyOverride() throws Throwable {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDelegatedFun() throws Exception {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFakeOverrideFun() throws Exception {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDelegatedProperty() throws Exception {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testClassObjectInStaticNestedClass() throws Exception {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFakeOverrideProperty() throws Exception {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testFakeOverrideFunWithMostRelevantImplementation() throws Exception {
|
|
||||||
doTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doTest() {
|
|
||||||
try {
|
|
||||||
myFixture.configureByFile(fileName());
|
|
||||||
Project project = myFixture.getProject();
|
|
||||||
Document document = myFixture.getEditor().getDocument();
|
|
||||||
|
|
||||||
ExpectedHighlightingData data = new ExpectedHighlightingData(document, false, false, false, myFixture.getFile());
|
|
||||||
data.init();
|
|
||||||
|
|
||||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
|
||||||
|
|
||||||
myFixture.doHighlighting();
|
|
||||||
|
|
||||||
List<LineMarkerInfo> markers = DaemonCodeAnalyzerImpl.getLineMarkers(document, project);
|
|
||||||
|
|
||||||
try {
|
|
||||||
data.checkLineMarkers(markers, document.getText());
|
|
||||||
}
|
|
||||||
catch (AssertionError error) {
|
|
||||||
try {
|
|
||||||
String actualTextWithTestData = HighlightTestDataUtil.insertInfoTags(markers, false, myFixture.getFile().getText());
|
|
||||||
JetTestUtils.assertEqualsToFile(new File(getTestDataPath(), fileName()), actualTextWithTestData);
|
|
||||||
}
|
|
||||||
catch (FileComparisonFailure failure) {
|
|
||||||
throw new FileComparisonFailure(error.getMessage() + "\n" + failure.getMessage(),
|
|
||||||
failure.getExpected(),
|
|
||||||
failure.getActual(),
|
|
||||||
failure.getFilePath());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception exc) {
|
|
||||||
throw new RuntimeException(exc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010-2013 JetBrains s.r.o.
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -17,19 +17,18 @@
|
|||||||
package org.jetbrains.jet.plugin.libraries;
|
package org.jetbrains.jet.plugin.libraries;
|
||||||
|
|
||||||
import com.intellij.openapi.editor.Document;
|
import com.intellij.openapi.editor.Document;
|
||||||
import com.intellij.openapi.editor.EditorFactory;
|
|
||||||
import com.intellij.openapi.roots.ProjectFileIndex;
|
import com.intellij.openapi.roots.ProjectFileIndex;
|
||||||
import com.intellij.openapi.util.Pair;
|
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import com.intellij.psi.PsiDocumentManager;
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.PsiReference;
|
import com.intellij.psi.PsiReference;
|
||||||
import com.intellij.testFramework.LightProjectDescriptor;
|
import com.intellij.testFramework.LightProjectDescriptor;
|
||||||
import com.intellij.util.containers.MultiMap;
|
import com.intellij.util.Function;
|
||||||
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor;
|
import org.jetbrains.jet.plugin.JdkAndMockLibraryProjectDescriptor;
|
||||||
|
import org.jetbrains.jet.plugin.navigation.NavigationTestUtils;
|
||||||
import org.jetbrains.jet.plugin.references.JetReference;
|
import org.jetbrains.jet.plugin.references.JetReference;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -109,7 +108,8 @@ public class NavigateToLibrarySourceTest extends AbstractNavigateToLibraryTest {
|
|||||||
|
|
||||||
private void checkAnnotatedLibraryCode(boolean forceResolve) {
|
private void checkAnnotatedLibraryCode(boolean forceResolve) {
|
||||||
JetSourceNavigationHelper.setForceResolve(forceResolve);
|
JetSourceNavigationHelper.setForceResolve(forceResolve);
|
||||||
String actualCode = getActualAnnotatedLibraryCode();
|
String actualCode = NavigationTestUtils
|
||||||
|
.getNavigateElementsText(myFixture.getProject(), collectInterestingNavigationElements());
|
||||||
String expectedCode = getExpectedAnnotatedLibraryCode();
|
String expectedCode = getExpectedAnnotatedLibraryCode();
|
||||||
assertSameLines(expectedCode, actualCode);
|
assertSameLines(expectedCode, actualCode);
|
||||||
}
|
}
|
||||||
@@ -134,63 +134,15 @@ public class NavigateToLibrarySourceTest extends AbstractNavigateToLibraryTest {
|
|||||||
return referenceContainersToReferences.values();
|
return referenceContainersToReferences.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getActualAnnotatedLibraryCode() {
|
private Collection<PsiElement> collectInterestingNavigationElements() {
|
||||||
MultiMap<PsiFile, Pair<Integer, Integer>> filesToNumbersAndOffsets = new MultiMap<PsiFile, Pair<Integer, Integer>>();
|
return ContainerUtil.map(collectInterestingReferences(), new Function<JetReference, PsiElement>() {
|
||||||
int refNumber = 1;
|
|
||||||
for (JetReference ref : collectInterestingReferences()) {
|
|
||||||
PsiElement target = ref.resolve();
|
|
||||||
assertNotNull(target);
|
|
||||||
PsiElement navigationElement = target.getNavigationElement();
|
|
||||||
Pair<Integer, Integer> numberAndOffset = new Pair<Integer, Integer>(refNumber++, navigationElement.getTextOffset());
|
|
||||||
filesToNumbersAndOffsets.putValue(navigationElement.getContainingFile(), numberAndOffset);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filesToNumbersAndOffsets.isEmpty()) {
|
|
||||||
return "<no references>";
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PsiFile> files = new ArrayList<PsiFile>(filesToNumbersAndOffsets.keySet());
|
|
||||||
Collections.sort(files, new Comparator<PsiFile>() {
|
|
||||||
@Override
|
@Override
|
||||||
public int compare(PsiFile o1, PsiFile o2) {
|
public PsiElement fun(JetReference reference) {
|
||||||
return o1.getName().compareTo(o2.getName());
|
PsiElement target = reference.resolve();
|
||||||
|
assertNotNull(target);
|
||||||
|
return target.getNavigationElement();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder();
|
|
||||||
for (PsiFile file : files) {
|
|
||||||
List<Pair<Integer, Integer>> numbersAndOffsets = new ArrayList<Pair<Integer, Integer>>(filesToNumbersAndOffsets.get(file));
|
|
||||||
|
|
||||||
Collections.sort(numbersAndOffsets, Collections.reverseOrder(new Comparator<Pair<Integer, Integer>>() {
|
|
||||||
@Override
|
|
||||||
public int compare(Pair<Integer, Integer> t1, Pair<Integer, Integer> t2) {
|
|
||||||
int offsets = t1.second.compareTo(t2.second);
|
|
||||||
return offsets == 0 ? t1.first.compareTo(t2.first) : offsets;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
|
|
||||||
assertNotNull(document);
|
|
||||||
StringBuilder resultForFile = new StringBuilder(document.getText());
|
|
||||||
for (Pair<Integer, Integer> numberOffset : numbersAndOffsets) {
|
|
||||||
resultForFile.insert(numberOffset.second, String.format("<%d>", numberOffset.first));
|
|
||||||
}
|
|
||||||
|
|
||||||
int minLine = Integer.MAX_VALUE;
|
|
||||||
int maxLine = Integer.MIN_VALUE;
|
|
||||||
for (Pair<Integer, Integer> numberOffset : numbersAndOffsets) {
|
|
||||||
int lineNumber = document.getLineNumber(numberOffset.second);
|
|
||||||
minLine = Math.min(minLine, lineNumber);
|
|
||||||
maxLine = Math.max(maxLine, lineNumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
Document annotated = EditorFactory.getInstance().createDocument(resultForFile);
|
|
||||||
String filePart = annotated.getText().substring(annotated.getLineStartOffset(minLine),
|
|
||||||
annotated.getLineEndOffset(maxLine));
|
|
||||||
result.append(" ").append(file.getName()).append("\n");
|
|
||||||
result.append(filePart).append("\n");
|
|
||||||
}
|
|
||||||
return result.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getExpectedAnnotatedLibraryCode() {
|
private String getExpectedAnnotatedLibraryCode() {
|
||||||
@@ -199,7 +151,6 @@ public class NavigateToLibrarySourceTest extends AbstractNavigateToLibraryTest {
|
|||||||
return JetTestUtils.getLastCommentedLines(document);
|
return JetTestUtils.getLastCommentedLines(document);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected LightProjectDescriptor getProjectDescriptor() {
|
protected LightProjectDescriptor getProjectDescriptor() {
|
||||||
|
|||||||
@@ -21,18 +21,24 @@ import com.google.common.collect.Lists;
|
|||||||
import com.google.common.collect.Ordering;
|
import com.google.common.collect.Ordering;
|
||||||
import com.intellij.codeInsight.navigation.GotoImplementationHandler;
|
import com.intellij.codeInsight.navigation.GotoImplementationHandler;
|
||||||
import com.intellij.codeInsight.navigation.GotoTargetHandler;
|
import com.intellij.codeInsight.navigation.GotoTargetHandler;
|
||||||
|
import com.intellij.openapi.editor.Document;
|
||||||
import com.intellij.openapi.editor.Editor;
|
import com.intellij.openapi.editor.Editor;
|
||||||
|
import com.intellij.openapi.editor.EditorFactory;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.openapi.util.Pair;
|
||||||
|
import com.intellij.psi.PsiDocumentManager;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.testFramework.UsefulTestCase;
|
import com.intellij.testFramework.UsefulTestCase;
|
||||||
|
import com.intellij.util.containers.MultiMap;
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.InTextDirectivesUtils;
|
import org.jetbrains.jet.InTextDirectivesUtils;
|
||||||
import org.jetbrains.jet.testing.ReferenceUtils;
|
import org.jetbrains.jet.testing.ReferenceUtils;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class NavigationTestUtils {
|
public final class NavigationTestUtils {
|
||||||
private NavigationTestUtils() {
|
private NavigationTestUtils() {
|
||||||
@@ -64,4 +70,60 @@ public final class NavigationTestUtils {
|
|||||||
UsefulTestCase.assertOrderedEquals(Collections.emptyList(), expectedReferences);
|
UsefulTestCase.assertOrderedEquals(Collections.emptyList(), expectedReferences);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getNavigateElementsText(Project project, Collection<? extends PsiElement> navigableElements) {
|
||||||
|
MultiMap<PsiFile, Pair<Integer, Integer>> filesToNumbersAndOffsets = new MultiMap<PsiFile, Pair<Integer, Integer>>();
|
||||||
|
int refNumber = 1;
|
||||||
|
for (PsiElement navigationElement : navigableElements) {
|
||||||
|
Pair<Integer, Integer> numberAndOffset = new Pair<Integer, Integer>(refNumber++, navigationElement.getTextOffset());
|
||||||
|
filesToNumbersAndOffsets.putValue(navigationElement.getContainingFile(), numberAndOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filesToNumbersAndOffsets.isEmpty()) {
|
||||||
|
return "<no references>";
|
||||||
|
}
|
||||||
|
|
||||||
|
List<PsiFile> files = new ArrayList<PsiFile>(filesToNumbersAndOffsets.keySet());
|
||||||
|
Collections.sort(files, new Comparator<PsiFile>() {
|
||||||
|
@Override
|
||||||
|
public int compare(@NotNull PsiFile f1, @NotNull PsiFile f2) {
|
||||||
|
return f1.getName().compareTo(f2.getName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (PsiFile file : files) {
|
||||||
|
List<Pair<Integer, Integer>> numbersAndOffsets = new ArrayList<Pair<Integer, Integer>>(filesToNumbersAndOffsets.get(file));
|
||||||
|
|
||||||
|
Collections.sort(numbersAndOffsets, Collections.reverseOrder(new Comparator<Pair<Integer, Integer>>() {
|
||||||
|
@Override
|
||||||
|
public int compare(Pair<Integer, Integer> t1, Pair<Integer, Integer> t2) {
|
||||||
|
int offsets = t1.second.compareTo(t2.second);
|
||||||
|
return offsets == 0 ? t1.first.compareTo(t2.first) : offsets;
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
|
||||||
|
TestCase.assertNotNull(document);
|
||||||
|
StringBuilder resultForFile = new StringBuilder(document.getText());
|
||||||
|
for (Pair<Integer, Integer> numberOffset : numbersAndOffsets) {
|
||||||
|
resultForFile.insert(numberOffset.second, String.format("<%d>", numberOffset.first));
|
||||||
|
}
|
||||||
|
|
||||||
|
int minLine = Integer.MAX_VALUE;
|
||||||
|
int maxLine = Integer.MIN_VALUE;
|
||||||
|
for (Pair<Integer, Integer> numberOffset : numbersAndOffsets) {
|
||||||
|
int lineNumber = document.getLineNumber(numberOffset.second);
|
||||||
|
minLine = Math.min(minLine, lineNumber);
|
||||||
|
maxLine = Math.max(maxLine, lineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
Document annotated = EditorFactory.getInstance().createDocument(resultForFile);
|
||||||
|
String filePart = annotated.getText().substring(annotated.getLineStartOffset(minLine),
|
||||||
|
annotated.getLineEndOffset(maxLine));
|
||||||
|
result.append(" ").append(file.getName()).append("\n");
|
||||||
|
result.append(filePart).append("\n");
|
||||||
|
}
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user