BindingTrace & Context refactored to heterogeneous containers
This commit is contained in:
@@ -1,18 +1,13 @@
|
||||
package org.jetbrains.jet;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.ErrorHandler;
|
||||
import org.jetbrains.jet.lang.ErrorHandlerWithRegions;
|
||||
import org.jetbrains.jet.lang.JetDiagnostic;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.util.ReadOnlySlice;
|
||||
import org.jetbrains.jet.util.WritableSlice;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -22,222 +17,46 @@ import java.util.Collection;
|
||||
public class JetTestUtils {
|
||||
public static final BindingTrace DUMMY_TRACE = new BindingTrace() {
|
||||
|
||||
@Override
|
||||
public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordReferenceResolution(@NotNull JetReferenceExpression expression, @NotNull DeclarationDescriptor descriptor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordLabelResolution(@NotNull JetReferenceExpression expression, @NotNull PsiElement element) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordDeclarationResolution(@NotNull PsiElement declaration, @NotNull DeclarationDescriptor descriptor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordValueParameterAsPropertyResolution(@NotNull JetParameter declaration, @NotNull PropertyDescriptor descriptor) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAnnotationResolution(@NotNull JetAnnotationEntry annotationEntry, @NotNull AnnotationDescriptor annotationDescriptor) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordCompileTimeValue(@NotNull JetExpression expression, @NotNull CompileTimeConstant<?> value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordBlock(JetFunctionLiteralExpression expression) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordStatement(@NotNull JetElement statement) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordVariableReassignment(@NotNull JetExpression expression) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordResolutionScope(@NotNull JetExpression expression, @NotNull JetScope scope) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeStatementRecord(@NotNull JetElement statement) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recordAutoCast(@NotNull JetExpression expression, @NotNull JetType type) {
|
||||
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ErrorHandlerWithRegions getErrorHandler() {
|
||||
return new ErrorHandlerWithRegions(new ErrorHandler() {
|
||||
public ErrorHandler getErrorHandler() {
|
||||
return new ErrorHandler() {
|
||||
@Override
|
||||
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
|
||||
throw new IllegalStateException("Unresolved: " + referenceExpression.getText());
|
||||
}
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProcessed(@NotNull JetExpression expression) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markAsProcessed(@NotNull JetExpression expression) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingContext getBindingContext() {
|
||||
return new BindingContext() {
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor getDeclarationDescriptor(PsiElement declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public NamespaceDescriptor getNamespaceDescriptor(JetNamespace declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getClassDescriptor(JetClassOrObject declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeParameterDescriptor getTypeParameterDescriptor(JetTypeParameter declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public FunctionDescriptor getFunctionDescriptor(JetNamedFunction declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorDescriptor getConstructorDescriptor(JetElement declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public AnnotationDescriptor getAnnotationDescriptor(JetAnnotationEntry annotationEntry) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompileTimeConstant<?> getCompileTimeValue(JetExpression expression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableDescriptor getVariableDescriptor(JetProperty declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public VariableDescriptor getVariableDescriptor(JetParameter declaration) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor getPropertyDescriptor(JetParameter primaryConstructorParameter) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public PropertyDescriptor getPropertyDescriptor(JetObjectDeclarationName objectDeclarationName) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getExpressionType(JetExpression expression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor resolveReferenceExpression(JetReferenceExpression referenceExpression) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType resolveTypeReference(JetTypeReference typeReference) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement resolveToDeclarationPsiElement(JetReferenceExpression referenceExpression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiElement getDeclarationPsiElement(DeclarationDescriptor descriptor) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBlock(JetFunctionLiteralExpression expression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStatement(JetExpression expression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBackingField(PropertyDescriptor propertyDescriptor) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isVariableReassignment(JetExpression expression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConstructorDescriptor resolveSuperConstructor(JetDelegatorToSuperCall superCall) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetType getAutoCastType(@NotNull JetExpression expression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public JetScope getResolutionScope(@NotNull JetExpression expression) {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<JetDiagnostic> getDiagnostics() {
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
return DUMMY_TRACE.get(slice, key);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> void record(WritableSlice<K, V> slice, K key, V value) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K> void record(WritableSlice<K, Boolean> slice, K key) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public <K, V> V get(ReadOnlySlice<K, V> slice, K key) {
|
||||
if (slice == BindingContext.PROCESSED) return (V) Boolean.FALSE;
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -12,9 +12,15 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -78,7 +84,7 @@ public class ExpectedResolveData {
|
||||
text = document.getText();
|
||||
}
|
||||
|
||||
System.out.println("text = " + text);
|
||||
System.out.println(text);
|
||||
}
|
||||
|
||||
public void checkResult(JetFile file) {
|
||||
@@ -117,7 +123,7 @@ public class ExpectedResolveData {
|
||||
assertTrue(
|
||||
"Must have been unresolved: " +
|
||||
renderReferenceInContext(referenceExpression) +
|
||||
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.resolveReferenceExpression(referenceExpression)),
|
||||
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(BindingContext.REFERENCE_TARGET, referenceExpression)),
|
||||
unresolvedReferences.contains(referenceExpression));
|
||||
continue;
|
||||
}
|
||||
@@ -125,8 +131,8 @@ public class ExpectedResolveData {
|
||||
assertTrue(
|
||||
"Must have been resolved to null: " +
|
||||
renderReferenceInContext(referenceExpression) +
|
||||
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.resolveReferenceExpression(referenceExpression)),
|
||||
bindingContext.getExpressionType(referenceExpression) == null
|
||||
" but was resolved to " + DescriptorRenderer.TEXT.render(bindingContext.get(BindingContext.REFERENCE_TARGET, referenceExpression)),
|
||||
bindingContext.get(BindingContext.EXPRESSION_TYPE, referenceExpression) == null
|
||||
);
|
||||
continue;
|
||||
}
|
||||
@@ -144,12 +150,12 @@ public class ExpectedResolveData {
|
||||
DeclarationDescriptor expectedDescriptor = nameToDescriptor.get(name);
|
||||
JetTypeReference typeReference = getAncestorOfType(JetTypeReference.class, element);
|
||||
if (expectedDescriptor != null) {
|
||||
DeclarationDescriptor actual = bindingContext.resolveReferenceExpression(reference);
|
||||
DeclarationDescriptor actual = bindingContext.get(BindingContext.REFERENCE_TARGET, reference);
|
||||
assertSame("Expected: " + name, expectedDescriptor.getOriginal(), actual == null ? null : actual.getOriginal());
|
||||
continue;
|
||||
}
|
||||
|
||||
JetType actualType = bindingContext.resolveTypeReference(typeReference);
|
||||
JetType actualType = bindingContext.get(BindingContext.TYPE, typeReference);
|
||||
assertNotNull("Type " + name + " not resolved for reference " + name, actualType);
|
||||
ClassifierDescriptor expectedClass = lib.getLibraryScope().getClassifier(name.substring(5));
|
||||
assertNotNull("Expected class not found: " + name);
|
||||
@@ -158,7 +164,7 @@ public class ExpectedResolveData {
|
||||
}
|
||||
assert expected != null : "No declaration for " + name;
|
||||
|
||||
PsiElement actual = bindingContext.resolveToDeclarationPsiElement(reference);
|
||||
PsiElement actual = BindingContextUtils.resolveToDeclarationPsiElement(bindingContext, reference);
|
||||
|
||||
String actualName = null;
|
||||
if (actual != null) {
|
||||
@@ -172,17 +178,17 @@ public class ExpectedResolveData {
|
||||
if (expected instanceof JetParameter || actual instanceof JetParameter) {
|
||||
DeclarationDescriptor expectedDescriptor;
|
||||
if (name.startsWith("$")) {
|
||||
expectedDescriptor = bindingContext.getPropertyDescriptor((JetParameter) expected);
|
||||
expectedDescriptor = bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, (JetParameter) expected);
|
||||
}
|
||||
else {
|
||||
expectedDescriptor = bindingContext.getDeclarationDescriptor(expected);
|
||||
expectedDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, expected);
|
||||
if (expectedDescriptor == null) {
|
||||
expectedDescriptor = bindingContext.getConstructorDescriptor((JetElement) expected);
|
||||
expectedDescriptor = bindingContext.get(BindingContext.CONSTRUCTOR, (JetElement) expected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
DeclarationDescriptor actualDescriptor = bindingContext.resolveReferenceExpression(reference);
|
||||
DeclarationDescriptor actualDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, reference);
|
||||
if (actualDescriptor instanceof VariableAsFunctionDescriptor) {
|
||||
VariableAsFunctionDescriptor descriptor = (VariableAsFunctionDescriptor) actualDescriptor;
|
||||
actualDescriptor = descriptor.getVariableDescriptor();
|
||||
@@ -206,7 +212,7 @@ public class ExpectedResolveData {
|
||||
PsiElement element = file.findElementAt(position);
|
||||
JetExpression expression = getAncestorOfType(JetExpression.class, element);
|
||||
|
||||
JetType expressionType = bindingContext.getExpressionType(expression);
|
||||
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
TypeConstructor expectedTypeConstructor;
|
||||
if (typeName.startsWith("std::")) {
|
||||
ClassifierDescriptor expectedClass = lib.getLibraryScope().getClassifier(typeName.substring(5));
|
||||
@@ -221,11 +227,11 @@ public class ExpectedResolveData {
|
||||
JetDeclaration declaration = getAncestorOfType(JetDeclaration.class, declElement);
|
||||
assertNotNull(declaration);
|
||||
if (declaration instanceof JetClass) {
|
||||
ClassDescriptor classDescriptor = bindingContext.getClassDescriptor((JetClass) declaration);
|
||||
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.CLASS, (JetClass) declaration);
|
||||
expectedTypeConstructor = classDescriptor.getTypeConstructor();
|
||||
}
|
||||
else if (declaration instanceof JetTypeParameter) {
|
||||
TypeParameterDescriptor typeParameterDescriptor = bindingContext.getTypeParameterDescriptor((JetTypeParameter) declaration);
|
||||
TypeParameterDescriptor typeParameterDescriptor = bindingContext.get(BindingContext.TYPE_PARAMETER, (JetTypeParameter) declaration);
|
||||
expectedTypeConstructor = typeParameterDescriptor.getTypeConstructor();
|
||||
}
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user