Added LibrariesWithSourcesTest.
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
package testData.libraries
|
||||
|
||||
trait SimpleTrait {
|
||||
}
|
||||
|
||||
class SimpleClass {
|
||||
}
|
||||
|
||||
class SimpleTraitImpl : SimpleTrait {
|
||||
}
|
||||
|
||||
class WithInnerAndObject {
|
||||
class object {
|
||||
fun foo() {
|
||||
}
|
||||
}
|
||||
|
||||
class MyInner {
|
||||
trait MyInnerInner {
|
||||
fun innerInnerMethod()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class WithTraitClassObject {
|
||||
class object : SimpleTrait
|
||||
}
|
||||
|
||||
abstract class AbstractClass {
|
||||
}
|
||||
|
||||
enum class <4><5>Color(val <6>rgb : Int) {
|
||||
RED : Color(0xFF0000)
|
||||
GREEN : Color(0x00FF00)
|
||||
BLUE : Color(0x0000FF)
|
||||
}
|
||||
|
||||
abstract class <1>ClassWithAbstractAndOpenMembers {
|
||||
abstract fun abstractFun()
|
||||
open fun openFun() {
|
||||
}
|
||||
|
||||
abstract val abstractVal : String
|
||||
open val openVal : String = ""
|
||||
open val openValWithGetter : String
|
||||
get() {
|
||||
return "239"
|
||||
}
|
||||
|
||||
abstract var <2><3>abstractVar : String
|
||||
open var openVar : String = ""
|
||||
open var openVarWithGetter : String
|
||||
get() {
|
||||
return "239"
|
||||
}
|
||||
set(value) {
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
}
|
||||
|
||||
val <7>globalVal : #(Int, String) = #(239, "239")
|
||||
|
||||
val <8>globalValWithGetter : Long
|
||||
get() {
|
||||
return System.currentTimeMillis()
|
||||
}
|
||||
|
||||
val String.<9>exProp : String
|
||||
get() {
|
||||
return this
|
||||
}
|
||||
|
||||
val Int.exProp : Int
|
||||
get() {
|
||||
return this
|
||||
}
|
||||
|
||||
val <T> #(T, T).<10>exProp : String
|
||||
get() {
|
||||
return "${this._1} : ${this._2}"
|
||||
}
|
||||
|
||||
fun <11><12>func(a : Int, b : String = "55") {
|
||||
}
|
||||
|
||||
fun <13>func(a : Int, b : Int) {
|
||||
}
|
||||
|
||||
fun <14>func() {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
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()
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright 2010-2012 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.libraries;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import jet.Tuple2;
|
||||
import org.jetbrains.jet.plugin.references.JetPsiReference;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
* @since 3/23/12
|
||||
*/
|
||||
public class LibrariesWithSourcesTest extends AbstractLibrariesTest {
|
||||
|
||||
private VirtualFile myLibrarySourceFile;
|
||||
|
||||
public void test() {
|
||||
myLibrarySourceFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/library/library.kt");
|
||||
assertNotNull(myLibrarySourceFile);
|
||||
|
||||
String annotatedLibrary = getAnnotatedLibrarySourceText();
|
||||
assertSameLinesWithFile(TEST_DATA_PATH + "/usercode/library.marked.kt", annotatedLibrary);
|
||||
}
|
||||
|
||||
private Collection<JetPsiReference> collectInterestingReferences() {
|
||||
VirtualFile userFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/usercode/usercode.kt");
|
||||
assert userFile != null;
|
||||
|
||||
PsiFile psiFile = getPsiManager().findFile(userFile);
|
||||
assert psiFile != null;
|
||||
Map<PsiElement, JetPsiReference> referenceContainersToReferences = new LinkedHashMap<PsiElement, JetPsiReference>();
|
||||
for (int offset = 0; offset < psiFile.getTextLength(); offset++) {
|
||||
PsiReference ref = psiFile.findReferenceAt(offset);
|
||||
if (ref instanceof JetPsiReference && !referenceContainersToReferences.containsKey(ref.getElement())) {
|
||||
PsiElement target = ref.resolve();
|
||||
if (target == null) {
|
||||
continue;
|
||||
}
|
||||
PsiFile targetNavPsiFile = target.getNavigationElement().getContainingFile();
|
||||
if (targetNavPsiFile == null) {
|
||||
continue;
|
||||
}
|
||||
if (myLibrarySourceFile.equals(targetNavPsiFile.getVirtualFile())) {
|
||||
referenceContainersToReferences.put(ref.getElement(), (JetPsiReference)ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
return referenceContainersToReferences.values();
|
||||
}
|
||||
|
||||
private String getAnnotatedLibrarySourceText() {
|
||||
List<Tuple2<Integer, Integer>> numbersAndOffsets = new ArrayList<Tuple2<Integer, Integer>>();
|
||||
for (JetPsiReference ref : collectInterestingReferences()) {
|
||||
PsiElement target = ref.resolve();
|
||||
assertNotNull(target);
|
||||
PsiElement navigationElement = target.getNavigationElement();
|
||||
numbersAndOffsets.add(new Tuple2<Integer, Integer>(numbersAndOffsets.size() + 1, navigationElement.getTextOffset()));
|
||||
}
|
||||
|
||||
Collections.sort(numbersAndOffsets, Collections.reverseOrder(new Comparator<Tuple2<Integer, Integer>>() {
|
||||
@Override
|
||||
public int compare(Tuple2<Integer, Integer> t1, Tuple2<Integer, Integer> t2) {
|
||||
int offsets = t1._2.compareTo(t2._2);
|
||||
return offsets == 0 ? t1._1.compareTo(t2._1) : offsets;
|
||||
}
|
||||
}));
|
||||
|
||||
Document document = FileDocumentManager.getInstance().getDocument(myLibrarySourceFile);
|
||||
assertNotNull(document);
|
||||
StringBuilder result = new StringBuilder(document.getText());
|
||||
for (Tuple2<Integer, Integer> numberOffset : numbersAndOffsets) {
|
||||
result.insert(numberOffset._2, String.format("<%d>", numberOffset._1));
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isWithSources() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user