Navigation problems in the IDE fixed

This commit is contained in:
Andrey Breslav
2011-05-16 21:07:29 +04:00
parent 0f63489f7c
commit 9103923d39
8 changed files with 204 additions and 83 deletions
@@ -12,74 +12,6 @@ import org.jetbrains.jet.lang.types.JetType;
* @author abreslav * @author abreslav
*/ */
public interface BindingTrace { public interface BindingTrace {
public static final BindingTrace DUMMY = 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 recordBlock(JetFunctionLiteralExpression expression) {
}
@Override
public void recordStatement(@NotNull JetElement statement) {
}
@Override
public void removeStatementRecord(@NotNull JetElement statement) {
}
@Override
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression) {
}
@Override
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor) {
}
@NotNull
@Override
public ErrorHandler getErrorHandler() {
return ErrorHandler.DO_NOTHING;
}
@Override
public boolean isProcessed(@NotNull JetExpression expression) {
return false;
}
@Override
public void markAsProcessed(@NotNull JetExpression expression) {
}
@Override
public BindingContext getBindingContext() {
throw new UnsupportedOperationException();
}
};
void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type); void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type);
@@ -71,7 +71,7 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
@Override @Override
public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type) { public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type) {
expressionTypes.put(expression, type); safePut(expressionTypes, expression, type);
} }
@Override @Override
@@ -81,7 +81,7 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
@Override @Override
public void recordLabelResolution(@NotNull JetReferenceExpression expression, @NotNull PsiElement element) { public void recordLabelResolution(@NotNull JetReferenceExpression expression, @NotNull PsiElement element) {
labelResolutionResults.put(expression, element); safePut(labelResolutionResults, expression, element);
} }
@Override @Override
@@ -91,7 +91,7 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
@Override @Override
public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type) { public void recordTypeResolution(@NotNull JetTypeReference typeReference, @NotNull JetType type) {
types.put(typeReference, type); safePut(types, typeReference, type);
} }
@Override @Override
@@ -106,7 +106,7 @@ public class BindingTraceContext implements BindingContext, BindingTrace {
@Override @Override
public Void visitNamespaceDescriptor(NamespaceDescriptor descriptor, PsiElement declaration) { public Void visitNamespaceDescriptor(NamespaceDescriptor descriptor, PsiElement declaration) {
namespaceDeclarationsToDescriptors.put(declaration, descriptor); safePut(namespaceDeclarationsToDescriptors, declaration, descriptor);
return null; return null;
} }
@@ -573,15 +573,15 @@ public class TopDownAnalyzer {
public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) { public void visitDelegationToSuperCallSpecifier(JetDelegatorToSuperCall call) {
JetTypeReference typeReference = call.getTypeReference(); JetTypeReference typeReference = call.getTypeReference();
if (typeReference != null) { if (typeReference != null) {
if (!jetClass.hasPrimaryConstructor()) { if (jetClass.hasPrimaryConstructor()) {
typeInferrer.checkConstructorCall(scopeForConstructor, typeReference, call);
}
else {
JetArgumentList valueArgumentList = call.getValueArgumentList(); JetArgumentList valueArgumentList = call.getValueArgumentList();
assert valueArgumentList != null; assert valueArgumentList != null;
trace.getErrorHandler().genericError(valueArgumentList.getNode(), trace.getErrorHandler().genericError(valueArgumentList.getNode(),
"Class " + JetPsiUtil.safeName(jetClass.getName()) + " must have a constructor in order to be able to initialize supertypes"); "Class " + JetPsiUtil.safeName(jetClass.getName()) + " must have a constructor in order to be able to initialize supertypes");
} }
else {
typeInferrer.checkConstructorCall(scopeForConstructor, typeReference, call);
}
} }
} }
@@ -28,6 +28,9 @@ public class TypeResolver {
@NotNull @NotNull
public JetType resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference) { public JetType resolveType(@NotNull final JetScope scope, @NotNull final JetTypeReference typeReference) {
JetType cachedType = trace.getBindingContext().resolveTypeReference(typeReference);
if (cachedType != null) return cachedType;
final List<Annotation> annotations = AnnotationResolver.INSTANCE.resolveAnnotations(typeReference.getAttributes()); final List<Annotation> annotations = AnnotationResolver.INSTANCE.resolveAnnotations(typeReference.getAttributes());
JetTypeElement typeElement = typeReference.getTypeElement(); JetTypeElement typeElement = typeReference.getTypeElement();
@@ -494,6 +494,7 @@ public class JetTypeInferrer {
else { else {
trace.getErrorHandler().genericError(((JetElement) call).getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : review the message trace.getErrorHandler().genericError(((JetElement) call).getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : review the message
} }
return null;
} }
else { else {
if (typeElement != null) { if (typeElement != null) {
@@ -0,0 +1,184 @@
package org.jetbrains.jet;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.ClassCodegen;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.JetDiagnostic;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.types.JetType;
import java.util.Collection;
/**
* @author abreslav
*/
public class JetTestUtils {
public static final BindingTrace DUMMY = 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 recordBlock(JetFunctionLiteralExpression expression) {
}
@Override
public void recordStatement(@NotNull JetElement statement) {
}
@Override
public void removeStatementRecord(@NotNull JetElement statement) {
}
@Override
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression) {
}
@Override
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor) {
}
@NotNull
@Override
public ErrorHandler getErrorHandler() {
return ErrorHandler.DO_NOTHING;
}
@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(JetClass declaration) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public TypeParameterDescriptor getTypeParameterDescriptor(JetTypeParameter declaration) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public FunctionDescriptor getFunctionDescriptor(JetFunction declaration) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public ConstructorDescriptor getConstructorDescriptor(JetElement declaration) {
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 JetType getExpressionType(JetExpression expression) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public DeclarationDescriptor resolveReferenceExpression(JetReferenceExpression referenceExpression) {
throw new UnsupportedOperationException(); // TODO
}
@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 ConstructorDescriptor resolveSuperConstructor(JetDelegatorToSuperCall superCall, ClassCodegen classCodegen) {
throw new UnsupportedOperationException(); // TODO
}
@Override
public Collection<JetDiagnostic> getDiagnostics() {
throw new UnsupportedOperationException(); // TODO
}
};
}
};
}
@@ -2,13 +2,13 @@ package org.jetbrains.jet.types;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase; import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor; import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil; import org.jetbrains.jet.lang.descriptors.FunctionDescriptorUtil;
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor; import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
import org.jetbrains.jet.lang.psi.JetChangeUtil; import org.jetbrains.jet.lang.psi.JetChangeUtil;
import org.jetbrains.jet.lang.psi.JetFunction; import org.jetbrains.jet.lang.psi.JetFunction;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver; import org.jetbrains.jet.lang.resolve.ClassDescriptorResolver;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.parsing.JetParsingTest; import org.jetbrains.jet.parsing.JetParsingTest;
@@ -30,7 +30,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
super.setUp(); super.setUp();
library = JetStandardLibrary.getJetStandardLibrary(getProject()); library = JetStandardLibrary.getJetStandardLibrary(getProject());
semanticServices = JetSemanticServices.createSemanticServices(library); semanticServices = JetSemanticServices.createSemanticServices(library);
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY); classDescriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY);
} }
@Override @Override
@@ -5,6 +5,7 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.application.PathManager; import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider; import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
@@ -34,7 +35,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
library = JetStandardLibrary.getJetStandardLibrary(getProject()); library = JetStandardLibrary.getJetStandardLibrary(getProject());
semanticServices = JetSemanticServices.createSemanticServices(library); semanticServices = JetSemanticServices.createSemanticServices(library);
classDefinitions = new ClassDefinitions(); classDefinitions = new ClassDefinitions();
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY); classDescriptorResolver = semanticServices.getClassDescriptorResolver(JetTestUtils.DUMMY);
} }
@Override @Override
@@ -487,14 +488,14 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private void assertType(String expression, JetType expectedType) { private void assertType(String expression, JetType expectedType) {
Project project = getProject(); Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression); JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
JetType type = semanticServices.getTypeInferrer(BindingTrace.DUMMY, JetFlowInformationProvider.NONE).getType(classDefinitions.BASIC_SCOPE, jetExpression, false); JetType type = semanticServices.getTypeInferrer(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
assertTrue(type + " != " + expectedType, type.equals(expectedType)); assertTrue(type + " != " + expectedType, type.equals(expectedType));
} }
private void assertErrorType(String expression) { private void assertErrorType(String expression) {
Project project = getProject(); Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression); JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
JetType type = semanticServices.getTypeInferrer(BindingTrace.DUMMY, JetFlowInformationProvider.NONE).safeGetType(classDefinitions.BASIC_SCOPE, jetExpression, false); JetType type = semanticServices.getTypeInferrer(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).safeGetType(classDefinitions.BASIC_SCOPE, jetExpression, false);
assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type)); assertTrue("Error type expected but " + type + " returned", ErrorUtils.isErrorType(type));
} }
@@ -517,7 +518,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private void assertType(JetScope scope, String expression, String expectedTypeStr) { private void assertType(JetScope scope, String expression, String expectedTypeStr) {
Project project = getProject(); Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression); JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
JetType type = semanticServices.getTypeInferrer(BindingTrace.DUMMY, JetFlowInformationProvider.NONE).getType(scope, jetExpression, false); JetType type = semanticServices.getTypeInferrer(JetTestUtils.DUMMY, JetFlowInformationProvider.NONE).getType(scope, jetExpression, false);
JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr); JetType expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
assertEquals(expectedType, type); assertEquals(expectedType, type);
} }
@@ -527,7 +528,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
} }
private JetType makeType(JetScope scope, String typeStr) { private JetType makeType(JetScope scope, String typeStr) {
return new TypeResolver(semanticServices, BindingTrace.DUMMY, true).resolveType(scope, JetChangeUtil.createType(getProject(), typeStr)); return new TypeResolver(semanticServices, JetTestUtils.DUMMY, true).resolveType(scope, JetChangeUtil.createType(getProject(), typeStr));
} }
private class ClassDefinitions { private class ClassDefinitions {