jaxws/src/share/classes/com/sun/codemodel/internal/package-info.java
author thurka
Mon, 16 Nov 2009 15:33:05 +0100
changeset 4240 ca8d98aeb09e
parent 3530 18fb7507984b
permissions -rw-r--r--
6858708: HotspotDiagnosticMXBean.setVMOption() throws NullPointerException Summary: Add a null check for the VM option string Reviewed-by: mchung, ohair
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
474761f14bca Initial load
duke
parents:
diff changeset
     1
/*
2678
57cf2a1c1a05 6831313: update jaxws in OpenJDK7 to 2.1 plus bug fixes from OpenJDK 6
tbell
parents: 8
diff changeset
     2
 * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
8
474761f14bca Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
474761f14bca Initial load
duke
parents:
diff changeset
     4
 *
474761f14bca Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
474761f14bca Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
474761f14bca Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
474761f14bca Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
474761f14bca Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
474761f14bca Initial load
duke
parents:
diff changeset
    10
 *
474761f14bca Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
474761f14bca Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
474761f14bca Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
474761f14bca Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
474761f14bca Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
474761f14bca Initial load
duke
parents:
diff changeset
    16
 *
474761f14bca Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
474761f14bca Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
474761f14bca Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
474761f14bca Initial load
duke
parents:
diff changeset
    20
 *
474761f14bca Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
474761f14bca Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
474761f14bca Initial load
duke
parents:
diff changeset
    23
 * have any questions.
474761f14bca Initial load
duke
parents:
diff changeset
    24
 */
3530
18fb7507984b 6813167: 6u14 JAX-WS audit mutable static bugs
asaha
parents: 2678
diff changeset
    25
8
474761f14bca Initial load
duke
parents:
diff changeset
    26
