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 - Interaction between GeneratorUtilities.importFQNs and WorkingCopy.rewrite
Summary: Interaction between GeneratorUtilities.importFQNs and WorkingCopy.rewrite
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Source (show other bugs)
Version: 6.x
Hardware: All All
: P2 blocker (vote)
Assignee: Rastislav Komara
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-03-09 22:06 UTC by tronicek
Modified: 2009-11-02 10:58 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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