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.

Bug 159941

Summary: Interaction between GeneratorUtilities.importFQNs and WorkingCopy.rewrite
Product: java Reporter: tronicek <tronicek>
Component: SourceAssignee: Rastislav Komara <moonko>
Status: RESOLVED WONTFIX    
Severity: blocker CC: mmirilovic
Priority: P2    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description tronicek 2009-03-09 22:06:49 UTC
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.
Comment 1 Rastislav Komara 2009-03-12 13:20:24 UTC
Please, provide exact algorithm of replacing nodes. Or provide test case file. Thank you.
Comment 2 tronicek 2009-03-13 08:57:02 UTC
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.
Comment 3 Marian Mirilovic 2009-04-23 12:04:04 UTC
... requested information provided - remove INCOMPLETE
Comment 4 Rastislav Komara 2009-04-29 10:41:40 UTC
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.
Comment 5 Rastislav Komara 2009-05-04 10:31:53 UTC
waived.
Comment 6 Quality Engineering 2009-11-02 10:58:01 UTC
NetBeans.org Migration: changing resolution from LATER to WONTFIX