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 197848
Collapse All | Expand All

(-)a/java.source/apichanges.xml (+13 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="TreePathHandle-from-ElementHandle">
112
             <api name="general"/>
113
             <summary>TreePathHandle can be created from ElementHandle</summary>
114
             <version major="0" minor="78"/>
115
             <date day="26" month="4" year="2011"/>
116
             <author login="jlahoda"/>
117
             <compatibility addition="yes" binary="compatible" deletion="no" deprecation="no" modification="no" semantic="compatible" source="compatible"/>
118
             <description>
119
                 <code>TreePathHandle</code> has a new <code>from(ElementHandle)</code> method.
120
             </description>
121
             <class package="org.netbeans.api.java.source" name="TreePathHandle"/>
122
             <issue number="999999"/>
123
        </change>
111
        <change id="run-modification-task-sourceless">
124
        <change id="run-modification-task-sourceless">
112
             <api name="general"/>
125
             <api name="general"/>
113
             <summary>JavaSource.runModificationTask can run on source-less JavaSources</summary>
126
             <summary>JavaSource.runModificationTask can run on source-less JavaSources</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.77.0
49
spec.version.base=0.78.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/TreePathHandle.java (+14 lines)
Lines 324-329 Link Here
324
        }
324
        }
325
        throw new IllegalStateException("Cannot create PositionRef for file " + file.getPath() + ". CloneableEditorSupport not found");
325
        throw new IllegalStateException("Cannot create PositionRef for file " + file.getPath() + ". CloneableEditorSupport not found");
326
    }
326
    }
327
328
    /**Constructs a <code>TreePathHandle</code> that corresponds to the given <code>ElementHandle</code>.
329
     *
330
     * @param handle an <code>ElementHandle</code> for which the <code>TreePathHandle</code> should be constructed
331
     * @param cpInfo a classpath which is supposed to contain the element described by given the <code>ElementHandle</code>
332
     * @return a newly constructed <code>TreePathHandle</code>
333
     * @since 0.78
334
     */
335
    public static @NonNull TreePathHandle from(@NonNull ElementHandle<?> handle, @NonNull ClasspathInfo cpInfo) {
336
        Parameters.notNull("handle", handle);
337
        Parameters.notNull("cpInfo", cpInfo);
338
339
        return new TreePathHandle(new ElementDelegate(handle, null, null, cpInfo));
340
    }
327
    
341
    
328
    @Override
342
    @Override
329
    public String toString() {
343
    public String toString() {
(-)a/java.source/test/unit/src/org/netbeans/api/java/source/TreePathHandleTest.java (+28 lines)
Lines 45-56 Link Here
45
package org.netbeans.api.java.source;
45
package org.netbeans.api.java.source;
46
46
47
import com.sun.source.tree.ClassTree;
47
import com.sun.source.tree.ClassTree;
48
import com.sun.source.tree.MethodTree;
48
import com.sun.source.tree.Tree.Kind;
49
import com.sun.source.tree.Tree.Kind;
49
import com.sun.source.tree.VariableTree;
50
import com.sun.source.tree.VariableTree;
50
import com.sun.source.util.TreePath;
51
import com.sun.source.util.TreePath;
51
import java.io.File;
52
import java.io.File;
52
import java.io.OutputStream;
53
import java.io.OutputStream;
53
import java.security.Permission;
54
import java.security.Permission;
55
import javax.lang.model.element.Element;
54
import javax.lang.model.element.TypeElement;
56
import javax.lang.model.element.TypeElement;
55
import org.netbeans.api.java.source.JavaSource.Phase;
57
import org.netbeans.api.java.source.JavaSource.Phase;
56
import org.netbeans.junit.NbTestCase;
58
import org.netbeans.junit.NbTestCase;
Lines 336-341 Link Here
336
        assertTrue(tp.getLeaf() == resolved.getLeaf());
338
        assertTrue(tp.getLeaf() == resolved.getLeaf());
337
    }
339
    }
338
340
341
    public void testFromElementHandle() throws Exception {
342
        FileObject file = FileUtil.createData(sourceRoot, "test/test.java");
343
        String code = "package test;\n" +
344
                      "public class Test {\n" +
345
                      "    public static void test() {\n" +
346
                      "    }\n" +
347
                      "}";
348
349
        writeIntoFile(file,code);
350
351
        JavaSource js = JavaSource.forFileObject(file);
352
        CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED);
353
354
        ClassTree clazz = (ClassTree) info.getCompilationUnit().getTypeDecls().get(0);
355
        MethodTree method = (MethodTree) clazz.getMembers().get(1);
356
        TreePath tp = TreePath.getPath(info.getCompilationUnit(), method);
357
        Element el = info.getTrees().getElement(tp);
358
        ElementHandle<?> elHandle = ElementHandle.create(el);
359
        TreePathHandle handle   = TreePathHandle.from(elHandle, info.getClasspathInfo());
360
        TreePath       resolved = handle.resolve(info);
361
362
        assertNotNull(resolved);
363
364
        assertTrue(tp.getLeaf() == resolved.getLeaf());
365
    }
366
339
    private static final class SecMan extends SecurityManager {
367
    private static final class SecMan extends SecurityManager {
340
368
341
        @Override
369
        @Override

Return to bug 197848