Unresolved references highlighted in the editor. Resolve test added
This commit is contained in:
@@ -1,109 +0,0 @@
|
||||
package org.jetbrains.jet.checkers;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.testFramework.ExpectedHighlightingData;
|
||||
import com.intellij.testFramework.FileTreeAccessFilter;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class ExtensibleHighlightingTestCase extends LightCodeInsightTestCase {
|
||||
private final FileTreeAccessFilter myJavaFilesFilter = new FileTreeAccessFilter();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject())).prepareForTest(true);
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
((DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(getProject())).cleanupAfterTest(true); // has to cleanup by hand since light project does not get disposed any time soon
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
final Throwable[] throwable = {null};
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRunTest();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throwable[0] = t;
|
||||
}
|
||||
}
|
||||
}, "", null);
|
||||
if (throwable[0] != null) {
|
||||
throw throwable[0];
|
||||
}
|
||||
}
|
||||
|
||||
protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFile(filePath);
|
||||
doTestConfiguredFile(checkWarnings, checkInfos);
|
||||
}
|
||||
|
||||
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos) {
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
ExpectedHighlightingData expectedData = new ExpectedHighlightingData(getEditor().getDocument(),checkWarnings, checkInfos) {
|
||||
@Override
|
||||
protected void initAdditionalHighlightingTypes() {
|
||||
// this.this.put();
|
||||
}
|
||||
};
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
getFile().getText(); //to load text
|
||||
myJavaFilesFilter.allowTreeAccessForFile(getVFile());
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(myJavaFilesFilter); // check repository work
|
||||
|
||||
Collection<HighlightInfo> infos = doHighlighting();
|
||||
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
expectedData.checkResult(infos, getEditor().getDocument().getText());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<HighlightInfo> doHighlighting() {
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
|
||||
int[] toIgnore = doFolding() ? ArrayUtil.EMPTY_INT_ARRAY : new int[]{Pass.UPDATE_FOLDING};
|
||||
Editor editor = getEditor();
|
||||
PsiFile file = getFile();
|
||||
if (editor instanceof EditorWindow) {
|
||||
editor = ((EditorWindow)editor).getDelegate();
|
||||
file = InjectedLanguageUtil.getTopLevelFile(file);
|
||||
}
|
||||
|
||||
return CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, toIgnore, false);
|
||||
}
|
||||
|
||||
protected boolean doFolding() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.TopDownAnalyzer;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertSame;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class ExpectedResolveData {
|
||||
|
||||
private final Map<String, Integer> declarationToPosition = new HashMap<String, Integer>();
|
||||
private final Map<Integer, String> positionToReference = new HashMap<Integer, String>();
|
||||
|
||||
public ExpectedResolveData(final Document document) {
|
||||
new WriteCommandAction.Simple(null) {
|
||||
public void run() {
|
||||
extractData(document);
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
private void extractData(Document document) {
|
||||
String text = document.getText();
|
||||
|
||||
Pattern pattern = Pattern.compile("(~[^~]+~)|(`[^`]+`)");
|
||||
while (true) {
|
||||
Matcher matcher = pattern.matcher(text);
|
||||
if (!matcher.find()) break;
|
||||
|
||||
String group = matcher.group();
|
||||
String name = group.substring(1, group.length() - 1);
|
||||
if (group.startsWith("~")) {
|
||||
if (declarationToPosition.put(name, matcher.start()) != null) {
|
||||
throw new IllegalArgumentException("Redeclaration: " + name);
|
||||
}
|
||||
}
|
||||
else if (group.startsWith("`")) {
|
||||
positionToReference.put(matcher.start(), name);
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
document.replaceString(matcher.start(), matcher.end(), "");
|
||||
text = document.getText();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkResult(JetFile file) {
|
||||
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(file.getProject(), ErrorHandler.THROW_EXCEPTION);
|
||||
JetStandardLibrary lib = semanticServices.getStandardLibrary();
|
||||
Map<String, DeclarationDescriptor> nameToDescriptor = new HashMap<String, DeclarationDescriptor>();
|
||||
nameToDescriptor.put("std::Int.plus(Int)", standardFunction(lib.getInt(), "plus", lib.getIntType()));
|
||||
|
||||
TopDownAnalyzer topDownAnalyzer = new TopDownAnalyzer(semanticServices);
|
||||
BindingContext bindingContext = topDownAnalyzer.process(lib.getLibraryScope(), file.getRootNamespace().getDeclarations());
|
||||
|
||||
Map<String, JetDeclaration> nameToDeclaration = new HashMap<String, JetDeclaration>();
|
||||
|
||||
Map<JetDeclaration, String> declarationToName = new HashMap<JetDeclaration, String>();
|
||||
for (Map.Entry<String, Integer> entry : declarationToPosition.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Integer position = entry.getValue();
|
||||
PsiElement element = file.findElementAt(position);
|
||||
|
||||
JetDeclaration ancestorOfType = getAncestorOfType(JetDeclaration.class, element);
|
||||
nameToDeclaration.put(name, ancestorOfType);
|
||||
declarationToName.put(ancestorOfType, name);
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, String> entry : positionToReference.entrySet()) {
|
||||
Integer position = entry.getKey();
|
||||
String name = entry.getValue();
|
||||
PsiElement element = file.findElementAt(position);
|
||||
|
||||
JetDeclaration expected = nameToDeclaration.get(name);
|
||||
|
||||
JetReferenceExpression reference = getAncestorOfType(JetReferenceExpression.class, element);
|
||||
if (expected == null && name.startsWith("std::")) {
|
||||
DeclarationDescriptor expectedDescriptor = nameToDescriptor.get(name);
|
||||
JetTypeReference typeReference = getAncestorOfType(JetTypeReference.class, element);
|
||||
if (expectedDescriptor != null) {
|
||||
DeclarationDescriptor actual = bindingContext.resolveReferenceExpression(reference);
|
||||
assertSame(expectedDescriptor, actual);
|
||||
continue;
|
||||
}
|
||||
|
||||
Type actualType = bindingContext.resolveTypeReference(typeReference);
|
||||
assertNotNull("Type " + name + " not resolved for reference " + name, actualType);
|
||||
ClassDescriptor expectedClass = lib.getLibraryScope().getClass(name.substring(5));
|
||||
assertNotNull("Expected class not found: " + name);
|
||||
assertSame("Type resolution mismatch: ", expectedClass.getTypeConstructor(), actualType.getConstructor());
|
||||
continue;
|
||||
}
|
||||
assert expected != null : "No declaration for " + name;
|
||||
|
||||
PsiElement actual = bindingContext.resolveToDeclarationPsiElement(reference);
|
||||
String actualName = null;
|
||||
if (actual != null) {
|
||||
actualName = declarationToName.get(actual);
|
||||
if (actualName == null) {
|
||||
actualName = actual.toString();
|
||||
}
|
||||
}
|
||||
assertSame(
|
||||
"Reference `" + name + "`" + reference.getReferencedName() + " at " + reference.getTextOffset() + " is resolved into " + actualName + ".",
|
||||
expected, actual);
|
||||
}
|
||||
}
|
||||
|
||||
private DeclarationDescriptor standardFunction(ClassDescriptor classDescriptor, String name, Type parameterType) {
|
||||
FunctionGroup functionGroup = classDescriptor.getMemberScope(Collections.<TypeProjection>emptyList()).getFunctionGroup(name);
|
||||
Collection<FunctionDescriptor> functions = functionGroup.getPossiblyApplicableFunctions(Collections.<Type>emptyList(), Collections.singletonList(parameterType));
|
||||
for (FunctionDescriptor function : functions) {
|
||||
if (function.getUnsubstitutedValueParameters().get(0).getType().equals(parameterType)) {
|
||||
return function;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Not found: std::" + classDescriptor.getName() + "." + name + "(" + parameterType + ")");
|
||||
}
|
||||
|
||||
private <T> T getAncestorOfType(Class<T> type, PsiElement element) {
|
||||
while (element != null && !type.isInstance(element)) {
|
||||
element = element.getParent();
|
||||
}
|
||||
@SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"})
|
||||
T result = (T) element;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzerSettings;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.testFramework.FileTreeAccessFilter;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public abstract class ExtensibleResolveTestCase extends LightCodeInsightTestCase {
|
||||
private final FileTreeAccessFilter myJavaFilesFilter = new FileTreeAccessFilter();
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject())).prepareForTest(true);
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
((DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject())).cleanupAfterTest(true); // has to cleanup by hand since light project does not get disposed any time soon
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
final Throwable[] throwable = {null};
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRunTest();
|
||||
} catch (Throwable t) {
|
||||
throwable[0] = t;
|
||||
}
|
||||
}
|
||||
}, "", null);
|
||||
if (throwable[0] != null) {
|
||||
throw throwable[0];
|
||||
}
|
||||
}
|
||||
|
||||
protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFile(filePath);
|
||||
doTestConfiguredFile(checkWarnings, checkInfos);
|
||||
}
|
||||
|
||||
protected void doTestConfiguredFile(boolean checkWarnings, boolean checkInfos) {
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
// ExpectedHighlightingData expectedData = new ExpectedHighlightingData(getEditor().getDocument(), checkWarnings, checkInfos);
|
||||
ExpectedResolveData expectedData = new ExpectedResolveData(getEditor().getDocument());
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
getFile().getText(); //to load text
|
||||
myJavaFilesFilter.allowTreeAccessForFile(getVFile());
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(myJavaFilesFilter); // check repository work
|
||||
|
||||
Collection<HighlightInfo> infos = doHighlighting();
|
||||
|
||||
getJavaFacade().setAssertOnFileLoadingFilter(VirtualFileFilter.NONE);
|
||||
|
||||
expectedData.checkResult((JetFile) getFile());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected List<HighlightInfo> doHighlighting() {
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
|
||||
int[] toIgnore = doFolding() ? ArrayUtil.EMPTY_INT_ARRAY : new int[]{Pass.UPDATE_FOLDING};
|
||||
Editor editor = getEditor();
|
||||
PsiFile file = getFile();
|
||||
if (editor instanceof EditorWindow) {
|
||||
editor = ((EditorWindow) editor).getDelegate();
|
||||
file = InjectedLanguageUtil.getTopLevelFile(file);
|
||||
}
|
||||
|
||||
return CodeInsightTestFixtureImpl.instantiateAndRun(file, editor, toIgnore, false);
|
||||
}
|
||||
|
||||
protected boolean doFolding() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,21 @@
|
||||
package org.jetbrains.jet.resolve;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.*;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadDomain;
|
||||
import org.jetbrains.jet.lang.resolve.OverloadResolver;
|
||||
import org.jetbrains.jet.lang.types.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.Type;
|
||||
import org.jetbrains.jet.parsing.JetParsingTest;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetResolveTest extends LightDaemonAnalyzerTestCase {
|
||||
public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
private JetStandardLibrary library;
|
||||
|
||||
@Override
|
||||
@@ -38,81 +34,82 @@ public class JetResolveTest extends LightDaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
public void testBasic() throws Exception {
|
||||
JetFile jetFile = JetChangeUtil.createFile(getProject(), FileUtil.loadTextAndClose(new FileReader(getTestDataPath() + "/resolve/Basic.jet")));
|
||||
List<JetDeclaration> declarations = jetFile.getRootNamespace().getDeclarations();
|
||||
BindingContext bindingContext = new TopDownAnalyzer(JetSemanticServices.createSemanticServices(library, ErrorHandler.THROW_EXCEPTION)).process(library.getLibraryScope(), declarations);
|
||||
|
||||
JetClass classADecl = (JetClass) declarations.get(0);
|
||||
ClassDescriptor classA = bindingContext.getClassDescriptor(classADecl);
|
||||
assertNotNull(classA);
|
||||
|
||||
JetScope membersOfA = classA.getMemberScope(Collections.<TypeProjection>emptyList());
|
||||
ClassDescriptor classB = membersOfA.getClass("B");
|
||||
assertNotNull(classB);
|
||||
|
||||
{
|
||||
FunctionGroup fooFG = membersOfA.getFunctionGroup("foo");
|
||||
assertFalse(fooFG.isEmpty());
|
||||
}
|
||||
|
||||
assertReturnType(membersOfA, "foo", library.getIntType());
|
||||
assertReturnType(membersOfA, "foo1", new TypeImpl(classB));
|
||||
assertReturnType(membersOfA, "fooB", library.getIntType());
|
||||
|
||||
JetFunction fooDecl = (JetFunction) classADecl.getDeclarations().get(1);
|
||||
Type expressionType = bindingContext.getExpressionType(fooDecl.getBodyExpression());
|
||||
assertEquals(library.getIntType(), expressionType);
|
||||
|
||||
{
|
||||
DeclarationDescriptor resolve = bindingContext.resolveReferenceExpression((JetReferenceExpression) fooDecl.getBodyExpression());
|
||||
assertSame(bindingContext.getFunctionDescriptor(fooDecl).getUnsubstitutedValueParameters().get(0), resolve);
|
||||
}
|
||||
|
||||
{
|
||||
JetFunction fooBDecl = (JetFunction) classADecl.getDeclarations().get(2);
|
||||
JetCallExpression fooBBody = (JetCallExpression) fooBDecl.getBodyExpression();
|
||||
JetReferenceExpression refToFoo = (JetReferenceExpression) fooBBody.getCalleeExpression();
|
||||
FunctionDescriptor mustBeFoo = (FunctionDescriptor) bindingContext.resolveReferenceExpression(refToFoo);
|
||||
assertSame(bindingContext.getFunctionDescriptor(fooDecl), FunctionDescriptorUtil.getOriginal(mustBeFoo));
|
||||
}
|
||||
|
||||
{
|
||||
JetFunction fooIntDecl = (JetFunction) classADecl.getDeclarations().get(3);
|
||||
JetCallExpression fooIntBody = (JetCallExpression) fooIntDecl.getBodyExpression();
|
||||
JetDotQualifiedExpression qualifiedPlus = (JetDotQualifiedExpression) fooIntBody.getCalleeExpression();
|
||||
JetReferenceExpression refToPlus = (JetReferenceExpression) qualifiedPlus.getSelectorExpression();
|
||||
FunctionDescriptor mustBePlus = (FunctionDescriptor) bindingContext.resolveReferenceExpression(refToPlus);
|
||||
FunctionGroup plusGroup = library.getInt().getMemberScope(Collections.<TypeProjection>emptyList()).getFunctionGroup("plus");
|
||||
Collection<FunctionDescriptor> pluses = plusGroup.getPossiblyApplicableFunctions(Collections.<Type>emptyList(), Collections.singletonList(library.getIntType()));
|
||||
FunctionDescriptor intPlus = null;
|
||||
for (FunctionDescriptor plus : pluses) {
|
||||
intPlus = plus;
|
||||
}
|
||||
assertSame(intPlus, FunctionDescriptorUtil.getOriginal(mustBePlus));
|
||||
}
|
||||
|
||||
{
|
||||
PropertyDescriptor a = classA.getMemberScope(Collections.<TypeProjection>emptyList()).getProperty("a");
|
||||
JetProperty aDecl = (JetProperty) classADecl.getDeclarations().get(5);
|
||||
PropertyDescriptor mustBeA = bindingContext.getPropertyDescriptor(aDecl);
|
||||
assertSame(a, mustBeA);
|
||||
|
||||
JetTypeReference propertyTypeRef = aDecl.getPropertyTypeRef();
|
||||
Type type = bindingContext.resolveTypeReference(propertyTypeRef);
|
||||
assertEquals(library.getIntType(), type);
|
||||
}
|
||||
|
||||
JetClass classCDecl = (JetClass) declarations.get(1);
|
||||
ClassDescriptor classC = bindingContext.getClassDescriptor(classCDecl);
|
||||
assertNotNull(classC);
|
||||
assertEquals(1, classC.getTypeConstructor().getSupertypes().size());
|
||||
assertEquals(classA.getTypeConstructor(), classC.getTypeConstructor().getSupertypes().iterator().next().getConstructor());
|
||||
|
||||
JetScope cScope = classC.getMemberScope(Collections.<TypeProjection>emptyList());
|
||||
ClassDescriptor classC_B = cScope.getClass("B");
|
||||
assertNotNull(classC_B);
|
||||
assertNotSame(classC_B, classB);
|
||||
assertEquals(classC.getTypeConstructor(), classC_B.getTypeConstructor().getSupertypes().iterator().next().getConstructor());
|
||||
doTest("/resolve/Basic.jet", true, true);
|
||||
// JetFile jetFile = JetChangeUtil.createFile(getProject(), FileUtil.loadTextAndClose(new FileReader(getTestDataPath() + "/resolve/Basic.jet")));
|
||||
// List<JetDeclaration> declarations = jetFile.getRootNamespace().getDeclarations();
|
||||
// BindingContext bindingContext = new TopDownAnalyzer(JetSemanticServices.createSemanticServices(library, ErrorHandler.THROW_EXCEPTION)).process(library.getLibraryScope(), declarations);
|
||||
//
|
||||
// JetClass classADecl = (JetClass) declarations.get(0);
|
||||
// ClassDescriptor classA = bindingContext.getClassDescriptor(classADecl);
|
||||
// assertNotNull(classA);
|
||||
//
|
||||
// JetScope membersOfA = classA.getMemberScope(Collections.<TypeProjection>emptyList());
|
||||
// ClassDescriptor classB = membersOfA.getClass("B");
|
||||
// assertNotNull(classB);
|
||||
//
|
||||
// {
|
||||
// FunctionGroup fooFG = membersOfA.getFunctionGroup("foo");
|
||||
// assertFalse(fooFG.isEmpty());
|
||||
// }
|
||||
//
|
||||
// assertReturnType(membersOfA, "foo", library.getIntType());
|
||||
// assertReturnType(membersOfA, "foo1", new TypeImpl(classB));
|
||||
// assertReturnType(membersOfA, "fooB", library.getIntType());
|
||||
//
|
||||
// JetFunction fooDecl = (JetFunction) classADecl.getDeclarations().get(1);
|
||||
// Type expressionType = bindingContext.getExpressionType(fooDecl.getBodyExpression());
|
||||
// assertEquals(library.getIntType(), expressionType);
|
||||
//
|
||||
// {
|
||||
// DeclarationDescriptor resolve = bindingContext.resolveReferenceExpression((JetReferenceExpression) fooDecl.getBodyExpression());
|
||||
// assertSame(bindingContext.getFunctionDescriptor(fooDecl).getUnsubstitutedValueParameters().get(0), resolve);
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// JetFunction fooBDecl = (JetFunction) classADecl.getDeclarations().get(2);
|
||||
// JetCallExpression fooBBody = (JetCallExpression) fooBDecl.getBodyExpression();
|
||||
// JetReferenceExpression refToFoo = (JetReferenceExpression) fooBBody.getCalleeExpression();
|
||||
// FunctionDescriptor mustBeFoo = (FunctionDescriptor) bindingContext.resolveReferenceExpression(refToFoo);
|
||||
// assertSame(bindingContext.getFunctionDescriptor(fooDecl), FunctionDescriptorUtil.getOriginal(mustBeFoo));
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// JetFunction fooIntDecl = (JetFunction) classADecl.getDeclarations().get(3);
|
||||
// JetCallExpression fooIntBody = (JetCallExpression) fooIntDecl.getBodyExpression();
|
||||
// JetDotQualifiedExpression qualifiedPlus = (JetDotQualifiedExpression) fooIntBody.getCalleeExpression();
|
||||
// JetReferenceExpression refToPlus = (JetReferenceExpression) qualifiedPlus.getSelectorExpression();
|
||||
// FunctionDescriptor mustBePlus = (FunctionDescriptor) bindingContext.resolveReferenceExpression(refToPlus);
|
||||
// FunctionGroup plusGroup = library.getInt().getMemberScope(Collections.<TypeProjection>emptyList()).getFunctionGroup("plus");
|
||||
// Collection<FunctionDescriptor> pluses = plusGroup.getPossiblyApplicableFunctions(Collections.<Type>emptyList(), Collections.singletonList(library.getIntType()));
|
||||
// FunctionDescriptor intPlus = null;
|
||||
// for (FunctionDescriptor plus : pluses) {
|
||||
// intPlus = plus;
|
||||
// }
|
||||
// assertSame(intPlus, FunctionDescriptorUtil.getOriginal(mustBePlus));
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// PropertyDescriptor a = classA.getMemberScope(Collections.<TypeProjection>emptyList()).getProperty("a");
|
||||
// JetProperty aDecl = (JetProperty) classADecl.getDeclarations().get(5);
|
||||
// PropertyDescriptor mustBeA = bindingContext.getPropertyDescriptor(aDecl);
|
||||
// assertSame(a, mustBeA);
|
||||
//
|
||||
// JetTypeReference propertyTypeRef = aDecl.getPropertyTypeRef();
|
||||
// Type type = bindingContext.resolveTypeReference(propertyTypeRef);
|
||||
// assertEquals(library.getIntType(), type);
|
||||
// }
|
||||
//
|
||||
// JetClass classCDecl = (JetClass) declarations.get(1);
|
||||
// ClassDescriptor classC = bindingContext.getClassDescriptor(classCDecl);
|
||||
// assertNotNull(classC);
|
||||
// assertEquals(1, classC.getTypeConstructor().getSupertypes().size());
|
||||
// assertEquals(classA.getTypeConstructor(), classC.getTypeConstructor().getSupertypes().iterator().next().getConstructor());
|
||||
//
|
||||
// JetScope cScope = classC.getMemberScope(Collections.<TypeProjection>emptyList());
|
||||
// ClassDescriptor classC_B = cScope.getClass("B");
|
||||
// assertNotNull(classC_B);
|
||||
// assertNotSame(classC_B, classB);
|
||||
// assertEquals(classC.getTypeConstructor(), classC_B.getTypeConstructor().getSupertypes().iterator().next().getConstructor());
|
||||
}
|
||||
|
||||
private void assertReturnType(JetScope membersOfA, String foo, Type returnType) {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
library = new JetStandardLibrary(getProject());
|
||||
semanticServices = JetSemanticServices.createSemanticServices(library, ErrorHandler.THROW_EXCEPTION);
|
||||
semanticServices = JetSemanticServices.createSemanticServices(library, ErrorHandler.DO_NOTHING);
|
||||
classDefinitions = new ClassDefinitions();
|
||||
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
|
||||
}
|
||||
@@ -489,7 +489,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
private static Type makeType(JetScope scope, String typeStr) {
|
||||
return new TypeResolver(BindingTrace.DUMMY).resolveType(scope, JetChangeUtil.createType(getProject(), typeStr));
|
||||
return new TypeResolver(BindingTrace.DUMMY, ErrorHandler.THROW_EXCEPTION).resolveType(scope, JetChangeUtil.createType(getProject(), typeStr));
|
||||
}
|
||||
|
||||
private class ClassDefinitions {
|
||||
@@ -522,7 +522,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
|
||||
public JetScope BASIC_SCOPE = new JetScopeAdapter(library.getLibraryScope()) {
|
||||
@Override
|
||||
public ClassDescriptor getClass(String name) {
|
||||
public ClassDescriptor getClass(@NotNull String name) {
|
||||
if (CLASSES.isEmpty()) {
|
||||
for (String classDeclaration : CLASS_DECLARATIONS) {
|
||||
JetClass classElement = JetChangeUtil.createClass(getProject(), classDeclaration);
|
||||
|
||||
Reference in New Issue
Block a user