325N/A * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * Root of the code DOM. 325N/A * Here's your typical CodeModel application. 325N/A * JCodeModel cm = new JCodeModel(); 325N/A * // generate source code by populating the 'cm' tree. 325N/A * cm.build(new File(".")); 325N/A * Every CodeModel node is always owned by one {@link JCodeModel} object 325N/A * at any given time (which can be often accesesd by the <tt>owner()</tt> method.) 325N/A * As such, when you generate Java code, most of the operation works 325N/A * in a top-down fashion. For example, you create a class from {@link JCodeModel}, 325N/A * which gives you a {@link JDefinedClass}. Then you invoke a method on it 325N/A * to generate a new method, which gives you {@link JMethod}, and so on. 325N/A * There are a few exceptions to this, most notably building {@link JExpression}s, 325N/A * but generally you work with CodeModel in a top-down fashion. 325N/A * Because of this design, most of the CodeModel classes aren't directly instanciable. 325N/A * <h2>Where to go from here?</h2> 325N/A * Most of the time you'd want to populate new type definitions in a {@link JCodeModel}. 325N/A * See {@link #_class(String, ClassType)}. 325N/A /** The packages that this JCodeWriter contains. */ 325N/A /** All JReferencedClasses are pooled here. */ 325N/A /** Obtains a reference to the special "null" type. */ 325N/A * If the flag is true, we will consider two classes "Foo" and "foo" 325N/A // let the system property override, in case the user really 325N/A // on Unix, it's case sensitive. 325N/A * Add a package to the list of packages to be generated 325N/A * Name of the package. Use "" to indicate the root package. 325N/A * @return Newly generated package 325N/A * Returns an iterator that walks the packages defined using this code 325N/A * Creates a new generated class. 325N/A * @exception JClassAlreadyExistsException 325N/A * Creates a dummy, unknown {@link JClass} that represents a given name. 325N/A * This method is useful when the code generation needs to include the user-specified 325N/A * class that may or may not exist, and only thing known about it is a class name. 325N/A * Creates a new generated class. 325N/A * @exception JClassAlreadyExistsException 325N/A * Creates a new generated class. 325N/A * @exception JClassAlreadyExistsException 325N/A * Gets a reference to the already created generated class. 325N/A * If the class is not yet created. 325N/A * @see JPackage#_getClass(String) 325N/A * Creates a new anonymous class. 325N/A * The naming convention doesn't match the rest of the CodeModel. 325N/A * Use {@link #anonymousClass(JClass)} instead. 325N/A * Creates a new anonymous class. 325N/A * Generates Java source code. 325N/A * A convenience method for <code>build(destDir,destDir,System.out)</code>. 325N/A * source files are generated into this directory. 325N/A * if non-null, progress indication will be sent to this stream. 325N/A * Generates Java source code. 325N/A * A convenience method that calls {@link #build(CodeWriter,CodeWriter)}. 325N/A * Java source files are generated into this directory. 325N/A * Other resource files are generated into this directory. 325N/A * if non-null, progress indication will be sent to this stream. 325N/A * A convenience method for <code>build(destDir,System.out)</code>. 325N/A * A convenience method for <code>build(srcDir,resourceDir,System.out)</code>. 325N/A * A convenience method for <code>build(out,out)</code>. 325N/A * Generates Java source code. 325N/A // avoid concurrent modification exception 325N/A * Returns the number of files to be generated if 325N/A * {@link #build} is invoked now. 325N/A // avoid concurrent modification exception 325N/A * Obtains a reference to an existing class from its Class object. 325N/A * The parameter may not be primitive. 325N/A * @see #_ref(Class) for the version that handles more cases. 325N/A * Obtains a reference to an existing class from its fully-qualified 325N/A * First, this method attempts to load the class of the given name. 325N/A * If that fails, we assume that the class is derived straight from 325N/A * {@link Object}, and return a {@link JClass}. 325N/A // try the context class loader first 325N/A // then the default mechanism. 325N/A // assume it's not visible to us. 325N/A * Cached for {@link #wildcard()}. 325N/A * Gets a {@link JClass} representation for "?", 325N/A * which is equivalent to "? extends Object". 325N/A * Obtains a type object from a type name. 325N/A * This method handles primitive types, arrays, and existing {@link Class}es. 325N/A * @exception ClassNotFoundException 325N/A * If the specified type is not found. 325N/A * Parses a type name token T (which can be potentially of the form Tr&ly;T1,T2,...>, 325N/A * @return the index of the character next to T. 325N/A * Parses additional left-associative suffixes, like type arguments 325N/A * and array specifiers. 325N/A * Parses '<T1,T2,...,Tn>' 325N/A * @return the index of the character next to '>' 325N/A * References to existing classes. 325N/A * JReferencedClass is kept in a pool so that they are shared. 325N/A * There is one pool for each JCodeModel object. 325N/A * It is impossible to cache JReferencedClass globally only because 325N/A * there is the _package() method, which obtains the owner JPackage 325N/A * object, which is scoped to JCodeModel. 325N/A // TODO: does JDK 1.5 reflection provides these information? 325N/A // TODO: does JDK 1.5 reflection provides these information? 325N/A * Conversion from primitive type {@link Class} (such as {@link Integer#TYPE} 325N/A * to its boxed type (such as <tt>Integer.class</tt>) 325N/A * The reverse look up for {@link #primitiveToBox}