Example usage for javax.tools StandardLocation CLASS_OUTPUT

List of usage examples for javax.tools StandardLocation CLASS_OUTPUT

Introduction

In this page you can find the example usage for javax.tools StandardLocation CLASS_OUTPUT.

Prototype

StandardLocation CLASS_OUTPUT

To view the source code for javax.tools StandardLocation CLASS_OUTPUT.

Click Source Link

Document

Location of new class files.

Usage

From source file:org.versly.rest.wsdoc.AnnotationProcessor.java

private FileObject getOutputFile() throws IOException {
    return this.processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
            Utils.SERIALIZED_RESOURCE_LOCATION);
}

From source file:com.wavemaker.tools.compiler.ProjectCompiler.java

public String compile(Folder webAppRootFolder, Iterable<Folder> sources, Folder destination,
        Iterable<Resource> classpath) {
    try {//from   ww w.j a v  a 2 s .  c  o m
        if (webAppRootFolder != null) {
            copyRuntimeServiceFiles(webAppRootFolder, destination);
        }
        JavaCompiler compiler = new WaveMakerJavaCompiler();
        StandardJavaFileManager standardFileManager = compiler.getStandardFileManager(null, null, null);
        standardFileManager.setLocation(StandardLocation.CLASS_PATH, getStandardClassPath());
        ResourceJavaFileManager projectFileManager = new ResourceJavaFileManager(standardFileManager);
        projectFileManager.setLocation(StandardLocation.SOURCE_PATH, sources);
        ArrayList<Folder> destinations = new ArrayList<Folder>();
        destinations.add(destination);
        projectFileManager.setLocation(StandardLocation.CLASS_OUTPUT, destinations);
        projectFileManager.setLocation(StandardLocation.CLASS_PATH, classpath);
        Iterable<JavaFileObject> compilationUnits = projectFileManager.list(StandardLocation.SOURCE_PATH, "",
                Collections.singleton(Kind.SOURCE), true);
        StringWriter compilerOutput = new StringWriter();
        CompilationTask compilationTask = compiler.getTask(compilerOutput, projectFileManager, null,
                getCompilerOptions(), null, compilationUnits);
        if (!compilationTask.call()) {
            throw new WMRuntimeException("Compile failed with output:\n\n" + compilerOutput.toString());
        }
        return compilerOutput.toString();
    } catch (IOException e) {
        throw new WMRuntimeException("Compile error: " + e);
    }
}

From source file:com.predic8.membrane.annot.SpringConfigurationXSDGeneratingAnnotationProcessor.java

