< prev index next >

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

Print this page




  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 java.util.Iterator;
  29 
  30 import com.sun.source.tree.CaseTree.CaseKind;
  31 import com.sun.source.tree.ModuleTree.ModuleKind;
  32 import com.sun.source.tree.Tree.Kind;
  33 import com.sun.tools.javac.code.*;
  34 import com.sun.tools.javac.code.Attribute.UnresolvedClass;
  35 import com.sun.tools.javac.code.Symbol.*;
  36 import com.sun.tools.javac.code.Type.*;
  37 import com.sun.tools.javac.util.*;
  38 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  39 
  40 import com.sun.tools.javac.tree.JCTree.*;
  41 
  42 import static com.sun.tools.javac.code.Flags.*;
  43 import static com.sun.tools.javac.code.Kinds.Kind.*;
  44 import static com.sun.tools.javac.code.TypeTag.*;
  45 
  46 /** Factory class for trees.
  47  *
  48  *  <p><b>This is NOT part of any supported API.
  49  *  If you write code that depends on this, you do so at your own risk.
  50  *  This code and its internal interfaces are subject to change or
  51  *  deletion without notice.</b>
  52  */


 145         Assert.checkNonNull(annotations);
 146         Assert.checkNonNull(pid);
 147         JCPackageDecl tree = new JCPackageDecl(annotations, pid);
 148         tree.pos = pos;
 149         return tree;
 150     }
 151 
 152     public JCImport Import(JCTree qualid, boolean importStatic) {
 153         JCImport tree = new JCImport(qualid, importStatic);
 154         tree.pos = pos;
 155         return tree;
 156     }
 157 
 158     public JCClassDecl ClassDef(JCModifiers mods,
 159                                 Name name,
 160                                 List<JCTypeParameter> typarams,
 161                                 JCExpression extending,
 162                                 List<JCExpression> implementing,
 163                                 List<JCTree> defs)
 164     {











 165         JCClassDecl tree = new JCClassDecl(mods,
 166                                      name,
 167                                      typarams,
 168                                      extending,
 169                                      implementing,

 170                                      defs,
 171                                      null);
 172         tree.pos = pos;
 173         return tree;
 174     }
 175 
 176     public JCMethodDecl MethodDef(JCModifiers mods,
 177                                Name name,
 178                                JCExpression restype,
 179                                List<JCTypeParameter> typarams,
 180                                List<JCVariableDecl> params,
 181                                List<JCExpression> thrown,
 182                                JCBlock body,
 183                                JCExpression defaultValue) {
 184         return MethodDef(
 185                 mods, name, restype, typarams, null, params,
 186                 thrown, body, defaultValue);
 187     }
 188 
 189     public JCMethodDecl MethodDef(JCModifiers mods,


 194                                List<JCVariableDecl> params,
 195                                List<JCExpression> thrown,
 196                                JCBlock body,
 197                                JCExpression defaultValue)
 198     {
 199         JCMethodDecl tree = new JCMethodDecl(mods,
 200                                        name,
 201                                        restype,
 202                                        typarams,
 203                                        recvparam,
 204                                        params,
 205                                        thrown,
 206                                        body,
 207                                        defaultValue,
 208                                        null);
 209         tree.pos = pos;
 210         return tree;
 211     }
 212 
 213     public JCVariableDecl VarDef(JCModifiers mods, Name name, JCExpression vartype, JCExpression init) {
 214         JCVariableDecl tree = new JCVariableDecl(mods, name, vartype, init, null);




 215         tree.pos = pos;
 216         return tree;
 217     }
 218 
 219     public JCVariableDecl ReceiverVarDef(JCModifiers mods, JCExpression name, JCExpression vartype) {
 220         JCVariableDecl tree = new JCVariableDecl(mods, name, vartype);
 221         tree.pos = pos;
 222         return tree;
 223     }
 224 
 225     public JCSkip Skip() {
 226         JCSkip tree = new JCSkip();
 227         tree.pos = pos;
 228         return tree;
 229     }
 230 
 231     public JCBlock Block(long flags, List<JCStatement> stats) {
 232         JCBlock tree = new JCBlock(flags, stats);
 233         tree.pos = pos;
 234         return tree;


 448     }
 449 
 450     public JCBinary Binary(JCTree.Tag opcode, JCExpression lhs, JCExpression rhs) {
 451         JCBinary tree = new JCBinary(opcode, lhs, rhs, null);
 452         tree.pos = pos;
 453         return tree;
 454     }
 455 
 456     public JCTypeCast TypeCast(JCTree clazz, JCExpression expr) {
 457         JCTypeCast tree = new JCTypeCast(clazz, expr);
 458         tree.pos = pos;
 459         return tree;
 460     }
 461 
 462     public JCInstanceOf TypeTest(JCExpression expr, JCTree clazz) {
 463         JCInstanceOf tree = new JCInstanceOf(expr, clazz);
 464         tree.pos = pos;
 465         return tree;
 466     }
 467 






 468     public JCArrayAccess Indexed(JCExpression indexed, JCExpression index) {
 469         JCArrayAccess tree = new JCArrayAccess(indexed, index);
 470         tree.pos = pos;
 471         return tree;
 472     }
 473 
 474     public JCFieldAccess Select(JCExpression selected, Name selector) {
 475         JCFieldAccess tree = new JCFieldAccess(selected, selector, null);
 476         tree.pos = pos;
 477         return tree;
 478     }
 479 
 480     public JCMemberReference Reference(JCMemberReference.ReferenceMode mode, Name name,
 481             JCExpression expr, List<JCExpression> typeargs) {
 482         JCMemberReference tree = new JCMemberReference(mode, name, expr, typeargs);
 483         tree.pos = pos;
 484         return tree;
 485     }
 486 
 487     public JCIdent Ident(Name name) {


 823 
 824     /** Create a list of trees representing given list of types.
 825      */
 826     public List<JCExpression> Types(List<Type> ts) {
 827         ListBuffer<JCExpression> lb = new ListBuffer<>();
 828         for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
 829             lb.append(Type(l.head));
 830         return lb.toList();
 831     }
 832 
 833     /** Create a variable definition from a variable symbol and an initializer
 834      *  expression.
 835      */
 836     public JCVariableDecl VarDef(VarSymbol v, JCExpression init) {
 837         return (JCVariableDecl)
 838             new JCVariableDecl(
 839                 Modifiers(v.flags(), Annotations(v.getRawAttributes())),
 840                 v.name,
 841                 Type(v.type),
 842                 init,
 843                 v).setPos(pos).setType(v.type);
 844     }
 845 
 846     /** Create annotation trees from annotations.
 847      */
 848     public List<JCAnnotation> Annotations(List<Attribute.Compound> attributes) {
 849         if (attributes == null) return List.nil();
 850         ListBuffer<JCAnnotation> result = new ListBuffer<>();
 851         for (List<Attribute.Compound> i = attributes; i.nonEmpty(); i=i.tail) {
 852             Attribute a = i.head;
 853             result.append(Annotation(a));
 854         }
 855         return result.toList();
 856     }
 857 
 858     public JCLiteral Literal(Object value) {
 859         JCLiteral result = null;
 860         if (value instanceof String) {
 861             result = Literal(CLASS, value).
 862                 setType(syms.stringType.constType(value));
 863         } else if (value instanceof Integer) {




  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 java.util.Iterator;
  29 
  30 import com.sun.source.tree.CaseTree.CaseKind;
  31 import com.sun.source.tree.ModuleTree.ModuleKind;

  32 import com.sun.tools.javac.code.*;
  33 import com.sun.tools.javac.code.Attribute.UnresolvedClass;
  34 import com.sun.tools.javac.code.Symbol.*;
  35 import com.sun.tools.javac.code.Type.*;
  36 import com.sun.tools.javac.util.*;
  37 import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
  38 
  39 import com.sun.tools.javac.tree.JCTree.*;
  40 
  41 import static com.sun.tools.javac.code.Flags.*;
  42 import static com.sun.tools.javac.code.Kinds.Kind.*;
  43 import static com.sun.tools.javac.code.TypeTag.*;
  44 
  45 /** Factory class for trees.
  46  *
  47  *  <p><b>This is NOT part of any supported API.
  48  *  If you write code that depends on this, you do so at your own risk.
  49  *  This code and its internal interfaces are subject to change or
  50  *  deletion without notice.</b>
  51  */


 144         Assert.checkNonNull(annotations);
 145         Assert.checkNonNull(pid);
 146         JCPackageDecl tree = new JCPackageDecl(annotations, pid);
 147         tree.pos = pos;
 148         return tree;
 149     }
 150 
 151     public JCImport Import(JCTree qualid, boolean importStatic) {
 152         JCImport tree = new JCImport(qualid, importStatic);
 153         tree.pos = pos;
 154         return tree;
 155     }
 156 
 157     public JCClassDecl ClassDef(JCModifiers mods,
 158                                 Name name,
 159                                 List<JCTypeParameter> typarams,
 160                                 JCExpression extending,
 161                                 List<JCExpression> implementing,
 162                                 List<JCTree> defs)
 163     {
 164         return ClassDef(mods, name, typarams, extending, implementing, List.nil(), defs);
 165     }
 166 
 167     public JCClassDecl ClassDef(JCModifiers mods,
 168                                 Name name,
 169                                 List<JCTypeParameter> typarams,
 170                                 JCExpression extending,
 171                                 List<JCExpression> implementing,
 172                                 List<JCExpression> permitting,
 173                                 List<JCTree> defs)
 174     {
 175         JCClassDecl tree = new JCClassDecl(mods,
 176                                      name,
 177                                      typarams,
 178                                      extending,
 179                                      implementing,
 180                                      permitting,
 181                                      defs,
 182                                      null);
 183         tree.pos = pos;
 184         return tree;
 185     }
 186 
 187     public JCMethodDecl MethodDef(JCModifiers mods,
 188                                Name name,
 189                                JCExpression restype,
 190                                List<JCTypeParameter> typarams,
 191                                List<JCVariableDecl> params,
 192                                List<JCExpression> thrown,
 193                                JCBlock body,
 194                                JCExpression defaultValue) {
 195         return MethodDef(
 196                 mods, name, restype, typarams, null, params,
 197                 thrown, body, defaultValue);
 198     }
 199 
 200     public JCMethodDecl MethodDef(JCModifiers mods,


 205                                List<JCVariableDecl> params,
 206                                List<JCExpression> thrown,
 207                                JCBlock body,
 208                                JCExpression defaultValue)
 209     {
 210         JCMethodDecl tree = new JCMethodDecl(mods,
 211                                        name,
 212                                        restype,
 213                                        typarams,
 214                                        recvparam,
 215                                        params,
 216                                        thrown,
 217                                        body,
 218                                        defaultValue,
 219                                        null);
 220         tree.pos = pos;
 221         return tree;
 222     }
 223 
 224     public JCVariableDecl VarDef(JCModifiers mods, Name name, JCExpression vartype, JCExpression init) {
 225         return VarDef(mods, name, vartype, init, null);
 226     }
 227 
 228     public JCVariableDecl VarDef(JCModifiers mods, Name name, JCExpression vartype, JCExpression init, List<Pair<Accessors.Kind, Name>> accessors) {
 229         JCVariableDecl tree = new JCVariableDecl(mods, name, vartype, init, null, accessors);
 230         tree.pos = pos;
 231         return tree;
 232     }
 233 
 234     public JCVariableDecl ReceiverVarDef(JCModifiers mods, JCExpression name, JCExpression vartype) {
 235         JCVariableDecl tree = new JCVariableDecl(mods, name, vartype);
 236         tree.pos = pos;
 237         return tree;
 238     }
 239 
 240     public JCSkip Skip() {
 241         JCSkip tree = new JCSkip();
 242         tree.pos = pos;
 243         return tree;
 244     }
 245 
 246     public JCBlock Block(long flags, List<JCStatement> stats) {
 247         JCBlock tree = new JCBlock(flags, stats);
 248         tree.pos = pos;
 249         return tree;


 463     }
 464 
 465     public JCBinary Binary(JCTree.Tag opcode, JCExpression lhs, JCExpression rhs) {
 466         JCBinary tree = new JCBinary(opcode, lhs, rhs, null);
 467         tree.pos = pos;
 468         return tree;
 469     }
 470 
 471     public JCTypeCast TypeCast(JCTree clazz, JCExpression expr) {
 472         JCTypeCast tree = new JCTypeCast(clazz, expr);
 473         tree.pos = pos;
 474         return tree;
 475     }
 476 
 477     public JCInstanceOf TypeTest(JCExpression expr, JCTree clazz) {
 478         JCInstanceOf tree = new JCInstanceOf(expr, clazz);
 479         tree.pos = pos;
 480         return tree;
 481     }
 482 
 483     public JCBindingPattern BindingPattern(Name name, JCTree vartype) {
 484         JCBindingPattern tree = new JCBindingPattern(name, null, vartype);
 485         tree.pos = pos;
 486         return tree;
 487     }
 488 
 489     public JCArrayAccess Indexed(JCExpression indexed, JCExpression index) {
 490         JCArrayAccess tree = new JCArrayAccess(indexed, index);
 491         tree.pos = pos;
 492         return tree;
 493     }
 494 
 495     public JCFieldAccess Select(JCExpression selected, Name selector) {
 496         JCFieldAccess tree = new JCFieldAccess(selected, selector, null);
 497         tree.pos = pos;
 498         return tree;
 499     }
 500 
 501     public JCMemberReference Reference(JCMemberReference.ReferenceMode mode, Name name,
 502             JCExpression expr, List<JCExpression> typeargs) {
 503         JCMemberReference tree = new JCMemberReference(mode, name, expr, typeargs);
 504         tree.pos = pos;
 505         return tree;
 506     }
 507 
 508     public JCIdent Ident(Name name) {


 844 
 845     /** Create a list of trees representing given list of types.
 846      */
 847     public List<JCExpression> Types(List<Type> ts) {
 848         ListBuffer<JCExpression> lb = new ListBuffer<>();
 849         for (List<Type> l = ts; l.nonEmpty(); l = l.tail)
 850             lb.append(Type(l.head));
 851         return lb.toList();
 852     }
 853 
 854     /** Create a variable definition from a variable symbol and an initializer
 855      *  expression.
 856      */
 857     public JCVariableDecl VarDef(VarSymbol v, JCExpression init) {
 858         return (JCVariableDecl)
 859             new JCVariableDecl(
 860                 Modifiers(v.flags(), Annotations(v.getRawAttributes())),
 861                 v.name,
 862                 Type(v.type),
 863                 init,
 864                 v, null).setPos(pos).setType(v.type);
 865     }
 866 
 867     /** Create annotation trees from annotations.
 868      */
 869     public List<JCAnnotation> Annotations(List<Attribute.Compound> attributes) {
 870         if (attributes == null) return List.nil();
 871         ListBuffer<JCAnnotation> result = new ListBuffer<>();
 872         for (List<Attribute.Compound> i = attributes; i.nonEmpty(); i=i.tail) {
 873             Attribute a = i.head;
 874             result.append(Annotation(a));
 875         }
 876         return result.toList();
 877     }
 878 
 879     public JCLiteral Literal(Object value) {
 880         JCLiteral result = null;
 881         if (value instanceof String) {
 882             result = Literal(CLASS, value).
 883                 setType(syms.stringType.constType(value));
 884         } else if (value instanceof Integer) {


< prev index next >