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.

View | Details | Raw Unified | Return to bug 209375
Collapse All | Expand All

(-)a/java.source/apichanges.xml (+14 lines)
Lines 108-113 Link Here
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
    <!-- ACTUAL CHANGES BEGIN HERE: -->
109
109
110
    <changes>
110
    <changes>
111
        <change id="WorkingCopy-resolveRewriteTarget">
112
             <api name="general"/>
113
             <summary>Added <code>WorkingCopy.resolveRewriteTarget</code>.</summary>
114
             <version major="0" minor="101"/>
115
             <date day="9" month="4" year="2012"/>
116
             <author login="jlahoda"/>
117
            <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
118
             <description>
119
                 Added a method<code>resolveRewriteTarget</code> to class <code>WorkingCopy</code>,
120
                 that returns the tree into which the given tree has been rewritten.
121
             </description>
122
             <class package="org.netbeans.api.java.source" name="WorkingCopy"/>
123
             <issue number="209375"/>
124
        </change>
111
        <change id="GeneratorUtilities-appendToAnnotationValue">
125
        <change id="GeneratorUtilities-appendToAnnotationValue">
112
             <api name="general"/>
126
             <api name="general"/>
113
             <summary>Added <code>GeneratorUtilities.appendToAnnotationValue</code>.</summary>
127
             <summary>Added <code>GeneratorUtilities.appendToAnnotationValue</code>.</summary>
(-)a/java.source/nbproject/project.properties (-1 / +1 lines)
Lines 46-52 Link Here
46
javadoc.title=Java Source
46
javadoc.title=Java Source
47
javadoc.arch=${basedir}/arch.xml
47
javadoc.arch=${basedir}/arch.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
48
javadoc.apichanges=${basedir}/apichanges.xml
49
spec.version.base=0.100.0
49
spec.version.base=0.101.0
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
50
test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
51
test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
52
    ${o.n.core.dir}/lib/boot.jar:\
(-)a/java.source/src/org/netbeans/api/java/source/WorkingCopy.java (+27 lines)
Lines 295-300 Link Here
295
    public synchronized void tag(@NonNull Tree t, @NonNull Object tag) {
295
    public synchronized void tag(@NonNull Tree t, @NonNull Object tag) {
296
        tree2Tag.put(t, tag);
296
        tree2Tag.put(t, tag);
297
    }
297
    }
298
299
    /**Returns the tree into which the given tree was rewritten using the
300
     * {@link #rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) } method,
301
     * transitively.
302
     * Will return the input tree if the input tree was never passed as the first
303
     * parameter of the {@link #rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) }
304
     * method.
305
     *
306
     * <p>Note that the returned tree will be exactly equivalent to a tree passed as
307
     * the second parameter to {@link #rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) }.
308
     * No attribution or other information will be added (or removed) to (or from) the tree.
309
     *
310
     * @param in the tree to inspect
311
     * @return tree into which the given tree was rewritten using the
312
     * {@link #rewrite(com.sun.source.tree.Tree, com.sun.source.tree.Tree) } method,
313
     * transitively
314
     * @since 0.101
315
     */
316
    public synchronized @NonNull Tree resolveRewriteTarget(@NonNull Tree in) {
317
        Map<Tree, Tree> localChanges = new IdentityHashMap<Tree, Tree>(changes);
318
319
        while (localChanges.containsKey(in)) {
320
            in = localChanges.remove(in);
321
        }
322
323
        return in;
324
    }
298
    
325
    
299
    // Package private methods -------------------------------------------------        
326
    // Package private methods -------------------------------------------------        
300
    
327
    
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/WorkingCopyTest.java (+40 lines)
Lines 116-119 Link Here
116
            }
116
            }
117
        }, true);
117
        }, true);
118
    }
118
    }
119
120
    public void testResolveRewriteTarget() throws Exception {
121
        File f = new File(getWorkDir(), "TestClass.java");
122
        String code = "package foo;" +
123
                      "public class TestClass{" +
124
                      "   public void foo() {" +
125
                      "   }" +
126
                      "}";
127
128
        TestUtilities.copyStringToFile(f, code);
129
        FileObject fo = FileUtil.toFileObject(f);
130
        JavaSource javaSource = JavaSource.forFileObject(fo);
131
        javaSource.runModificationTask(new Task<WorkingCopy>() {
132
133
            public void run(WorkingCopy copy) throws Exception {
134
                copy.toPhase(Phase.RESOLVED);
135
136
                TreeMaker maker = copy.getTreeMaker();
137
                ClassTree classTree = (ClassTree)copy.getCompilationUnit().getTypeDecls().get(0);
138
                TypeElement serializableElement = copy.getElements().getTypeElement("java.io.Serializable");
139
                ExpressionTree serializableTree = maker.QualIdent(serializableElement);
140
                ClassTree newClassTree = maker.addClassImplementsClause(classTree, serializableTree);
141
142
                copy.rewrite(classTree, newClassTree);
143
144
                assertSame(newClassTree, copy.resolveRewriteTarget(classTree));
145
146
                ClassTree finalClassTree = maker.removeClassImplementsClause(newClassTree, 0);
147
148
                copy.rewrite(newClassTree, finalClassTree);
149
150
                assertSame(finalClassTree, copy.resolveRewriteTarget(classTree));
151
152
                // remove the following to make the test pass
153
                copy.toPhase(Phase.RESOLVED);
154
            }
155
        }).commit();
156
157
        assertEquals(code, fo.asText());
158
    }
119
}
159
}

Return to bug 209375