ErrorHandler moved to BindingTrace

This commit is contained in:
Andrey Breslav
2011-05-06 19:46:44 +04:00
parent 392d3c340d
commit a912bef5c5
16 changed files with 183 additions and 183 deletions
@@ -10,23 +10,21 @@ import org.jetbrains.jet.lang.types.*;
* @author abreslav
*/
public class JetSemanticServices {
public static JetSemanticServices createSemanticServices(JetStandardLibrary standardLibrary, ErrorHandler errorHandler) {
return new JetSemanticServices(standardLibrary, errorHandler);
public static JetSemanticServices createSemanticServices(JetStandardLibrary standardLibrary) {
return new JetSemanticServices(standardLibrary);
}
public static JetSemanticServices createSemanticServices(Project project, ErrorHandler errorHandler) {
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project), errorHandler);
public static JetSemanticServices createSemanticServices(Project project) {
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project));
}
private final JetStandardLibrary standardLibrary;
private final JetTypeChecker typeChecker;
private final OverloadResolver overloadResolver;
private final ErrorHandler errorHandler;
private JetSemanticServices(JetStandardLibrary standardLibrary, ErrorHandler errorHandler) {
private JetSemanticServices(JetStandardLibrary standardLibrary) {
this.standardLibrary = standardLibrary;
this.errorHandler = errorHandler;
this.typeChecker = new JetTypeChecker(standardLibrary);
this.overloadResolver = new OverloadResolver(typeChecker);
}
@@ -46,11 +44,11 @@ public class JetSemanticServices {
return new JetTypeInferrer(trace, flowInformationProvider, this);
}
@NotNull
public ErrorHandler getErrorHandler() {
return errorHandler;
}
// @NotNull
// public ErrorHandler getErrorHandler() {
// return errorHandler;
// }
//
@NotNull
public JetTypeChecker getTypeChecker() {
return typeChecker;
@@ -61,13 +59,4 @@ public class JetSemanticServices {
return overloadResolver;
}
@NotNull
public WritableScope createWritableScope(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner) {
return new WritableScopeImpl(scope, owner, errorHandler, null);
}
@NotNull
public WritableScope createWritableScope(@NotNull JetScope scope, @NotNull DeclarationDescriptor owner, @NotNull DeclarationDescriptorVisitor<?, ? super WritableScope> modificationListener) {
return new WritableScopeImpl(scope, owner, errorHandler, modificationListener);
}
}
@@ -17,7 +17,6 @@ import com.intellij.psi.util.PsiUtilBase;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.Function;
import com.intellij.util.PsiNavigateUtil;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetFunction;
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
@@ -44,12 +43,12 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
JetFile file = PsiTreeUtil.getParentOfType(element, JetFile.class);
assert file != null;
final BindingContext bindingContext = AnalyzingUtils.analyzeFile(file, ErrorHandler.DO_NOTHING);
final BindingContext bindingContext = AnalyzingUtils.analyzeFile(file);
FunctionDescriptor functionDescriptor = bindingContext.getFunctionDescriptor(jetFunction);
final Set<? extends FunctionDescriptor> overriddenFunctions = functionDescriptor.getOverriddenFunctions();
if (!overriddenFunctions.isEmpty()) {
return new LineMarkerInfo<JetFunction>(
jetFunction, jetFunction.getTextOffset(), OVERRIDING_FUNCTION, Pass.UPDATE_ALL,
jetFunction, jetFunction.getTextOffset(), OVERRIDING_FUNCTION, Pass.UPDATE_ALL,
new Function<JetFunction, String>() {
@Override
public String fun(JetFunction jetFunction) {
@@ -66,32 +65,30 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
}
if (list.isEmpty()) {
String myEmptyText = "empty text";
if (myEmptyText != null) {
final JComponent renderer = HintUtil.createErrorLabel(myEmptyText);
final JBPopup popup = JBPopupFactory.getInstance().createComponentPopupBuilder(renderer, renderer).createPopup();
if (event != null) {
popup.show(new RelativePoint(event));
popup.show(new RelativePoint(event));
}
}
return;
return;
}
if (list.size() == 1) {
PsiNavigateUtil.navigate(list.iterator().next());
PsiNavigateUtil.navigate(list.iterator().next());
}
else {
final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() {
@Override
public String getElementText(PsiElement element) {
if (element instanceof JetFunction) {
JetFunction function = (JetFunction) element;
return bindingContext.getFunctionDescriptor(function).toString();
}
return super.getElementText(element);
}
}, "title");
if (event != null) {
popup.show(new RelativePoint(event));
}
final JBPopup popup = NavigationUtil.getPsiElementPopup(PsiUtilBase.toPsiElementArray(list), new DefaultPsiElementCellRenderer() {
@Override
public String getElementText(PsiElement element) {
if (element instanceof JetFunction) {
JetFunction function = (JetFunction) element;
return bindingContext.getFunctionDescriptor(function).toString();
}
return super.getElementText(element);
}
}, "title");
if (event != null) {
popup.show(new RelativePoint(event));
}
}
}
}
@@ -75,11 +75,11 @@ public class JetControlFlowProcessor {
private JetElement resolveLabel(@NotNull String labelName, @NotNull JetSimpleNameExpression labelExpression) {
Stack<JetElement> stack = labeledElements.get(labelName);
if (stack == null || stack.isEmpty()) {
semanticServices.getErrorHandler().unresolvedReference(labelExpression);
trace.getErrorHandler().unresolvedReference(labelExpression);
return null;
}
else if (stack.size() > 1) {
semanticServices.getErrorHandler().genericWarning(labelExpression.getNode(), "There is more than one label with such a name in this scope");
trace.getErrorHandler().genericWarning(labelExpression.getNode(), "There is more than one label with such a name in this scope");
}
JetElement result = stack.peek();
@@ -417,14 +417,14 @@ public class JetControlFlowProcessor {
assert targetLabel != null;
loop = resolveLabel(labelName, targetLabel);
if (!isLoop(loop)) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "The label '" + targetLabel.getText() + "' does not denote a loop");
trace.getErrorHandler().genericError(expression.getNode(), "The label '" + targetLabel.getText() + "' does not denote a loop");
loop = null;
}
}
else {
loop = builder.getCurrentLoop();
if (loop == null) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "'break' and 'continue' are only allowed inside a loop");
trace.getErrorHandler().genericError(expression.getNode(), "'break' and 'continue' are only allowed inside a loop");
}
}
return loop;
@@ -52,11 +52,11 @@ public class AnalyzingUtils {
Project project = namespace.getProject();
BindingTraceContext bindingTraceContext = new BindingTraceContext();
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project, bindingTraceContext.getErrorHandler());
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(project);
JavaSemanticServices javaSemanticServices = new JavaSemanticServices(project, semanticServices, bindingTraceContext);
JetScope libraryScope = semanticServices.getStandardLibrary().getLibraryScope();
WritableScope scope = semanticServices.createWritableScope(libraryScope, new ModuleDescriptor("<module>"));
WritableScope scope = new WritableScopeImpl(libraryScope, new ModuleDescriptor("<module>"), bindingTraceContext.getErrorHandler(), null);
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("").getMemberScope());
// scope.importScope(javaSemanticServices.getDescriptorResolver().resolveNamespace("java.lang").getMemberScope());
scope.importScope(new JavaPackageScope("", null, javaSemanticServices));
@@ -40,7 +40,7 @@ public class ClassDescriptorResolver {
trace.recordDeclarationResolution(classElement, classDescriptor);
WritableScope parameterScope = semanticServices.createWritableScope(scope, classDescriptor);
WritableScope parameterScope = new WritableScopeImpl(scope, classDescriptor, trace.getErrorHandler(), null);
// This call has side-effects on the parameterScope (fills it in)
List<TypeParameterDescriptor> typeParameters
@@ -124,7 +124,7 @@ public class ClassDescriptorResolver {
final JetScope typeParameterScope,
final Collection<? extends JetType> supertypes) {
final WritableScope memberDeclarations = semanticServices.createWritableScope(typeParameterScope, classDescriptor);
final WritableScope memberDeclarations = new WritableScopeImpl(typeParameterScope, classDescriptor, trace.getErrorHandler(), null);
List<JetDeclaration> declarations = classElement.getDeclarations();
for (JetDeclaration declaration : declarations) {
@@ -166,7 +166,7 @@ public class ClassDescriptorResolver {
AnnotationResolver.INSTANCE.resolveAnnotations(function.getModifierList()),
JetPsiUtil.safeName(function.getName())
);
WritableScope innerScope = semanticServices.createWritableScope(scope, functionDescriptor);
WritableScope innerScope = new WritableScopeImpl(scope, functionDescriptor, trace.getErrorHandler(), null);
innerScope.addLabeledDeclaration(functionDescriptor);
// The two calls below have side-effects on parameterScope
@@ -197,12 +197,12 @@ public class ClassDescriptorResolver {
ASTNode valOrVarNode = valueParameter.getValOrVarNode();
if (valueParameter.isRef() && valOrVarNode != null) {
semanticServices.getErrorHandler().genericError(valOrVarNode, "'val' and 'var' are not allowed on ref-parameters");
trace.getErrorHandler().genericError(valOrVarNode, "'val' and 'var' are not allowed on ref-parameters");
}
JetType type;
if (typeReference == null) {
semanticServices.getErrorHandler().genericError(valueParameter.getNode(), "A type annotation is required on a value parameter");
trace.getErrorHandler().genericError(valueParameter.getNode(), "A type annotation is required on a value parameter");
type = ErrorUtils.createErrorType("Type annotation was missing");
} else {
type = typeResolver.resolveType(parameterScope, typeReference);
@@ -359,7 +359,7 @@ public class ClassDescriptorResolver {
private PropertySetterDescriptor resolvePropertySetterDescriptor(@NotNull JetScope scope, @NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
JetPropertyAccessor setter = property.getSetter();
if (setter != null && !property.isVar()) {
semanticServices.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
trace.getErrorHandler().genericError(setter.asElement().getNode(), "A 'val'-property cannot have a setter");
return null;
}
PropertySetterDescriptor setterDescriptor = null;
@@ -370,13 +370,13 @@ public class ClassDescriptorResolver {
setterDescriptor = new PropertySetterDescriptor(propertyDescriptor, annotations, setter.getBodyExpression() != null);
if (parameter != null) {
if (parameter.isRef()) {
semanticServices.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'");
trace.getErrorHandler().genericError(parameter.getRefNode(), "Setter parameters can not be 'ref'");
}
// This check is redundant: the parser does not allow a default value, but we'll keep it just in case
JetExpression defaultValue = parameter.getDefaultValue();
if (defaultValue != null) {
semanticServices.getErrorHandler().genericError(defaultValue.getNode(), "Setter parameters can not have default values");
trace.getErrorHandler().genericError(defaultValue.getNode(), "Setter parameters can not have default values");
}
JetType type;
@@ -389,7 +389,7 @@ public class ClassDescriptorResolver {
JetType inType = propertyDescriptor.getInType();
if (inType != null) {
if (!semanticServices.getTypeChecker().isSubtypeOf(type, inType)) {
semanticServices.getErrorHandler().genericError(typeReference.getNode(), "Setter parameter type must be a subtype of the type of the property, i.e. " + inType);
trace.getErrorHandler().genericError(typeReference.getNode(), "Setter parameter type must be a subtype of the type of the property, i.e. " + inType);
}
}
else {
@@ -433,7 +433,7 @@ public class ClassDescriptorResolver {
if (propertyTypeRef == null) {
JetExpression initializer = property.getInitializer();
if (initializer == null) {
semanticServices.getErrorHandler().genericError(property.getNode(), "This property must either have a type annotation or be initialized");
trace.getErrorHandler().genericError(property.getNode(), "This property must either have a type annotation or be initialized");
type = ErrorUtils.createErrorType("No type, no body");
} else {
// TODO : ??? Fix-point here: what if we have something like "val a = foo {a.bar()}"
@@ -467,7 +467,7 @@ public class ClassDescriptorResolver {
return constructorDescriptor.initialize(
resolveValueParameters(
constructorDescriptor,
semanticServices.createWritableScope(scope, classDescriptor),
new WritableScopeImpl(scope, classDescriptor, trace.getErrorHandler(), null),
valueParameters));
}
@@ -496,7 +496,7 @@ public class ClassDescriptorResolver {
if (modifierList != null) {
ASTNode abstractNode = modifierList.getModifierNode(JetTokens.ABSTRACT_KEYWORD);
if (abstractNode != null) {
semanticServices.getErrorHandler().genericError(abstractNode, "This property cannot be declared abstract");
trace.getErrorHandler().genericError(abstractNode, "This property cannot be declared abstract");
}
}
@@ -3,7 +3,6 @@ package org.jetbrains.jet.lang.resolve;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.types.*;
import java.util.List;
@@ -26,10 +25,10 @@ public class MutableClassDescriptor extends MutableDeclarationDescriptor impleme
private final WritableScope writableMemberScope;
private JetScope unsubstitutedMemberScope;
public MutableClassDescriptor(@NotNull JetSemanticServices semanticServices, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
public MutableClassDescriptor(@NotNull BindingTrace trace, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetScope outerScope) {
super(containingDeclaration);
this.classHeaderScope = semanticServices.createWritableScope(outerScope, this);
this.writableMemberScope = semanticServices.createWritableScope(classHeaderScope, this, new DeclarationDescriptorVisitor<Void, WritableScope>() {
this.classHeaderScope = new WritableScopeImpl(outerScope, this, trace.getErrorHandler(), null);
this.writableMemberScope = new WritableScopeImpl(classHeaderScope, this, trace.getErrorHandler(), new DeclarationDescriptorVisitor<Void, WritableScope>() {
@Override
public Void visitPropertyDescriptor(PropertyDescriptor descriptor, WritableScope data) {
properties.add(descriptor);
@@ -55,7 +55,7 @@ public class TopDownAnalyzer {
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
if (simpleNameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
if (!trace.hasBackingField((PropertyDescriptor) descriptor)) {
TopDownAnalyzer.this.semanticServices.getErrorHandler().genericError(expression.getNode(), "This property does not have a backing field");
TopDownAnalyzer.this.trace.getErrorHandler().genericError(expression.getNode(), "This property does not have a backing field");
}
}
}
@@ -86,7 +86,7 @@ public class TopDownAnalyzer {
}
public void process(@NotNull JetScope outerScope, @NotNull List<JetDeclaration> declarations) {
final WritableScope toplevelScope = semanticServices.createWritableScope(outerScope, outerScope.getContainingDeclaration()); // TODO ?!
final WritableScope toplevelScope = new WritableScopeImpl(outerScope, outerScope.getContainingDeclaration(), trace.getErrorHandler(), null); // TODO ?!
trace.setToplevelScope(toplevelScope); // TODO : this is a hack
collectTypeDeclarators(toplevelScope, declarations);
resolveTypeDeclarations();
@@ -123,7 +123,7 @@ public class TopDownAnalyzer {
Collections.<Annotation>emptyList(), // TODO
name
);
namespaceDescriptor.initialize(semanticServices.createWritableScope(JetScope.EMPTY, namespaceDescriptor));
namespaceDescriptor.initialize(new WritableScopeImpl(JetScope.EMPTY, namespaceDescriptor, trace.getErrorHandler(), null));
declaringScope.addNamespace(namespaceDescriptor);
trace.recordDeclarationResolution(namespace, namespaceDescriptor);
}
@@ -165,7 +165,7 @@ public class TopDownAnalyzer {
}
private WritableScope processClass(@NotNull WritableScope declaringScope, JetClass klass) {
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(semanticServices, declaringScope.getContainingDeclaration(), declaringScope);
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(trace, declaringScope.getContainingDeclaration(), declaringScope);
mutableClassDescriptor.setName(JetPsiUtil.safeName(klass.getName()));
declaringScope.addClassifierDescriptor(mutableClassDescriptor);
@@ -235,7 +235,7 @@ public class TopDownAnalyzer {
processSecondaryConstructor((MutableClassDescriptor) containingDeclaration, constructor);
}
else {
semanticServices.getErrorHandler().genericError(constructor.getNode(), "Constructors are only allowed inside classes");
trace.getErrorHandler().genericError(constructor.getNode(), "Constructors are only allowed inside classes");
}
}
@@ -246,7 +246,7 @@ public class TopDownAnalyzer {
@Override
public void visitDeclaration(JetDeclaration dcl) {
semanticServices.getErrorHandler().genericError(dcl.getNode(), "[TopDownAnalyzer] Unsupported declaration: " + dcl); // TODO
trace.getErrorHandler().genericError(dcl.getNode(), "[TopDownAnalyzer] Unsupported declaration: " + dcl); // TODO
}
});
}
@@ -301,7 +301,7 @@ public class TopDownAnalyzer {
}
private void processClassObject(JetClassObject classObject) {
semanticServices.getErrorHandler().genericError(classObject.getNode(), "Class objects are not supported yet"); // TODO
trace.getErrorHandler().genericError(classObject.getNode(), "Class objects are not supported yet"); // TODO
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -357,7 +357,7 @@ public class TopDownAnalyzer {
if (trace.hasBackingField(propertyDescriptor)) {
PsiElement nameIdentifier = jetClass.getNameIdentifier();
if (nameIdentifier != null) {
semanticServices.getErrorHandler().genericError(nameIdentifier.getNode(),
trace.getErrorHandler().genericError(nameIdentifier.getNode(),
"This class must have a primary constructor, because property " + propertyDescriptor.getName() + " has a backing field");
}
break;
@@ -386,7 +386,7 @@ public class TopDownAnalyzer {
JetType type = typeInferrer.getType(scope, delegateExpression, false);
JetType supertype = trace.resolveTypeReference(specifier.getTypeReference());
if (type != null && !semanticServices.getTypeChecker().isSubtypeOf(type, supertype)) { // TODO : Convertible?
semanticServices.getErrorHandler().typeMismatch(delegateExpression, supertype, type);
trace.getErrorHandler().typeMismatch(delegateExpression, supertype, type);
}
}
}
@@ -398,7 +398,7 @@ public class TopDownAnalyzer {
if (!jetClass.hasPrimaryConstructor()) {
JetArgumentList valueArgumentList = call.getValueArgumentList();
assert valueArgumentList != null;
semanticServices.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");
}
else {
@@ -415,11 +415,11 @@ public class TopDownAnalyzer {
if (declarationDescriptor instanceof ClassDescriptor) {
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
if (classDescriptor.hasConstructors()) {
semanticServices.getErrorHandler().genericError(specifier.getNode(), "This type has a constructor, and thus must be initialized here");
trace.getErrorHandler().genericError(specifier.getNode(), "This type has a constructor, and thus must be initialized here");
}
}
else {
semanticServices.getErrorHandler().genericError(specifier.getNode(), "Only classes may serve as supertypes");
trace.getErrorHandler().genericError(specifier.getNode(), "Only classes may serve as supertypes");
}
}
@@ -456,7 +456,7 @@ public class TopDownAnalyzer {
}
else {
for (JetClassInitializer anonymousInitializer : anonymousInitializers) {
semanticServices.getErrorHandler().genericError(anonymousInitializer.getNode(), "Anonymous initializers are only allowed in the presence of a primary constructor");
trace.getErrorHandler().genericError(anonymousInitializer.getNode(), "Anonymous initializers are only allowed in the presence of a primary constructor");
}
}
}
@@ -484,12 +484,12 @@ public class TopDownAnalyzer {
JetClass containingClass = PsiTreeUtil.getParentOfType(declaration, JetClass.class);
assert containingClass != null : "This must be guaranteed by the parser";
if (!containingClass.hasPrimaryConstructor()) {
semanticServices.getErrorHandler().genericError(declaration.getNameNode(), "A secondary constructor may appear only in a class that has a primary constructor");
trace.getErrorHandler().genericError(declaration.getNameNode(), "A secondary constructor may appear only in a class that has a primary constructor");
}
else {
List<JetDelegationSpecifier> initializers = declaration.getInitializers();
if (initializers.isEmpty()) {
semanticServices.getErrorHandler().genericError(declaration.getNameNode(), "Secondary constructors must have an initializer list");
trace.getErrorHandler().genericError(declaration.getNameNode(), "Secondary constructors must have an initializer list");
}
else {
initializers.get(0).accept(new JetVisitor() {
@@ -516,12 +516,12 @@ public class TopDownAnalyzer {
@Override
public void visitDelegationByExpressionSpecifier(JetDelegatorByExpressionSpecifier specifier) {
semanticServices.getErrorHandler().genericError(specifier.getNode(), "'by'-clause is only supported for primary constructors");
trace.getErrorHandler().genericError(specifier.getNode(), "'by'-clause is only supported for primary constructors");
}
@Override
public void visitDelegationToSuperClassSpecifier(JetDelegatorToSuperClass specifier) {
semanticServices.getErrorHandler().genericError(specifier.getNode(), "Constructor parameters required");
trace.getErrorHandler().genericError(specifier.getNode(), "Constructor parameters required");
}
@Override
@@ -531,7 +531,7 @@ public class TopDownAnalyzer {
});
for (int i = 1, initializersSize = initializers.size(); i < initializersSize; i++) {
JetDelegationSpecifier initializer = initializers.get(i);
semanticServices.getErrorHandler().genericError(initializer.getNode(), "Only one call to 'this(...)' is allowed");
trace.getErrorHandler().genericError(initializer.getNode(), "Only one call to 'this(...)' is allowed");
}
}
}
@@ -547,11 +547,11 @@ public class TopDownAnalyzer {
@NotNull
private JetScope getInnerScopeForConstructor(@NotNull ConstructorDescriptor descriptor, @NotNull JetScope declaringScope) {
WritableScope constructorScope = semanticServices.createWritableScope(declaringScope, declaringScope.getContainingDeclaration());
WritableScope constructorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), trace.getErrorHandler(), null);
for (PropertyDescriptor propertyDescriptor : declaringScopesToProperties.get(descriptor.getContainingDeclaration())) {
constructorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
}
return FunctionDescriptorUtil.getFunctionInnerScope(constructorScope, descriptor, semanticServices);
return FunctionDescriptorUtil.getFunctionInnerScope(constructorScope, descriptor, trace);
}
private void resolvePropertyDeclarationBodies() {
@@ -572,7 +572,7 @@ public class TopDownAnalyzer {
if (initializer != null) {
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
if (primaryConstructor == null) {
semanticServices.getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed when no primary constructor is present");
trace.getErrorHandler().genericError(initializer.getNode(), "Property initializers are not allowed when no primary constructor is present");
}
else {
JetScope scope = getInnerScopeForConstructor(primaryConstructor, classDescriptor.getWritableUnsubstitutedMemberScope());
@@ -605,7 +605,7 @@ public class TopDownAnalyzer {
private void resolvePropertyAccessors(JetProperty property, PropertyDescriptor propertyDescriptor, WritableScope declaringScope) {
BindingTraceAdapter fieldAccessTrackingTrace = createFieldTrackingTrace(propertyDescriptor);
WritableScope accessorScope = semanticServices.createWritableScope(declaringScope, declaringScope.getContainingDeclaration());
WritableScope accessorScope = new WritableScopeImpl(declaringScope, declaringScope.getContainingDeclaration(), trace.getErrorHandler(), null);
accessorScope.addPropertyDescriptorByFieldName("$" + propertyDescriptor.getName(), propertyDescriptor);
JetPropertyAccessor getter = property.getGetter();
@@ -622,7 +622,7 @@ public class TopDownAnalyzer {
JetExpression initializer = property.getInitializer();
if (!property.isVar() && initializer != null && !trace.hasBackingField(propertyDescriptor)) {
semanticServices.getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no setter and no backing field either");
trace.getErrorHandler().genericError(initializer.getNode(), "Initializer is not allowed here because this property has no setter and no backing field either");
}
}
@@ -662,7 +662,7 @@ public class TopDownAnalyzer {
}
if (type != null && expectedType != null
&& !semanticServices.getTypeChecker().isConvertibleTo(type, expectedType)) {
semanticServices.getErrorHandler().typeMismatch(initializer, expectedType, type);
trace.getErrorHandler().typeMismatch(initializer, expectedType, type);
}
}
@@ -714,12 +714,12 @@ public class TopDownAnalyzer {
// though it'd better be reported more specifically
for (JetElement element : rootElements) {
semanticServices.getErrorHandler().genericError(element.getNode(), "Unreachable code");
trace.getErrorHandler().genericError(element.getNode(), "Unreachable code");
}
}
else {
if (!functionDescriptor.isReturnTypeSet()) {
semanticServices.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
trace.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
functionDescriptor.setUnsubstitutedReturnType(ErrorUtils.createErrorType("No type, no body"));
}
}
@@ -844,7 +844,7 @@ public class TopDownAnalyzer {
@Override
public void visitUnsupportedElementInstruction(UnsupportedElementInstruction instruction) {
semanticServices.getErrorHandler().genericError(instruction.getElement().getNode(), "Unsupported by control-flow builder " + instruction.getElement());
trace.getErrorHandler().genericError(instruction.getElement().getNode(), "Unsupported by control-flow builder " + instruction.getElement());
}
@Override
@@ -866,7 +866,7 @@ public class TopDownAnalyzer {
public void visitInstruction(Instruction instruction) {
if (instruction instanceof JetElementInstructionImpl) {
JetElementInstructionImpl elementInstruction = (JetElementInstructionImpl) instruction;
semanticServices.getErrorHandler().genericError(elementInstruction.getElement().getNode(), "Unsupported by control-flow builder " + elementInstruction.getElement());
trace.getErrorHandler().genericError(elementInstruction.getElement().getNode(), "Unsupported by control-flow builder " + elementInstruction.getElement());
}
else {
throw new UnsupportedOperationException(instruction.toString());
@@ -83,9 +83,9 @@ public class TypeResolver {
if (actualArgumentCount != expectedArgumentCount) {
String errorMessage = (expectedArgumentCount == 0 ? "No" : expectedArgumentCount) + " type arguments expected";
if (actualArgumentCount == 0) {
semanticServices.getErrorHandler().genericError(type.getNode(), errorMessage);
trace.getErrorHandler().genericError(type.getNode(), errorMessage);
} else if (expectedArgumentCount == 0) {
semanticServices.getErrorHandler().genericError(type.getTypeArgumentList().getNode(), errorMessage);
trace.getErrorHandler().genericError(type.getTypeArgumentList().getNode(), errorMessage);
}
} else {
result[0] = new JetTypeImpl(
@@ -188,7 +188,7 @@ public class TypeResolver {
ClassifierDescriptor classifierDescriptor = resolveClassWithoutErrorReporting(scope, userType);
if (classifierDescriptor == null) {
semanticServices.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
trace.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
}
return classifierDescriptor;
@@ -231,7 +231,7 @@ public class TypeResolver {
NamespaceDescriptor namespaceDescriptor = resolveNamespace(scope, userType);
if (namespaceDescriptor == null) {
semanticServices.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
trace.getErrorHandler().unresolvedReference(userType.getReferenceExpression());
return null;
}
return namespaceDescriptor.getMemberScope();
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.types;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.JetScope;
@@ -59,6 +60,12 @@ public interface BindingTrace {
@Override
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor) {
}
@NotNull
@Override
public ErrorHandler getErrorHandler() {
return ErrorHandler.DO_NOTHING;
}
};
public void recordExpressionType(@NotNull JetExpression expression, @NotNull JetType type);
@@ -84,4 +91,7 @@ public interface BindingTrace {
public void removeReferenceResolution(@NotNull JetReferenceExpression referenceExpression);
public void requireBackingField(@NotNull PropertyDescriptor propertyDescriptor);
@NotNull
public ErrorHandler getErrorHandler();
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.types;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.JetScope;
@@ -62,6 +63,12 @@ public class BindingTraceAdapter implements BindingTrace {
originalTrace.requireBackingField(propertyDescriptor);
}
@NotNull
@Override
public ErrorHandler getErrorHandler() {
return originalTrace.getErrorHandler();
}
@Override
public void removeStatementRecord(@NotNull JetElement statement) {
originalTrace.removeStatementRecord(statement);
@@ -5,9 +5,9 @@ import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.resolve.JetScope;
import org.jetbrains.jet.lang.resolve.WritableScope;
import org.jetbrains.jet.lang.resolve.WritableScopeImpl;
import java.util.*;
@@ -95,8 +95,8 @@ public class FunctionDescriptorUtil {
}
@NotNull
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull JetSemanticServices semanticServices) {
WritableScope parameterScope = semanticServices.createWritableScope(outerScope, descriptor);
public static JetScope getFunctionInnerScope(@NotNull JetScope outerScope, @NotNull FunctionDescriptor descriptor, @NotNull BindingTrace trace) {
WritableScope parameterScope = new WritableScopeImpl(outerScope, descriptor, trace.getErrorHandler(), null);
for (TypeParameterDescriptor typeParameter : descriptor.getTypeParameters()) {
parameterScope.addTypeParameterDescriptor(typeParameter);
}
@@ -4,7 +4,6 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiFileFactory;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.JetFileType;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.psi.JetFile;
@@ -69,7 +68,7 @@ public class JetStandardLibrary {
JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet",
JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream)));
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this, ErrorHandler.DO_NOTHING);
JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this);
BindingTraceContext bindingTraceContext = new BindingTraceContext();
TopDownAnalyzer bootstrappingTDA = new TopDownAnalyzer(bootstrappingSemanticServices, bindingTraceContext);
bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations());
@@ -184,7 +184,7 @@ public class JetTypeInferrer {
@Override
public void visitJetElement(JetElement elem) {
semanticServices.getErrorHandler().genericError(elem.getNode(), "Unsupported in call element"); // TODO : Message
trace.getErrorHandler().genericError(elem.getNode(), "Unsupported in call element"); // TODO : Message
}
});
return wrapForTracing(result[0], reference[0], argumentList, true);
@@ -195,14 +195,14 @@ public class JetTypeInferrer {
boolean namespaceType = receiverType instanceof NamespaceType;
boolean nullable = !namespaceType && receiverType.isNullable();
if (nullable && expression.getOperationSign() == JetTokens.DOT) {
semanticServices.getErrorHandler().genericError(expression.getOperationTokenNode(), "Only safe calls (?.) are allowed on a nullable receiver of type " + receiverType);
trace.getErrorHandler().genericError(expression.getOperationTokenNode(), "Only safe calls (?.) are allowed on a nullable receiver of type " + receiverType);
}
else if (!nullable && expression.getOperationSign() == JetTokens.SAFE_ACCESS) {
if (namespaceType) {
semanticServices.getErrorHandler().genericError(expression.getOperationTokenNode(), "Safe calls are not allowed on namespaces");
trace.getErrorHandler().genericError(expression.getOperationTokenNode(), "Safe calls are not allowed on namespaces");
}
else {
semanticServices.getErrorHandler().genericWarning(expression.getOperationTokenNode(), "Unnecessary safe call on a non-null receiver of type " + receiverType);
trace.getErrorHandler().genericWarning(expression.getOperationTokenNode(), "Unnecessary safe call on a non-null receiver of type " + receiverType);
}
}
}
@@ -239,24 +239,24 @@ public class JetTypeInferrer {
if (reportErrors) {
switch (resolutionResult.getResultCode()) {
case NAME_NOT_FOUND:
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
trace.getErrorHandler().unresolvedReference(referenceExpression);
break;
case SINGLE_FUNCTION_ARGUMENT_MISMATCH:
if (argumentList != null) {
// TODO : More helpful message. NOTE: there's a separate handling for this for constructors
semanticServices.getErrorHandler().genericError(argumentList.getNode(), "Arguments do not match " + DescriptorUtil.renderPresentableText(resolutionResult.getFunctionDescriptor()));
trace.getErrorHandler().genericError(argumentList.getNode(), "Arguments do not match " + DescriptorUtil.renderPresentableText(resolutionResult.getFunctionDescriptor()));
}
else {
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
trace.getErrorHandler().unresolvedReference(referenceExpression);
}
break;
case AMBIGUITY:
if (argumentList != null) {
// TODO : More helpful message. NOTE: there's a separate handling for this for constructors
semanticServices.getErrorHandler().genericError(argumentList.getNode(), "Overload ambiguity [TODO : more helpful message]");
trace.getErrorHandler().genericError(argumentList.getNode(), "Overload ambiguity [TODO : more helpful message]");
}
else {
semanticServices.getErrorHandler().unresolvedReference(referenceExpression);
trace.getErrorHandler().unresolvedReference(referenceExpression);
}
break;
default:
@@ -298,21 +298,21 @@ public class JetTypeInferrer {
if (typeChecker.isConvertibleBySpecialConversion(actualType, expectedReturnType)) {
if (expectedReturnType.getConstructor().equals(JetStandardClasses.getUnitType().getConstructor())
&& element.getParent() instanceof JetReturnExpression) {
semanticServices.getErrorHandler().genericError(element.getNode(), "This function must return a value of type Unit");
trace.getErrorHandler().genericError(element.getNode(), "This function must return a value of type Unit");
}
}
else {
if (element == function) {
JetExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null;
semanticServices.getErrorHandler().genericError(bodyExpression.getNode(), "This function must return a value of type " + expectedReturnType);
trace.getErrorHandler().genericError(bodyExpression.getNode(), "This function must return a value of type " + expectedReturnType);
}
else if (element instanceof JetExpression) {
JetExpression expression = (JetExpression) element;
semanticServices.getErrorHandler().typeMismatch(expression, expectedReturnType, actualType);
trace.getErrorHandler().typeMismatch(expression, expectedReturnType, actualType);
}
else {
semanticServices.getErrorHandler().genericError(element.getNode(), "This function must return a value of type " + expectedReturnType);
trace.getErrorHandler().genericError(element.getNode(), "This function must return a value of type " + expectedReturnType);
}
}
}
@@ -322,7 +322,7 @@ public class JetTypeInferrer {
private Map<JetElement, JetType> collectReturnedExpressions(JetScope outerScope, JetDeclarationWithBody function, FunctionDescriptor functionDescriptor) {
JetExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null;
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, semanticServices);
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(outerScope, functionDescriptor, trace);
getType(functionInnerScope, bodyExpression, function.hasBlockBody());
Collection<JetExpression> returnedExpressions = new ArrayList<JetExpression>();
Collection<JetElement> elementsReturningUnit = new ArrayList<JetElement>();
@@ -348,7 +348,7 @@ public class JetTypeInferrer {
}
DeclarationDescriptor containingDescriptor = outerScope.getContainingDeclaration();
WritableScope scope = semanticServices.createWritableScope(outerScope, containingDescriptor);
WritableScope scope = new WritableScopeImpl(outerScope, containingDescriptor, trace.getErrorHandler(), null);
return getBlockReturnedTypeWithWritableScope(scope, block);
}
@@ -403,7 +403,7 @@ public class JetTypeInferrer {
for (JetTypeProjection typeArgument : typeArguments) {
if (typeArgument.getProjectionKind() != JetProjectionKind.NONE) {
semanticServices.getErrorHandler().genericError(typeArgument.getNode(), "Projections are not allowed on type parameters for methods"); // TODO : better positioning
trace.getErrorHandler().genericError(typeArgument.getNode(), "Projections are not allowed on type parameters for methods"); // TODO : better positioning
}
}
@@ -478,7 +478,7 @@ public class JetTypeInferrer {
case OUT:
case STAR:
// TODO : Bug in the editor
semanticServices.getErrorHandler().genericError(typeProjection.getProjectionNode(), "Projections are not allowed in constructor type arguments");
trace.getErrorHandler().genericError(typeProjection.getProjectionNode(), "Projections are not allowed in constructor type arguments");
break;
case NONE:
break;
@@ -491,12 +491,12 @@ public class JetTypeInferrer {
}
}
else {
semanticServices.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
}
}
else {
if (typeElement != null) {
semanticServices.getErrorHandler().genericError(typeElement.getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : Better message
trace.getErrorHandler().genericError(typeElement.getNode(), "Calling a constructor is only supported for ordinary classes"); // TODO : Better message
}
}
return null;
@@ -546,7 +546,7 @@ public class JetTypeInferrer {
// TODO : more helpful message
JetArgumentList argumentList = call.getValueArgumentList();
if (argumentList != null) {
semanticServices.getErrorHandler().genericError(argumentList.getNode(), "Cannot find an overload for these arguments");
trace.getErrorHandler().genericError(argumentList.getNode(), "Cannot find an overload for these arguments");
}
constructorReturnedType = receiverType;
}
@@ -615,7 +615,7 @@ public class JetTypeInferrer {
flowInformationProvider.collectDominatedExpressions(expression, dominated);
Set<JetElement> rootExpressions = JetPsiUtil.findRootExpressions(dominated);
for (JetElement rootExpression : rootExpressions) {
semanticServices.getErrorHandler().genericError(rootExpression.getNode(),
trace.getErrorHandler().genericError(rootExpression.getNode(),
"This code is unreachable, because '" + expression.getText() + "' never terminates normally");
}
}
@@ -631,7 +631,7 @@ public class JetTypeInferrer {
&& referencedName != null) {
PropertyDescriptor property = scope.getPropertyByFieldReference(referencedName);
if (property == null) {
semanticServices.getErrorHandler().unresolvedReference(expression);
trace.getErrorHandler().unresolvedReference(expression);
}
else {
trace.recordReferenceResolution(expression, property);
@@ -646,13 +646,13 @@ public class JetTypeInferrer {
trace.recordReferenceResolution(expression, variable);
result = variable.getOutType();
if (result == null) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "This variable is not readable in this context");
trace.getErrorHandler().genericError(expression.getNode(), "This variable is not readable in this context");
}
return;
} else if (furtherNameLookup(expression, referencedName)) {
return;
}
semanticServices.getErrorHandler().unresolvedReference(expression);
trace.getErrorHandler().unresolvedReference(expression);
}
}
}
@@ -660,7 +660,7 @@ public class JetTypeInferrer {
protected boolean furtherNameLookup(@NotNull JetSimpleNameExpression expression, @NotNull String referencedName) {
NamespaceType namespaceType = lookupNamespaceType(expression, referencedName);
if (namespaceType != null) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "Expression expected, but a namespace name found");
trace.getErrorHandler().genericError(expression.getNode(), "Expression expected, but a namespace name found");
return true;
}
return false;
@@ -712,7 +712,7 @@ public class JetTypeInferrer {
if (returnTypeRef != null) {
returnType = typeResolver.resolveType(scope, returnTypeRef);
} else {
WritableScope writableScope = semanticServices.createWritableScope(scope, functionDescriptor);
WritableScope writableScope = new WritableScopeImpl(scope, functionDescriptor, trace.getErrorHandler(), null);
for (VariableDescriptor variableDescriptor : parameterDescriptors.values()) {
writableScope.addVariableDescriptor(variableDescriptor);
}
@@ -739,7 +739,7 @@ public class JetTypeInferrer {
if (elementType == JetNodeTypes.INTEGER_CONSTANT) {
Object value = expression.getValue();
if (value == null) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "Number is of range for Long");
trace.getErrorHandler().genericError(expression.getNode(), "Number is of range for Long");
}
else if (value instanceof Long) {
result = standardLibrary.getLongType();
@@ -813,7 +813,7 @@ public class JetTypeInferrer {
@Override
public void visitTypeofExpression(JetTypeofExpression expression) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "Return some reflection interface"); // TODO
trace.getErrorHandler().genericError(expression.getNode(), "Return some reflection interface"); // TODO
}
@Override
@@ -825,7 +825,7 @@ public class JetTypeInferrer {
JetType targetType = typeResolver.resolveType(scope, right);
if (operationType == JetTokens.COLON) {
if (actualType != null && !semanticServices.getTypeChecker().isSubtypeOf(actualType, targetType)) {
semanticServices.getErrorHandler().typeMismatch(expression.getLeft(), targetType, actualType);
trace.getErrorHandler().typeMismatch(expression.getLeft(), targetType, actualType);
}
result = targetType;
}
@@ -838,7 +838,7 @@ public class JetTypeInferrer {
result = TypeUtils.makeNullable(targetType);
}
else {
semanticServices.getErrorHandler().genericError(expression.getOperationSign().getNode(), "Unsupported binary operation");
trace.getErrorHandler().genericError(expression.getOperationSign().getNode(), "Unsupported binary operation");
}
}
}
@@ -849,15 +849,15 @@ public class JetTypeInferrer {
JetTypeChecker typeChecker = semanticServices.getTypeChecker();
if (!typeChecker.isSubtypeOf(targetType, actualType)) {
if (typeChecker.isSubtypeOf(actualType, targetType)) {
semanticServices.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed, use ':' instead");
trace.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed, use ':' instead");
}
else {
semanticServices.getErrorHandler().genericError(expression.getOperationSign().getNode(), "This cast can never succeed");
trace.getErrorHandler().genericError(expression.getOperationSign().getNode(), "This cast can never succeed");
}
}
else {
if (typeChecker.isSubtypeOf(actualType, targetType)) {
semanticServices.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed");
trace.getErrorHandler().genericWarning(expression.getOperationSign().getNode(), "No cast needed");
}
}
}
@@ -892,12 +892,12 @@ public class JetTypeInferrer {
}
}
else if (size == 0) {
semanticServices.getErrorHandler().unresolvedReference(expression.getTargetLabel());
trace.getErrorHandler().unresolvedReference(expression.getTargetLabel());
}
else {
JetSimpleNameExpression labelElement = expression.getTargetLabel();
assert labelElement != null;
semanticServices.getErrorHandler().genericError(labelElement.getNode(), "Ambiguous label");
trace.getErrorHandler().genericError(labelElement.getNode(), "Ambiguous label");
}
}
else {
@@ -906,7 +906,7 @@ public class JetTypeInferrer {
if (thisType != null) {
if (JetStandardClasses.isNothing(thisType)) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "'this' is not defined in this context");
trace.getErrorHandler().genericError(expression.getNode(), "'this' is not defined in this context");
}
else {
JetTypeReference superTypeQualifier = expression.getSuperTypeQualifier();
@@ -929,7 +929,7 @@ public class JetTypeInferrer {
}
}
if (result == null) {
semanticServices.getErrorHandler().genericError(superTypeElement.getNode(), "Not a superclass");
trace.getErrorHandler().genericError(superTypeElement.getNode(), "Not a superclass");
}
}
}
@@ -965,7 +965,7 @@ public class JetTypeInferrer {
if (catchParameter != null) {
VariableDescriptor variableDescriptor = classDescriptorResolver.resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, catchParameter);
if (catchBody != null) {
WritableScope catchScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
WritableScope catchScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
catchScope.addVariableDescriptor(variableDescriptor);
JetType type = getType(catchScope, catchBody, true);
if (type != null) {
@@ -1031,7 +1031,7 @@ public class JetTypeInferrer {
JetType conditionType = getType(scope, condition, false);
if (conditionType != null && !isBoolean(conditionType)) {
semanticServices.getErrorHandler().genericError(condition.getNode(), "Condition must be of type Boolean, but was of type " + conditionType);
trace.getErrorHandler().genericError(condition.getNode(), "Condition must be of type Boolean, but was of type " + conditionType);
}
}
}
@@ -1053,7 +1053,7 @@ public class JetTypeInferrer {
if (body instanceof JetFunctionLiteralExpression) {
JetFunctionLiteralExpression function = (JetFunctionLiteralExpression) body;
if (!function.hasParameterSpecification()) {
WritableScope writableScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
WritableScope writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
conditionScope = writableScope;
getBlockReturnedTypeWithWritableScope(writableScope, function.getBody());
trace.recordBlock(function);
@@ -1062,7 +1062,7 @@ public class JetTypeInferrer {
}
}
else if (body != null) {
WritableScope writableScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
WritableScope writableScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
conditionScope = writableScope;
getBlockReturnedTypeWithWritableScope(writableScope, Collections.singletonList(body));
}
@@ -1083,7 +1083,7 @@ public class JetTypeInferrer {
expectedParameterType = checkIterableConvention(loopRangeType, loopRange.getNode());
}
WritableScope loopScope = semanticServices.createWritableScope(scope, scope.getContainingDeclaration());
WritableScope loopScope = new WritableScopeImpl(scope, scope.getContainingDeclaration(), trace.getErrorHandler(), null);
if (loopParameter != null) {
JetTypeReference typeReference = loopParameter.getTypeReference();
@@ -1094,7 +1094,7 @@ public class JetTypeInferrer {
if (expectedParameterType != null &&
actualParameterType != null &&
!semanticServices.getTypeChecker().isSubtypeOf(expectedParameterType, actualParameterType)) {
semanticServices.getErrorHandler().genericError(typeReference.getNode(), "The loop iterates over values of type " + expectedParameterType + " but the parameter is declared to be " + actualParameterType);
trace.getErrorHandler().genericError(typeReference.getNode(), "The loop iterates over values of type " + expectedParameterType + " but the parameter is declared to be " + actualParameterType);
}
}
else {
@@ -1123,17 +1123,17 @@ public class JetTypeInferrer {
boolean hasNextPropertySupported = checkHasNextPropertySupport(reportErrorsOn, iteratorType);
if (hasNextFunctionSupported && hasNextPropertySupported && !ErrorUtils.isErrorType(iteratorType)) {
// TODO : overload resolution rules impose priorities here???
semanticServices.getErrorHandler().genericError(reportErrorsOn, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext()' property");
trace.getErrorHandler().genericError(reportErrorsOn, "An ambiguity between 'iterator().hasNext()' function and 'iterator().hasNext()' property");
}
else if (!hasNextFunctionSupported && !hasNextPropertySupported) {
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
trace.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().hasNext()' function or an 'iterator().hasNext' property");
}
OverloadResolutionResult nextResolutionResult = resolveNoParametersFunction(iteratorType, scope, "next");
if (nextResolutionResult.isAmbiguity()) {
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().next()' is ambiguous for this expression");
trace.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().next()' is ambiguous for this expression");
} else if (nextResolutionResult.isNothing()) {
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().next()' method");
trace.getErrorHandler().genericError(reportErrorsOn, "Loop range must have an 'iterator().next()' method");
} else {
return nextResolutionResult.getFunctionDescriptor().getUnsubstitutedReturnType();
}
@@ -1143,7 +1143,7 @@ public class JetTypeInferrer {
if (iteratorResolutionResult.isAmbiguity()) {
errorMessage = "Method 'iterator()' is ambiguous for this expression";
}
semanticServices.getErrorHandler().genericError(reportErrorsOn, errorMessage);
trace.getErrorHandler().genericError(reportErrorsOn, errorMessage);
}
return null;
}
@@ -1151,13 +1151,13 @@ public class JetTypeInferrer {
private boolean checkHasNextFunctionSupport(@NotNull ASTNode reportErrorsOn, @NotNull JetType iteratorType) {
OverloadResolutionResult hasNextResolutionResult = resolveNoParametersFunction(iteratorType, scope, "hasNext");
if (hasNextResolutionResult.isAmbiguity()) {
semanticServices.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().hasNext()' is ambiguous for this expression");
trace.getErrorHandler().genericError(reportErrorsOn, "Method 'iterator().hasNext()' is ambiguous for this expression");
} else if (hasNextResolutionResult.isNothing()) {
return false;
} else {
JetType hasNextReturnType = hasNextResolutionResult.getFunctionDescriptor().getUnsubstitutedReturnType();
if (!isBoolean(hasNextReturnType)) {
semanticServices.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext()' method of the loop range must return Boolean, but returns " + hasNextReturnType);
trace.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext()' method of the loop range must return Boolean, but returns " + hasNextReturnType);
}
}
return true;
@@ -1172,10 +1172,10 @@ public class JetTypeInferrer {
JetType hasNextReturnType = hasNextProperty.getOutType();
if (hasNextReturnType == null) {
// TODO : accessibility
semanticServices.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must be readable");
trace.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must be readable");
}
else if (!isBoolean(hasNextReturnType)) {
semanticServices.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must return Boolean, but returns " + hasNextReturnType);
trace.getErrorHandler().genericError(reportErrorsOn, "The 'iterator().hasNext' property of the loop range must return Boolean, but returns " + hasNextReturnType);
}
}
return true;
@@ -1198,7 +1198,7 @@ public class JetTypeInferrer {
@Override
public void visitHashQualifiedExpression(JetHashQualifiedExpression expression) {
semanticServices.getErrorHandler().genericError(expression.getOperationTokenNode(), "Unsupported");
trace.getErrorHandler().genericError(expression.getOperationTokenNode(), "Unsupported");
}
@Override
@@ -1213,7 +1213,7 @@ public class JetTypeInferrer {
if (expression.getOperationSign() == JetTokens.QUEST) {
if (selectorReturnType != null && !isBoolean(selectorReturnType)) {
// TODO : more comprehensible error message
semanticServices.getErrorHandler().typeMismatch(selectorExpression, semanticServices.getStandardLibrary().getBooleanType(), selectorReturnType);
trace.getErrorHandler().typeMismatch(selectorExpression, semanticServices.getStandardLibrary().getBooleanType(), selectorReturnType);
}
result = TypeUtils.makeNullable(receiverType);
}
@@ -1238,7 +1238,7 @@ public class JetTypeInferrer {
}
else if (selectorExpression != null) {
// TODO : not a simple name -> resolve in scope, expect property type or a function type
semanticServices.getErrorHandler().genericError(selectorExpression.getNode(), "Unsupported selector element type: " + selectorExpression);
trace.getErrorHandler().genericError(selectorExpression.getNode(), "Unsupported selector element type: " + selectorExpression);
}
return receiverType;
}
@@ -1267,7 +1267,7 @@ public class JetTypeInferrer {
IElementType operationType = operationSign.getReferencedNameElementType();
String name = unaryOperationNames.get(operationType);
if (name == null) {
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "Unknown unary operation");
trace.getErrorHandler().genericError(operationSign.getNode(), "Unknown unary operation");
}
else {
JetType receiverType = getType(scope, expression.getBaseExpression(), false);
@@ -1281,7 +1281,7 @@ public class JetTypeInferrer {
}
else {
if (!semanticServices.getTypeChecker().isSubtypeOf(returnType, receiverType)) {
semanticServices.getErrorHandler().genericError(operationSign.getNode(), name + " must return " + receiverType + " but returns " + returnType);
trace.getErrorHandler().genericError(operationSign.getNode(), name + " must return " + receiverType + " but returns " + returnType);
}
// TODO : Maybe returnType?
result = receiverType;
@@ -1326,7 +1326,7 @@ public class JetTypeInferrer {
if (constructor.equals(intTypeConstructor)) {
result = standardLibrary.getBooleanType();
} else {
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "compareTo must return Int, but returns " + compareToReturnType);
trace.getErrorHandler().genericError(operationSign.getNode(), "compareTo must return Int, but returns " + compareToReturnType);
}
}
}
@@ -1346,7 +1346,7 @@ public class JetTypeInferrer {
}
}
else {
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "No method 'equals(Any?) : Boolean' available");
trace.getErrorHandler().genericError(operationSign.getNode(), "No method 'equals(Any?) : Boolean' available");
}
}
}
@@ -1373,10 +1373,10 @@ public class JetTypeInferrer {
JetType leftType = getType(scope, left, false);
JetType rightType = right == null ? null : getType(scope, right, false);
if (leftType != null && !isBoolean(leftType)) {
semanticServices.getErrorHandler().typeMismatch(left, semanticServices.getStandardLibrary().getBooleanType(), leftType);
trace.getErrorHandler().typeMismatch(left, semanticServices.getStandardLibrary().getBooleanType(), leftType);
}
if (rightType != null && !isBoolean(rightType)) {
semanticServices.getErrorHandler().typeMismatch(right, semanticServices.getStandardLibrary().getBooleanType(), rightType);
trace.getErrorHandler().typeMismatch(right, semanticServices.getStandardLibrary().getBooleanType(), rightType);
}
result = semanticServices.getStandardLibrary().getBooleanType();
}
@@ -1385,7 +1385,7 @@ public class JetTypeInferrer {
JetType rightType = right == null ? null : getType(scope, right, false);
if (leftType != null) {
if (!leftType.isNullable()) {
semanticServices.getErrorHandler().genericWarning(left.getNode(), "Elvis operator (?:) is always returns the left operand of non-nullable type " + leftType);
trace.getErrorHandler().genericWarning(left.getNode(), "Elvis operator (?:) is always returns the left operand of non-nullable type " + leftType);
}
if (rightType != null) {
result = TypeUtils.makeNullableAsSpecified(semanticServices.getTypeChecker().commonSupertype(leftType, rightType), rightType.isNullable());
@@ -1393,7 +1393,7 @@ public class JetTypeInferrer {
}
}
else {
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "Unknown operation");
trace.getErrorHandler().genericError(operationSign.getNode(), "Unknown operation");
}
}
@@ -1410,7 +1410,7 @@ public class JetTypeInferrer {
if (rightType != null) {
JetType intersect = TypeUtils.intersect(semanticServices.getTypeChecker(), new HashSet<JetType>(Arrays.asList(leftType, rightType)));
if (intersect == null) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "Operator " + operationSign.getReferencedName() + " cannot be applied to " + leftType + " and " + rightType);
trace.getErrorHandler().genericError(expression.getNode(), "Operator " + operationSign.getReferencedName() + " cannot be applied to " + leftType + " and " + rightType);
}
}
}
@@ -1425,14 +1425,14 @@ public class JetTypeInferrer {
}
private void assignmentIsNotAnExpressionError(JetBinaryExpression expression) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "Assignments are not expressions, and only expressions are allowed in this context");
trace.getErrorHandler().genericError(expression.getNode(), "Assignments are not expressions, and only expressions are allowed in this context");
}
private boolean ensureBooleanResult(JetSimpleNameExpression operationSign, String name, JetType resultType) {
if (resultType != null) {
// TODO : Relax?
if (!isBoolean(resultType)) {
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "'" + name + "' must return Boolean but returns " + resultType);
trace.getErrorHandler().genericError(operationSign.getNode(), "'" + name + "' must return Boolean but returns " + resultType);
return false;
}
}
@@ -1491,7 +1491,7 @@ public class JetTypeInferrer {
if (functionDescriptor != null) {
if (leftType.isNullable()) {
// TODO : better error message for '1 + nullableVar' case
semanticServices.getErrorHandler().genericError(operationSign.getNode(),
trace.getErrorHandler().genericError(operationSign.getNode(),
"Infix call corresponds to a dot-qualified call '" +
left.getText() + "." + name + "(" + right.getText() + ")'" +
" which is not allowed on a nullable receiver '" + right.getText() + "'." +
@@ -1505,18 +1505,18 @@ public class JetTypeInferrer {
@Override
public void visitDeclaration(JetDeclaration dcl) {
semanticServices.getErrorHandler().genericError(dcl.getNode(), "Declarations are not allowed in this position");
trace.getErrorHandler().genericError(dcl.getNode(), "Declarations are not allowed in this position");
}
@Override
public void visitRootNamespaceExpression(JetRootNamespaceExpression expression) {
semanticServices.getErrorHandler().genericError(expression.getNode(), "'namespace' is not an expression");
trace.getErrorHandler().genericError(expression.getNode(), "'namespace' is not an expression");
result = null;
}
@Override
public void visitJetElement(JetElement elem) {
semanticServices.getErrorHandler().genericError(elem.getNode(), "[JetTypeInferrer] Unsupported element: " + elem + " " + elem.getClass().getCanonicalName());
trace.getErrorHandler().genericError(elem.getNode(), "[JetTypeInferrer] Unsupported element: " + elem + " " + elem.getClass().getCanonicalName());
}
}
@@ -1557,12 +1557,12 @@ public class JetTypeInferrer {
JetPropertyAccessor getter = property.getGetter();
if (getter != null) {
semanticServices.getErrorHandler().genericError(getter.getNode(), "Local variables are not allowed to have getters");
trace.getErrorHandler().genericError(getter.getNode(), "Local variables are not allowed to have getters");
}
JetPropertyAccessor setter = property.getSetter();
if (setter != null) {
semanticServices.getErrorHandler().genericError(setter.getNode(), "Local variables are not allowed to have setters");
trace.getErrorHandler().genericError(setter.getNode(), "Local variables are not allowed to have setters");
}
VariableDescriptor propertyDescriptor = classDescriptorResolver.resolveLocalVariableDescriptor(scope.getContainingDeclaration(), scope, property);
@@ -1573,7 +1573,7 @@ public class JetTypeInferrer {
if (outType != null &&
initializerType != null &&
!semanticServices.getTypeChecker().isConvertibleTo(initializerType, outType)) {
semanticServices.getErrorHandler().typeMismatch(initializer, outType, initializerType);
trace.getErrorHandler().typeMismatch(initializer, outType, initializerType);
}
}
@@ -1634,7 +1634,7 @@ public class JetTypeInferrer {
if (rightType != null &&
leftType != null &&
!semanticServices.getTypeChecker().isConvertibleTo(rightType, leftType)) {
semanticServices.getErrorHandler().typeMismatch(right, leftType, rightType);
trace.getErrorHandler().typeMismatch(right, leftType, rightType);
}
}
}
@@ -1661,7 +1661,7 @@ public class JetTypeInferrer {
@Override
public void visitJetElement(JetElement elem) {
semanticServices.getErrorHandler().genericError(elem.getNode(), "Unsupported element in a block: " + elem + " " + elem.getClass().getCanonicalName());
trace.getErrorHandler().genericError(elem.getNode(), "Unsupported element in a block: " + elem + " " + elem.getClass().getCanonicalName());
}
}
@@ -81,15 +81,16 @@ public class ExpectedResolveData {
public void checkResult(JetFile file) {
final Set<PsiElement> unresolvedReferences = new HashSet<PsiElement>();
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(file.getProject(), new ErrorHandler() {
ErrorHandler errorHandler = new ErrorHandler() {
@Override
public void unresolvedReference(@NotNull JetReferenceExpression referenceExpression) {
unresolvedReferences.add(referenceExpression);
}
});
};
JetSemanticServices semanticServices = JetSemanticServices.createSemanticServices(file.getProject());
JetStandardLibrary lib = semanticServices.getStandardLibrary();
BindingContext bindingContext = AnalyzingUtils.analyzeFile(file, semanticServices.getErrorHandler());
BindingContext bindingContext = AnalyzingUtils.analyzeFile(file, errorHandler);
Map<String, JetDeclaration> nameToDeclaration = new HashMap<String, JetDeclaration>();
@@ -2,7 +2,6 @@ package org.jetbrains.jet.types;
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.application.PathManager;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.psi.JetChangeUtil;
import org.jetbrains.jet.lang.psi.JetFunction;
@@ -26,7 +25,7 @@ public class JetOverridingTest extends LightDaemonAnalyzerTestCase {
public void setUp() throws Exception {
super.setUp();
library = JetStandardLibrary.getJetStandardLibrary(getProject());
semanticServices = JetSemanticServices.createSemanticServices(library, ErrorHandler.DO_NOTHING);
semanticServices = JetSemanticServices.createSemanticServices(library);
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
}
@@ -5,7 +5,6 @@ import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
import com.intellij.openapi.application.PathManager;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.ErrorHandler;
import org.jetbrains.jet.lang.JetSemanticServices;
import org.jetbrains.jet.lang.cfg.JetFlowInformationProvider;
import org.jetbrains.jet.lang.psi.JetChangeUtil;
@@ -32,7 +31,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
public void setUp() throws Exception {
super.setUp();
library = JetStandardLibrary.getJetStandardLibrary(getProject());
semanticServices = JetSemanticServices.createSemanticServices(library, ErrorHandler.DO_NOTHING);
semanticServices = JetSemanticServices.createSemanticServices(library);
classDefinitions = new ClassDefinitions();
classDescriptorResolver = semanticServices.getClassDescriptorResolver(BindingTrace.DUMMY);
}