--- a/java.source/apichanges.xml +++ b/java.source/apichanges.xml @@ -108,6 +108,20 @@ + + + Added TreeMaker.QualIdent(String) and TreeMaker.Type(String) method. + + + + + + Added TreeMaker.QualIdent(String) and TreeMaker.Type(String) method, which allow + to construct QualIdents and Types from String specification. + + + + Added TreeUtilities.translate method. --- a/java.source/nbproject/project.properties +++ b/java.source/nbproject/project.properties @@ -46,7 +46,7 @@ javadoc.title=Java Source javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml -spec.version.base=0.63.0 +spec.version.base=0.64.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:\ @@ -128,7 +128,9 @@ org/netbeans/api/java/source/CommentCollectorTest.class,\ org/netbeans/api/java/source/gen/RewriteInCommentTest.class,\ org/netbeans/api/java/source/gen/MoveTreeTest.class,\ - org/netbeans/api/java/source/gen/BlockTest.class + org/netbeans/api/java/source/gen/BlockTest.class,\ + org/netbeans/api/java/source/gen/ImportAnalysisTest.class,\ + org/netbeans/api/java/source/gen/ImportAnalysis2Test.class test.config.jet-main.includes=${test.config.generator.includes},\ org/netbeans/api/java/source/TypeUtilitiesTest.class --- a/java.source/src/org/netbeans/api/java/source/TreeMaker.java +++ b/java.source/src/org/netbeans/api/java/source/TreeMaker.java @@ -43,6 +43,7 @@ */ package org.netbeans.api.java.source; +import java.util.Map; import com.sun.source.tree.*; import org.netbeans.modules.java.source.parsing.FileObjects; import org.openide.filesystems.FileObject; @@ -56,6 +57,7 @@ import com.sun.tools.javac.code.Flags; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.JCModifiers; +import java.util.HashMap; import javax.lang.model.element.*; import javax.lang.model.type.*; import javax.tools.JavaFileObject; @@ -806,6 +808,17 @@ Parameters.notNull("element", element); return delegate.QualIdent(element); } + + /** + * Creates a qualified identifier for a given String. + * + * @param name FQN for which to create the QualIdent + * @since 0.64 + */ + public @NonNull ExpressionTree QualIdent(@NonNull String name) { + Parameters.notNull("name", name); + return delegate.QualIdent(name); + } /** * Creates a new ReturnTree. @@ -875,6 +888,35 @@ } /** + * Creates a new Tree for a given String type specification. + * + * @param type String type specification + * @see com.sun.source.tree.ExpressionTree + * @since 0.64 + */ + public @NonNull Tree Type(@NonNull String type) { + Parameters.notNull("type", type); + + Tree typeTree = copy.getTreeUtilities().parseType(type); + final Map translate = new HashMap(); + + new TreeScanner() { + @Override + public Void visitMemberSelect(MemberSelectTree node, Void p) { + translate.put(node, QualIdent(node.toString())); + return null; + } + @Override + public Void visitIdentifier(IdentifierTree node, Void p) { + translate.put(node, QualIdent(node.toString())); + return null; + } + }.scan(typeTree, null); + + return copy.getTreeUtilities().translate(typeTree, translate); + } + + /** * Creates a new TypeCastTree. * * @param type the class or interface to cast.