use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.
the class ExpectedHighlightingData method extractExpectedHighlight.
private int extractExpectedHighlight(final Matcher matcher, final String text, final Document document, final Ref<Integer> textOffset) {
document.deleteString(textOffset.get(), textOffset.get() + matcher.end() - matcher.start());
int groupIdx = 1;
final String marker = matcher.group(groupIdx++);
String descr = matcher.group(groupIdx++);
final String typeString = matcher.group(groupIdx++);
final String foregroundColor = matcher.group(groupIdx++);
final String backgroundColor = matcher.group(groupIdx++);
final String effectColor = matcher.group(groupIdx++);
final String effectType = matcher.group(groupIdx++);
final String fontType = matcher.group(groupIdx++);
final String attrKey = matcher.group(groupIdx++);
final String bundleMessage = matcher.group(groupIdx++);
final boolean closed = matcher.group(groupIdx) != null;
if (descr == null) {
// no descr means any string by default
descr = ANY_TEXT;
} else if (descr.equals("null")) {
// explicit "null" descr
descr = null;
}
if (descr != null) {
// replace: \\" to ", doesn't check symbol before sequence \\"
descr = descr.replaceAll("\\\\\\\\\"", "\"");
descr = descr.replaceAll("\\\\\"", "\"");
}
HighlightInfoType type = WHATEVER;
if (typeString != null) {
try {
type = getTypeByName(typeString);
} catch (Exception e) {
LOG.error(e);
}
LOG.assertTrue(type != null, "Wrong highlight type: " + typeString);
}
TextAttributes forcedAttributes = null;
if (foregroundColor != null) {
//noinspection MagicConstant
forcedAttributes = new TextAttributes(Color.decode(foregroundColor), Color.decode(backgroundColor), Color.decode(effectColor), EffectType.valueOf(effectType), Integer.parseInt(fontType));
}
final int rangeStart = textOffset.get();
final int toContinueFrom;
if (closed) {
toContinueFrom = matcher.end();
} else {
int pos = matcher.end();
final Matcher closingTagMatcher = Pattern.compile("</" + marker + ">").matcher(text);
while (true) {
if (!closingTagMatcher.find(pos)) {
LOG.error("Cannot find closing </" + marker + "> in position " + pos);
}
final int nextTagStart = matcher.find(pos) ? matcher.start() : text.length();
if (closingTagMatcher.start() < nextTagStart) {
textOffset.set(textOffset.get() + closingTagMatcher.start() - pos);
document.deleteString(textOffset.get(), textOffset.get() + closingTagMatcher.end() - closingTagMatcher.start());
toContinueFrom = closingTagMatcher.end();
break;
}
textOffset.set(textOffset.get() + nextTagStart - pos);
pos = extractExpectedHighlight(matcher, text, document, textOffset);
}
}
final ExpectedHighlightingSet expectedHighlightingSet = myHighlightingTypes.get(marker);
if (expectedHighlightingSet.enabled) {
TextAttributesKey forcedTextAttributesKey = attrKey == null ? null : TextAttributesKey.createTextAttributesKey(attrKey);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(rangeStart, textOffset.get()).severity(expectedHighlightingSet.severity);
if (forcedAttributes != null)
builder.textAttributes(forcedAttributes);
if (forcedTextAttributesKey != null)
builder.textAttributes(forcedTextAttributesKey);
if (bundleMessage != null) {
final List<String> split = StringUtil.split(bundleMessage, "|");
final ResourceBundle bundle = ResourceBundle.getBundle(split.get(0));
descr = CommonBundle.message(bundle, split.get(1), split.stream().skip(2).toArray());
}
if (descr != null) {
builder.description(descr);
builder.unescapedToolTip(descr);
}
if (expectedHighlightingSet.endOfLine)
builder.endOfLine();
HighlightInfo highlightInfo = builder.createUnconditionally();
expectedHighlightingSet.infos.add(highlightInfo);
}
return toContinueFrom;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.
the class HighlightNamesUtil method highlightVariableName.
@Nullable
static HighlightInfo highlightVariableName(@NotNull PsiVariable variable, @NotNull PsiElement elementToHighlight, @NotNull TextAttributesScheme colorsScheme) {
HighlightInfoType varType = getVariableNameHighlightType(variable);
if (varType == null) {
return null;
}
if (variable instanceof PsiField) {
TextAttributes attributes = mergeWithScopeAttributes(variable, varType, colorsScheme);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(varType).range(elementToHighlight.getTextRange());
if (attributes != null) {
builder.textAttributes(attributes);
}
return builder.createUnconditionally();
}
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(varType).range(elementToHighlight);
return RainbowHighlighter.isRainbowEnabledWithInheritance(colorsScheme, JavaLanguage.INSTANCE) ? builder.createUnconditionally() : builder.create();
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.
the class HighlightNamesUtil method highlightMethodName.
/**
* @param methodOrClass method to highlight; class is passed instead of implicit constructor
*/
@Nullable
static HighlightInfo highlightMethodName(@NotNull PsiMember methodOrClass, @NotNull PsiElement elementToHighlight, @NotNull TextRange range, @NotNull TextAttributesScheme colorsScheme, final boolean isDeclaration) {
boolean isInherited = false;
if (!isDeclaration) {
if (isCalledOnThis(elementToHighlight)) {
final PsiClass containingClass = methodOrClass instanceof PsiMethod ? methodOrClass.getContainingClass() : null;
PsiClass enclosingClass = containingClass == null ? null : PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class);
while (enclosingClass != null) {
isInherited = enclosingClass.isInheritor(containingClass, true);
if (isInherited)
break;
enclosingClass = PsiTreeUtil.getParentOfType(enclosingClass, PsiClass.class, true);
}
}
}
LOG.assertTrue(methodOrClass instanceof PsiMethod || !isDeclaration);
HighlightInfoType type = methodOrClass instanceof PsiMethod ? getMethodNameHighlightType((PsiMethod) methodOrClass, isDeclaration, isInherited) : JavaHighlightInfoTypes.CONSTRUCTOR_CALL;
if (type != null) {
TextAttributes attributes = mergeWithScopeAttributes(methodOrClass, type, colorsScheme);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
if (attributes != null) {
builder.textAttributes(attributes);
}
return builder.createUnconditionally();
}
return null;
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.
the class HighlightNamesUtil method highlightClassName.
@NotNull
static HighlightInfo highlightClassName(@Nullable PsiClass aClass, @NotNull PsiElement elementToHighlight, @NotNull TextAttributesScheme colorsScheme) {
TextRange range = elementToHighlight.getTextRange();
if (elementToHighlight instanceof PsiJavaCodeReferenceElement) {
final PsiJavaCodeReferenceElement referenceElement = (PsiJavaCodeReferenceElement) elementToHighlight;
PsiElement identifier = referenceElement.getReferenceNameElement();
if (identifier != null) {
range = identifier.getTextRange();
}
}
// This will highlight @ sign in annotation as well.
final PsiElement parent = elementToHighlight.getParent();
if (parent instanceof PsiAnnotation) {
final PsiAnnotation psiAnnotation = (PsiAnnotation) parent;
range = new TextRange(psiAnnotation.getTextRange().getStartOffset(), range.getEndOffset());
}
HighlightInfoType type = getClassNameHighlightType(aClass, elementToHighlight);
TextAttributes attributes = mergeWithScopeAttributes(aClass, type, colorsScheme);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
if (attributes != null) {
builder.textAttributes(attributes);
}
return builder.createUnconditionally();
}
use of com.intellij.codeInsight.daemon.impl.HighlightInfoType in project intellij-community by JetBrains.
the class HighlightNamesUtil method highlightPackage.
static HighlightInfo highlightPackage(@NotNull PsiElement resolved, @NotNull PsiJavaCodeReferenceElement elementToHighlight, @NotNull TextAttributesScheme scheme) {
PsiElement referenceNameElement = elementToHighlight.getReferenceNameElement();
TextRange range;
if (referenceNameElement == null) {
range = elementToHighlight.getTextRange();
} else {
PsiElement nextSibling = PsiTreeUtil.nextLeaf(referenceNameElement);
if (nextSibling != null && nextSibling.getTextRange().isEmpty()) {
// empty PsiReferenceParameterList
nextSibling = PsiTreeUtil.nextLeaf(nextSibling);
}
if (nextSibling instanceof PsiJavaToken && ((PsiJavaToken) nextSibling).getTokenType() == JavaTokenType.DOT) {
range = new TextRange(referenceNameElement.getTextRange().getStartOffset(), nextSibling.getTextRange().getEndOffset());
} else {
range = referenceNameElement.getTextRange();
}
}
HighlightInfoType type = JavaHighlightInfoTypes.CLASS_NAME;
TextAttributes attributes = mergeWithScopeAttributes(resolved, type, scheme);
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(type).range(range);
if (attributes != null) {
builder.textAttributes(attributes);
}
return builder.createUnconditionally();
}
Aggregations