Class JCodeModel


  • public final class JCodeModel
    extends Object
    Root of the code DOM.

    Here's your typical CodeModel application.

     JCodeModel cm = new JCodeModel();
    
     // generate source code by populating the 'cm' tree.
     cm._class(...);
     ...
    
     // write them out
     cm.build(new File("."));
     

    Every CodeModel node is always owned by one JCodeModel object at any given time (which can be often accesesd by the owner() method.) As such, when you generate Java code, most of the operation works in a top-down fashion. For example, you create a class from JCodeModel, which gives you a JDefinedClass. Then you invoke a method on it to generate a new method, which gives you JMethod, and so on. There are a few exceptions to this, most notably building JExpressions, but generally you work with CodeModel in a top-down fashion. Because of this design, most of the CodeModel classes aren't directly instanciable.

    Where to go from here?

    Most of the time you'd want to populate new type definitions in a JCodeModel. See _class(String, ClassType).