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