com.sun.codemodel.internal.JPackage Java Examples

The following examples show how to use com.sun.codemodel.internal.JPackage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns all <i>used</i> JPackages.
 *
 * A JPackage is considered as "used" if a ClassItem or
 * a InterfaceItem resides in that package.
 *
 * This value is dynamically calculated every time because
 * one can freely remove ClassItem/InterfaceItem.
 *
 * @return
 *         Given the same input, the order of packages in the array
 *         is always the same regardless of the environment.
 */
public final JPackage[] getUsedPackages(Aspect aspect) {
    Set<JPackage> s = new TreeSet<JPackage>();

    for (CClassInfo bean : model.beans().values()) {
        JClassContainer cont = getContainer(bean.parent(), aspect);
        if (cont.isPackage()) {
            s.add((JPackage) cont);
        }
    }

    for (CElementInfo e : model.getElementMappings(null).values()) {
        // at the first glance you might think we should be iterating all elements,
        // not just global ones, but if you think about it, local ones live inside
        // another class, so those packages are already enumerated when we were
        // walking over CClassInfos.
        s.add(e._package());
    }

    return s.toArray(new JPackage[s.size()]);
}
 
Example #2
Source File: PrologCodeWriter.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public Writer openSource(JPackage pkg, String fileName) throws IOException {
    Writer w = super.openSource(pkg,fileName);

    PrintWriter out = new PrintWriter(w);

    // write prolog if this is a java source file
    if( prolog != null ) {
        out.println( "//" );

        String s = prolog;
        int idx;
        while( (idx=s.indexOf('\n'))!=-1 ) {
            out.println("// "+ s.substring(0,idx) );
            s = s.substring(idx+1);
        }
        out.println("//");
        out.println();
    }
    out.flush();    // we can't close the stream for that would close the undelying stream.

    return w;
}
 
Example #3
Source File: SignatureWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void dump() throws IOException {

        // collect packages used in the class.
        Set<JPackage> packages = new TreeSet<JPackage>(new Comparator<JPackage>() {
            public int compare(JPackage lhs, JPackage rhs) {
                return lhs.name().compareTo(rhs.name());
            }
        });
        for( ClassOutline ci : classes )
            packages.add(ci._package()._package());

        for( JPackage pkg : packages )
            dump( pkg );

        out.flush();
    }
 
Example #4
Source File: PrologCodeWriter.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public Writer openSource(JPackage pkg, String fileName) throws IOException {
    Writer w = super.openSource(pkg,fileName);

    PrintWriter out = new PrintWriter(w);

    // write prolog if this is a java source file
    if( prolog != null ) {
        out.println( "//" );

        String s = prolog;
        int idx;
        while( (idx=s.indexOf('\n'))!=-1 ) {
            out.println("// "+ s.substring(0,idx) );
            s = s.substring(idx+1);
        }
        out.println("//");
        out.println();
    }
    out.flush();    // we can't close the stream for that would close the undelying stream.

    return w;
}
 
Example #5
Source File: PrologCodeWriter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Writer openSource(JPackage pkg, String fileName) throws IOException {
    Writer w = super.openSource(pkg,fileName);

    PrintWriter out = new PrintWriter(w);

    // write prolog if this is a java source file
    if( prolog != null ) {
        out.println( "//" );

        String s = prolog;
        int idx;
        while( (idx=s.indexOf('\n'))!=-1 ) {
            out.println("// "+ s.substring(0,idx) );
            s = s.substring(idx+1);
        }
        out.println("//");
        out.println();
    }
    out.flush();    // we can't close the stream for that would close the undelying stream.

    return w;
}
 
Example #6
Source File: BeanGenerator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public JClass generateStaticClass(Class src, JPackage out) {
    String shortName = getShortName(src.getName());

    // some people didn't like our jars to contain files with .java extension,
    // so when we build jars, we'' use ".java_". But when we run from the workspace,
    // we want the original source code to be used, so we check both here.
    // see bug 6211503.
    URL res = src.getResource(shortName + ".java");
    if (res == null) {
        res = src.getResource(shortName + ".java_");
    }
    if (res == null) {
        throw new InternalError("Unable to load source code of " + src.getName() + " as a resource");
    }

    JStaticJavaFile sjf = new JStaticJavaFile(out, shortName, res, null);
    out.addResourceFile(sjf);
    return sjf.getJClass();
}
 
