Split on big fat test case in LibrariesWithSourcesTest into several smaller ones.
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
WithInnerAndObject.foo()
|
||||||
|
}
|
||||||
|
|
||||||
|
//public class <1>WithInnerAndObject {
|
||||||
|
// class object {
|
||||||
|
// fun <2>foo() {
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
val color: Color? = Color.RED
|
||||||
|
val rgb = color?.rgb
|
||||||
|
|
||||||
|
//public enum class <1><2>Color(val <3>rgb : Int) {
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
val v = 5.filter { it % 2 == 1 }
|
||||||
|
|
||||||
|
//public inline fun <T> T.<1>filter(predicate: (T)-> Boolean) : T? = this
|
||||||
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
println("".exProp)
|
||||||
|
println(#(1, 2).exProp)
|
||||||
|
}
|
||||||
|
|
||||||
|
//public val String.<1>exProp : String
|
||||||
|
//get() {
|
||||||
|
// return this
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//public val Int.exProp : Int
|
||||||
|
//get() {
|
||||||
|
// return this
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//public val <T> #(T, T).<2>exProp : String
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
func(5)
|
||||||
|
func(5, "5")
|
||||||
|
func(5, 5)
|
||||||
|
func()
|
||||||
|
}
|
||||||
|
|
||||||
|
//public fun <1><2>func(a : Int, b : String = "55") {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//public fun <3>func(a : Int, b : Int) {
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//public fun <4>func() {
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
println(testData.libraries.globalVal)
|
||||||
|
println(globalValWithGetter)
|
||||||
|
}
|
||||||
|
|
||||||
|
//public val <1>globalVal : #(Int, String) = #(239, "239")
|
||||||
|
//
|
||||||
|
//public val <2>globalValWithGetter : Long
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
fun foo(a : ClassWithAbstractAndOpenMembers) {
|
||||||
|
a.abstractVar = "v"
|
||||||
|
println(a.abstractVar)
|
||||||
|
}
|
||||||
|
|
||||||
|
//public abstract class <1>ClassWithAbstractAndOpenMembers {
|
||||||
|
// public abstract fun abstractFun()
|
||||||
|
// public open fun openFun() {
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public abstract val abstractVal : String
|
||||||
|
// public open val openVal : String = ""
|
||||||
|
// public open val openValWithGetter : String
|
||||||
|
// get() {
|
||||||
|
// return "239"
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public abstract var <2><3>abstractVar : String
|
||||||
|
|
||||||
@@ -1,96 +0,0 @@
|
|||||||
package testData.libraries
|
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
public trait SimpleTrait {
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SimpleClass {
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SimpleTraitImpl : SimpleTrait {
|
|
||||||
}
|
|
||||||
|
|
||||||
public class <15>WithInnerAndObject {
|
|
||||||
class object {
|
|
||||||
fun <16>foo() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyInner {
|
|
||||||
trait MyInnerInner {
|
|
||||||
fun innerInnerMethod()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class WithTraitClassObject {
|
|
||||||
class object : SimpleTrait
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class AbstractClass {
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum class <4><5>Color(val <6>rgb : Int) {
|
|
||||||
RED : Color(0xFF0000)
|
|
||||||
GREEN : Color(0x00FF00)
|
|
||||||
BLUE : Color(0x0000FF)
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract class <1>ClassWithAbstractAndOpenMembers {
|
|
||||||
public abstract fun abstractFun()
|
|
||||||
public open fun openFun() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract val abstractVal : String
|
|
||||||
public open val openVal : String = ""
|
|
||||||
public open val openValWithGetter : String
|
|
||||||
get() {
|
|
||||||
return "239"
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract var <2><3>abstractVar : String
|
|
||||||
public open var openVar : String = ""
|
|
||||||
public open var openVarWithGetter : String
|
|
||||||
get() {
|
|
||||||
return "239"
|
|
||||||
}
|
|
||||||
set(value) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun main(args : Array<String>) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public val <7>globalVal : #(Int, String) = #(239, "239")
|
|
||||||
|
|
||||||
public val <8>globalValWithGetter : Long
|
|
||||||
get() {
|
|
||||||
return System.currentTimeMillis()
|
|
||||||
}
|
|
||||||
|
|
||||||
public val String.<9>exProp : String
|
|
||||||
get() {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public val Int.exProp : Int
|
|
||||||
get() {
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
public val <T> #(T, T).<10>exProp : String
|
|
||||||
get() {
|
|
||||||
return "${this._1} : ${this._2}"
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun <11><12>func(a : Int, b : String = "55") {
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun <13>func(a : Int, b : Int) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public fun <14>func() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public inline fun <T> T.<17>filter(predicate: (T)-> Boolean) : T? = this
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package userpackage
|
|
||||||
|
|
||||||
import testData.libraries.*
|
|
||||||
|
|
||||||
fun foo(a : ClassWithAbstractAndOpenMembers) {
|
|
||||||
a.abstractVar = "v"
|
|
||||||
println(a.abstractVar)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun main(args : Array<String>) : Unit {
|
|
||||||
val color: Color? = Color.RED
|
|
||||||
color?.rgb
|
|
||||||
|
|
||||||
println(testData.libraries.globalVal)
|
|
||||||
println(testData.libraries.globalValWithGetter)
|
|
||||||
println("".exProp)
|
|
||||||
println(#(1, 2).exProp)
|
|
||||||
func(5)
|
|
||||||
func(5, "5")
|
|
||||||
func(5, 5)
|
|
||||||
func()
|
|
||||||
|
|
||||||
WithInnerAndObject.foo()
|
|
||||||
5.filter { it % 2 == 1 }
|
|
||||||
}
|
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
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.fileEditor.FileDocumentManager;
|
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
@@ -29,25 +30,56 @@ import org.jetbrains.jet.plugin.references.JetPsiReference;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Attaching library with sources, and trying to navigate to its entities from source code.
|
||||||
|
*
|
||||||
* @author Evgeny Gerashchenko
|
* @author Evgeny Gerashchenko
|
||||||
* @since 3/23/12
|
* @since 3/23/12
|
||||||
*/
|
*/
|
||||||
public class LibrariesWithSourcesTest extends AbstractLibrariesTest {
|
public class LibrariesWithSourcesTest extends AbstractLibrariesTest {
|
||||||
|
|
||||||
private VirtualFile myLibrarySourceFile;
|
private VirtualFile librarySourceFile;
|
||||||
|
private VirtualFile userFile;
|
||||||
|
|
||||||
public void test() {
|
public void testEnum() {
|
||||||
myLibrarySourceFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/library/library.kt");
|
doTest();
|
||||||
assertNotNull(myLibrarySourceFile);
|
}
|
||||||
|
|
||||||
String annotatedLibrary = getAnnotatedLibrarySourceText();
|
public void testProperty() {
|
||||||
assertSameLinesWithFile(TEST_DATA_PATH + "/usercode/library.marked.kt", annotatedLibrary);
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGlobalProperty() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExtensionProperty() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGlobalFunction() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testClassObject() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExtensionFunction() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTest() {
|
||||||
|
librarySourceFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/library/library.kt");
|
||||||
|
assertNotNull(librarySourceFile);
|
||||||
|
userFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/usercode/" + getTestName(false) + ".kt");
|
||||||
|
assertNotNull(userFile);
|
||||||
|
|
||||||
|
String actualCode = getActualAnnotatedLibraryCode();
|
||||||
|
String expectedCode = getExpectedAnnotatedLibraryCode();
|
||||||
|
assertSameLines(expectedCode, actualCode);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collection<JetPsiReference> collectInterestingReferences() {
|
private Collection<JetPsiReference> collectInterestingReferences() {
|
||||||
VirtualFile userFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/usercode/usercode.kt");
|
|
||||||
assert userFile != null;
|
|
||||||
|
|
||||||
PsiFile psiFile = getPsiManager().findFile(userFile);
|
PsiFile psiFile = getPsiManager().findFile(userFile);
|
||||||
assert psiFile != null;
|
assert psiFile != null;
|
||||||
Map<PsiElement, JetPsiReference> referenceContainersToReferences = new LinkedHashMap<PsiElement, JetPsiReference>();
|
Map<PsiElement, JetPsiReference> referenceContainersToReferences = new LinkedHashMap<PsiElement, JetPsiReference>();
|
||||||
@@ -62,7 +94,7 @@ public class LibrariesWithSourcesTest extends AbstractLibrariesTest {
|
|||||||
if (targetNavPsiFile == null) {
|
if (targetNavPsiFile == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (myLibrarySourceFile.equals(targetNavPsiFile.getVirtualFile())) {
|
if (librarySourceFile.equals(targetNavPsiFile.getVirtualFile())) {
|
||||||
referenceContainersToReferences.put(ref.getElement(), (JetPsiReference)ref);
|
referenceContainersToReferences.put(ref.getElement(), (JetPsiReference)ref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +102,7 @@ public class LibrariesWithSourcesTest extends AbstractLibrariesTest {
|
|||||||
return referenceContainersToReferences.values();
|
return referenceContainersToReferences.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getAnnotatedLibrarySourceText() {
|
private String getActualAnnotatedLibraryCode() {
|
||||||
List<Tuple2<Integer, Integer>> numbersAndOffsets = new ArrayList<Tuple2<Integer, Integer>>();
|
List<Tuple2<Integer, Integer>> numbersAndOffsets = new ArrayList<Tuple2<Integer, Integer>>();
|
||||||
for (JetPsiReference ref : collectInterestingReferences()) {
|
for (JetPsiReference ref : collectInterestingReferences()) {
|
||||||
PsiElement target = ref.resolve();
|
PsiElement target = ref.resolve();
|
||||||
@@ -87,13 +119,52 @@ public class LibrariesWithSourcesTest extends AbstractLibrariesTest {
|
|||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Document document = FileDocumentManager.getInstance().getDocument(myLibrarySourceFile);
|
Document document = FileDocumentManager.getInstance().getDocument(librarySourceFile);
|
||||||
assertNotNull(document);
|
assertNotNull(document);
|
||||||
StringBuilder result = new StringBuilder(document.getText());
|
StringBuilder result = new StringBuilder(document.getText());
|
||||||
for (Tuple2<Integer, Integer> numberOffset : numbersAndOffsets) {
|
for (Tuple2<Integer, Integer> numberOffset : numbersAndOffsets) {
|
||||||
result.insert(numberOffset._2, String.format("<%d>", numberOffset._1));
|
result.insert(numberOffset._2, String.format("<%d>", numberOffset._1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (numbersAndOffsets.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
int minLine = Integer.MAX_VALUE;
|
||||||
|
int maxLine = Integer.MIN_VALUE;
|
||||||
|
for (Tuple2<Integer, Integer> numberOffset : numbersAndOffsets) {
|
||||||
|
int lineNumber = document.getLineNumber(numberOffset._2);
|
||||||
|
minLine = Math.min(minLine, lineNumber);
|
||||||
|
maxLine = Math.max(maxLine, lineNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
Document annotated = EditorFactory.getInstance().createDocument(result);
|
||||||
|
return annotated.getText().substring(annotated.getLineStartOffset(minLine),
|
||||||
|
annotated.getLineEndOffset(maxLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getExpectedAnnotatedLibraryCode() {
|
||||||
|
Document document = FileDocumentManager.getInstance().getDocument(userFile);
|
||||||
|
assertNotNull(document);
|
||||||
|
List<CharSequence> resultLines = new ArrayList<CharSequence>();
|
||||||
|
for (int i = document.getLineCount() - 1; i >= 0; i--) {
|
||||||
|
int lineStart = document.getLineStartOffset(i);
|
||||||
|
int lineEnd = document.getLineEndOffset(i);
|
||||||
|
if (document.getCharsSequence().subSequence(lineStart, lineEnd).toString().trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ("//".equals(document.getCharsSequence().subSequence(lineStart, lineStart + 2).toString())) {
|
||||||
|
resultLines.add(document.getCharsSequence().subSequence(lineStart + 2, lineEnd));
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.reverse(resultLines);
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
for (CharSequence line : resultLines) {
|
||||||
|
result.append(line).append("\n");
|
||||||
|
}
|
||||||
|
result.delete(result.length() - 1, result.length());
|
||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user