Resolve test data fixed
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
package Foo {
|
package Foo
|
||||||
fun bar() = 610
|
fun bar() = 610
|
||||||
}
|
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
return if (Foo.bar() == 610) "OK" else "fail"
|
return if (Foo.bar() == 610) "OK" else "fail"
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
package root
|
// FILE: f.kt
|
||||||
|
~a~package a
|
||||||
~a~package a {
|
|
||||||
import java.*
|
import java.*
|
||||||
|
|
||||||
~a.a~val a : util.List<Int>? = null
|
~a.a~val a : util.List<Int>? = null
|
||||||
|
|
||||||
val y : Any? = `a.b`b
|
val y : Any? = `a.b`b
|
||||||
|
|
||||||
}
|
// FILE: f.kt
|
||||||
|
package a
|
||||||
package a {
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
~a.b~val b : List<Int>? = null
|
~a.b~val b : List<Int>? = null
|
||||||
|
|
||||||
val x = `a.a`a
|
val x = `a.a`a
|
||||||
}
|
|
||||||
|
|
||||||
|
// FILE: f.kt
|
||||||
|
package root
|
||||||
val x = `a`a.`a.a`a
|
val x = `a`a.`a.a`a
|
||||||
|
|
||||||
val y = `a`a.`a.b`b
|
val y = `a`a.`a.b`b
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
~ns~package nestedObjects {
|
~ns~package nestedObjects
|
||||||
object ~A~A {
|
object ~A~A {
|
||||||
val b = `A.B`B
|
val b = `A.B`B
|
||||||
val d = `A`A.`A.B`B.`A.B.A`A
|
val d = `A`A.`A.B`B.`A.B.A`A
|
||||||
@@ -25,4 +25,3 @@
|
|||||||
val c = `A`A.`A.B`B
|
val c = `A`A.`A.B`B
|
||||||
val d = A.B.`A.B.A`A
|
val d = A.B.`A.B.A`A
|
||||||
val e = B.`!`A.B
|
val e = B.`!`A.B
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.jetbrains.jet;
|
package org.jetbrains.jet;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import com.intellij.openapi.Disposable;
|
import com.intellij.openapi.Disposable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
@@ -18,6 +19,9 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -168,5 +172,43 @@ public class JetTestUtils {
|
|||||||
mkdirs(file);
|
mkdirs(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE);
|
||||||
|
public interface TestFileFactory<F> {
|
||||||
|
F create(String fileName, String text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <F> List<F> createTestFiles(String testFileName, String expectedText, TestFileFactory<F> factory) {
|
||||||
|
List<F> testFileFiles = Lists.newArrayList();
|
||||||
|
Matcher matcher = FILE_PATTERN.matcher(expectedText);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
// One file
|
||||||
|
testFileFiles.add(factory.create(testFileName, expectedText));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int processedChars = 0;
|
||||||
|
// Many files
|
||||||
|
while (true) {
|
||||||
|
String fileName = matcher.group(1);
|
||||||
|
int start = matcher.start();
|
||||||
|
assert start == processedChars : "Characters skipped from " + processedChars + " to " + matcher.start();
|
||||||
|
|
||||||
|
boolean nextFileExists = matcher.find();
|
||||||
|
int end;
|
||||||
|
if (nextFileExists) {
|
||||||
|
end = matcher.start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
end = expectedText.length();
|
||||||
|
}
|
||||||
|
String fileText = expectedText.substring(start, end);
|
||||||
|
processedChars = end;
|
||||||
|
|
||||||
|
testFileFiles.add(factory.create(fileName, fileText));
|
||||||
|
|
||||||
|
if (!nextFileExists) break;
|
||||||
|
}
|
||||||
|
assert processedChars == expectedText.length() : "Characters skipped from " + processedChars + " to " + (expectedText.length() - 1);
|
||||||
|
}
|
||||||
|
return testFileFiles;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NonNls;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.Configuration;
|
import org.jetbrains.jet.lang.Configuration;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
|
||||||
@@ -20,15 +21,12 @@ import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class JetDiagnosticsTest extends JetLiteFixture {
|
public class JetDiagnosticsTest extends JetLiteFixture {
|
||||||
private String name;
|
private String name;
|
||||||
public static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE);
|
|
||||||
|
|
||||||
public JetDiagnosticsTest(@NonNls String dataPath, String name) {
|
public JetDiagnosticsTest(@NonNls String dataPath, String name) {
|
||||||
super(dataPath);
|
super(dataPath);
|
||||||
@@ -88,7 +86,12 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
|||||||
|
|
||||||
String expectedText = loadFile(testFileName);
|
String expectedText = loadFile(testFileName);
|
||||||
|
|
||||||
List<TestFile> testFileFiles = createTestFiles(testFileName, expectedText);
|
List<TestFile> testFileFiles = JetTestUtils.createTestFiles(testFileName, expectedText, new JetTestUtils.TestFileFactory<TestFile>() {
|
||||||
|
@Override
|
||||||
|
public TestFile create(String fileName, String text) {
|
||||||
|
return new TestFile(fileName, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
boolean importJdk = expectedText.contains("+JDK");
|
boolean importJdk = expectedText.contains("+JDK");
|
||||||
// Configuration configuration = importJdk ? JavaBridgeConfiguration.createJavaBridgeConfiguration(getProject()) : Configuration.EMPTY;
|
// Configuration configuration = importJdk ? JavaBridgeConfiguration.createJavaBridgeConfiguration(getProject()) : Configuration.EMPTY;
|
||||||
@@ -114,41 +117,6 @@ public class JetDiagnosticsTest extends JetLiteFixture {
|
|||||||
assertEquals(expectedText, actualText.toString());
|
assertEquals(expectedText, actualText.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<TestFile> createTestFiles(String testFileName, String expectedText) {
|
|
||||||
List<TestFile> testFileFiles = Lists.newArrayList();
|
|
||||||
Matcher matcher = FILE_PATTERN.matcher(expectedText);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
// One file
|
|
||||||
testFileFiles.add(new TestFile(testFileName, expectedText));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
int processedChars = 0;
|
|
||||||
// Many files
|
|
||||||
while (true) {
|
|
||||||
String fileName = matcher.group(1);
|
|
||||||
int start = matcher.start();
|
|
||||||
assertTrue("Characters skipped from " + processedChars + " to " + matcher.start(), start == processedChars);
|
|
||||||
|
|
||||||
boolean nextFileExists = matcher.find();
|
|
||||||
int end;
|
|
||||||
if (nextFileExists) {
|
|
||||||
end = matcher.start();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
end = expectedText.length();
|
|
||||||
}
|
|
||||||
String fileText = expectedText.substring(start, end);
|
|
||||||
processedChars = end;
|
|
||||||
|
|
||||||
testFileFiles.add(new TestFile(fileName, fileText));
|
|
||||||
|
|
||||||
if (!nextFileExists) break;
|
|
||||||
}
|
|
||||||
assertTrue("Characters skipped from " + processedChars + " to " + (expectedText.length() - 1), processedChars == expectedText.length());
|
|
||||||
}
|
|
||||||
return testFileFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
// private void convert(File src, File dest) throws IOException {
|
// private void convert(File src, File dest) throws IOException {
|
||||||
// File[] files = src.listFiles();
|
// File[] files = src.listFiles();
|
||||||
// for (File file : files) {
|
// for (File file : files) {
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
package org.jetbrains.jet.resolve;
|
package org.jetbrains.jet.resolve;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import org.jetbrains.jet.JetTestUtils;
|
|
||||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -12,13 +17,14 @@ import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
|
|||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -31,22 +37,37 @@ import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class ExpectedResolveData {
|
public abstract class ExpectedResolveData {
|
||||||
|
|
||||||
private final Map<String, Integer> declarationToPosition = new HashMap<String, Integer>();
|
private static class Position {
|
||||||
private final Map<Integer, String> positionToReference = new HashMap<Integer, String>();
|
private final PsiElement element;
|
||||||
private final Map<Integer, String> positionToType = new HashMap<Integer, String>();
|
|
||||||
private final Map<String, DeclarationDescriptor> nameToDescriptor;
|
|
||||||
private final Map<String, PsiElement> nameToPsiElement;
|
|
||||||
// private final Map<String, JetType> nameToType;
|
|
||||||
|
|
||||||
public ExpectedResolveData(Map<String, DeclarationDescriptor> nameToDescriptor, Map<String, PsiElement> nameToPsiElement/*, Map<String, JetType> nameToType*/) {
|
private Position(JetFile file, int offset) {
|
||||||
this.nameToDescriptor = nameToDescriptor;
|
this.element = file.findElementAt(offset);
|
||||||
this.nameToPsiElement = nameToPsiElement;
|
}
|
||||||
// this.nameToType = nameToType;
|
|
||||||
|
public PsiElement getElement() {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String extractData(String text) {
|
private final Map<String, Position> declarationToPosition = Maps.newHashMap();
|
||||||
|
private final Map<Position, String> positionToReference = Maps.newHashMap();
|
||||||
|
private final Map<Position, String> positionToType = Maps.newHashMap();
|
||||||
|
|
||||||
|
private final Map<String, DeclarationDescriptor> nameToDescriptor;
|
||||||
|
private final Map<String, PsiElement> nameToPsiElement;
|
||||||
|
|
||||||
|
public ExpectedResolveData(Map<String, DeclarationDescriptor> nameToDescriptor, Map<String, PsiElement> nameToPsiElement) {
|
||||||
|
this.nameToDescriptor = nameToDescriptor;
|
||||||
|
this.nameToPsiElement = nameToPsiElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final JetFile createFileFromMarkedUpText(String fileName, String text) {
|
||||||
|
Map<String, Integer> declarationToIntPosition = Maps.newHashMap();
|
||||||
|
Map<Integer, String> intPositionToReference = Maps.newHashMap();
|
||||||
|
Map<Integer, String> intPositionToType = Maps.newHashMap();
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("(~[^~]+~)|(`[^`]+`)");
|
Pattern pattern = Pattern.compile("(~[^~]+~)|(`[^`]+`)");
|
||||||
while (true) {
|
while (true) {
|
||||||
Matcher matcher = pattern.matcher(text);
|
Matcher matcher = pattern.matcher(text);
|
||||||
@@ -56,16 +77,16 @@ public class ExpectedResolveData {
|
|||||||
String name = group.substring(1, group.length() - 1);
|
String name = group.substring(1, group.length() - 1);
|
||||||
int start = matcher.start();
|
int start = matcher.start();
|
||||||
if (group.startsWith("~")) {
|
if (group.startsWith("~")) {
|
||||||
if (declarationToPosition.put(name, start) != null) {
|
if (declarationToIntPosition.put(name, start) != null) {
|
||||||
throw new IllegalArgumentException("Redeclaration: " + name);
|
throw new IllegalArgumentException("Redeclaration: " + name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (group.startsWith("`")) {
|
else if (group.startsWith("`")) {
|
||||||
if (name.startsWith(":")) {
|
if (name.startsWith(":")) {
|
||||||
positionToType.put(start - 1, name.substring(1));
|
intPositionToType.put(start - 1, name.substring(1));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
positionToReference.put(start, name);
|
intPositionToReference.put(start, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -75,16 +96,38 @@ public class ExpectedResolveData {
|
|||||||
text = text.substring(0, start) + text.substring(matcher.end());
|
text = text.substring(0, start) + text.substring(matcher.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println(text);
|
JetFile jetFile = createJetFile(fileName, text);
|
||||||
return text;
|
|
||||||
|
for (Map.Entry<Integer, String> entry : intPositionToType.entrySet()) {
|
||||||
|
positionToType.put(new Position(jetFile, entry.getKey()), entry.getValue());
|
||||||
|
}
|
||||||
|
for (Map.Entry<String, Integer> entry : declarationToIntPosition.entrySet()) {
|
||||||
|
declarationToPosition.put(entry.getKey(), new Position(jetFile, entry.getValue()));
|
||||||
|
}
|
||||||
|
for (Map.Entry<Integer, String> entry : intPositionToReference.entrySet()) {
|
||||||
|
positionToReference.put(new Position(jetFile, entry.getKey()), entry.getValue());
|
||||||
|
}
|
||||||
|
return jetFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkResult(JetFile file) {
|
protected abstract JetFile createJetFile(String fileName, String text);
|
||||||
final Set<PsiElement> unresolvedReferences = new HashSet<PsiElement>();
|
|
||||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(file.getProject());
|
public final void checkResult(List<JetFile> files) {
|
||||||
|
if (files.isEmpty()) {
|
||||||
|
System.err.println("Suspicious: no files");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final Set<PsiElement> unresolvedReferences = Sets.newHashSet();
|
||||||
|
Project project = files.iterator().next().getProject();
|
||||||
|
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
|
||||||
JetStandardLibrary lib = semanticServices.getStandardLibrary();
|
JetStandardLibrary lib = semanticServices.getStandardLibrary();
|
||||||
|
|
||||||
BindingContext bindingContext = JetTestUtils.analyzeNamespace(file.getRootNamespace(), JetControlFlowDataTraceFactory.EMPTY);
|
List<JetDeclaration> declarations = Lists.newArrayList();
|
||||||
|
for (JetFile file : files) {
|
||||||
|
declarations.add(file.getRootNamespace());
|
||||||
|
}
|
||||||
|
|
||||||
|
BindingContext bindingContext = AnalyzerFacade.analyzeNamespacesWithJavaIntegration(project, declarations, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||||
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
|
if (diagnostic instanceof UnresolvedReferenceDiagnostic) {
|
||||||
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
|
UnresolvedReferenceDiagnostic unresolvedReferenceDiagnostic = (UnresolvedReferenceDiagnostic) diagnostic;
|
||||||
@@ -95,20 +138,20 @@ public class ExpectedResolveData {
|
|||||||
Map<String, JetDeclaration> nameToDeclaration = new HashMap<String, JetDeclaration>();
|
Map<String, JetDeclaration> nameToDeclaration = new HashMap<String, JetDeclaration>();
|
||||||
|
|
||||||
Map<JetDeclaration, String> declarationToName = new HashMap<JetDeclaration, String>();
|
Map<JetDeclaration, String> declarationToName = new HashMap<JetDeclaration, String>();
|
||||||
for (Map.Entry<String, Integer> entry : declarationToPosition.entrySet()) {
|
for (Map.Entry<String, Position> entry : declarationToPosition.entrySet()) {
|
||||||
String name = entry.getKey();
|
String name = entry.getKey();
|
||||||
Integer position = entry.getValue();
|
Position position = entry.getValue();
|
||||||
PsiElement element = file.findElementAt(position);
|
PsiElement element = position.getElement();
|
||||||
|
|
||||||
JetDeclaration ancestorOfType = getAncestorOfType(JetDeclaration.class, element);
|
JetDeclaration ancestorOfType = getAncestorOfType(JetDeclaration.class, element);
|
||||||
nameToDeclaration.put(name, ancestorOfType);
|
nameToDeclaration.put(name, ancestorOfType);
|
||||||
declarationToName.put(ancestorOfType, name);
|
declarationToName.put(ancestorOfType, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Integer, String> entry : positionToReference.entrySet()) {
|
for (Map.Entry<Position, String> entry : positionToReference.entrySet()) {
|
||||||
Integer position = entry.getKey();
|
Position position = entry.getKey();
|
||||||
String name = entry.getValue();
|
String name = entry.getValue();
|
||||||
PsiElement element = file.findElementAt(position);
|
PsiElement element = position.getElement();
|
||||||
|
|
||||||
JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(element, JetReferenceExpression.class);
|
JetReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(element, JetReferenceExpression.class);
|
||||||
if ("!".equals(name)) {
|
if ("!".equals(name)) {
|
||||||
@@ -216,11 +259,11 @@ public class ExpectedResolveData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Map.Entry<Integer, String> entry : positionToType.entrySet()) {
|
for (Map.Entry<Position, String> entry : positionToType.entrySet()) {
|
||||||
Integer position = entry.getKey();
|
Position position = entry.getKey();
|
||||||
String typeName = entry.getValue();
|
String typeName = entry.getValue();
|
||||||
|
|
||||||
PsiElement element = file.findElementAt(position);
|
PsiElement element = position.getElement();
|
||||||
JetExpression expression = getAncestorOfType(JetExpression.class, element);
|
JetExpression expression = getAncestorOfType(JetExpression.class, element);
|
||||||
|
|
||||||
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||||
@@ -230,15 +273,16 @@ public class ExpectedResolveData {
|
|||||||
|
|
||||||
assertNotNull("Expected class not found: " + typeName, expectedClass);
|
assertNotNull("Expected class not found: " + typeName, expectedClass);
|
||||||
expectedTypeConstructor = expectedClass.getTypeConstructor();
|
expectedTypeConstructor = expectedClass.getTypeConstructor();
|
||||||
} else {
|
}
|
||||||
Integer declarationPosition = declarationToPosition.get(typeName);
|
else {
|
||||||
|
Position declarationPosition = declarationToPosition.get(typeName);
|
||||||
assertNotNull("Undeclared: " + typeName, declarationPosition);
|
assertNotNull("Undeclared: " + typeName, declarationPosition);
|
||||||
PsiElement declElement = file.findElementAt(declarationPosition);
|
PsiElement declElement = declarationPosition.getElement();
|
||||||
assertNotNull(declarationPosition);
|
assertNotNull(declarationPosition);
|
||||||
JetDeclaration declaration = getAncestorOfType(JetDeclaration.class, declElement);
|
JetDeclaration declaration = getAncestorOfType(JetDeclaration.class, declElement);
|
||||||
assertNotNull(declaration);
|
assertNotNull(declaration);
|
||||||
if (declaration instanceof JetClass) {
|
if (declaration instanceof JetClass) {
|
||||||
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, (JetClass) declaration);
|
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, declaration);
|
||||||
expectedTypeConstructor = classDescriptor.getTypeConstructor();
|
expectedTypeConstructor = classDescriptor.getTypeConstructor();
|
||||||
}
|
}
|
||||||
else if (declaration instanceof JetTypeParameter) {
|
else if (declaration instanceof JetTypeParameter) {
|
||||||
|
|||||||
@@ -2,9 +2,10 @@ package org.jetbrains.jet.resolve;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NonNls;
|
import org.jetbrains.annotations.NonNls;
|
||||||
import org.jetbrains.jet.JetLiteFixture;
|
import org.jetbrains.jet.JetLiteFixture;
|
||||||
|
import org.jetbrains.jet.JetTestUtils;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
@@ -22,8 +23,12 @@ public abstract class ExtensibleResolveTestCase extends JetLiteFixture {
|
|||||||
|
|
||||||
protected void doTest(@NonNls String filePath) throws Exception {
|
protected void doTest(@NonNls String filePath) throws Exception {
|
||||||
String text = loadFile(filePath);
|
String text = loadFile(filePath);
|
||||||
text = expectedResolveData.extractData(text);
|
List<JetFile> files = JetTestUtils.createTestFiles("file.kt", text, new JetTestUtils.TestFileFactory<JetFile>() {
|
||||||
JetFile jetFile = createPsiFile(new File(filePath).getName(), text);
|
@Override
|
||||||
expectedResolveData.checkResult(jetFile);
|
public JetFile create(String fileName, String text) {
|
||||||
|
return expectedResolveData.createFileFromMarkedUpText(fileName, text);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expectedResolveData.checkResult(files);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetFile;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
@@ -54,7 +55,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
|||||||
FunctionDescriptor descriptorForSet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "set", lib.getIntType(), lib.getIntType());
|
FunctionDescriptor descriptorForSet = standardFunction(lib.getArray(), Collections.singletonList(new TypeProjection(lib.getIntType())), "set", lib.getIntType(), lib.getIntType());
|
||||||
nameToDescriptor.put("std::Array.set(Int, Int)", descriptorForSet.getOriginal());
|
nameToDescriptor.put("std::Array.set(Int, Int)", descriptorForSet.getOriginal());
|
||||||
|
|
||||||
Map<String,PsiElement> nameToDeclaration = new HashMap<String, PsiElement>();
|
Map<String, PsiElement> nameToDeclaration = new HashMap<String, PsiElement>();
|
||||||
PsiClass java_util_Collections = findClass("java.util.Collections");
|
PsiClass java_util_Collections = findClass("java.util.Collections");
|
||||||
nameToDeclaration.put("java::java.util.Collections.emptyList()", findMethod(java_util_Collections, "emptyList"));
|
nameToDeclaration.put("java::java.util.Collections.emptyList()", findMethod(java_util_Collections, "emptyList"));
|
||||||
nameToDeclaration.put("java::java.util.Collections", java_util_Collections);
|
nameToDeclaration.put("java::java.util.Collections", java_util_Collections);
|
||||||
@@ -78,7 +79,12 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
|||||||
nameToDeclaration.put("java::java.lang.Number", java_lang_Number);
|
nameToDeclaration.put("java::java.lang.Number", java_lang_Number);
|
||||||
nameToDeclaration.put("java::java.lang.Number.intValue()", java_lang_Number.findMethodsByName("intValue", true)[0]);
|
nameToDeclaration.put("java::java.lang.Number.intValue()", java_lang_Number.findMethodsByName("intValue", true)[0]);
|
||||||
|
|
||||||
return new ExpectedResolveData(nameToDescriptor, nameToDeclaration);
|
return new ExpectedResolveData(nameToDescriptor, nameToDeclaration) {
|
||||||
|
@Override
|
||||||
|
protected JetFile createJetFile(String fileName, String text) {
|
||||||
|
return createCheckAndReturnPsiFile(fileName, text);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -154,6 +160,9 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
|
// TestSuite suite = new TestSuite();
|
||||||
|
// suite.addTest(new JetResolveTest("/resolve/Basic.jet", "basic"));
|
||||||
|
// return suite;
|
||||||
return JetTestCaseBuilder.suiteForDirectory(getHomeDirectory() + "/compiler/testData/", "/resolve/", true, new JetTestCaseBuilder.NamedTestFactory() {
|
return JetTestCaseBuilder.suiteForDirectory(getHomeDirectory() + "/compiler/testData/", "/resolve/", true, new JetTestCaseBuilder.NamedTestFactory() {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user