Example #7
Source File: SignatureWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private void dump() throws IOException {

        // collect packages used in the class.
        Set<JPackage> packages = new TreeSet<JPackage>(new Comparator<JPackage>() {
            public int compare(JPackage lhs, JPackage rhs) {
                return lhs.name().compareTo(rhs.name());
            }
        });
        for( ClassOutline ci : classes )
            packages.add(ci._package()._package());

        for( JPackage pkg : packages )
            dump( pkg );

        out.flush();
    }
 
Example #8
Source File: PrologCodeWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Writer openSource(JPackage pkg, String fileName) throws IOException {
    Writer w = super.openSource(pkg,fileName);

    PrintWriter out = new PrintWriter(w);

    // write prolog if this is a java source file
    if( prolog != null ) {
        out.println( "//" );

        String s = prolog;
        int idx;
        while( (idx=s.indexOf('\n'))!=-1 ) {
            out.println("// "+ s.substring(0,idx) );
            s = s.substring(idx+1);
        }
        out.println("//");
        out.println();
    }
    out.flush();    // we can't close the stream for that would close the undelying stream.

    return w;
}
 
Example #9
Source File: BeanGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns all <i>used</i> JPackages.
 *
 * A JPackage is considered as "used" if a ClassItem or
 * a InterfaceItem resides in that package.
 *
 * This value is dynamically calculated every time because
 * one can freely remove ClassItem/InterfaceItem.
 *
 * @return
 *         Given the same input, the order of packages in the array
 *         is always the same regardless of the environment.
 */
public final JPackage[] getUsedPackages(Aspect aspect) {
    Set<JPackage> s = new TreeSet<JPackage>();

    for (CClassInfo bean : model.beans().values()) {
        JClassContainer cont = getContainer(bean.parent(), aspect);
        if (cont.isPackage()) {
            s.add((JPackage) cont);
        }
    }

    for (CElementInfo e : model.getElementMappings(null).values()) {
        // at the first glance you might think we should be iterating all elements,
        // not just global ones, but if you think about it, local ones live inside
        // another class, so those packages are already enumerated when we were
        // walking over CClassInfos.
        s.add(e._package());
    }

    return s.toArray(new JPackage[s.size()]);
}
 
Example #10
Source File: PrologCodeWriter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Writer openSource(JPackage pkg, String fileName) throws IOException {
    Writer w = super.openSource(pkg,fileName);

    PrintWriter out = new PrintWriter(w);

    // write prolog if this is a java source file
    if( prolog != null ) {
        out.println( "//" );

        String s = prolog;
        int idx;
        while( (idx=s.indexOf('\n'))!=-1 ) {
            out.println("// "+ s.substring(0,idx) );
            s = s.substring(idx+1);
        }
        out.println("//");
        out.println();
    }
    out.flush();    // we can't close the stream for that would close the undelying stream.

    return w;
}
 
Example #11
Source File: SingleStreamCodeWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    String pkgName = pkg.name();
    if(pkgName.length()!=0)     pkgName += '.';

    out.println(
        "-----------------------------------" + pkgName+fileName +
        "-----------------------------------");

    return new FilterOutputStream(out) {
        public void close() {
            // don't let this stream close
        }
    };
}
 
Example #12
Source File: FilerCodeWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public Writer openSource(JPackage pkg, String fileName) throws IOException {
    String name;
    if(pkg.isUnnamed())
        name = fileName;
    else
        name = pkg.name()+'.'+fileName;

    name = name.substring(0,name.length()-5);   // strip ".java"

    return filer.createSourceFile(name).openWriter();
}
 
