类 com.sun.codemodel.internal.JPackage 源码实例Demo

下面列出了怎么用 com.sun.codemodel.internal.JPackage 的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjdk-jdk8u   文件: PrologCodeWriter.java

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;
}
 

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;
}
 
源代码3 项目: openjdk-jdk8u   文件: SignatureWriter.java

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();
    }
 

/**
 * 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()]);
}
 
源代码5 项目: openjdk-8-source   文件: BeanGenerator.java

/**
 * 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()]);
}
 
源代码6 项目: jdk8u60   文件: PrologCodeWriter.java

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;
}
 
源代码7 项目: jdk8u60   文件: BeanGenerator.java

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();
}
 
源代码8 项目: openjdk-8   文件: PrologCodeWriter.java

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;
}
 
源代码9 项目: jdk8u60   文件: SignatureWriter.java

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();
    }
 
源代码10 项目: hottub   文件: PrologCodeWriter.java

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;
}
 
源代码11 项目: TencentKona-8   文件: WSCodeWriter.java

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;
}
 

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();
}
 
源代码13 项目: openjdk-jdk9   文件: ProgressCodeWriter.java

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);
}
 
源代码14 项目: openjdk-8   文件: FilerCodeWriter.java

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();
}
 
源代码15 项目: openjdk-8   文件: BindInfo.java

/**
 * 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);
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: WSCodeWriter.java

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;
}
 
源代码17 项目: TencentKona-8   文件: PackageOutlineImpl.java

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();
    }
}
 
源代码18 项目: openjdk-jdk8u   文件: BeanGenerator.java

public final JClass addRuntime(Class clazz) {
    JClass g = generatedRuntime.get(clazz);
    if (g == null) {
        // put code into a separate package to avoid name conflicts.
        JPackage implPkg = getUsedPackages(Aspect.IMPLEMENTATION)[0].subPackage("runtime");
        g = generateStaticClass(clazz, implPkg);
        generatedRuntime.put(clazz, g);
    }
    return g;
}
 
源代码19 项目: openjdk-8-source   文件: FilerCodeWriter.java

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();
}
 
源代码20 项目: TencentKona-8   文件: FilerCodeWriter.java

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();
}
 

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();
    }
}
 
源代码22 项目: hottub   文件: FilerCodeWriter.java

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();
}
 
源代码23 项目: openjdk-8   文件: ZipCodeWriter.java

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;
}
 
源代码24 项目: TencentKona-8   文件: ProgressCodeWriter.java

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);
}
 

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
        }
    };
}
 
源代码26 项目: openjdk-jdk8u   文件: SignatureWriter.java

private void dump( JPackage pkg ) throws IOException {
    println("package "+pkg.name()+" {");
    indent++;
    dumpChildren(pkg);
    indent--;
    println("}");
}
 

public OutputStream openBinary(JPackage pkg, String fileName)
                throws IOException {
        return new FilterOutputStream(out) {
                public void close() {
                        // don't let this stream close
                }
        };
}
 
源代码28 项目: jdk8u60   文件: FilerCodeWriter.java

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;
}
 
源代码29 项目: hottub   文件: SingleStreamCodeWriter.java

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
        }
    };
}
 

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);
}
 
 类所在包
 类方法
 同包方法