Example usage for javax.tools StandardLocation SOURCE_OUTPUT

List of usage examples for javax.tools StandardLocation SOURCE_OUTPUT

Introduction

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

Prototype

StandardLocation SOURCE_OUTPUT

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

Click Source Link

Document

Location of new source files.

Usage

From source file:dz.jtsgen.processor.helper.OutputHelper.java

public static List<String> findSourceLine(Compilation c, String packageName, String fileName, Pattern pattern)
        throws IOException {
    Assert.assertTrue(c.generatedFile(StandardLocation.SOURCE_OUTPUT, packageName, fileName).isPresent());
    JavaFileObject jfo = c.generatedFile(StandardLocation.SOURCE_OUTPUT, packageName, fileName).get();
    try (Reader r = jfo.openReader(false)) {
        return IOUtils.readLines(r).stream().filter((x) -> pattern.matcher(x).find())
                .collect(Collectors.toList());
    }//from   w  w  w  .  j  a v  a  2 s. c o  m
}

From source file:info.archinnov.achilles.internals.apt.processors.meta.AchillesProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!this.processed) {

        try {/*from w w w .  ja va2  s .c  o  m*/
            final GlobalParsingContext parsingContext = parseCodecRegistry(annotations, roundEnv);

            final List<EntityMetaSignature> tableAndViewSignatures = discoverAndValidateTablesAndViews(
                    annotations, roundEnv, parsingContext);

            final FunctionsContext udfContext = parseAndValidateFunctionRegistry(parsingContext, annotations,
                    roundEnv, tableAndViewSignatures);

            final TypeSpec managerFactoryBuilder = ManagerFactoryBuilderCodeGen.buildInstance();
            final ManagersAndDSLClasses managersAndDSLClasses = ManagerFactoryCodeGen.buildInstance(aptUtils,
                    tableAndViewSignatures, udfContext, parsingContext);

            aptUtils.printNote("[Achilles] Reading previously generated source files (if exist)");
            try {
                final FileObject resource = aptUtils.filer.getResource(StandardLocation.SOURCE_OUTPUT,
                        GENERATED_PACKAGE, MANAGER_FACTORY_BUILDER_CLASS);
                final File generatedSourceFolder = new File(resource.toUri().getRawPath()
                        .replaceAll("(.+/info/archinnov/achilles/generated/).+", "$1"));
                aptUtils.printNote("[Achilles] Cleaning previously generated source files folder : '%s'",
                        generatedSourceFolder.getPath());
                FileUtils.deleteDirectory(generatedSourceFolder);
            } catch (IOException ioe) {
                aptUtils.printNote(
                        "[Achilles] No previously generated source files found, proceed to code generation");
            }

            aptUtils.printNote("[Achilles] Generating CQL compatible types (used by the application) as class");
            for (TypeSpec typeSpec : FunctionParameterTypesCodeGen.buildParameterTypesClasses(udfContext)) {
                JavaFile.builder(FUNCTION_PACKAGE, typeSpec).build().writeTo(aptUtils.filer);
            }

            aptUtils.printNote("[Achilles] Generating SystemFunctions");
            JavaFile.builder(FUNCTION_PACKAGE, FunctionsRegistryCodeGen
                    .generateFunctionsRegistryClass(SYSTEM_FUNCTIONS_CLASS, SYSTEM_FUNCTIONS)).build()
                    .writeTo(aptUtils.filer);

            aptUtils.printNote("[Achilles] Generating FunctionsRegistry");
            JavaFile.builder(FUNCTION_PACKAGE, FunctionsRegistryCodeGen
                    .generateFunctionsRegistryClass(FUNCTIONS_REGISTRY_CLASS, udfContext.functionSignatures))
                    .build().writeTo(aptUtils.filer);

            aptUtils.printNote("[Achilles] Generating ManagerFactoryBuilder");
            JavaFile.builder(GENERATED_PACKAGE, managerFactoryBuilder).build().writeTo(aptUtils.filer);

            aptUtils.printNote("[Achilles] Generating Manager factory class");
            JavaFile.builder(GENERATED_PACKAGE, managersAndDSLClasses.managerFactoryClass).build()
                    .writeTo(aptUtils.filer);

            aptUtils.printNote("[Achilles] Generating UDT meta classes");
            for (TypeSpec typeSpec : parsingContext.udtTypes.values()) {
                JavaFile.builder(UDT_META_PACKAGE, typeSpec).build().writeTo(aptUtils.filer);
            }

            aptUtils.printNote("[Achilles] Generating entity meta classes");
            for (EntityMetaSignature signature : tableAndViewSignatures) {
                JavaFile.builder(ENTITY_META_PACKAGE, signature.sourceCode).build().writeTo(aptUtils.filer);
            }

            aptUtils.printNote("[Achilles] Generating manager classes");
            for (TypeSpec manager : managersAndDSLClasses.managerClasses) {
                JavaFile.builder(MANAGER_PACKAGE, manager).build().writeTo(aptUtils.filer);
            }

            aptUtils.printNote("[Achilles] Generating DSL classes");
            for (TypeSpec dsl : managersAndDSLClasses.dslClasses) {
                JavaFile.builder(DSL_PACKAGE, dsl).build().writeTo(aptUtils.filer);
            }
        } catch (AchillesException e) {
            e.printStackTrace();
            aptUtils.printError("Error while parsing: %s", e.getMessage(), e);
        } catch (IllegalStateException e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            aptUtils.printError("Error while parsing: %s", sw.toString(), e);
        } catch (IOException e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            aptUtils.printError("Fail generating source file : %s", sw.toString(), e);

        } catch (Throwable throwable) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            throwable.printStackTrace(pw);
            aptUtils.printError("Fail generating source file : %s", sw.toString(), throwable);
        } finally {
            this.processed = true;
        }

    }
    return true;
}