Example #13
Source File: PackageOutlineImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected PackageOutlineImpl( BeanGenerator outline, Model model, JPackage _pkg ) {
    this._model = model;
    this._package = _pkg;
    switch(model.strategy) {
    case BEAN_ONLY:
        objectFactoryGenerator = new PublicObjectFactoryGenerator(outline,model,_pkg);
        break;
    case INTF_AND_IMPL:
        objectFactoryGenerator = new DualObjectFactoryGenerator(outline,model,_pkg);
        break;
    default:
        throw new IllegalStateException();
    }
}
 
Example #14
Source File: BindInfo.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the specified package name (options/@package).
 */
public JPackage getTargetPackage() {
    if(model.options.defaultPackage!=null)
        // "-p" takes precedence over everything else
        return codeModel._package(model.options.defaultPackage);

    String p;
    if( defaultPackage!=null )
        p = defaultPackage;
    else
        p = getOption("package", "");
    return codeModel._package(p);
}
 
Example #15
Source File: WSCodeWriter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected File getFile(JPackage pkg, String fileName ) throws IOException {
    File f = super.getFile(pkg, fileName);

    options.addGeneratedFile(f);
    // we can't really tell the file type, for we don't know
    // what this file is used for. Fortunately,
    // FILE_TYPE doesn't seem to be used, so it doesn't really
    // matter what we set.

    return f;
}
 
Example #16
Source File: PackageOutlineImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
protected PackageOutlineImpl( BeanGenerator outline, Model model, JPackage _pkg ) {
    this._model = model;
    this._package = _pkg;
    switch(model.strategy) {
    case BEAN_ONLY:
        objectFactoryGenerator = new PublicObjectFactoryGenerator(outline,model,_pkg);
        break;
    case INTF_AND_IMPL:
        objectFactoryGenerator = new DualObjectFactoryGenerator(outline,model,_pkg);
        break;
    default:
        throw new IllegalStateException();
    }
}
 
Example #17
Source File: BindInfo.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the specified package name (options/@package).
 */
public JPackage getTargetPackage() {
    if(model.options.defaultPackage!=null)
        // "-p" takes precedence over everything else
        return codeModel._package(model.options.defaultPackage);

    String p;
    if( defaultPackage!=null )
        p = defaultPackage;
    else
        p = getOption("package", "");
    return codeModel._package(p);
}
 
Example #18
Source File: PackageOutlineImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
protected PackageOutlineImpl( BeanGenerator outline, Model model, JPackage _pkg ) {
    this._model = model;
    this._package = _pkg;
    switch(model.strategy) {
    case BEAN_ONLY:
        objectFactoryGenerator = new PublicObjectFactoryGenerator(outline,model,_pkg);
        break;
    case INTF_AND_IMPL:
        objectFactoryGenerator = new DualObjectFactoryGenerator(outline,model,_pkg);
        break;
    default:
        throw new IllegalStateException();
    }
}
 
Example #19
Source File: OutputStreamCodeWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public OutputStream openBinary(JPackage pkg, String fileName)
                throws IOException {
        return new FilterOutputStream(out) {
                public void close() {
                        // don't let this stream close
                }
        };
}
 
Example #20
Source File: ProgressCodeWriter.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void report(JPackage pkg, String fileName) {
    if(pkg == null || pkg.isUnnamed())
        progress.println(fileName);
    else
        progress.println(
            pkg.name().replace('.',File.separatorChar)
                +File.separatorChar+fileName);
}
 
