Skip to content

Add support for Java record definitions in JavaXref#4933

Open
NA-V10 wants to merge 1 commit intooracle:masterfrom
NA-V10:fix-java-record-definitions
Open

Add support for Java record definitions in JavaXref#4933
NA-V10 wants to merge 1 commit intooracle:masterfrom
NA-V10:fix-java-record-definitions

Conversation

@NA-V10
Copy link
Copy Markdown

@NA-V10 NA-V10 commented Apr 5, 2026

What changes were proposed in this pull request?

This change adds handling for Java record declarations in JavaXref.lex.

Previously, record declarations were treated as normal identifiers, so the record name was not highlighted or indexed similarly to classes, interfaces, and enums.

This update adds a dedicated lexer rule for:

record User(String name, int age) {}

so that User is recognized as a symbol and can participate in navigation and definition lookup.

Why are these changes needed?

Java records are now commonly used in modern Java codebases, but OpenGrok did not recognize record declarations in the same way as other type definitions.

Without this change, record names were not indexed correctly, making navigation less useful for projects using Java records.

How was this patch tested?
Built the opengrok-indexer module successfully with Java 21
Verified that the updated lexer compiles correctly
Added a sample Java record declaration locally to confirm the lexer rule matches record definitions

Example used during testing:

record User(String name, int age) {}
Related Issue

Fixes #4930

@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Apr 5, 2026
@NA-V10
Copy link
Copy Markdown
Author

NA-V10 commented Apr 5, 2026

Hello,

I have opened this PR to add support for Java record declarations in JavaXref.lex.

The change introduces a dedicated lexer rule so record names are recognized similarly to classes, interfaces, and enums.

I verified that the opengrok-indexer module builds successfully with Java 21 after the change, and I also tested locally with a simple example such as:

record User(String name, int age) {}

Please let me know if you would like me to also add a dedicated test case for record declarations.

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

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenGrok records definition

1 participant