From source file:ch.rasc.extclassgenerator.ModelAnnotationProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE,
            "Running " + getClass().getSimpleName());

    if (roundEnv.processingOver() || annotations.size() == 0) {
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }/*from ww w  . j  a va 2 s. c  o  m*/

    if (roundEnv.getRootElements() == null || roundEnv.getRootElements().isEmpty()) {
        this.processingEnv.getMessager().printMessage(Diagnostic.Kind.NOTE, "No sources to process");
        return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
    }

    OutputConfig outputConfig = new OutputConfig();

    outputConfig.setDebug(!"false".equals(this.processingEnv.getOptions().get(OPTION_DEBUG)));
    boolean createBaseAndSubclass = "true"
            .equals(this.processingEnv.getOptions().get(OPTION_CREATEBASEANDSUBCLASS));

    String outputFormatString = this.processingEnv.getOptions().get(OPTION_OUTPUTFORMAT);
    outputConfig.setOutputFormat(OutputFormat.EXTJS4);
    if (StringUtils.hasText(outputFormatString)) {
        if (OutputFormat.TOUCH2.name().equalsIgnoreCase(outputFormatString)) {
            outputConfig.setOutputFormat(OutputFormat.TOUCH2);
        } else if (OutputFormat.EXTJS5.name().equalsIgnoreCase(outputFormatString)) {
            outputConfig.setOutputFormat(OutputFormat.EXTJS5);
        }
    }

    String includeValidationString = this.processingEnv.getOptions().get(OPTION_INCLUDEVALIDATION);
    outputConfig.setIncludeValidation(IncludeValidation.NONE);
    if (StringUtils.hasText(includeValidationString)) {
        if (IncludeValidation.ALL.name().equalsIgnoreCase(includeValidationString)) {
            outputConfig.setIncludeValidation(IncludeValidation.ALL);
        } else if (IncludeValidation.BUILTIN.name().equalsIgnoreCase(includeValidationString)) {
            outputConfig.setIncludeValidation(IncludeValidation.BUILTIN);
        }
    }

    outputConfig.setUseSingleQuotes("true".equals(this.processingEnv.getOptions().get(OPTION_USESINGLEQUOTES)));
    outputConfig.setSurroundApiWithQuotes(
            "true".equals(this.processingEnv.getOptions().get(OPTION_SURROUNDAPIWITHQUOTES)));

    for (TypeElement annotation : annotations) {
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
        for (Element element : elements) {

            try {
                TypeElement typeElement = (TypeElement) element;

                String qualifiedName = typeElement.getQualifiedName().toString();
                Class<?> modelClass = Class.forName(qualifiedName);

                String code = ModelGenerator.generateJavascript(modelClass, outputConfig);

                Model modelAnnotation = element.getAnnotation(Model.class);
                String modelName = modelAnnotation.value();
                String fileName;
                String packageName = "";
                if (StringUtils.hasText(modelName)) {
                    int lastDot = modelName.lastIndexOf('.');
                    if (lastDot != -1) {
                        fileName = modelName.substring(lastDot + 1);
                        int firstDot = modelName.indexOf('.');
                        if (firstDot < lastDot) {
                            packageName = modelName.substring(firstDot + 1, lastDot);
                        }
                    } else {
                        fileName = modelName;
                    }
                } else {
                    fileName = typeElement.getSimpleName().toString();
                }

                if (createBaseAndSubclass) {
                    code = code.replaceFirst("(Ext.define\\([\"'].+?)([\"'],)", "$1Base$2");
                    FileObject fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT,
                            packageName, fileName + "Base.js");
                    OutputStream os = fo.openOutputStream();
                    os.write(code.getBytes(ModelGenerator.UTF8_CHARSET));
                    os.close();

                    try {
                        fo = this.processingEnv.getFiler().getResource(StandardLocation.SOURCE_OUTPUT,
                                packageName, fileName + ".js");
                        InputStream is = fo.openInputStream();
                        is.close();
                    } catch (FileNotFoundException e) {
                        String subClassCode = generateSubclassCode(modelClass, outputConfig);
                        fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT,
                                packageName, fileName + ".js");
                        os = fo.openOutputStream();
                        os.write(subClassCode.getBytes(ModelGenerator.UTF8_CHARSET));
                        os.close();
                    }

                } else {
                    FileObject fo = this.processingEnv.getFiler().createResource(StandardLocation.SOURCE_OUTPUT,
                            packageName, fileName + ".js");
                    OutputStream os = fo.openOutputStream();
                    os.write(code.getBytes(ModelGenerator.UTF8_CHARSET));
                    os.close();
                }

            } catch (ClassNotFoundException e) {
                this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
            } catch (IOException e) {
                this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, e.getMessage());
            }

        }
    }

    return ALLOW_OTHER_PROCESSORS_TO_CLAIM_ANNOTATIONS;
}

From source file:org.jannocessor.processor.JannocessorProcessorBase.java

protected String getOutputPath() {
    if (outputPath == null) {
        outputPath = getPath(StandardLocation.SOURCE_OUTPUT);
    }
    return outputPath;
}

From source file:org.squashtest.tm.tools.annotation.processor.DynamicComponentProcessor.java

private Writer openWriter() throws IOException {
    FileObject file;//w  ww  .  jav  a 2 s  . c om
    Writer writer;
    file = filer.createResource(StandardLocation.SOURCE_OUTPUT, "spring", generatedFileName(),
            (Element[]) null);

    writer = file.openWriter();
    return writer;
}