< prev index next >

src/jdk.xml.bind/share/classes/com/sun/codemodel/internal/JCodeModel.java

Print this page




  42 
  43 /**
  44  * Root of the code DOM.
  45  *
  46  * <p>
  47  * Here's your typical CodeModel application.
  48  *
  49  * <pre>
  50  * JCodeModel cm = new JCodeModel();
  51  *
  52  * // generate source code by populating the 'cm' tree.
  53  * cm._class(...);
  54  * ...
  55  *
  56  * // write them out
  57  * cm.build(new File("."));
  58  * </pre>
  59  *
  60  * <p>
  61  * Every CodeModel node is always owned by one {@link JCodeModel} object
  62  * at any given time (which can be often accesesd by the <tt>owner()</tt> method.)
  63  *
  64  * As such, when you generate Java code, most of the operation works
  65  * in a top-down fashion. For example, you create a class from {@link JCodeModel},
  66  * which gives you a {@link JDefinedClass}. Then you invoke a method on it
  67  * to generate a new method, which gives you {@link JMethod}, and so on.
  68  *
  69  * There are a few exceptions to this, most notably building {@link JExpression}s,
  70  * but generally you work with CodeModel in a top-down fashion.
  71  *
  72  * Because of this design, most of the CodeModel classes aren't directly instanciable.
  73  *
  74  *
  75  * <h2>Where to go from here?</h2>
  76  * <p>
  77  * Most of the time you'd want to populate new type definitions in a {@link JCodeModel}.
  78  * See {@link #_class(String, ClassType)}.
  79  */
  80 public final class JCodeModel {
  81 
  82     /** The packages that this JCodeWriter contains. */


 618         public boolean isArray() {
 619             return false;
 620         }
 621 
 622         public void declare(JFormatter f) {
 623         }
 624 
 625         public JTypeVar[] typeParams() {
 626             // TODO: does JDK 1.5 reflection provides these information?
 627             return super.typeParams();
 628         }
 629 
 630         protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) {
 631             // TODO: does JDK 1.5 reflection provides these information?
 632             return this;
 633         }
 634     }
 635 
 636     /**
 637      * Conversion from primitive type {@link Class} (such as {@link Integer#TYPE}
 638      * to its boxed type (such as <tt>Integer.class</tt>)
 639      */
 640     public static final Map<Class<?>,Class<?>> primitiveToBox;
 641     /**
 642      * The reverse look up for {@link #primitiveToBox}
 643      */
 644     public static final Map<Class<?>,Class<?>> boxToPrimitive;
 645 
 646     static {
 647         Map<Class<?>,Class<?>> m1 = new HashMap<Class<?>,Class<?>>();
 648         Map<Class<?>,Class<?>> m2 = new HashMap<Class<?>,Class<?>>();
 649 
 650         m1.put(Boolean.class,Boolean.TYPE);
 651         m1.put(Byte.class,Byte.TYPE);
 652         m1.put(Character.class,Character.TYPE);
 653         m1.put(Double.class,Double.TYPE);
 654         m1.put(Float.class,Float.TYPE);
 655         m1.put(Integer.class,Integer.TYPE);
 656         m1.put(Long.class,Long.TYPE);
 657         m1.put(Short.class,Short.TYPE);
 658         m1.put(Void.class,Void.TYPE);


  42 
  43 /**
  44  * Root of the code DOM.
  45  *
  46  * <p>
  47  * Here's your typical CodeModel application.
  48  *
  49  * <pre>
  50  * JCodeModel cm = new JCodeModel();
  51  *
  52  * // generate source code by populating the 'cm' tree.
  53  * cm._class(...);
  54  * ...
  55  *
  56  * // write them out
  57  * cm.build(new File("."));
  58  * </pre>
  59  *
  60  * <p>
  61  * Every CodeModel node is always owned by one {@link JCodeModel} object
  62  * at any given time (which can be often accesesd by the {@code owner()} method.)
  63  *
  64  * As such, when you generate Java code, most of the operation works
  65  * in a top-down fashion. For example, you create a class from {@link JCodeModel},
  66  * which gives you a {@link JDefinedClass}. Then you invoke a method on it
  67  * to generate a new method, which gives you {@link JMethod}, and so on.
  68  *
  69  * There are a few exceptions to this, most notably building {@link JExpression}s,
  70  * but generally you work with CodeModel in a top-down fashion.
  71  *
  72  * Because of this design, most of the CodeModel classes aren't directly instanciable.
  73  *
  74  *
  75  * <h2>Where to go from here?</h2>
  76  * <p>
  77  * Most of the time you'd want to populate new type definitions in a {@link JCodeModel}.
  78  * See {@link #_class(String, ClassType)}.
  79  */
  80 public final class JCodeModel {
  81 
  82     /** The packages that this JCodeWriter contains. */


 618         public boolean isArray() {
 619             return false;
 620         }
 621 
 622         public void declare(JFormatter f) {
 623         }
 624 
 625         public JTypeVar[] typeParams() {
 626             // TODO: does JDK 1.5 reflection provides these information?
 627             return super.typeParams();
 628         }
 629 
 630         protected JClass substituteParams(JTypeVar[] variables, List<JClass> bindings) {
 631             // TODO: does JDK 1.5 reflection provides these information?
 632             return this;
 633         }
 634     }
 635 
 636     /**
 637      * Conversion from primitive type {@link Class} (such as {@link Integer#TYPE}
 638      * to its boxed type (such as {@code Integer.class})
 639      */
 640     public static final Map<Class<?>,Class<?>> primitiveToBox;
 641     /**
 642      * The reverse look up for {@link #primitiveToBox}
 643      */
 644     public static final Map<Class<?>,Class<?>> boxToPrimitive;
 645 
 646     static {
 647         Map<Class<?>,Class<?>> m1 = new HashMap<Class<?>,Class<?>>();
 648         Map<Class<?>,Class<?>> m2 = new HashMap<Class<?>,Class<?>>();
 649 
 650         m1.put(Boolean.class,Boolean.TYPE);
 651         m1.put(Byte.class,Byte.TYPE);
 652         m1.put(Character.class,Character.TYPE);
 653         m1.put(Double.class,Double.TYPE);
 654         m1.put(Float.class,Float.TYPE);
 655         m1.put(Integer.class,Integer.TYPE);
 656         m1.put(Long.class,Long.TYPE);
 657         m1.put(Short.class,Short.TYPE);
 658         m1.put(Void.class,Void.TYPE);
< prev index next >