Example #21
Source File: ObjectFactoryGeneratorImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public ObjectFactoryGeneratorImpl( BeanGenerator outline, Model model, JPackage targetPackage ) {
    this.outline = outline;
    this.model = model;
    this.codeModel = this.model.codeModel;
    this.classRef = codeModel.ref(Class.class);

    // create the ObjectFactory class skeleton
    objectFactory = this.outline.getClassFactory().createClass(
            targetPackage, "ObjectFactory", null );
    objectFactory.annotate2(XmlRegistryWriter.class);

    // generate the default constructor
    //
    // m1 result:
    //        public ObjectFactory() {}
    JMethod m1 = objectFactory.constructor(JMod.PUBLIC);
    m1.javadoc().append("Create a new ObjectFactory that can be used to " +
                     "create new instances of schema derived classes " +
                     "for package: " + targetPackage.name());

    // add some class javadoc
    objectFactory.javadoc().append(
        "This object contains factory methods for each \n" +
        "Java content interface and Java element interface \n" +
        "generated in the " + targetPackage.name() + " package. \n" +
        "<p>An ObjectFactory allows you to programatically \n" +
        "construct new instances of the Java representation \n" +
        "for XML content. The Java representation of XML \n" +
        "content can consist of schema derived interfaces \n" +
        "and classes representing the binding of schema \n" +
        "type definitions, element declarations and model \n" +
        "groups.  Factory methods for each of these are \n" +
        "provided in this class." );

}
 
Example #22
Source File: FilerCodeWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    StandardLocation loc;
    if(fileName.endsWith(".java")) {
        // Annotation Processing doesn't do the proper Unicode escaping on Java source files,
        // so we can't rely on Filer.createSourceFile.
        loc = SOURCE_PATH;
    } else {
        // put non-Java files directly to the output folder
        loc = CLASS_PATH;
    }
    return filer.createResource(loc, pkg.name(), fileName).openOutputStream();
}
 
Example #23
Source File: ProgressCodeWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void report(JPackage pkg, String fileName) {
    String name = pkg.name().replace('.', File.separatorChar);
    if(name.length()!=0)    name +=     File.separatorChar;
    name += fileName;

    if(progress.isCanceled())
        throw new AbortException();
    progress.generatedFile(name,current++,totalFileCount);
}
 
Example #24
Source File: ZipCodeWriter.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    String name = fileName;
    if(!pkg.isUnnamed())    name = toDirName(pkg)+name;

    zip.putNextEntry(new ZipEntry(name));
    return filter;
}
 
Example #25
Source File: ProgressCodeWriter.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void report(JPackage pkg, String fileName) {
    String name = pkg.name().replace('.', File.separatorChar);
    if(name.length()!=0)    name +=     File.separatorChar;
    name += fileName;

    if(progress.isCanceled())
        throw new AbortException();
    progress.generatedFile(name,current++,totalFileCount);
}
 
Example #26
Source File: SingleStreamCodeWriter.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    String pkgName = pkg.name();
    if(pkgName.length()!=0)     pkgName += '.';

    out.println(
        "-----------------------------------" + pkgName+fileName +
        "-----------------------------------");

    return new FilterOutputStream(out) {
        public void close() {
            // don't let this stream close
        }
    };
}
 
Example #27
Source File: ProgressCodeWriter.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void report(JPackage pkg, String fileName) {
    String name = pkg.name().replace('.', File.separatorChar);
    if(name.length()!=0)    name +=     File.separatorChar;
    name += fileName;

    if(progress.isCanceled())
        throw new AbortException();
    progress.generatedFile(name,current++,totalFileCount);
}
 
Example #28
Source File: SingleStreamCodeWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public OutputStream openBinary(JPackage pkg, String fileName) throws IOException {
    String pkgName = pkg.name();
    if(pkgName.length()!=0)     pkgName += '.';

    out.println(
        "-----------------------------------" + pkgName+fileName +
        "-----------------------------------");

    return new FilterOutputStream(out) {
        public void close() {
            // don't let this stream close
        }
    };
}
 
Example #29
Source File: SignatureWriter.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void dump( JPackage pkg ) throws IOException {
    println("package "+pkg.name()+" {");
    indent++;
    dumpChildren(pkg);
    indent--;
    println("}");
}
 
Example #30
Source File: FilerCodeWriter.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public Writer openSource(JPackage pkg, String fileName) throws IOException {
    String tmp = fileName.substring(0, fileName.length()-5);
    if (pkg.name() != null && ! "".equals(pkg.name())) {
            w = filer.createSourceFile(pkg.name() + "." + tmp).openWriter();
    } else {
            w = filer.createSourceFile(tmp).openWriter();
    }
    return w;
}