Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a custom color for Java Annotations #6749

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<fontscolors>
<!-- JavaTokenId categories -->
<fontcolor name="annotation-separator" foreColor="ff66ccff" default="separator"/>
<fontcolor name="character" default="char"/>
<fontcolor name="errors" default="error"/>
<fontcolor name="identifier" default="identifier"/>
Expand Down Expand Up @@ -52,7 +53,7 @@
</fontcolor>
<fontcolor name="mod-class" />
<fontcolor name="mod-interface" />
<fontcolor name="mod-annotation-type" />
<fontcolor name="mod-annotation-type" foreColor="ff66ccff" default="identifier" />
<fontcolor name="mod-enum" />
<fontcolor name="mod-deprecated" strikeThrough="404040" />
<fontcolor name="mod-static" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ private Collection<ColoringAttributes> getVariableColoring(Element decl) {
private void handlePossibleIdentifier(TreePath expr, boolean declaration) {
handlePossibleIdentifier(expr, declaration, null);
}


@SuppressWarnings("AssignmentToMethodParameter")
private void handlePossibleIdentifier(TreePath expr, boolean declaration, Element decl) {
if (Utilities.isKeyword(expr.getLeaf())) {
//ignore keywords:
Expand All @@ -504,6 +505,12 @@ private void handlePossibleIdentifier(TreePath expr, boolean declaration, Elemen
TreePath currentPath = getCurrentPath();
TreePath parent = currentPath.getParentPath();

if (isDeclType &&
parent.getLeaf().getKind() == Kind.IMPORT) {
// Coloring types upon their kind is distracting on import statements
return;
}

//for new <type>(), highlight <type> as a constructor:
if (isDeclType &&
parent.getLeaf().getKind() == Kind.NEW_CLASS) {
Expand Down Expand Up @@ -533,12 +540,12 @@ private void handlePossibleIdentifier(TreePath expr, boolean declaration, Elemen
}

if (decl.getKind() == ElementKind.MODULE) {
c = new ArrayList<ColoringAttributes>();
c = new ArrayList<>();
c.add(ColoringAttributes.MODULE);
}

if (isDeclType) {
c = new ArrayList<ColoringAttributes>();
c = new ArrayList<>();

addModifiers(decl, c);

Expand All @@ -557,7 +564,7 @@ private void handlePossibleIdentifier(TreePath expr, boolean declaration, Elemen

if (declaration) {
if (c == null) {
c = new ArrayList<ColoringAttributes>();
c = new ArrayList<>();
}

c.add(ColoringAttributes.DECLARATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ operator=Operator
comment=Comment
literal=Literal
separator=Separator
annotation-separator=Annotation Separator

# JavaStringTokenId categories
string-escape=String Escape Sequence
Expand Down Expand Up @@ -67,6 +68,7 @@ mod-private=Private Element
mod-package-private=Package Private Element
mod-protected=Protected Element
mod-public=Public Element
mod-keyword=Contextual Keyword

mod-field-declaration=Field Declaration
mod-record-component-declaration=Record Component Declaration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

<fontscolors>
<!-- JavaTokenId categories -->
<fontcolor name="annotation-separator" foreColor="996600" default="separator"/>
<fontcolor name="character" default="char"/>
<fontcolor name="identifier" default="identifier"/>
<fontcolor name="keyword" default="keyword"/>
Expand Down Expand Up @@ -52,16 +53,16 @@
<font style="bold" />
</fontcolor>
<fontcolor name="mod-module-declaration" default="identifier">
<font style="bold" />
<font style="bold" />
</fontcolor>
<fontcolor name="mod-class-declaration" default="identifier">
<font style="bold" />
<font style="bold" />
</fontcolor>
<fontcolor name="mod-interface-declaration" default="identifier">
<font style="bold" />
<font style="bold" />
</fontcolor>
<fontcolor name="mod-annotation-type-declaration" default="identifier">
<font style="bold" />
<font style="bold" />
</fontcolor>
<fontcolor name="mod-enum-declaration" default="identifier">
<font style="bold" />
Expand All @@ -77,7 +78,7 @@
<fontcolor name="mod-class" default="identifier"/>
<fontcolor name="mod-record" default="identifier"/>
<fontcolor name="mod-interface" default="identifier"/>
<fontcolor name="mod-annotation-type" default="identifier"/>
<fontcolor name="mod-annotation-type" foreColor="996600" default="identifier"/>
<fontcolor name="mod-enum" default="identifier"/>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public final class ColoringManager {
put("mod-deprecated", DEPRECATED);
put("mod-undefined", UNDEFINED);
put("mod-unused", UNUSED);
put("mod-keyword", KEYWORD);
//put("mod-keyword", KEYWORD);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, not. I was trying to figure out what exactly it is used for. I'm still not sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the semantic highlighter it would be mostly used from the parser info in module-info.java files. But right now we do not parse that section of the code (in the semantic highlighter).

put("javadoc-identifier", JAVADOC_IDENTIFIER);
put("mod-unindented-text-block", UNINDENTED_TEXT_BLOCK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public enum JavaTokenId implements TokenId {
/**@since 1.23*/
ARROW("->", "operator"),

ELLIPSIS("...", "special"),
AT("@", "special"),
ELLIPSIS("...", "separator"), // Both '...' and '@' are separators in Java 8 language spec
AT("@", "annotation-separator"),

WHITESPACE(null, "whitespace"),
LINE_COMMENT(null, "comment"), // Token includes ending new-line
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void testTokenIds() {
Set testCats = language.tokenCategories();
Collection cats = Arrays.asList(new String[] {
"error", "identifier", "operator", "separator", "whitespace", "error", "comment",
"keyword", "string", "character", "number", "literal", "special", "keyword-directive"
"keyword", "string", "character", "number", "literal", "annotation-separator", "keyword-directive"
});
LexerTestUtilities.assertCollectionsEqual("Invalid categories", cats, testCats);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
-->
<!DOCTYPE fontscolors PUBLIC "-//NetBeans//DTD Editor Fonts and Colors settings 1.1//EN" "http://www.netbeans.org/dtds/EditorFontsColors-1_1.dtd">
<fontscolors>
<fontcolor name="annotation-separator" foreColor="ffffafaf" default="separator"/>
<fontcolor name="character" default="char"/>
<fontcolor name="character-escape" default="character"><font style="bold"/></fontcolor>
<fontcolor name="character-escape-invalid" default="character"><font style="italic"/></fontcolor>
Expand All @@ -34,7 +35,7 @@
<fontcolor name="keyword-directive" default="keyword"/>
<fontcolor name="literal" default="keyword"/>
<fontcolor name="mod-abstract"/>
<fontcolor name="mod-annotation-type" default="identifier"/>
<fontcolor name="mod-annotation-type" foreColor="fffffafa" default="identifier"/>
<fontcolor name="mod-annotation-type-declaration" default="identifier"><font style="bold"/></fontcolor>
<fontcolor name="mod-class" default="identifier"/>
<fontcolor name="mod-class-declaration" default="identifier"/>
Expand Down
Loading