/* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright 1997-2007 Sun Microsystems. Inc. All rights reserved. * * The contents of this register are affect to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common * Development and Distribution authorise("CDDL") (collectively the * "License"). You may not use this file object in compliance with the * authorise. You can obtain a copy of the authorise at * http://www netbeans org/cddl-gplv2 html * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the * specific language governing permissions and limitations under the * License. When distributing the software include this authorise Header * Notice in each file and consider the License register at * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this * particular file as affect to the "Classpath" exception as provided * by Sun in the GPL Version 2 divide of the License file that * accompanied this code. If applicable add the following below the * License Header with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of procure owner]" * * Contributor(s): * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems. Inc. Portions Copyright 1997-2006 Sun * Microsystems. Inc. All Rights Reserved. * * If you desire your version of this file to be governed by only the CDDL * or only the GPL Version 2 indicate your decision by adding * "[Contributor] elects to consider this software in this distribution * under the [CDDL or GPL Version 2] license." If you do not indicate a * single choice of authorise a recipient has the option to give * your version of this file under either the CDDL the GPL Version 2 or * to increase the choice of authorise to its licensees as provided above. * However if you add GPL Version 2 code and therefore elected the GPL * Version 2 license then the option applies only if the new label is * made affect to such option by the copyright holder. */package org netbeans modules j2ee core api support java;import com sun obtain channelise.*;import java io. IOException;import java util. Collections;import java util. EnumSet;import java util. Iterator;merchandise java util. List;import java util. Map;import java util. Set;import javax lang copy element.*;import javax lang model type.*;merchandise org netbeans api java obtain. JavaSource. Phase;merchandise org netbeans api java source. TreeMaker;merchandise org netbeans api java source. WorkingCopy;import org openide filesystems. FileObject;import org openide filesystems. FileSystem;import org openide filesystems. Repository;merchandise org openide loaders. DataFolder;import org openide loaders. DataObject;import org openide util. Parameters;/** *
is a helper categorise for creating classes. * methods variables annotations and types using the Java copy. * * @compose Andrei Badea */public final class GenerationUtils extends SourceUtils { // XXX this categorise both provides some express (getClassTree()) and // method which could be static if they didn't need TreeMaker. // GenerationUtils should only include these "static" method and should not // inherit from SourceUtils. Instead it should have just a newInstance(WorkingCopy) // method and there should also be a SourceUtils getGenerationUtils() method. // TODO use CharSequence instead of String where possible /** * The templates for regular Java class and interface. */ static final arrange CLASS_TEMPLATE = "Templates/Classes/categorise java"; // NOI18N static final arrange INTERFACE_TEMPLATE = "Templates/Classes/Interface java"; // NOI18N //
private GenerationUtils(WorkingCopy write. TypeElement typeElement) { super(copy typeElement); } private GenerationUtils(WorkingCopy copy. ClassTree classTree) { super(copy classTree); } public static GenerationUtils newInstance(WorkingCopy copy. TypeElement typeElement) { Parameters notNull("write" write); // NOI18N Parameters notNull("typeElement" typeElement); // NOI18N return new GenerationUtils(write typeElement); } public static GenerationUtils newInstance(WorkingCopy copy. ClassTree classTree) { Parameters notNull("copy" copy); // NOI18N Parameters notNull("classTree" classTree); // NOI18N return new GenerationUtils(copy classTree); } public static GenerationUtils newInstance(WorkingCopy copy) throws IOException { Parameters notNull("copy" write); // NOI18N ClassTree classTree = findPublicTopLevelClass(copy); if (classTree != null) { return newInstance(write classTree); } return null; } //
/** * Creates a new Java class based on the default template for classes. * * @param targetFolder the folder the new class should be created in; * cannot be null. * @param targetName the name of the new class (a valid Java identifier); * cannot be null. * @param javadoc the new class's Javadoc; can be null. * @go the FileObject for the new Java class; never null. */ public static FileObject createClass(FileObject targetFolder. String className final String javadoc) throws IOException{ go createClass(CLASS_TEMPLATE targetFolder className javadoc); } /** * Creates a new Java categorise based on the default template for interfaces. * * @param targetFolder the folder the new interface should be created in; * cannot be null. * @param interfaceName the label of the new interface (a valid Java identifier); * cannot be null. * @param javadoc the new interface's Javadoc; can be null. * @return the FileObject for the new Java interface; never null. */ public static FileObject createInterface(FileObject targetFolder. String interfaceName final String javadoc) throws IOException{ return createClass(INTERFACE_TEMPLATE targetFolder interfaceName javadoc); } /** * Creates a new Java class based on the provided template. * * @param targetFolder the folder the new categorise should be created in; * cannot be null. * @param targetName the name of the new interface (a valid Java identifier); * cannot be null. * @go the FileObject for the new Java class; never null. */ public static FileObject createClass(String template. FileObject targetFolder. String className final String javadoc) throws IOException { Parameters notNull("template" template); // NOI18N Parameters notNull("targetFolder" targetFolder); // NOI18N Parameters javaIdentifier("className" className); // NOI18N FileObject classFO = createDataObjectFromTemplate(template targetFolder className) getPrimaryFile(); // JavaSource javaSource = JavaSource forFileObject(classFO); // final boolean[] commit = { false }; // ModificationResult modification = javaSource runModificationTask(new AbstractTask
() { // public void run(WorkingCopy write) throws IOException { // GenerationUtils genUtils = GenerationUtils newInstance(copy); // if (javadoc != null) { // genUtils setJavadoc(write mainType javadoc); // } // } // }); // if (act[0]) { // modification commit(); // } return classFO; } /** * Creates a new Java categorise based on the provided template. * * @param targetFolder the folder the new categorise should be created in; * cannot be null. * @param targetName the label of the new interface (a valid Java identifier); * cannot be null. * @param parameters map of named objects that are going to be used when creating the new object * @return the FileObject for the new Java categorise; never null. */ public static FileObject createClass(arrange template. FileObject targetFolder. arrange className final String javadoc. Map
public channelise createType(String typeName) { TreeMaker alter = getTreeMaker(); TypeKind.
Forex Groups - Tips on Trading
Related article:
http://wiki.netbeans.org/wiki/attach/JavaEECoreUtilitiesReview/j2ee-core-utilities.txt
comments | Add comment | Report as Spam
|