Skip to content

fix(java): support qualified generic type arguments - #4455

Merged
joshgoebel merged 1 commit into
highlightjs:mainfrom
Baltsat:codex/fix-3677-java-qualified-generics
Aug 14, 2026
Merged

joshgoebel merged 1 commit into
highlightjs:mainfrom
Baltsat:codex/fix-3677-java-qualified-generics

Conversation

@Baltsat

@Baltsat Baltsat commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Changes

The Java grammar accepted only one identifier inside a generic type argument, so a declaration such as List<java.lang.String> bar() was not recognized as a method.

This change:

  • permits dot-separated qualified names inside Java generic type arguments;
  • adds the exact List<java.lang.String> regression to the existing Java generics fixture; and
  • records the fix in CHANGES.md.

The behavior introduced by #4346 remains covered: all 11 Java markup fixtures pass, and top-level qualified declarations are unchanged.

Fixes #3677

Verification

  • npm run build
  • ONLY_LANGUAGES=java npm run test-markup — 11 passing
  • Java language ESLint — passed
  • npm run lint-languages — passed
  • npm run lint — passed with one existing ignored-vendor warning
  • npm test — 1,583 passing, 3 pending
  • git diff --check — passed
  • Red→green: the added fixture failed on unpatched main with 10 passing and 1 failing, then passed after the grammar change.
  • Revert proof: reverting only src/languages/java.js reproduced the focused failure; restoring it returned all 11 Java fixtures to green.

A fresh npm ci was unavailable because registry DNS failed in the isolated Linux environment. Verification reused the exact unchanged lockfile dependency tree plus the official lock-resolved Rollup Linux package; npm ls --all reported 782 nodes and no problems.

Checklist

  • Added markup tests
  • Updated CHANGES.md

Assistance disclosure

This patch and its verification were prepared with OpenAI Codex assistance. The final diff and test outputs were reviewed before publication.

Copilot AI review requested due to automatic review settings July 26, 2026 16:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +19 B

View Changes
file base pr diff
es/core.min.js 8.24 KB 8.24 KB +1 B
es/highlight.min.js 8.24 KB 8.24 KB +1 B
es/languages/java.min.js 1.33 KB 1.34 KB +8 B
highlight.min.js 8.28 KB 8.28 KB +1 B
languages/java.min.js 1.34 KB 1.35 KB +8 B

@joshgoebel joshgoebel left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional nits only — LGTM overall.

interface FooBar {
List<String> foo();
List<java.lang.String> bar();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Optional: one more case covering FQNs inside nested/wildcard type args would lock the TYPE_ARG_RE path a bit harder, e.g.:

Suggested change
}
interface FooBar {
List<String> foo();
List<java.lang.String> bar();
Map<java.lang.String, java.util.List<String>> nested();
List<? extends java.lang.Number> bounded();
}

(and matching lines in generics.expect.txt after a rebuild/ONLY_LANGUAGES=java npm run test-markup.)

Comment thread src/languages/java.js Outdated
Comment on lines +39 to +41
// A simple Java type: a type name, optionally followed by type arguments and/or array brackets
// '<@@@>' is replaced with the pattern for optional type arguments by recurRegex below.
const SIMPLE_TYPE_RE = JAVA_IDENT_RE + '<@@@>' + ARRAY_BRACKETS_OPTIONAL_RE;
const SIMPLE_TYPE_RE = JAVA_IDENT_RE + '(?:\\.' + JAVA_IDENT_RE + ')*<@@@>' + ARRAY_BRACKETS_OPTIONAL_RE;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nit: worth updating the comment so it mentions qualified names:

Suggested change
// A simple Java type: a type name, optionally followed by type arguments and/or array brackets
// '<@@@>' is replaced with the pattern for optional type arguments by recurRegex below.
const SIMPLE_TYPE_RE = JAVA_IDENT_RE + '<@@@>' + ARRAY_BRACKETS_OPTIONAL_RE;
const SIMPLE_TYPE_RE = JAVA_IDENT_RE + '(?:\\.' + JAVA_IDENT_RE + ')*<@@@>' + ARRAY_BRACKETS_OPTIONAL_RE;
// A simple Java type: a type name (optionally package-qualified), optionally followed by type arguments and/or array brackets
// '<@@@>' is replaced with the pattern for optional type arguments by recurRegex below.
const SIMPLE_TYPE_RE = JAVA_IDENT_RE + '(?:\.' + JAVA_IDENT_RE + ')*<@@@>' + ARRAY_BRACKETS_OPTIONAL_RE;

joshgoebel added a commit to Baltsat/highlight.js that referenced this pull request Aug 14, 2026
- update comment to mention package-qualified names
- add nested/wildcard FQN fixtures: Map<java.lang.String, java.util.List<String>> and List<? extends java.lang.Number>

Co-authored-by: joshgoebel <[email protected]>
@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

5 files changed

Total change +10 B

View Changes
file base pr diff
es/core.min.js 8.22 KB 8.22 KB -1 B
es/highlight.min.js 8.22 KB 8.22 KB -1 B
es/languages/java.min.js 1.33 KB 1.34 KB +7 B
highlight.min.js 8.26 KB 8.25 KB -3 B
languages/java.min.js 1.34 KB 1.35 KB +8 B

@joshgoebel
joshgoebel force-pushed the codex/fix-3677-java-qualified-generics branch from 68a1faa to 2bf8d51 Compare August 14, 2026 16:16
@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

2 files changed

Total change +15 B

View Changes
file base pr diff
es/languages/java.min.js 1.33 KB 1.34 KB +7 B
languages/java.min.js 1.34 KB 1.35 KB +8 B

@joshgoebel
joshgoebel force-pushed the codex/fix-3677-java-qualified-generics branch from 2bf8d51 to 6a56382 Compare August 14, 2026 17:06
@joshgoebel
joshgoebel merged commit d49ab4c into highlightjs:main Aug 14, 2026
12 checks passed
@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

3 files changed

Total change -3 B

View Changes
file base pr diff
es/core.min.js 8.22 KB 8.22 KB -1 B
es/highlight.min.js 8.22 KB 8.22 KB -1 B
highlight.min.js 8.26 KB 8.26 KB -1 B

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.

(java) Highlighting breaks on Generics with fully-qualified-name

3 participants