|
|
|
@@ -16,21 +16,12 @@
|
|
|
|
|
|
|
|
|
|
package org.jetbrains.jet.plugin.highlighter;
|
|
|
|
|
|
|
|
|
|
import com.intellij.psi.PsiElement;
|
|
|
|
|
import com.intellij.psi.util.PsiTreeUtil;
|
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
import org.jetbrains.jet.lang.descriptors.*;
|
|
|
|
|
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
|
|
|
|
import org.jetbrains.jet.lang.diagnostics.DiagnosticWithParameters1;
|
|
|
|
|
import org.jetbrains.jet.lang.diagnostics.Errors;
|
|
|
|
|
import org.jetbrains.jet.lang.psi.JetValueArgument;
|
|
|
|
|
import org.jetbrains.jet.lang.psi.ValueArgument;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCallImpl;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.calls.model.*;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
|
|
|
|
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
|
|
|
|
import org.jetbrains.jet.lang.types.JetType;
|
|
|
|
@@ -38,11 +29,10 @@ import org.jetbrains.jet.renderer.DescriptorRenderer;
|
|
|
|
|
import org.jetbrains.jet.renderer.Renderer;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import static org.jetbrains.jet.lang.diagnostics.rendering.Renderers.*;
|
|
|
|
|
import static org.jetbrains.jet.lang.resolve.calls.util.UtilPackage.hasErrorOnParameter;
|
|
|
|
|
import static org.jetbrains.jet.lang.resolve.calls.util.UtilPackage.hasUnmappedArguments;
|
|
|
|
|
|
|
|
|
|
public class IdeRenderers {
|
|
|
|
|
private static final String RED_TEMPLATE = "<font color=red><b>%s</b></font>";
|
|
|
|
@@ -85,51 +75,14 @@ public class IdeRenderers {
|
|
|
|
|
|
|
|
|
|
public static final Renderer<Collection<? extends ResolvedCall<?>>> HTML_NONE_APPLICABLE_CALLS =
|
|
|
|
|
new Renderer<Collection<? extends ResolvedCall<?>>>() {
|
|
|
|
|
@Nullable
|
|
|
|
|
private ValueParameterDescriptor findParameterByArgumentExpression(ResolvedCall<?> call, JetValueArgument argument) {
|
|
|
|
|
for (Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> entry : call.getValueArguments().entrySet()) {
|
|
|
|
|
for (ValueArgument va : entry.getValue().getArguments()) {
|
|
|
|
|
if (va == argument) {
|
|
|
|
|
return entry.getKey();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Set<ValueParameterDescriptor> getParametersToHighlight(ResolvedCall<?> call) {
|
|
|
|
|
Set<ValueParameterDescriptor> parameters = new HashSet<ValueParameterDescriptor>();
|
|
|
|
|
if (call instanceof ResolvedCallImpl) {
|
|
|
|
|
Iterable<Diagnostic> diagnostics = ((ResolvedCallImpl)call).getTrace().getBindingContext().getDiagnostics();
|
|
|
|
|
for (Diagnostic diagnostic : diagnostics) {
|
|
|
|
|
if (diagnostic.getFactory() == Errors.TOO_MANY_ARGUMENTS) {
|
|
|
|
|
parameters.add(null);
|
|
|
|
|
} else if (diagnostic.getFactory() == Errors.NO_VALUE_FOR_PARAMETER) {
|
|
|
|
|
ValueParameterDescriptor parameter =
|
|
|
|
|
((DiagnosticWithParameters1<PsiElement, ValueParameterDescriptor>)diagnostic).getA();
|
|
|
|
|
parameters.add(parameter);
|
|
|
|
|
} else {
|
|
|
|
|
JetValueArgument argument = PsiTreeUtil.getParentOfType(diagnostic.getPsiElement(), JetValueArgument.class, false);
|
|
|
|
|
if (argument != null) {
|
|
|
|
|
ValueParameterDescriptor parameter = findParameterByArgumentExpression(call, argument);
|
|
|
|
|
if (parameter != null) {
|
|
|
|
|
parameters.add(parameter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return parameters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
|
@Override
|
|
|
|
|
public String render(@NotNull Collection<? extends ResolvedCall<?>> calls) {
|
|
|
|
|
StringBuilder stringBuilder = new StringBuilder("");
|
|
|
|
|
for (ResolvedCall<?> call : calls) {
|
|
|
|
|
for (ResolvedCall<?> resolvedCall : calls) {
|
|
|
|
|
stringBuilder.append("<li>");
|
|
|
|
|
CallableDescriptor funDescriptor = call.getResultingDescriptor();
|
|
|
|
|
Set<ValueParameterDescriptor> parametersToHighlight = getParametersToHighlight(call);
|
|
|
|
|
CallableDescriptor funDescriptor = resolvedCall.getResultingDescriptor();
|
|
|
|
|
|
|
|
|
|
DescriptorRenderer htmlRenderer = DescriptorRenderer.HTML;
|
|
|
|
|
ReceiverParameterDescriptor receiverParameter = funDescriptor.getReceiverParameter();
|
|
|
|
@@ -151,14 +104,14 @@ public class IdeRenderers {
|
|
|
|
|
if (parameter.hasDefaultValue()) {
|
|
|
|
|
paramString += " = ...";
|
|
|
|
|
}
|
|
|
|
|
if (parametersToHighlight.contains(parameter)) {
|
|
|
|
|
if (hasErrorOnParameter(resolvedCall, parameter)) {
|
|
|
|
|
paramString = String.format(RED_TEMPLATE, paramString);
|
|
|
|
|
}
|
|
|
|
|
stringBuilder.append(paramString);
|
|
|
|
|
|
|
|
|
|
first = false;
|
|
|
|
|
}
|
|
|
|
|
stringBuilder.append(parametersToHighlight.contains(null) ? String.format(RED_TEMPLATE, ")") : ")");
|
|
|
|
|
stringBuilder.append(hasUnmappedArguments(resolvedCall) ? String.format(RED_TEMPLATE, ")") : ")");
|
|
|
|
|
stringBuilder.append(" <i>defined in</i> ");
|
|
|
|
|
DeclarationDescriptor containingDeclaration = funDescriptor.getContainingDeclaration();
|
|
|
|
|
FqNameUnsafe fqName = DescriptorUtils.getFqName(containingDeclaration);
|
|
|
|
|