Skip to content

Commit

Permalink
Use a custom color for Java Annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
lkishalmi committed Dec 27, 2023
1 parent 5fe7d3d commit d0a512d
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 15 deletions.
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);
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

0 comments on commit d0a512d

Please sign in to comment.