src/share/jaxws_classes/com/sun/codemodel/internal/JDefinedClass.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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


  54     implements JDeclaration, JClassContainer, JGenerifiable, JAnnotatable, JDocCommentable {
  55 
  56     /** Name of this class. Null if anonymous. */
  57     private String name = null;
  58 
  59     /** Modifiers for the class declaration */
  60     private JMods mods;
  61 
  62     /** Name of the super class of this class. */
  63     private JClass superClass;
  64 
  65     /** List of interfaces that this class implements */
  66     private final Set<JClass> interfaces = new TreeSet<JClass>();
  67 
  68     /** Fields keyed by their names. */
  69     /*package*/ final Map<String,JFieldVar> fields = new LinkedHashMap<String,JFieldVar>();
  70 
  71     /** Static initializer, if this class has one */
  72     private JBlock init = null;
  73 



  74     /** class javadoc */
  75     private JDocComment jdoc = null;
  76 
  77     /** Set of constructors for this class, if any */
  78     private final List<JMethod> constructors = new ArrayList<JMethod>();
  79 
  80     /** Set of methods that are members of this class */
  81     private final List<JMethod> methods = new ArrayList<JMethod>();
  82 
  83     /**
  84      * Nested classes as a map from name to JDefinedClass.
  85      * The name is all capitalized in a case sensitive file system
  86      * ({@link JCodeModel#isCaseSensitiveFileSystem}) to avoid conflicts.
  87      *
  88      * Lazily created to save footprint.
  89      *
  90      * @see #getClasses()
  91      */
  92     private Map<String,JDefinedClass> classes;
  93 


 501      *      if the given field is not a field on this class.
 502      */
 503     public void removeField(JFieldVar field) {
 504         if(fields.remove(field.name())!=field)
 505             throw new IllegalArgumentException();
 506     }
 507 
 508     /**
 509      * Creates, if necessary, and returns the static initializer
 510      * for this class.
 511      *
 512      * @return JBlock containing initialization statements for this class
 513      */
 514     public JBlock init() {
 515         if (init == null)
 516             init = new JBlock();
 517         return init;
 518     }
 519 
 520     /**












 521      * Adds a constructor to this class.
 522      *
 523      * @param mods
 524      *        Modifiers for this constructor
 525      */
 526     public JMethod constructor(int mods) {
 527         JMethod c = new JMethod(mods, this);
 528         constructors.add(c);
 529         return c;
 530     }
 531 
 532     /**
 533      * Returns an iterator that walks the constructors defined in this class.
 534      */
 535     public Iterator<JMethod> constructors() {
 536         return constructors.iterator();
 537     }
 538 
 539     /**
 540      * Looks for a method that has the specified method signature


 776     /**
 777      * prints the body of a class.
 778      */
 779     protected void declareBody(JFormatter f) {
 780         f.p('{').nl().nl().i();
 781         boolean first = true;
 782 
 783         if (!enumConstantsByName.isEmpty()) {
 784             for (JEnumConstant c : enumConstantsByName.values()) {
 785                 if (!first) f.p(',').nl();
 786                 f.d(c);
 787                 first = false;
 788             }
 789                 f.p(';').nl();
 790         }
 791 
 792         for( JFieldVar field : fields.values() )
 793             f.d(field);
 794         if (init != null)
 795             f.nl().p("static").s(init);


 796         for (JMethod m : constructors) {
 797             f.nl().d(m);
 798         }
 799         for (JMethod m : methods) {
 800             f.nl().d(m);
 801         }
 802         if(classes!=null)
 803             for (JDefinedClass dc : classes.values())
 804                 f.nl().d(dc);
 805 
 806 
 807         if (directBlock != null)
 808             f.p(directBlock);
 809         f.nl().o().p('}').nl();
 810     }
 811 
 812     /**
 813      * Places the given string directly inside the generated class.
 814      *
 815      * This method can be used to add methods/fields that are not


   1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   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


  54     implements JDeclaration, JClassContainer, JGenerifiable, JAnnotatable, JDocCommentable {
  55 
  56     /** Name of this class. Null if anonymous. */
  57     private String name = null;
  58 
  59     /** Modifiers for the class declaration */
  60     private JMods mods;
  61 
  62     /** Name of the super class of this class. */
  63     private JClass superClass;
  64 
  65     /** List of interfaces that this class implements */
  66     private final Set<JClass> interfaces = new TreeSet<JClass>();
  67 
  68     /** Fields keyed by their names. */
  69     /*package*/ final Map<String,JFieldVar> fields = new LinkedHashMap<String,JFieldVar>();
  70 
  71     /** Static initializer, if this class has one */
  72     private JBlock init = null;
  73 
  74     /** Instance initializer, if this class has one */
  75     private JBlock instanceInit = null;
  76 
  77     /** class javadoc */
  78     private JDocComment jdoc = null;
  79 
  80     /** Set of constructors for this class, if any */
  81     private final List<JMethod> constructors = new ArrayList<JMethod>();
  82 
  83     /** Set of methods that are members of this class */
  84     private final List<JMethod> methods = new ArrayList<JMethod>();
  85 
  86     /**
  87      * Nested classes as a map from name to JDefinedClass.
  88      * The name is all capitalized in a case sensitive file system
  89      * ({@link JCodeModel#isCaseSensitiveFileSystem}) to avoid conflicts.
  90      *
  91      * Lazily created to save footprint.
  92      *
  93      * @see #getClasses()
  94      */
  95     private Map<String,JDefinedClass> classes;
  96 


 504      *      if the given field is not a field on this class.
 505      */
 506     public void removeField(JFieldVar field) {
 507         if(fields.remove(field.name())!=field)
 508             throw new IllegalArgumentException();
 509     }
 510 
 511     /**
 512      * Creates, if necessary, and returns the static initializer
 513      * for this class.
 514      *
 515      * @return JBlock containing initialization statements for this class
 516      */
 517     public JBlock init() {
 518         if (init == null)
 519             init = new JBlock();
 520         return init;
 521     }
 522 
 523     /**
 524      * Creates, if necessary, and returns the instance initializer
 525      * for this class.
 526      *
 527      * @return JBlock containing initialization statements for this class
 528      */
 529     public JBlock instanceInit() {
 530         if (instanceInit == null)
 531             instanceInit = new JBlock();
 532         return instanceInit;
 533     }
 534 
 535     /**
 536      * Adds a constructor to this class.
 537      *
 538      * @param mods
 539      *        Modifiers for this constructor
 540      */
 541     public JMethod constructor(int mods) {
 542         JMethod c = new JMethod(mods, this);
 543         constructors.add(c);
 544         return c;
 545     }
 546 
 547     /**
 548      * Returns an iterator that walks the constructors defined in this class.
 549      */
 550     public Iterator<JMethod> constructors() {
 551         return constructors.iterator();
 552     }
 553 
 554     /**
 555      * Looks for a method that has the specified method signature


 791     /**
 792      * prints the body of a class.
 793      */
 794     protected void declareBody(JFormatter f) {
 795         f.p('{').nl().nl().i();
 796         boolean first = true;
 797 
 798         if (!enumConstantsByName.isEmpty()) {
 799             for (JEnumConstant c : enumConstantsByName.values()) {
 800                 if (!first) f.p(',').nl();
 801                 f.d(c);
 802                 first = false;
 803             }
 804                 f.p(';').nl();
 805         }
 806 
 807         for( JFieldVar field : fields.values() )
 808             f.d(field);
 809         if (init != null)
 810             f.nl().p("static").s(init);
 811         if (instanceInit != null)
 812             f.nl().s(instanceInit);
 813         for (JMethod m : constructors) {
 814             f.nl().d(m);
 815         }
 816         for (JMethod m : methods) {
 817             f.nl().d(m);
 818         }
 819         if(classes!=null)
 820             for (JDefinedClass dc : classes.values())
 821                 f.nl().d(dc);
 822 
 823 
 824         if (directBlock != null)
 825             f.p(directBlock);
 826         f.nl().o().p('}').nl();
 827     }
 828 
 829     /**
 830      * Places the given string directly inside the generated class.
 831      *
 832      * This method can be used to add methods/fields that are not