mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight more identifiers as rainbow: any variable-like highlight info is rainbow colored
This commit is contained in:
+2
-10
@@ -142,8 +142,7 @@ public class HighlightNamesUtil {
|
||||
@Nullable
|
||||
static HighlightInfo highlightVariableName(@NotNull PsiVariable variable,
|
||||
@NotNull PsiElement elementToHighlight,
|
||||
@NotNull TextAttributesScheme colorsScheme,
|
||||
@Nullable RainbowHighlighter rainbowHighlighter) {
|
||||
@NotNull TextAttributesScheme colorsScheme) {
|
||||
HighlightInfoType varType = getVariableNameHighlightType(variable);
|
||||
if (varType == null) {
|
||||
return null;
|
||||
@@ -158,14 +157,7 @@ public class HighlightNamesUtil {
|
||||
}
|
||||
|
||||
HighlightInfo.Builder builder = HighlightInfo.newHighlightInfo(varType).range(elementToHighlight);
|
||||
if (rainbowHighlighter != null && (varType == JavaHighlightInfoTypes.LOCAL_VARIABLE || varType == JavaHighlightInfoTypes.PARAMETER)) {
|
||||
String name = variable.getName();
|
||||
if (name != null) {
|
||||
TextAttributes rainbowAttributes = rainbowHighlighter.getAttributes(name);
|
||||
builder.textAttributes(rainbowAttributes);
|
||||
}
|
||||
}
|
||||
return builder.create();
|
||||
return RainbowHighlighter.isRainbowEnabled() ? builder.createUnconditionally() : builder.create();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+6
-13
@@ -16,7 +16,6 @@
|
||||
package com.intellij.codeInsight.daemon.impl.analysis;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeHighlighting.RainbowHighlighter;
|
||||
import com.intellij.codeInsight.daemon.JavaErrorMessages;
|
||||
import com.intellij.codeInsight.daemon.impl.*;
|
||||
import com.intellij.codeInsight.daemon.impl.analysis.HighlightUtil.Feature;
|
||||
@@ -53,10 +52,7 @@ import gnu.trove.TObjectIntHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
|
||||
public class HighlightVisitorImpl extends JavaElementVisitor implements HighlightVisitor {
|
||||
@NotNull
|
||||
@@ -94,7 +90,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
private final Map<PsiClass, MostlySingularMultiMap<MethodSignature, PsiMethod>> myDuplicateMethods = new THashMap<>();
|
||||
private LanguageLevel myLanguageLevel;
|
||||
private JavaSdkVersion myJavaSdkVersion;
|
||||
private RainbowHighlighter myRainbowHighlighter;
|
||||
|
||||
private static class Holder {
|
||||
private static final boolean CHECK_ELEMENT_LEVEL = ApplicationManager.getApplication().isUnitTestMode() || ApplicationManager.getApplication().isInternal();
|
||||
@@ -162,7 +157,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
@NotNull final Runnable highlight) {
|
||||
myFile = file;
|
||||
myHolder = Holder.CHECK_ELEMENT_LEVEL ? new CheckLevelHighlightInfoHolder(file, holder) : holder;
|
||||
myRainbowHighlighter = RainbowHighlighter.isRainbowEnabled() ? new RainbowHighlighter(holder.getColorsScheme()) : null;
|
||||
boolean success = true;
|
||||
try {
|
||||
myLanguageLevel = PsiUtil.getLanguageLevel(file);
|
||||
@@ -200,7 +194,6 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myFile = null;
|
||||
myHolder = null;
|
||||
myDuplicateMethods.clear();
|
||||
myRainbowHighlighter = null;
|
||||
}
|
||||
|
||||
return success;
|
||||
@@ -482,7 +475,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
colorsScheme));
|
||||
}
|
||||
else if (element instanceof PsiParameter) {
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName((PsiVariable)element, value.getNavigationElement(), colorsScheme, myRainbowHighlighter));
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName((PsiVariable)element, value.getNavigationElement(), colorsScheme));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -623,7 +616,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myHolder.add(HighlightNamesUtil.highlightReassignedVariable(variable, identifier));
|
||||
}
|
||||
else {
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, identifier, colorsScheme,myRainbowHighlighter));
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, identifier, colorsScheme));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -726,7 +719,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
else{
|
||||
myHolder.add(HighlightNamesUtil.highlightClassNameInQualifier(ref, colorsScheme));
|
||||
if (resolved instanceof PsiVariable) {
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName((PsiVariable)resolved, referenceNameElement, colorsScheme, myRainbowHighlighter));
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName((PsiVariable)resolved, referenceNameElement, colorsScheme));
|
||||
}
|
||||
else if (resolved instanceof PsiMethod) {
|
||||
myHolder.add(HighlightNamesUtil.highlightMethodName((PsiMethod)resolved, referenceNameElement, false, colorsScheme));
|
||||
@@ -812,7 +805,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myHolder.add(HighlightNamesUtil.highlightReassignedVariable(parameter, parameter.getNameIdentifier()));
|
||||
}
|
||||
else {
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName(parameter, parameter.getNameIdentifier(), colorsScheme, myRainbowHighlighter));
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName(parameter, parameter.getNameIdentifier(), colorsScheme));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1096,7 +1089,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
myHolder.add(HighlightNamesUtil.highlightReassignedVariable(variable, ref));
|
||||
}
|
||||
else {
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, ref.getReferenceNameElement(), colorsScheme, myRainbowHighlighter));
|
||||
myHolder.add(HighlightNamesUtil.highlightVariableName(variable, ref.getReferenceNameElement(), colorsScheme));
|
||||
}
|
||||
myHolder.add(HighlightNamesUtil.highlightClassNameInQualifier(ref, colorsScheme));
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeHighlighting.RainbowHighlighter;
|
||||
import com.intellij.codeInsight.daemon.GutterMark;
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
@@ -29,6 +30,7 @@ import com.intellij.lang.annotation.Annotation;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.lang.annotation.ProblemGroup;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.DefaultLanguageHighlighterColors;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.HighlighterColors;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
@@ -177,7 +179,23 @@ public class HighlightInfo implements Segment {
|
||||
return colorsScheme.getAttributes(forcedTextAttributesKey);
|
||||
}
|
||||
|
||||
return getAttributesByType(element, type, colorsScheme);
|
||||
TextAttributes attributes = getAttributesByType(element, type, colorsScheme);
|
||||
if (RainbowHighlighter.isRainbowEnabled() &&
|
||||
isLikeVariable(type.getAttributesKey()) && element != null) {
|
||||
String text = element.getContainingFile().getText();
|
||||
String name = text.substring(startOffset, endOffset);
|
||||
TextAttributes rainAttributes = new RainbowHighlighter(colorsScheme).getAttributes(name);
|
||||
attributes = TextAttributes.merge(attributes, rainAttributes);
|
||||
}
|
||||
return attributes;
|
||||
}
|
||||
|
||||
private static boolean isLikeVariable(TextAttributesKey key) {
|
||||
if (key == null) return false;
|
||||
TextAttributesKey fallbackAttributeKey = key.getFallbackAttributeKey();
|
||||
if (fallbackAttributeKey == null) return false;
|
||||
if (fallbackAttributeKey == DefaultLanguageHighlighterColors.LOCAL_VARIABLE || fallbackAttributeKey == DefaultLanguageHighlighterColors.PARAMETER) return true;
|
||||
return isLikeVariable(fallbackAttributeKey);
|
||||
}
|
||||
|
||||
public static TextAttributes getAttributesByType(@Nullable final PsiElement element,
|
||||
|
||||
Reference in New Issue
Block a user