This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
I call importFQNs just before rewrite: modified = GeneratorUtilities.get(wc).importFQNs(modified); wc.rewrite(node, modified); This is useful for importing new types. However, I found it interacts with rewriting and it does not work right sometimes. For example, when I rewrite BlockTree recursively, the result is different from the case when I omit the importFQNs call. Example: I rewrite a block that contains two identical statements to the block with one such statement. Input is: void m4(int[] p) { if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } if (p[1] > 0) { System.out.println("x"); } } if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } if (p[1] > 0) { System.out.println("x"); } } } The expected result is: if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } } I get this if I omit the importFQNs call. But with importFQNs, the result is: if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } if (p[1] > 0) { System.out.println("x"); } } The log is the same in both cases.
Please, provide exact algorithm of replacing nodes. Or provide test case file. Thank you.
Here it is: @Override public Void visitBlock(BlockTree node, Void p) { List<? extends StatementTree> st = node.getStatements(); if (st.size() == 2) { List<StatementTree> st2 = new ArrayList<StatementTree>(); st2.add(st.get(0)); TreeMaker make = wc.getTreeMaker(); BlockTree modified = make.Block(st2, node.isStatic()); modified = GeneratorUtilities.get(wc).importFQNs(modified); System.out.println("original: " + node); System.out.println("modified: " + modified); wc.rewrite(node, modified); } return super.visitBlock(node, p); } When I comment out line "modified = GeneratorUtilities.get(wc).importFQNs(modified);" and run it on the input void m4(int[] p) { if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } if (p[1] > 0) { System.out.println("x"); } } if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } if (p[1] > 0) { System.out.println("x"); } } } I get the result void m4(int[] p) { if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } } } This is correct. However, with the line "modified = GeneratorUtilities.get(wc).importFQNs(modified);", the result is void m4(int[] p) { if (p[0] > 0) { if (p[1] > 0) { System.out.println("x"); } if (p[1] > 0) { System.out.println("x"); } } } which is not correct.
... requested information provided - remove INCOMPLETE
This issue has no affect on existing editor/java functionality. Affected are only newly created manipulations on tree. Also this issue has no effect for current or future end user. The appropriate fix can cause higher risk of regression.
waived.
NetBeans.org Migration: changing resolution from LATER to WONTFIX