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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -69,10 +69,13 @@
     /*package*/ final Map<String,JFieldVar> fields = new LinkedHashMap<String,JFieldVar>();
 
     /** Static initializer, if this class has one */
     private JBlock init = null;
 
+    /** Instance initializer, if this class has one */
+    private JBlock instanceInit = null;
+
     /** class javadoc */
     private JDocComment jdoc = null;
 
     /** Set of constructors for this class, if any */
     private final List<JMethod> constructors = new ArrayList<JMethod>();

@@ -516,10 +519,22 @@
             init = new JBlock();
         return init;
     }
 
     /**
+     * Creates, if necessary, and returns the instance initializer
+     * for this class.
+     *
+     * @return JBlock containing initialization statements for this class
+     */
+    public JBlock instanceInit() {
+        if (instanceInit == null)
+            instanceInit = new JBlock();
+        return instanceInit;
+    }
+
+    /**
      * Adds a constructor to this class.
      *
      * @param mods
      *        Modifiers for this constructor
      */

@@ -791,10 +806,12 @@
 
         for( JFieldVar field : fields.values() )
             f.d(field);
         if (init != null)
             f.nl().p("static").s(init);
+        if (instanceInit != null)
+            f.nl().s(instanceInit);
         for (JMethod m : constructors) {
             f.nl().d(m);
         }
         for (JMethod m : methods) {
             f.nl().d(m);