mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
provide special colors for statically imported members (IDEA-98499)
This commit is contained in:
+4
-1
@@ -16,11 +16,11 @@
|
||||
package com.intellij.codeInsight.daemon.impl;
|
||||
|
||||
import com.intellij.codeInsight.daemon.HighlightDisplayKey;
|
||||
import com.intellij.codeInspection.unusedImport.UnusedImportInspection;
|
||||
import com.intellij.ide.highlighter.JavaHighlightingColors;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.codeInspection.unusedImport.UnusedImportInspection;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public final class JavaHighlightInfoTypes {
|
||||
@@ -37,7 +37,9 @@ public final class JavaHighlightInfoTypes {
|
||||
public final static HighlightInfoType INSTANCE_FIELD = createSymbolTypeInfo(JavaHighlightingColors.INSTANCE_FIELD_ATTRIBUTES);
|
||||
public final static HighlightInfoType INSTANCE_FINAL_FIELD = createSymbolTypeInfo(JavaHighlightingColors.INSTANCE_FINAL_FIELD_ATTRIBUTES);
|
||||
public final static HighlightInfoType STATIC_FIELD = createSymbolTypeInfo(JavaHighlightingColors.STATIC_FIELD_ATTRIBUTES);
|
||||
public final static HighlightInfoType STATIC_FIELD_IMPORTED = createSymbolTypeInfo(JavaHighlightingColors.STATIC_FIELD_IMPORTED_ATTRIBUTES);
|
||||
public final static HighlightInfoType STATIC_FINAL_FIELD = createSymbolTypeInfo(JavaHighlightingColors.STATIC_FINAL_FIELD_ATTRIBUTES);
|
||||
public final static HighlightInfoType STATIC_FINAL_FIELD_IMPORTED = createSymbolTypeInfo(JavaHighlightingColors.STATIC_FINAL_FIELD_IMPORTED_ATTRIBUTES);
|
||||
public final static HighlightInfoType PARAMETER = createSymbolTypeInfo(JavaHighlightingColors.PARAMETER_ATTRIBUTES);
|
||||
public final static HighlightInfoType LAMBDA_PARAMETER = createSymbolTypeInfo(JavaHighlightingColors.LAMBDA_PARAMETER_ATTRIBUTES);
|
||||
public final static HighlightInfoType METHOD_CALL = createSymbolTypeInfo(JavaHighlightingColors.METHOD_CALL_ATTRIBUTES);
|
||||
@@ -45,6 +47,7 @@ public final class JavaHighlightInfoTypes {
|
||||
public final static HighlightInfoType CONSTRUCTOR_CALL = createSymbolTypeInfo(JavaHighlightingColors.CONSTRUCTOR_CALL_ATTRIBUTES);
|
||||
public final static HighlightInfoType CONSTRUCTOR_DECLARATION = createSymbolTypeInfo(JavaHighlightingColors.CONSTRUCTOR_DECLARATION_ATTRIBUTES);
|
||||
public final static HighlightInfoType STATIC_METHOD = createSymbolTypeInfo(JavaHighlightingColors.STATIC_METHOD_ATTRIBUTES);
|
||||
public final static HighlightInfoType STATIC_METHOD_CALL_IMPORTED = createSymbolTypeInfo(JavaHighlightingColors.STATIC_METHOD_CALL_IMPORTED_ATTRIBUTES);
|
||||
public final static HighlightInfoType ABSTRACT_METHOD = createSymbolTypeInfo(JavaHighlightingColors.ABSTRACT_METHOD_ATTRIBUTES);
|
||||
public final static HighlightInfoType INHERITED_METHOD = createSymbolTypeInfo(JavaHighlightingColors.INHERITED_METHOD_ATTRIBUTES);
|
||||
public final static HighlightInfoType ANONYMOUS_CLASS_NAME = createSymbolTypeInfo(JavaHighlightingColors.ANONYMOUS_CLASS_NAME_ATTRIBUTES);
|
||||
|
||||
+31
-8
@@ -64,8 +64,10 @@ public class HighlightNamesUtil {
|
||||
@NotNull TextAttributesScheme colorsScheme,
|
||||
final boolean isDeclaration) {
|
||||
boolean isInherited = false;
|
||||
boolean isStaticallyImported = false;
|
||||
|
||||
if (!isDeclaration) {
|
||||
isStaticallyImported = isStaticallyImported(elementToHighlight);
|
||||
if (isCalledOnThis(elementToHighlight)) {
|
||||
final PsiClass containingClass = methodOrClass instanceof PsiMethod ? methodOrClass.getContainingClass() : null;
|
||||
PsiClass enclosingClass = containingClass == null ? null : PsiTreeUtil.getParentOfType(elementToHighlight, PsiClass.class);
|
||||
@@ -78,7 +80,7 @@ public class HighlightNamesUtil {
|
||||
}
|
||||
|
||||
LOG.assertTrue(methodOrClass instanceof PsiMethod || !isDeclaration);
|
||||
HighlightInfoType type = methodOrClass instanceof PsiMethod ? getMethodNameHighlightType((PsiMethod)methodOrClass, isDeclaration, isInherited)
|
||||
HighlightInfoType type = methodOrClass instanceof PsiMethod ? getMethodNameHighlightType((PsiMethod)methodOrClass, isDeclaration, isInherited, isStaticallyImported)
|
||||
: JavaHighlightInfoTypes.CONSTRUCTOR_CALL;
|
||||
if (type != null) {
|
||||
TextAttributes attributes = mergeWithScopeAttributes(methodOrClass, type, colorsScheme);
|
||||
@@ -102,6 +104,15 @@ public class HighlightNamesUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isStaticallyImported(@NotNull PsiElement elementToHighlight) {
|
||||
PsiReferenceExpression referenceExpression = PsiTreeUtil.getParentOfType(elementToHighlight, PsiReferenceExpression.class);
|
||||
if (referenceExpression != null) {
|
||||
JavaResolveResult result = referenceExpression.advancedResolve(false);
|
||||
return result.getCurrentFileResolveScope() instanceof PsiImportStaticStatement;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static TextAttributes mergeWithScopeAttributes(@Nullable PsiElement element,
|
||||
@NotNull HighlightInfoType type,
|
||||
@NotNull TextAttributesScheme colorsScheme) {
|
||||
@@ -142,7 +153,7 @@ public class HighlightNamesUtil {
|
||||
static HighlightInfo highlightVariableName(@NotNull PsiVariable variable,
|
||||
@NotNull PsiElement elementToHighlight,
|
||||
@NotNull TextAttributesScheme colorsScheme) {
|
||||
HighlightInfoType varType = getVariableNameHighlightType(variable);
|
||||
HighlightInfoType varType = getVariableNameHighlightType(variable, elementToHighlight);
|
||||
if (varType == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -174,13 +185,16 @@ public class HighlightNamesUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HighlightInfoType getMethodNameHighlightType(@NotNull PsiMethod method, boolean isDeclaration, boolean isInheritedMethod) {
|
||||
private static HighlightInfoType getMethodNameHighlightType(@NotNull PsiMethod method,
|
||||
boolean isDeclaration,
|
||||
boolean isInheritedMethod,
|
||||
boolean isStaticallyImported) {
|
||||
if (method.isConstructor()) {
|
||||
return isDeclaration ? JavaHighlightInfoTypes.CONSTRUCTOR_DECLARATION : JavaHighlightInfoTypes.CONSTRUCTOR_CALL;
|
||||
}
|
||||
if (isDeclaration) return JavaHighlightInfoTypes.METHOD_DECLARATION;
|
||||
if (method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
return JavaHighlightInfoTypes.STATIC_METHOD;
|
||||
return isStaticallyImported ? JavaHighlightInfoTypes.STATIC_METHOD_CALL_IMPORTED : JavaHighlightInfoTypes.STATIC_METHOD;
|
||||
}
|
||||
if (isInheritedMethod) return JavaHighlightInfoTypes.INHERITED_METHOD;
|
||||
if(method.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
@@ -190,15 +204,24 @@ public class HighlightNamesUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static HighlightInfoType getVariableNameHighlightType(@NotNull PsiVariable var) {
|
||||
private static HighlightInfoType getVariableNameHighlightType(@NotNull PsiVariable var, PsiElement elementToHighlight) {
|
||||
if (var instanceof PsiLocalVariable
|
||||
|| var instanceof PsiParameter && ((PsiParameter)var).getDeclarationScope() instanceof PsiForeachStatement) {
|
||||
return JavaHighlightInfoTypes.LOCAL_VARIABLE;
|
||||
}
|
||||
if (var instanceof PsiField) {
|
||||
return var.hasModifierProperty(PsiModifier.STATIC)
|
||||
? var.hasModifierProperty(PsiModifier.FINAL) ? JavaHighlightInfoTypes.STATIC_FINAL_FIELD : JavaHighlightInfoTypes.STATIC_FIELD
|
||||
: var.hasModifierProperty(PsiModifier.FINAL) ? JavaHighlightInfoTypes.INSTANCE_FINAL_FIELD : JavaHighlightInfoTypes.INSTANCE_FIELD;
|
||||
if (var.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
boolean staticallyImported = isStaticallyImported(elementToHighlight);
|
||||
if (var.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
return staticallyImported ? JavaHighlightInfoTypes.STATIC_FINAL_FIELD_IMPORTED : JavaHighlightInfoTypes.STATIC_FINAL_FIELD;
|
||||
}
|
||||
else {
|
||||
return staticallyImported ? JavaHighlightInfoTypes.STATIC_FIELD_IMPORTED : JavaHighlightInfoTypes.STATIC_FIELD;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return var.hasModifierProperty(PsiModifier.FINAL) ? JavaHighlightInfoTypes.INSTANCE_FINAL_FIELD : JavaHighlightInfoTypes.INSTANCE_FIELD;
|
||||
}
|
||||
}
|
||||
if (var instanceof PsiParameter) {
|
||||
return ((PsiParameter)var).getDeclarationScope() instanceof PsiLambdaExpression ? JavaHighlightInfoTypes.LAMBDA_PARAMETER
|
||||
|
||||
+7
-1
@@ -77,8 +77,12 @@ public class JavaHighlightingColors {
|
||||
= TextAttributesKey.createTextAttributesKey("INSTANCE_FINAL_FIELD_ATTRIBUTES", INSTANCE_FIELD_ATTRIBUTES);
|
||||
public static final TextAttributesKey STATIC_FIELD_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("STATIC_FIELD_ATTRIBUTES", DefaultLanguageHighlighterColors.STATIC_FIELD);
|
||||
public static final TextAttributesKey STATIC_FINAL_FIELD_ATTRIBUTES
|
||||
public static final TextAttributesKey STATIC_FIELD_IMPORTED_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("STATIC_FIELD_IMPORTED_ATTRIBUTES", STATIC_FIELD_ATTRIBUTES);
|
||||
public static final TextAttributesKey STATIC_FINAL_FIELD_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("STATIC_FINAL_FIELD_ATTRIBUTES", STATIC_FIELD_ATTRIBUTES);
|
||||
public static final TextAttributesKey STATIC_FINAL_FIELD_IMPORTED_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("STATIC_FINAL_FIELD_IMPORTED_ATTRIBUTES", STATIC_FINAL_FIELD_ATTRIBUTES);
|
||||
public static final TextAttributesKey CLASS_NAME_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("CLASS_NAME_ATTRIBUTES", DefaultLanguageHighlighterColors.CLASS_NAME);
|
||||
public static final TextAttributesKey ANONYMOUS_CLASS_NAME_ATTRIBUTES
|
||||
@@ -99,6 +103,8 @@ public class JavaHighlightingColors {
|
||||
= TextAttributesKey.createTextAttributesKey("METHOD_DECLARATION_ATTRIBUTES", DefaultLanguageHighlighterColors.FUNCTION_DECLARATION);
|
||||
public static final TextAttributesKey STATIC_METHOD_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("STATIC_METHOD_ATTRIBUTES", DefaultLanguageHighlighterColors.STATIC_METHOD);
|
||||
public static final TextAttributesKey STATIC_METHOD_CALL_IMPORTED_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("STATIC_METHOD_IMPORTED_ATTRIBUTES", STATIC_METHOD_ATTRIBUTES);
|
||||
public static final TextAttributesKey ABSTRACT_METHOD_ATTRIBUTES
|
||||
= TextAttributesKey.createTextAttributesKey("ABSTRACT_METHOD_ATTRIBUTES", METHOD_CALL_ATTRIBUTES);
|
||||
public static final TextAttributesKey INHERITED_METHOD_ATTRIBUTES
|
||||
|
||||
+3
-1
@@ -21,7 +21,6 @@ import com.intellij.ide.highlighter.JavaFileHighlighter;
|
||||
import com.intellij.ide.highlighter.JavaHighlightingColors;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.application.ApplicationBundle;
|
||||
import com.intellij.openapi.editor.colors.CodeInsightColors;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
@@ -77,10 +76,13 @@ public class JavaColorSettingsPage implements RainbowColorSettingsPage, Inspecti
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.instance.field"), JavaHighlightingColors.INSTANCE_FIELD_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.instance.final.field"), JavaHighlightingColors.INSTANCE_FINAL_FIELD_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.static.field"), JavaHighlightingColors.STATIC_FIELD_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.static.imported.field"), JavaHighlightingColors.STATIC_FIELD_IMPORTED_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.static.final.field"), JavaHighlightingColors.STATIC_FINAL_FIELD_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.static.final.imported.field"), JavaHighlightingColors.STATIC_FINAL_FIELD_IMPORTED_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.parameter"), JavaHighlightingColors.PARAMETER_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.lambda.parameter"), JavaHighlightingColors.LAMBDA_PARAMETER_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.method.call"), JavaHighlightingColors.METHOD_CALL_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.method.imported.call"), JavaHighlightingColors.STATIC_METHOD_CALL_IMPORTED_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.method.declaration"), JavaHighlightingColors.METHOD_DECLARATION_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.constructor.call"), JavaHighlightingColors.CONSTRUCTOR_CALL_ATTRIBUTES),
|
||||
new AttributesDescriptor(OptionsBundle.message("options.java.attribute.descriptor.constructor.declaration"), JavaHighlightingColors.CONSTRUCTOR_DECLARATION_ATTRIBUTES),
|
||||
|
||||
+3
-1
@@ -2,6 +2,7 @@ import <symbolName descr="null" type="CLASS_NAME">java.</symbolName><symbolName
|
||||
import <symbolName descr="null" type="CLASS_NAME">java.</symbolName><symbolName descr="null" type="CLASS_NAME">util.</symbolName>*; // highlight on demand import as class name
|
||||
import <symbolName descr="null" type="CLASS_NAME">java.</symbolName><symbolName descr="null" type="CLASS_NAME">lang</symbolName>/*comment*/.<symbolName descr="null" type="CLASS_NAME">String</symbolName>;
|
||||
import static <symbolName descr="null" type="CLASS_NAME">java.</symbolName><symbolName descr="null" type="CLASS_NAME">io.</symbolName><symbolName descr="null" type="CLASS_NAME">File</symbolName>.<symbolName descr="null" type="STATIC_FINAL_FIELD">pathSeparator</symbolName>;
|
||||
import static <symbolName descr="null" type="CLASS_NAME">java.</symbolName><symbolName descr="null" type="CLASS_NAME">lang.</symbolName><symbolName descr="null" type="CLASS_NAME">Integer</symbolName>.<symbolName descr="null" type="STATIC_METHOD">parseInt</symbolName>;
|
||||
import static <symbolName descr="null" type="CLASS_NAME">java.</symbolName><symbolName descr="null" type="CLASS_NAME">io.</symbolName><symbolName descr="null" type="CLASS_NAME">File</symbolName>.*;
|
||||
|
||||
class <symbolName descr="null" type="CLASS_NAME">a</symbolName> {
|
||||
@@ -22,6 +23,7 @@ class <symbolName descr="null" type="CLASS_NAME">a</symbolName> {
|
||||
static void <symbolName descr="null" type="METHOD_DECLARATION">f</symbolName>() {
|
||||
<symbolName descr="null" type="CLASS_NAME">Integer</symbolName>.<symbolName descr="null" type="STATIC_METHOD">parseInt</symbolName>("");
|
||||
<symbolName descr="null" type="CLASS_NAME">java.</symbolName><symbolName descr="null" type="CLASS_NAME">lang.</symbolName><symbolName descr="null" type="CLASS_NAME">Integer</symbolName>.<symbolName descr="null" type="STATIC_METHOD">parseInt</symbolName>("");
|
||||
<symbolName descr="null" type="STATIC_METHOD_CALL_IMPORTED">parseInt</symbolName>("");
|
||||
<symbolName descr="null" type="STATIC_METHOD">f</symbolName>();
|
||||
}
|
||||
|
||||
@@ -68,7 +70,7 @@ class <symbolName descr="null" type="CLASS_NAME">InheritedSymbolNames</symbolNam
|
||||
|
||||
private static class <symbolName descr="null" type="CLASS_NAME">A</symbolName> {
|
||||
public <symbolName descr="null" type="CLASS_NAME">String</symbolName> <symbolName descr="null" type="METHOD_DECLARATION">getName</symbolName>() {
|
||||
return "classA";
|
||||
return <symbolName descr="null" type="STATIC_FINAL_FIELD_IMPORTED">pathSeparator</symbolName>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,10 +86,13 @@ options.java.attribute.descriptor.inline.parameter.hint.current=Inline parameter
|
||||
options.java.attribute.descriptor.instance.field=Class Fields//Instance field
|
||||
options.java.attribute.descriptor.instance.final.field=Class Fields//Instance final field
|
||||
options.java.attribute.descriptor.static.field=Class Fields//Static field
|
||||
options.java.attribute.descriptor.static.imported.field=Class Fields//Static imported field
|
||||
options.java.attribute.descriptor.static.final.field=Class Fields//Constant (static final field)
|
||||
options.java.attribute.descriptor.static.final.imported.field=Class Fields//Constant (static final imported field)
|
||||
options.java.attribute.descriptor.parameter=Parameters//Parameter
|
||||
options.java.attribute.descriptor.lambda.parameter=Parameters//Lambda parameter
|
||||
options.java.attribute.descriptor.method.call=Methods//Method call
|
||||
options.java.attribute.descriptor.method.imported.call=Methods//Static imported method call
|
||||
options.java.attribute.descriptor.method.declaration=Methods//Method declaration
|
||||
options.java.attribute.descriptor.constructor.call=Methods//Constructor call
|
||||
options.java.attribute.descriptor.constructor.declaration=Methods//Constructor declaration
|
||||
|
||||
Reference in New Issue
Block a user