ConstraintsSystem interface changed
hasTypeConstructorMismatchAt(position) instead of getTypeConstructorMismatchConstraintPositions()
This commit is contained in:
@@ -16,10 +16,12 @@
|
||||
|
||||
package org.jetbrains.jet.lang.diagnostics.rendering;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Named;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
@@ -194,7 +196,7 @@ public class Renderers {
|
||||
for (CallableDescriptor substitutedDescriptor : substitutedDescriptors) {
|
||||
JetType receiverType = substitutedDescriptor.getReceiverParameter().exists() ? substitutedDescriptor.getReceiverParameter().getType() : null;
|
||||
|
||||
Collection<ConstraintPosition> errorPositions = Sets.newHashSet();
|
||||
final Collection<ConstraintPosition> errorPositions = Sets.newHashSet();
|
||||
List<JetType> valueArgumentTypes = Lists.newArrayList();
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : substitutedDescriptor.getValueParameters()) {
|
||||
valueArgumentTypes.add(valueParameterDescriptor.getType());
|
||||
@@ -209,7 +211,13 @@ public class Renderers {
|
||||
errorPositions.add(ConstraintPosition.RECEIVER_POSITION);
|
||||
}
|
||||
|
||||
table.functionArgumentTypeList(receiverType, valueArgumentTypes, errorPositions);
|
||||
Predicate<ConstraintPosition> isErrorPosition = new Predicate<ConstraintPosition>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable ConstraintPosition constraintPosition) {
|
||||
return errorPositions.contains(constraintPosition);
|
||||
}
|
||||
};
|
||||
table.functionArgumentTypeList(receiverType, valueArgumentTypes, isErrorPosition);
|
||||
}
|
||||
|
||||
table.text("can be applied to")
|
||||
@@ -218,16 +226,22 @@ public class Renderers {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static TabledDescriptorRenderer renderTypeConstructorMismatchError(InferenceErrorData inferenceErrorData,
|
||||
public static TabledDescriptorRenderer renderTypeConstructorMismatchError(final InferenceErrorData inferenceErrorData,
|
||||
TabledDescriptorRenderer renderer) {
|
||||
Predicate<ConstraintPosition> isErrorPosition = new Predicate<ConstraintPosition>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable ConstraintPosition constraintPosition) {
|
||||
assert constraintPosition != null;
|
||||
return inferenceErrorData.constraintsSystem.hasTypeConstructorMismatchAt(constraintPosition);
|
||||
}
|
||||
};
|
||||
return renderer.table(TabledDescriptorRenderer.newTable()
|
||||
.descriptor(inferenceErrorData.descriptor)
|
||||
.text("cannot be applied to")
|
||||
.functionArgumentTypeList(
|
||||
inferenceErrorData.receiverArgumentType,
|
||||
inferenceErrorData.valueArgumentsTypes,
|
||||
inferenceErrorData.constraintsSystem
|
||||
.getTypeConstructorMismatchConstraintPositions()));
|
||||
isErrorPosition));
|
||||
}
|
||||
|
||||
public static TabledDescriptorRenderer renderNoInformationForParameterError(InferenceErrorData inferenceErrorData,
|
||||
|
||||
+13
-11
@@ -16,19 +16,20 @@
|
||||
|
||||
package org.jetbrains.jet.lang.diagnostics.rendering;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.DescriptorRow;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.FunctionArgumentsRow;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.TableRow;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TextRenderer.TextElement;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TextRenderer.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -53,12 +54,12 @@ public class TabledDescriptorRenderer {
|
||||
public static class FunctionArgumentsRow implements TableRow {
|
||||
public final JetType receiverType;
|
||||
public final List<JetType> argumentTypes;
|
||||
public final Collection<ConstraintPosition> errorPositions;
|
||||
public final Predicate<ConstraintPosition> isErrorPosition;
|
||||
|
||||
public FunctionArgumentsRow(JetType receiverType, List<JetType> argumentTypes, Collection<ConstraintPosition> errorPositions) {
|
||||
public FunctionArgumentsRow(JetType receiverType, List<JetType> argumentTypes, Predicate<ConstraintPosition> isErrorPosition) {
|
||||
this.receiverType = receiverType;
|
||||
this.argumentTypes = argumentTypes;
|
||||
this.errorPositions = errorPositions;
|
||||
this.isErrorPosition = isErrorPosition;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,13 +72,14 @@ public class TabledDescriptorRenderer {
|
||||
}
|
||||
|
||||
public TableRenderer functionArgumentTypeList(@Nullable JetType receiverType, @NotNull List<JetType> argumentTypes) {
|
||||
return functionArgumentTypeList(receiverType, argumentTypes, Collections.<ConstraintPosition>emptyList());
|
||||
|
||||
return functionArgumentTypeList(receiverType, argumentTypes, Predicates.<ConstraintPosition>alwaysFalse());
|
||||
}
|
||||
|
||||
public TableRenderer functionArgumentTypeList(@Nullable JetType receiverType,
|
||||
@NotNull List<JetType> argumentTypes,
|
||||
Collection<ConstraintPosition> errorPositions) {
|
||||
rows.add(new FunctionArgumentsRow(receiverType, argumentTypes, errorPositions));
|
||||
@NotNull Predicate<ConstraintPosition> isErrorPosition) {
|
||||
rows.add(new FunctionArgumentsRow(receiverType, argumentTypes, isErrorPosition));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+13
-3
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.calls.inference;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
|
||||
@@ -37,7 +38,13 @@ public interface ConstraintsSystem {
|
||||
@NotNull
|
||||
Set<TypeParameterDescriptor> getTypeVariables();
|
||||
|
||||
// only subject type might contain type variables
|
||||
//todo
|
||||
/** only subject type might contain type variables
|
||||
*
|
||||
* @param subjectType
|
||||
* @param constrainingType
|
||||
* @param constraintPosition
|
||||
*/
|
||||
void addSubtypingConstraint(@NotNull JetType subjectType, @NotNull JetType constrainingType, @NotNull ConstraintPosition constraintPosition);
|
||||
|
||||
// only subject type might contain type variables
|
||||
@@ -53,12 +60,15 @@ public interface ConstraintsSystem {
|
||||
|
||||
boolean hasTypeConstructorMismatch();
|
||||
|
||||
@NotNull
|
||||
Set<ConstraintPosition> getTypeConstructorMismatchConstraintPositions();
|
||||
boolean hasTypeConstructorMismatchAt(@NotNull ConstraintPosition constraintPosition);
|
||||
|
||||
@Nullable
|
||||
TypeConstraints getTypeConstraints(@NotNull TypeParameterDescriptor typeParameterDescriptor);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@NotNull
|
||||
TypeSubstitutor getResultingSubstitutor();
|
||||
}
|
||||
|
||||
@@ -16,23 +16,26 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.highlighter;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.DescriptorRow;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.FunctionArgumentsRow;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.TableRow;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.resolve.DescriptorRenderer;
|
||||
|
||||
import static org.jetbrains.jet.plugin.highlighter.IdeRenderers.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.rendering.TabledDescriptorRenderer.TableRenderer.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.plugin.highlighter.IdeRenderers.error;
|
||||
import static org.jetbrains.jet.plugin.highlighter.IdeRenderers.strong;
|
||||
|
||||
/**
|
||||
* @author svtk
|
||||
*/
|
||||
@@ -92,7 +95,7 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
|
||||
}
|
||||
if (row instanceof FunctionArgumentsRow) {
|
||||
FunctionArgumentsRow functionArgumentsRow = (FunctionArgumentsRow) row;
|
||||
renderFunctionArguments(functionArgumentsRow.receiverType, functionArgumentsRow.argumentTypes, functionArgumentsRow.errorPositions, result);
|
||||
renderFunctionArguments(functionArgumentsRow.receiverType, functionArgumentsRow.argumentTypes, functionArgumentsRow.isErrorPosition, result);
|
||||
}
|
||||
result.append("</tr>");
|
||||
}
|
||||
@@ -101,13 +104,13 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
|
||||
result.append("</table>");
|
||||
}
|
||||
|
||||
private void renderFunctionArguments(@Nullable JetType receiverType, @NotNull List<JetType> argumentTypes, Collection<ConstraintPosition> errorPositions, StringBuilder result) {
|
||||
private void renderFunctionArguments(@Nullable JetType receiverType, @NotNull List<JetType> argumentTypes, Predicate<ConstraintPosition> isErrorPosition, StringBuilder result) {
|
||||
boolean hasReceiver = receiverType != null;
|
||||
tdSpace(result);
|
||||
String receiver = "";
|
||||
if (hasReceiver) {
|
||||
boolean error = false;
|
||||
if (errorPositions.contains(ConstraintPosition.RECEIVER_POSITION)) {
|
||||
if (isErrorPosition.apply(ConstraintPosition.RECEIVER_POSITION)) {
|
||||
error = true;
|
||||
}
|
||||
receiver = "receiver: " + strong(IdeRenderers.HTML_RENDER_TYPE.render(receiverType), error);
|
||||
@@ -124,7 +127,7 @@ public class HtmlTabledDescriptorRenderer extends TabledDescriptorRenderer {
|
||||
for (Iterator<JetType> iterator = argumentTypes.iterator(); iterator.hasNext(); ) {
|
||||
JetType argumentType = iterator.next();
|
||||
boolean error = false;
|
||||
if (errorPositions.contains(ConstraintPosition.getValueParameterPosition(i))) {
|
||||
if (isErrorPosition.apply(ConstraintPosition.getValueParameterPosition(i))) {
|
||||
error = true;
|
||||
}
|
||||
String renderedArgument = IdeRenderers.HTML_RENDER_TYPE.render(argumentType);
|
||||
|
||||
Reference in New Issue
Block a user