Added checks for navigation elements for cls members.
This commit is contained in:
@@ -28,6 +28,7 @@ import com.intellij.psi.impl.compiled.ClsElementImpl;
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
@@ -41,6 +42,7 @@ import java.util.Map;
|
||||
@SuppressWarnings("FieldAccessedSynchronizedAndUnsynchronized")
|
||||
public class JetDecompiledData {
|
||||
private JetFile myJetFile;
|
||||
|
||||
private Map<ClsElementImpl, JetDeclaration> myClsElementsToJetElements = new HashMap<ClsElementImpl, JetDeclaration>();
|
||||
|
||||
private static final Object LOCK = new String("decompiled data lock");
|
||||
@@ -96,4 +98,9 @@ public class JetDecompiledData {
|
||||
return decompiledData;
|
||||
}
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
Map<ClsElementImpl, JetDeclaration> getClsElementsToJetElements() {
|
||||
return myClsElementsToJetElements;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
abstract class AbstractClass {
|
||||
}
|
||||
[abstract class AbstractClass {
|
||||
}]
|
||||
@@ -3,20 +3,20 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
abstract class ClassWithAbstractAndOpenMembers {
|
||||
abstract fun abstractFun() : Unit
|
||||
[abstract class ClassWithAbstractAndOpenMembers {
|
||||
[abstract fun abstractFun() : Unit]
|
||||
|
||||
open fun openFun() : Unit { /* compiled code */ }
|
||||
[open fun openFun() : Unit { /* compiled code */ }]
|
||||
|
||||
abstract val abstractVal : jet.String
|
||||
[abstract val abstractVal : jet.String]
|
||||
|
||||
open val openVal : jet.String /* compiled code */
|
||||
[open val openVal : jet.String] /* compiled code */
|
||||
|
||||
open val openValWithGetter : jet.String /* compiled code */
|
||||
[open val openValWithGetter : jet.String] /* compiled code */
|
||||
|
||||
abstract var abstractVar : jet.String
|
||||
[abstract var abstractVar : jet.String]
|
||||
|
||||
open var openVar : jet.String /* compiled code */
|
||||
[open var openVar : jet.String] /* compiled code */
|
||||
|
||||
open var openVarWithGetter : jet.String /* compiled code */
|
||||
}
|
||||
[open var openVarWithGetter : jet.String] /* compiled code */
|
||||
}]
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
class Color {
|
||||
val rgb : jet.Int /* compiled code */
|
||||
}
|
||||
[class Color {
|
||||
[val rgb : jet.Int] /* compiled code */
|
||||
}]
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
class SimpleClass {
|
||||
}
|
||||
[class SimpleClass {
|
||||
}]
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
trait SimpleTrait {
|
||||
}
|
||||
[trait SimpleTrait {
|
||||
}]
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
class SimpleTraitImpl : testData.libraries.SimpleTrait {
|
||||
}
|
||||
[class SimpleTraitImpl : testData.libraries.SimpleTrait {
|
||||
}]
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
class WithInnerAndObject {
|
||||
[class WithInnerAndObject {
|
||||
class object {
|
||||
fun foo() : Unit { /* compiled code */ }
|
||||
[fun foo() : Unit { /* compiled code */ }]
|
||||
}
|
||||
|
||||
class MyInner {
|
||||
trait MyInnerInner {
|
||||
abstract fun innerInnerMethod() : Unit
|
||||
}
|
||||
}
|
||||
}
|
||||
[class MyInner {
|
||||
[trait MyInnerInner {
|
||||
[abstract fun innerInnerMethod() : Unit]
|
||||
}]
|
||||
}]
|
||||
}]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
class WithTraitClassObject {
|
||||
[class WithTraitClassObject {
|
||||
class object : testData.libraries.SimpleTrait {
|
||||
}
|
||||
}
|
||||
}]
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
package testData.libraries
|
||||
|
||||
fun main(val args : jet.Array<jet.String>) : Unit { /* compiled code */ }
|
||||
[fun main(val args : jet.Array<jet.String>) : Unit { /* compiled code */ }]
|
||||
|
||||
|
||||
@@ -23,13 +23,21 @@ import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.roots.libraries.Library;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.compiled.ClsElementImpl;
|
||||
import com.intellij.psi.impl.compiled.ClsFileImpl;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import org.jetbrains.jet.cli.KotlinCompiler;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
* @since 3/11/12
|
||||
@@ -39,6 +47,7 @@ public class LibrariesTest extends PlatformTestCase {
|
||||
private static final String PACKAGE = "testData.libraries";
|
||||
private static final String TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/libraries";
|
||||
private VirtualFile myLibraryDir;
|
||||
private VirtualFile myClassFile;
|
||||
|
||||
public void testAbstractClass() {
|
||||
doTest();
|
||||
@@ -77,15 +86,64 @@ public class LibrariesTest extends PlatformTestCase {
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
String testName = getTestName(false);
|
||||
myClassFile = getClassFile();
|
||||
|
||||
Map<ClsElementImpl, JetDeclaration> map = getDecompiledData(myClassFile).getClsElementsToJetElements();
|
||||
checkNavigationElements(map);
|
||||
String decompiledTextWithMarks = getDecompiledTextWithMarks(map);
|
||||
|
||||
assertSameLinesWithFile(TEST_DATA_PATH + "/" + getTestName(false) + ".kt", decompiledTextWithMarks);
|
||||
}
|
||||
|
||||
private String getDecompiledTextWithMarks(Map<ClsElementImpl, JetDeclaration> map) {
|
||||
String decompiledText = getDecompiledText();
|
||||
|
||||
int[] openings = new int[decompiledText.length() + 1];
|
||||
int[] closings = new int[decompiledText.length() + 1];
|
||||
for (JetDeclaration jetDeclaration : map.values()) {
|
||||
TextRange textRange = jetDeclaration.getTextRange();
|
||||
openings[textRange.getStartOffset()]++;
|
||||
closings[textRange.getEndOffset()]++;
|
||||
}
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i <= decompiledText.length(); i++) {
|
||||
result.append(StringUtil.repeat("]", closings[i]));
|
||||
result.append(StringUtil.repeat("[", openings[i]));
|
||||
if (i < decompiledText.length()) {
|
||||
result.append(decompiledText.charAt(i));
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private String getDecompiledText() {
|
||||
Document document = FileDocumentManager.getInstance().getDocument(myClassFile);
|
||||
assertNotNull(document);
|
||||
return document.getText();
|
||||
}
|
||||
|
||||
private JetDecompiledData getDecompiledData(VirtualFile classFile) {
|
||||
PsiFile classPsiFile = getPsiManager().findFile(classFile);
|
||||
assertInstanceOf(classPsiFile, ClsFileImpl.class);
|
||||
ClsFileImpl clsFile = (ClsFileImpl) classPsiFile;
|
||||
return JetDecompiledData.getDecompiledData(clsFile);
|
||||
}
|
||||
|
||||
private void checkNavigationElements(Map<ClsElementImpl, JetDeclaration> map) {
|
||||
PsiFile classPsiFile = getPsiManager().findFile(myClassFile);
|
||||
for (Map.Entry<ClsElementImpl, JetDeclaration> clsToJet : map.entrySet()) {
|
||||
assertSame(classPsiFile, clsToJet.getKey().getContainingFile());
|
||||
assertSame(clsToJet.getValue(), clsToJet.getKey().getNavigationElement());
|
||||
}
|
||||
}
|
||||
|
||||
private VirtualFile getClassFile() {
|
||||
VirtualFile packageDir = myLibraryDir.findFileByRelativePath(PACKAGE.replace(".", "/"));
|
||||
assertNotNull(packageDir);
|
||||
VirtualFile classFile = packageDir.findChild(testName + ".class");
|
||||
VirtualFile classFile = packageDir.findChild(getTestName(false) + ".class");
|
||||
assertNotNull(classFile);
|
||||
Document document = FileDocumentManager.getInstance().getDocument(classFile);
|
||||
assert document != null;
|
||||
String decompiledText = document.getText();
|
||||
assertSameLinesWithFile(TEST_DATA_PATH + "/" + testName + ".kt", decompiledText);
|
||||
return classFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user