diff -r cce2ec18522f java.source/apichanges.xml --- a/java.source/apichanges.xml Mon Apr 18 17:38:20 2011 +0200 +++ b/java.source/apichanges.xml Mon Apr 18 21:10:45 2011 +0200 @@ -108,6 +108,19 @@ + + + TreePathHandle can be created from ElementHandle + + + + + + TreePathHandle has a new from(ElementHandle) method. + + + + JavaSource.runModificationTask can run on source-less JavaSources diff -r cce2ec18522f java.source/nbproject/project.properties --- a/java.source/nbproject/project.properties Mon Apr 18 17:38:20 2011 +0200 +++ b/java.source/nbproject/project.properties Mon Apr 18 21:10:45 2011 +0200 @@ -46,7 +46,7 @@ javadoc.title=Java Source javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=0.77.0 +spec.version.base=0.78.0 test.qa-functional.cp.extra=${refactoring.java.dir}/modules/ext/javac-api-nb-7.0-b07.jar test.unit.run.cp.extra=${o.n.core.dir}/core/core.jar:\ ${o.n.core.dir}/lib/boot.jar:\ diff -r cce2ec18522f java.source/src/org/netbeans/api/java/source/TreePathHandle.java --- a/java.source/src/org/netbeans/api/java/source/TreePathHandle.java Mon Apr 18 17:38:20 2011 +0200 +++ b/java.source/src/org/netbeans/api/java/source/TreePathHandle.java Mon Apr 18 21:10:45 2011 +0200 @@ -324,6 +324,20 @@ } throw new IllegalStateException("Cannot create PositionRef for file " + file.getPath() + ". CloneableEditorSupport not found"); } + + /**Constructs a TreePathHandle that corresponds to the given ElementHandle. + * + * @param handle an ElementHandle for which the TreePathHandle should be constructed + * @param cpInfo a classpath which is supposed to contain the element described by given the ElementHandle + * @return a newly constructed TreePathHandle + * @since 0.78 + */ + public static @NonNull TreePathHandle from(@NonNull ElementHandle handle, @NonNull ClasspathInfo cpInfo) { + Parameters.notNull("handle", handle); + Parameters.notNull("cpInfo", cpInfo); + + return new TreePathHandle(new ElementDelegate(handle, null, null, cpInfo)); + } @Override public String toString() { diff -r cce2ec18522f java.source/test/unit/src/org/netbeans/api/java/source/TreePathHandleTest.java --- a/java.source/test/unit/src/org/netbeans/api/java/source/TreePathHandleTest.java Mon Apr 18 17:38:20 2011 +0200 +++ b/java.source/test/unit/src/org/netbeans/api/java/source/TreePathHandleTest.java Mon Apr 18 21:10:45 2011 +0200 @@ -45,12 +45,14 @@ package org.netbeans.api.java.source; import com.sun.source.tree.ClassTree; +import com.sun.source.tree.MethodTree; import com.sun.source.tree.Tree.Kind; import com.sun.source.tree.VariableTree; import com.sun.source.util.TreePath; import java.io.File; import java.io.OutputStream; import java.security.Permission; +import javax.lang.model.element.Element; import javax.lang.model.element.TypeElement; import org.netbeans.api.java.source.JavaSource.Phase; import org.netbeans.junit.NbTestCase; @@ -336,6 +338,32 @@ assertTrue(tp.getLeaf() == resolved.getLeaf()); } + public void testFromElementHandle() throws Exception { + FileObject file = FileUtil.createData(sourceRoot, "test/test.java"); + String code = "package test;\n" + + "public class Test {\n" + + " public static void test() {\n" + + " }\n" + + "}"; + + writeIntoFile(file,code); + + JavaSource js = JavaSource.forFileObject(file); + CompilationInfo info = SourceUtilsTestUtil.getCompilationInfo(js, Phase.RESOLVED); + + ClassTree clazz = (ClassTree) info.getCompilationUnit().getTypeDecls().get(0); + MethodTree method = (MethodTree) clazz.getMembers().get(1); + TreePath tp = TreePath.getPath(info.getCompilationUnit(), method); + Element el = info.getTrees().getElement(tp); + ElementHandle elHandle = ElementHandle.create(el); + TreePathHandle handle = TreePathHandle.from(elHandle, info.getClasspathInfo()); + TreePath resolved = handle.resolve(info); + + assertNotNull(resolved); + + assertTrue(tp.getLeaf() == resolved.getLeaf()); + } + private static final class SecMan extends SecurityManager { @Override