mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-36685: Provide better 'no matching constructor' warnings where possible
This commit is contained in:
@@ -20,20 +20,27 @@ import com.intellij.codeInsight.daemon.impl.SeverityRegistrar;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.intellij.lang.annotations.MagicConstant;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ProblemDescriptorUtil {
|
||||
public static final int NONE = 0x00000000;
|
||||
public static final int NONE = 0x00000000;
|
||||
public static final int APPEND_LINE_NUMBER = 0x00000001;
|
||||
public static final int TRIM_AT_END = 0x00000002;
|
||||
public static final int TRIM_AT_TREE_END = 0x00000004;
|
||||
public static final int TRIM_AT_END = 0x00000002;
|
||||
public static final int TRIM_AT_TREE_END = 0x00000004;
|
||||
|
||||
@MagicConstant(flags = {NONE, APPEND_LINE_NUMBER, TRIM_AT_END, TRIM_AT_TREE_END})
|
||||
@interface FlagConstant {}
|
||||
@interface FlagConstant {
|
||||
}
|
||||
|
||||
public static Pair<String, String> XML_CODE_MARKER = Pair.create("<xml-code>", "</xml-code>");
|
||||
|
||||
public static String extractHighlightedText(@NotNull CommonProblemDescriptor descriptor, PsiElement psiElement) {
|
||||
if (psiElement == null || !psiElement.isValid()) return "";
|
||||
@@ -65,10 +72,14 @@ public class ProblemDescriptorUtil {
|
||||
// noinspection ConstantConditions
|
||||
if (message == null) return "";
|
||||
|
||||
if ((flags & APPEND_LINE_NUMBER) != 0 && descriptor instanceof ProblemDescriptor && !message.contains("#ref") && message.contains("#loc")) {
|
||||
if ((flags & APPEND_LINE_NUMBER) != 0 &&
|
||||
descriptor instanceof ProblemDescriptor &&
|
||||
!message.contains("#ref") &&
|
||||
message.contains("#loc")) {
|
||||
final int lineNumber = ((ProblemDescriptor)descriptor).getLineNumber();
|
||||
if (lineNumber >= 0) {
|
||||
message = StringUtil.replace(message, "#loc", "(" + InspectionsBundle.message("inspection.export.results.at.line") + " " + lineNumber + ")");
|
||||
message = StringUtil
|
||||
.replace(message, "#loc", "(" + InspectionsBundle.message("inspection.export.results.at.line") + " " + lineNumber + ")");
|
||||
}
|
||||
}
|
||||
message = StringUtil.replace(message, "<code>", "'");
|
||||
@@ -89,17 +100,45 @@ public class ProblemDescriptorUtil {
|
||||
message = StringUtil.replace(message, "#end", "");
|
||||
message = StringUtil.replace(message, "#treeend", "");
|
||||
|
||||
message = StringUtil.unescapeXml(message).trim();
|
||||
if (message.contains(XML_CODE_MARKER.first)) {
|
||||
message = unescapeXmlCode(message);
|
||||
}
|
||||
else {
|
||||
message = StringUtil.unescapeXml(message).trim();
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
private static String unescapeXmlCode(final String message) {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
for (String string : StringUtil.split(message, XML_CODE_MARKER.first)) {
|
||||
if (string.contains(XML_CODE_MARKER.second)) {
|
||||
strings.addAll(StringUtil.split(string, XML_CODE_MARKER.second, false));
|
||||
}
|
||||
else {
|
||||
strings.add(string);
|
||||
}
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String string : strings) {
|
||||
if (string.contains(XML_CODE_MARKER.second)) {
|
||||
builder.append(string.replace(XML_CODE_MARKER.second, ""));
|
||||
} else {
|
||||
builder.append(StringUtil.unescapeXml(string));
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String renderDescriptionMessage(@NotNull CommonProblemDescriptor descriptor, PsiElement element) {
|
||||
return renderDescriptionMessage(descriptor, element, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HighlightInfoType highlightTypeFromDescriptor(@NotNull ProblemDescriptor problemDescriptor, @NotNull HighlightSeverity severity, @NotNull SeverityRegistrar severityRegistrar) {
|
||||
public static HighlightInfoType highlightTypeFromDescriptor(@NotNull ProblemDescriptor problemDescriptor,
|
||||
@NotNull HighlightSeverity severity,
|
||||
@NotNull SeverityRegistrar severityRegistrar) {
|
||||
final ProblemHighlightType highlightType = problemDescriptor.getHighlightType();
|
||||
switch (highlightType) {
|
||||
case GENERIC_ERROR_OR_WARNING:
|
||||
@@ -133,5 +172,4 @@ public class ProblemDescriptorUtil {
|
||||
}
|
||||
throw new RuntimeException("Cannot map " + highlightType);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user