private void write() {
    try {/*w  w  w .  j  a v  a2s  .c  o  m*/
        FileObject o = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
                "META-INF/membrane.cache");
        BufferedWriter bw = new BufferedWriter(o.openWriter());
        try {
            bw.write("1\n");

            for (Map.Entry<Class<? extends Annotation>, HashSet<Element>> e : cache.entrySet()) {
                bw.write(e.getKey().getName());
                bw.write("\n");
                for (Element f : e.getValue()) {
                    bw.write(" ");
                    bw.write(((TypeElement) f).getQualifiedName().toString());
                    bw.write("\n");
                }
            }
        } finally {
            bw.close();
        }
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:name.martingeisse.webide.features.java.compiler.memfile.MemoryFileManager.java

@Override
public JavaFileObject getJavaFileForOutput(final Location location, final String className, final Kind kind,
        final FileObject sibling) throws IOException {
    final String loggingName = "java output file; location [" + location + "], class [" + className
            + "], kind [" + kind + "], sibling [" + sibling + "]";
    if (location == StandardLocation.CLASS_OUTPUT) {
        logger.trace("searching memory files: " + loggingName);
        final String key = getJavaFileName(className, kind);
        final FileObject file = outputFiles.get(key);
        if (file instanceof JavaFileObject) {
            logger.trace("key [" + key + "] found");
            return (JavaFileObject) file;
        } else {/*w w w. j  av  a  2 s  .com*/
            logger.trace("key [" + key + "] "
                    + (file == null ? "not found, creating" : "found but not a java file, replacing"));
            final IMemoryJavaFileObject javaFileObject = (kind == Kind.SOURCE ? new MemoryJavaFileObject(key)
                    : new MemoryClassFileObject(key));
            outputFiles.put(key, javaFileObject);
            return javaFileObject;
        }
    } else {
        logger.trace("skipping memory files for " + loggingName);
    }
    return super.getJavaFileForOutput(location, className, kind, sibling);
}

From source file:name.martingeisse.webide.features.java.compiler.memfile.MemoryFileManager.java

@Override
public boolean hasLocation(final Location location) {
    if ((location == StandardLocation.SOURCE_PATH || location == StandardLocation.CLASS_OUTPUT)) {
        logger.trace("memory file manager has location [" + location + "]");
        return true;
    } else {//  w  w  w.  j  a  v a 2 s .c o  m
        logger.trace(
                "memory file manager doesn't have location [" + location + "], passing to next file manager");
        return super.hasLocation(location);
    }
}

From source file:com.mastfrog.parameters.processor.Processor.java

@Override
public boolean process(Set<? extends TypeElement> set, RoundEnvironment re) {

    SourceVersion sv = processingEnv.getSourceVersion();
    if (sv.ordinal() > SourceVersion.RELEASE_7.ordinal()) {
        optionalType = "java.util.Optional";
    } else {//from   ww w  .j a v a2 s.c o m
        TypeElement el = processingEnv.getElementUtils().getTypeElement(optionalType);
        if (el == null) {
            optionalType = "com.mastfrog.util.Optional";
        } else {
            optionalType = "com.google.common.base.Optional";
            fromNullable = "fromNullable";
        }
    }

    Set<? extends Element> all = re.getElementsAnnotatedWith(Params.class);
    List<GeneratedParamsClass> interfaces = new LinkedList<>();
    outer: for (Element e : all) {
        TypeElement te = (TypeElement) e;
        if (te.getSimpleName().toString().endsWith("__GenPage")) {
            continue;
        }
        PackageElement pkg = findPackage(e);
        if (pkg == null) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                    "@Params may not be used in the default package", e);
            continue;
        }
        if (!isPageSubtype(te)) {
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                    "@Params must be used on a subclass of org.apache.wicket.Page", e);
            continue;
        }
        String className = te.getQualifiedName().toString();
        Params params = te.getAnnotation(Params.class);

        Map<String, List<String>> validators = validatorsForParam(e);
        GeneratedParamsClass inf = new GeneratedParamsClass(className, te, pkg, params, validators);

        if (!params.useRequestBody()) {
            checkConstructor(te, inf);
        }
        interfaces.add(inf);
        Set<String> names = new HashSet<>();
        for (Param param : params.value()) {
            //                if (param.required() && !param.defaultValue().isEmpty()) {
            //                    processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Don't set required to "
            //                            + "true if you are providing a default value - required makes it an error not "
            //                            + "to have a value, and if there is a default value, that error is an impossibility "
            //                            + "because it will always have a value.", e);
            //                    continue outer;
            //                }
            if (param.value().trim().isEmpty()) {
                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Empty parameter name", e);
                continue outer;
            }
            if (!isJavaIdentifier(param.value())) {
                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                        "Not a valid Java identifier: " + param.value(), e);
                continue outer;
            }
            if (!names.add(param.value())) {
                processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                        "Duplicate parameter name '" + param.value() + "'", e);
                continue outer;
            }
            for (char c : ";,./*!@&^/\\<>?'\"[]{}-=+)(".toCharArray()) {
                if (param.value().contains("" + c)) {
                    processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                            "Param name may not contain the character '" + c + "'", e);
                }
            }
            inf.add(param);
        }
    }
    Filer filer = processingEnv.getFiler();
    StringBuilder listBuilder = new StringBuilder();
    for (GeneratedParamsClass inf : interfaces) {
        try {
            String pth = inf.packageAsPath() + '/' + inf.className;
            pth = pth.replace('/', '.');
            JavaFileObject obj = filer.createSourceFile(pth, inf.el);
            try (OutputStream out = obj.openOutputStream()) {
                out.write(inf.toString().getBytes("UTF-8"));
            }
            listBuilder.append(inf.className).append('\n');
        } catch (Exception ex) {
            ex.printStackTrace();
            processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR,
                    "Error processing annotation: " + ex.getMessage(), inf.el);
            Logger.getLogger(Processor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (re.processingOver()) {
        try {
            FileObject list = filer.createResource(StandardLocation.CLASS_OUTPUT, "",
                    "META-INF/paramanos/bind.list", all.toArray(new Element[0]));
            try (OutputStream out = list.openOutputStream()) {
                out.write(listBuilder.toString().getBytes("UTF-8"));
            }
        } catch (FilerException ex) {
            Logger.getLogger(Processor.class.getName()).log(Level.INFO, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(Processor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return true;
}

From source file:name.martingeisse.webide.features.java.compiler.memfile.MemoryFileManager.java

/**
 * /*from w  ww .ja  v  a 2 s.c om*/
 */
private Iterable<JavaFileObject> listThis(final Location location, final String packageName,
        final Set<Kind> kinds, final boolean recurse) throws IOException {

    // determine the file map to use
    final Map<String, IMemoryFileObject> fileMap;
    if (location == StandardLocation.SOURCE_PATH && kinds.contains(Kind.SOURCE)) {
        fileMap = inputFiles;
    } else if (location == StandardLocation.CLASS_OUTPUT && kinds.contains(Kind.CLASS)) {
        fileMap = outputFiles;
    } else {
        return new ArrayList<JavaFileObject>();
    }

    // create a filtered iterator
    final Pattern namePattern = Pattern.compile("\\/" + (packageName.replace(".", "\\/")) + "\\/[^\\/]+");
    return new AbstractIterableWrapper<IMemoryFileObject, JavaFileObject>(fileMap.values()) {
        @Override
        protected JavaFileObject handleElement(final IMemoryFileObject element) {
            if (element instanceof JavaFileObject) {
                if (namePattern.matcher(element.getName()).matches()) {
                    return (JavaFileObject) element;
                }
            }
            return null;
        }
    };

}

From source file:org.shredzone.commons.taglib.processor.TaglibProcessor.java

/**
 * Generates a TLD file for the tag library.
 *
 * @param tldfile// w w  w.  j av  a 2  s  .  co  m
 *            name of the TLD file to be generated
 * @throws IOException
 *             when the generated TLD file could not be saved.
 */
private void generateTaglibTld(String tldfile) throws IOException {
    FileObject file = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", tldfile);
    try (PrintWriter out = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8"))) {
        out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
        out.println(
                "<!DOCTYPE taglib PUBLIC \"-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN\" \"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd\">");
        out.println("<!-- Generated file, do not edit! -->");
        out.println("<taglib>");
        out.printf("  <tlibversion>%s</tlibversion>", taglib.getTlibversion()).println();
        out.printf("  <jspversion>%s</jspversion>", taglib.getJspversion()).println();
        out.printf("  <shortname>%s</shortname>", taglib.getShortname()).println();
        out.printf("  <uri>%s</uri>", escapeXml(taglib.getUri())).println();
        out.printf("  <info>%s</info>", escapeXml(taglib.getInfo())).println();

        for (TagBean tag : new TreeSet<TagBean>(taglib.getTags())) {
            out.println("  <tag>");
            out.printf("    <name>%s</name>", tag.getName()).println();
            out.printf("    <tagclass>%s</tagclass>", tag.getProxyClassName()).println();
            out.printf("    <bodycontent>%s</bodycontent>", tag.getBodycontent()).println();
            if (tag.getInfo() != null) {
                out.printf("    <info>%s</info>", escapeXml(tag.getInfo())).println();
            }

            for (AttributeBean attr : new TreeSet<AttributeBean>(tag.getAttributes())) {
                out.println("    <attribute>");
                out.printf("      <name>%s</name>", attr.getName()).println();
                out.printf("      <required>%s</required>", String.valueOf(attr.isRequired())).println();
                out.printf("      <rtexprvalue>%s</rtexprvalue>", String.valueOf(attr.isRtexprvalue()))
                        .println();
                out.println("    </attribute>");
            }

            out.println("  </tag>");
        }

        out.println("</taglib>");
    }
}

From source file:com.spotify.docgenerator.JacksonJerseyAnnotationProcessor.java

private void writeJsonToFile(Filer filer, String resourceFile, Object obj) {
    try {/* w w  w .ja va2 s  .com*/
        final FileObject outputFile = filer.createResource(StandardLocation.CLASS_OUTPUT, "", resourceFile);
        try (final OutputStream out = outputFile.openOutputStream()) {
            out.write(NORMALIZING_OBJECT_WRITER.writeValueAsBytes(obj));
        }
    } catch (IOException e) {
        fatalError("Failed writing to " + resourceFile + "\n");
        e.printStackTrace();
    }
}

From source file:cop.raml.processor.RestProcessor.java

@NotNull
private static Config getConfig() {
    Filer filter = ThreadLocalContext.getProcessingEnv().getFiler();

    if (filter == null)
        return Config.NULL;

    try (InputStream in = filter.getResource(StandardLocation.CLASS_OUTPUT, "", Config.YAML)
            .openInputStream()) {/*  ww w.j av  a2 s .  co m*/
        return Config.builder().parse(IOUtils.toString(in, StandardCharsets.UTF_8)).build();
    } catch (Exception e) {
        ThreadLocalContext.getMessager().printMessage(ERROR,
                String.format("Cannot read YAML config: '%s'", e.getMessage()));
        return Config.NULL;
    }
}