/**
474761f14bca Initial load
duke
parents:
diff changeset
    27
 * <h1>Library for generating Java source code</h1>.
474761f14bca Initial load
duke
parents:
diff changeset
    28
 *
474761f14bca Initial load
duke
parents:
diff changeset
    29
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    30
 * CodeModel is a library that allows you to generate Java source
474761f14bca Initial load
duke
parents:
diff changeset
    31
 * code in a type-safe fashion.
474761f14bca Initial load
duke
parents:
diff changeset
    32
 *
474761f14bca Initial load
duke
parents:
diff changeset
    33
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    34
 * With CodeModel, you build the java source code by first building AST,
474761f14bca Initial load
duke
parents:
diff changeset
    35
 * then writing it out as text files that is Java source files.
474761f14bca Initial load
duke
parents:
diff changeset
    36
 * The AST looks like this:
474761f14bca Initial load
duke
parents:
diff changeset
    37
 *
474761f14bca Initial load
duke
parents:
diff changeset
    38
 * {@DotDiagram
474761f14bca Initial load
duke
parents:
diff changeset
    39
    digraph G {
474761f14bca Initial load
duke
parents:
diff changeset
    40
        cls1 [label="JDefinedClass"];
474761f14bca Initial load
duke
parents:
diff changeset
    41
        cls2 [label="JDefinedClass"];
474761f14bca Initial load
duke
parents:
diff changeset
    42
        JCodeModel -> cls1 [label="generated class"];
474761f14bca Initial load
duke
parents:
diff changeset
    43
        JCodeModel -> cls2 [label="generated class"];
474761f14bca Initial load
duke
parents:
diff changeset
    44
474761f14bca Initial load
duke
parents:
diff changeset
    45
        m1 [label="JMethod"];
474761f14bca Initial load
duke
parents:
diff changeset
    46
        m2 [label="JMethod"];
474761f14bca Initial load
duke
parents:
diff changeset
    47
474761f14bca Initial load
duke
parents:
diff changeset
    48
        cls1 -> m1;
474761f14bca Initial load
duke
parents:
diff changeset
    49
        cls1 -> m2;
474761f14bca Initial load
duke
parents:
diff changeset
    50
        cls1 -> JField;
474761f14bca Initial load
duke
parents:
diff changeset
    51
474761f14bca Initial load
duke
parents:
diff changeset
    52
        m1 -> JVar [label="method parameter"];
474761f14bca Initial load
duke
parents:
diff changeset
    53
        m1 -> JBlock [label="code"];
474761f14bca Initial load
duke
parents:
diff changeset
    54
    }
474761f14bca Initial load
duke
parents:
diff changeset
    55
 * }
474761f14bca Initial load
duke
parents:
diff changeset
    56
 *
474761f14bca Initial load
duke
parents:
diff changeset
    57
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    58
 * You bulid this tree mostly from top-down. So, you first create
474761f14bca Initial load
duke
parents:
diff changeset
    59
 * a new {@link JDefinedClass} from {@link JCodeModel}, then you
474761f14bca Initial load
duke
parents:
diff changeset
    60
 * create a {@link JMethod} from {@link JDefinedClass}, and so on.
474761f14bca Initial load
duke
parents:
diff changeset
    61
 *
474761f14bca Initial load
duke
parents:
diff changeset
    62
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    63
 * This design brings the following beneefits:
474761f14bca Initial load
duke
parents:
diff changeset
    64
 *
474761f14bca Initial load
duke
parents:
diff changeset
    65
 * <ul>
474761f14bca Initial load
duke
parents:
diff changeset
    66
 *  <li>source code can be written in random order
474761f14bca Initial load
duke
parents:
diff changeset
    67
 *  <li>generated source code nicely imports other classes
474761f14bca Initial load
duke
parents:
diff changeset
    68
 *  <li>generated source code is lexically always correct
474761f14bca Initial load
duke
parents:
diff changeset
    69
 *      (no unbalanced parenthesis, etc.)
474761f14bca Initial load
duke
parents:
diff changeset
    70
 *  <li>code generation becomes relatively type-safe
474761f14bca Initial load
duke
parents:
diff changeset
    71
 * </ul>
474761f14bca Initial load
duke
parents:
diff changeset
    72
 *
474761f14bca Initial load
duke
parents:
diff changeset
    73
 * The price you pay for that is
474761f14bca Initial load
duke
parents:
diff changeset
    74
 * increased memory footprint and the generation speed.
474761f14bca Initial load
duke
parents:
diff changeset
    75
 * See <a href="#performance">performance section</a> for
474761f14bca Initial load
duke
parents:
diff changeset
    76
 * more discussions about the performance and possible improvements.
474761f14bca Initial load
duke
parents:
diff changeset
    77
 *
474761f14bca Initial load
duke
parents:
diff changeset
    78
 *
474761f14bca Initial load
duke
parents:
diff changeset
    79
 * <h2>Using CodeModel</h2>
474761f14bca Initial load
duke
parents:
diff changeset
    80
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    81
 * {@link com.sun.codemodel.internal.JCodeModel} is the entry point to
474761f14bca Initial load
duke
parents:
diff changeset
    82
 * the library. See its javadoc for more details about how to use
474761f14bca Initial load
duke
parents:
diff changeset
    83
 * CodeModel.
474761f14bca Initial load
duke
parents:
diff changeset
    84
 *
474761f14bca Initial load
duke
parents:
diff changeset
    85
 *
474761f14bca Initial load
duke
parents:
diff changeset
    86
 *
474761f14bca Initial load
duke
parents:
diff changeset
    87
 * <h2>Performance</h2>
474761f14bca Initial load
duke
parents:
diff changeset
    88
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    89
 * Generally speaking, CodeModel is expected to be used in
474761f14bca Initial load
duke
parents:
diff changeset
    90
 * an environment where the resource constraint is not severe.
474761f14bca Initial load
duke
parents:
diff changeset
    91
 * Therefore, we haven't spent much effort in trying to make
474761f14bca Initial load
duke
parents:
diff changeset
    92
 * this library lean and mean.
474761f14bca Initial load
duke
parents:
diff changeset
    93
 *
474761f14bca Initial load
duke
parents:
diff changeset
    94
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
    95
 * That said, we did some benchmark and performance analysis.
474761f14bca Initial load
duke
parents:
diff changeset
    96
 * In case anyone is interested in making this library
474761f14bca Initial load
duke
parents:
diff changeset
    97
 * better performance wise, here's the findings.
474761f14bca Initial load
duke
parents:
diff changeset
    98
 *
474761f14bca Initial load
duke
parents:
diff changeset
    99
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
   100
 * {@link List}s {@link Map}s, and other collections take up
474761f14bca Initial load
duke
parents:
diff changeset
   101
 * a lot of space. Allocating those things lazily is generally
474761f14bca Initial load
duke
parents:
diff changeset
   102
 * a good idea.
474761f14bca Initial load
duke
parents:
diff changeset
   103
 *
474761f14bca Initial load
duke
parents:
diff changeset
   104
 * <p>
474761f14bca Initial load
duke
parents:
diff changeset
   105
 * Compared to template-based code generator, the writing operation
474761f14bca Initial load
duke
parents:
diff changeset
   106
 * is slow, as it needs to traverse each AST node. Consider
474761f14bca Initial load
duke
parents:
diff changeset
   107
 * pre-encoding tokens (like 'public') to the target encoding,
474761f14bca Initial load
duke
parents:
diff changeset
   108
 * and consider exploting the subtree equivalence.
474761f14bca Initial load
duke
parents:
diff changeset
   109
 *
474761f14bca Initial load
duke
parents:
diff changeset
   110
 * @ArchitectureDocument
474761f14bca Initial load
duke
parents:
diff changeset
   111
 */
474761f14bca Initial load
duke
parents:
diff changeset
   112
package com.sun.codemodel.internal;
474761f14bca Initial load
duke
parents:
diff changeset
   113
474761f14bca Initial load
duke
parents:
diff changeset
   114
import java.util.List;
474761f14bca Initial load
duke
parents:
diff changeset
   115
import java.util.Map;