Skip to content

Highlight keywords conservatively#666

Open
nbauma109 wants to merge 19 commits into
bobbylight:masterfrom
nbauma109:fix-syntax-coloring-keywords
Open

Highlight keywords conservatively#666
nbauma109 wants to merge 19 commits into
bobbylight:masterfrom
nbauma109:fix-syntax-coloring-keywords

Conversation

@nbauma109
Copy link
Copy Markdown
Contributor

Fixes #665

Copilot AI review requested due to automatic review settings April 15, 2026 10:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 85.52632% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.68%. Comparing base (9528c1f) to head (ad4de9b).

Files with missing lines Patch % Lines
.../fife/ui/rsyntaxtextarea/modes/JavaTokenMaker.java 85.52% 0 Missing and 11 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master     #666      +/-   ##
============================================
+ Coverage     80.67%   80.68%   +0.01%     
- Complexity     7972     8024      +52     
============================================
  Files           181      181              
  Lines         30719    30795      +76     
  Branches       3957     3998      +41     
============================================
+ Hits          24783    24848      +65     
  Misses         4264     4264              
- Partials       1672     1683      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

nbauma109 and others added 14 commits April 15, 2026 13:04
- Fix noPreviousToken() to use passed array parameter consistently
- Remove yield keyword detection after -> (fixes 'case 0 -> yield;')
- Simplify yield detection to only treat as keyword after ':' or '{'
- Add isModuleKeyword() helper supporting annotations (e.g., @deprecated module)
- Update test case from invalid 'case 1 -> yield 42;' to valid 'case 1 -> { yield 42; }'
- Add test for 'case 0 -> yield;' expecting identifier

Agent-Logs-Url: https://github.com/nbauma109/RSyntaxTextArea/sessions/6d7003d5-ef8d-4189-b946-b81cd0e5c2cd

Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
Add isYieldKeywordAtLineStart() helper to handle yield statements at the beginning of lines (common formatting in switch blocks). The heuristic checks what follows yield:
- If followed by an expression/value (not '(', ':', or ';'), treat as keyword
- If followed by ';' or nothing, treat as identifier (ambiguous case)
- This enables correct highlighting of 'yield value;' on its own line in switch blocks

Agent-Logs-Url: https://github.com/nbauma109/RSyntaxTextArea/sessions/ff04e4e0-288e-4aeb-b548-64038033ff91

Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
- Fix noPreviousToken() to check against s.offset instead of 0 (handles non-zero segment offsets on lines after first in documents)
- Enhance isYieldKeyword() to recognize yield after ')' and ';' (fixes nested control flow like 'if (b) yield 1;')
- Apply fixes to both .java and .flex files for consistency

Agent-Logs-Url: https://github.com/nbauma109/RSyntaxTextArea/sessions/8916a861-fc85-40a9-8db6-ec748a717793

Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
- Add findNextNonWhitespaceSkipComments() to skip comments when peeking
- Enhance isModuleKeyword() to recognize module after bare annotations (e.g., @deprecated module)
- Add nextClassOrInterfaceKeyword() to accept non-adjacent modifiers after sealed
- Update sealed/non-sealed detection to handle cases like "sealed abstract class"
- Apply all changes to both JavaTokenMaker.java and .flex files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Agent-Logs-Url: https://github.com/nbauma109/RSyntaxTextArea/sessions/d2a92c03-1bdc-41f3-a342-a39dcd06397c

Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
…xpr)

- Update isYieldKeywordAtLineStart to use findNextNonWhitespaceSkipComments
- Fix isYieldKeywordAtLineStart to treat 'yield (' as keyword (yield statement)
- Update nextTokenEquals to skip comments when peeking next token
- Update nextTokenStartsIdentifier to skip comments when peeking next token
- Apply all changes to both JavaTokenMaker.java and .flex files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Agent-Logs-Url: https://github.com/nbauma109/RSyntaxTextArea/sessions/a1b21b5b-8e51-472e-abe0-eeb48a953fe0

Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
- Remove ')' from yield keyword detection to avoid treating yield as keyword after any closing paren (more conservative approach to prevent false positives)
- Add annotation skipping in nextClassOrInterfaceKeyword to handle cases like "sealed @deprecated class"
- Apply changes to both JavaTokenMaker.java and .flex files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Agent-Logs-Url: https://github.com/nbauma109/RSyntaxTextArea/sessions/d609853f-783c-4e7c-b4fe-eef4b11479e3

Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
- Add findPreviousNonWhitespaceSkipComments to skip comments when checking prefix context
- Update noPreviousToken to use comment-skipping version for module detection
- Improve restricted keyword detection (exports, record, etc.) to handle line breaks while still recognizing method/field usage
- Re-add ')' to yield keyword detection for conditional expressions (if (cond) yield value;)
- Apply all changes to both JavaTokenMaker.java and .flex files

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Agent-Logs-Url: https://github.com/nbauma109/RSyntaxTextArea/sessions/25ff1bd0-82fe-4c7b-990a-055758419dca

Co-authored-by: nbauma109 <9403560+nbauma109@users.noreply.github.com>
@siggemannen
Copy link
Copy Markdown

@claude[agent] are you OK?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Restricted and contextual Java keywords are highlighted when used as identifiers

4 participants