< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeCopier.java

Print this page




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.tree;
  27 
  28 import com.sun.source.tree.*;
  29 import com.sun.source.tree.Tree.Kind;
  30 import com.sun.tools.javac.tree.JCTree.*;
  31 import com.sun.tools.javac.util.DefinedBy;
  32 import com.sun.tools.javac.util.DefinedBy.Api;
  33 import com.sun.tools.javac.util.List;
  34 import com.sun.tools.javac.util.ListBuffer;
  35 
  36 /**
  37  * Creates a copy of a tree, using a given TreeMaker.
  38  * Names, literal values, etc are shared with the original.
  39  *
  40  *  <p><b>This is NOT part of any supported API.
  41  *  If you write code that depends on this, you do so at your own risk.
  42  *  This code and its internal interfaces are subject to change or
  43  *  deletion without notice.</b>
  44  */
  45 public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
  46     private TreeMaker M;
  47 
  48     /** Creates a new instance of TreeCopier */
  49     public TreeCopier(TreeMaker M) {


 466     }
 467 
 468     @DefinedBy(Api.COMPILER_TREE)
 469     public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
 470         JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
 471         return M.at(t.pos).TypeIdent(t.typetag);
 472     }
 473 
 474     @DefinedBy(Api.COMPILER_TREE)
 475     public JCTree visitTypeParameter(TypeParameterTree node, P p) {
 476         JCTypeParameter t = (JCTypeParameter) node;
 477         List<JCAnnotation> annos = copy(t.annotations, p);
 478         List<JCExpression> bounds = copy(t.bounds, p);
 479         return M.at(t.pos).TypeParameter(t.name, bounds, annos);
 480     }
 481 
 482     @DefinedBy(Api.COMPILER_TREE)
 483     public JCTree visitInstanceOf(InstanceOfTree node, P p) {
 484         JCInstanceOf t = (JCInstanceOf) node;
 485         JCExpression expr = copy(t.expr, p);
 486         JCTree clazz = copy(t.clazz, p);
 487         return M.at(t.pos).TypeTest(expr, clazz);







 488     }
 489 
 490     @DefinedBy(Api.COMPILER_TREE)
 491     public JCTree visitUnary(UnaryTree node, P p) {
 492         JCUnary t = (JCUnary) node;
 493         JCExpression arg = copy(t.arg, p);
 494         return M.at(t.pos).Unary(t.getTag(), arg);
 495     }
 496 
 497     @DefinedBy(Api.COMPILER_TREE)
 498     public JCTree visitVariable(VariableTree node, P p) {
 499         JCVariableDecl t = (JCVariableDecl) node;
 500         JCModifiers mods = copy(t.mods, p);
 501         JCExpression vartype = copy(t.vartype, p);
 502         if (t.nameexpr == null) {
 503             JCExpression init = copy(t.init, p);
 504             return M.at(t.pos).VarDef(mods, t.name, vartype, init);
 505         } else {
 506             JCExpression nameexpr = copy(t.nameexpr, p);
 507             return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);




   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.javac.tree;
  27 
  28 import com.sun.source.tree.*;

  29 import com.sun.tools.javac.tree.JCTree.*;
  30 import com.sun.tools.javac.util.DefinedBy;
  31 import com.sun.tools.javac.util.DefinedBy.Api;
  32 import com.sun.tools.javac.util.List;
  33 import com.sun.tools.javac.util.ListBuffer;
  34 
  35 /**
  36  * Creates a copy of a tree, using a given TreeMaker.
  37  * Names, literal values, etc are shared with the original.
  38  *
  39  *  <p><b>This is NOT part of any supported API.
  40  *  If you write code that depends on this, you do so at your own risk.
  41  *  This code and its internal interfaces are subject to change or
  42  *  deletion without notice.</b>
  43  */
  44 public class TreeCopier<P> implements TreeVisitor<JCTree,P> {
  45     private TreeMaker M;
  46 
  47     /** Creates a new instance of TreeCopier */
  48     public TreeCopier(TreeMaker M) {


 465     }
 466 
 467     @DefinedBy(Api.COMPILER_TREE)
 468     public JCTree visitPrimitiveType(PrimitiveTypeTree node, P p) {
 469         JCPrimitiveTypeTree t = (JCPrimitiveTypeTree) node;
 470         return M.at(t.pos).TypeIdent(t.typetag);
 471     }
 472 
 473     @DefinedBy(Api.COMPILER_TREE)
 474     public JCTree visitTypeParameter(TypeParameterTree node, P p) {
 475         JCTypeParameter t = (JCTypeParameter) node;
 476         List<JCAnnotation> annos = copy(t.annotations, p);
 477         List<JCExpression> bounds = copy(t.bounds, p);
 478         return M.at(t.pos).TypeParameter(t.name, bounds, annos);
 479     }
 480 
 481     @DefinedBy(Api.COMPILER_TREE)
 482     public JCTree visitInstanceOf(InstanceOfTree node, P p) {
 483         JCInstanceOf t = (JCInstanceOf) node;
 484         JCExpression expr = copy(t.expr, p);
 485         JCTree pattern = copy(t.pattern, p);
 486         return M.at(t.pos).TypeTest(expr, pattern);
 487     }
 488 
 489     @DefinedBy(Api.COMPILER_TREE)
 490     public JCTree visitBindingPattern(BindingPatternTree node, P p) {
 491         JCBindingPattern t = (JCBindingPattern) node;
 492         JCTree vartype = copy(t.vartype, p);
 493         return M.at(t.pos).BindingPattern(t.name, vartype);
 494     }
 495 
 496     @DefinedBy(Api.COMPILER_TREE)
 497     public JCTree visitUnary(UnaryTree node, P p) {
 498         JCUnary t = (JCUnary) node;
 499         JCExpression arg = copy(t.arg, p);
 500         return M.at(t.pos).Unary(t.getTag(), arg);
 501     }
 502 
 503     @DefinedBy(Api.COMPILER_TREE)
 504     public JCTree visitVariable(VariableTree node, P p) {
 505         JCVariableDecl t = (JCVariableDecl) node;
 506         JCModifiers mods = copy(t.mods, p);
 507         JCExpression vartype = copy(t.vartype, p);
 508         if (t.nameexpr == null) {
 509             JCExpression init = copy(t.init, p);
 510             return M.at(t.pos).VarDef(mods, t.name, vartype, init);
 511         } else {
 512             JCExpression nameexpr = copy(t.nameexpr, p);
 513             return M.at(t.pos).ReceiverVarDef(mods, nameexpr, vartype);


< prev index next >