Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 526605

Summary: [9][ast rewrite] Rewrite fails on simple module directive modifications
Product: [Eclipse Project] JDT Reporter: Mateusz Matela <mateusz.matela>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 4.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Mateusz Matela CLA 2017-10-28 17:18:37 EDT
While working on bug 517261 I was experimenting with ASTRewritingModuleDeclarationTest.testBug516731_0003_since_9 and I noticed that when the section for adding a new directive at the end is removed, the rewrite result is garbage ('requires' keywords are removed).

Searching for why this happens, I noticed the first difference is in ASTRewrite:221 - rewriteAST() calls getRootNode(), which returns either a CompilationUnit (when directive creation is included) or a RequiresDirective (without it). I guess it works this way to save on visiting unnecessary nodes, but the result down the line is that when the Scanner starts from RequiresDirective, its scanContext is INACTIVE so it doesn't recognize 'requires' as a keyword and fails, in this case in ASTRewriteAnalyzer.visit(RequiresDirective) the call to getPosAfterToken(... TokenNamerequires) returns an invalid value.

My idea for a solution is to modify getRootNode() so that when the compilation unit is a module declaration, it doesn't go inside and look for "savings". But I'm not familiar with the Rewriter so may have missed something.
Comment 1 Eclipse Genie CLA 2020-02-13 08:02:16 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.