Skip to content

fix(gui): keep rename enabled for variables named as contextual keywords - #3044

Merged
skylot merged 1 commit into
skylot:masterfrom
Henglie:fix/gui-rename-invalid-identifier
Oct 30, 2026
Merged

skylot merged 1 commit into
skylot:masterfrom
Henglie:fix/gui-rename-invalid-identifier

Conversation

@Henglie

@Henglie Henglie commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #3034

Root cause

The rename itself is valid: �ar is a legal Java variable name and jadx applies the rename correctly. The problem is in the code area after the rename.

RSyntaxTextArea tokenizes contextual keywords according to their Java grammar role:

  • �ar -> TokenTypes.DATA_TYPE
  • yield -> TokenTypes.RESERVED_WORD_2

ecord, sealed, module, ... -> TokenTypes.RESERVED_WORD

JadxTokenMaker only converted RESERVED_WORD contextual keywords back to IDENTIFIER. CodeArea.adjustOffsetForWordToken() accepts only identifiers/functions (plus static), so a variable named �ar could not be resolved from the caret. With no node under the caret, RenameAction was disabled, so the variable could not be renamed again.

Fix

Treat DATA_TYPE and RESERVED_WORD_2 tokens through the same contextual-keyword check as RESERVED_WORD, and run that check even for the first token of a line. Real keywords/types (int,
eturn, class) are not in the contextual set and keep their token type.

Validation

  • .\gradlew.bat :jadx-gui:test --tests "jadx.gui.ui.codearea.JadxTokenMakerTest" - 2 tests passed (asserts �ar/yield/
    ecord/... become identifiers while int/
    eturn/class are unchanged)
  • .\gradlew.bat :jadx-gui:spotlessJavaCheck - passed
  • .\gradlew.bat :jadx-gui:checkstyleMain :jadx-gui:checkstyleTest - passed
RSyntaxTextArea tokenizes contextual keywords like 'var' as DATA_TYPE and 'yield' as RESERVED_WORD_2. JadxTokenMaker only converted RESERVED_WORD contextual keywords back to identifiers, so CodeArea.adjustOffsetForWordToken rejected those tokens and disabled rename (and other node actions) for variables renamed to such names.

@skylot skylot left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for fix

@skylot
skylot merged commit 55982e0 into skylot:master Oct 30, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants