Search in sources :

Example 16 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project graal by oracle.

the class AbstractRegistrationProcessor method generateServicesRegistration.

static void generateServicesRegistration(String providerBinName, Map<String, Element> providerRegistrations) {
    ProcessorContext context = ProcessorContext.getInstance();
    ProcessingEnvironment env = context.getEnvironment();
    Elements elements = env.getElementUtils();
    String filename = "META-INF/services/" + providerBinName;
    List<String> providerClassNames = new ArrayList<>(providerRegistrations.size());
    for (String providerFqn : providerRegistrations.keySet()) {
        TypeElement te = ElementUtils.getTypeElement(env, providerFqn);
        if (te == null) {
            providerClassNames.add(providerFqn);
        } else {
            providerClassNames.add(elements.getBinaryName(te).toString());
        }
    }
    Collections.sort(providerClassNames);
    if (!providerClassNames.isEmpty()) {
        try {
            FileObject file = env.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", filename, providerRegistrations.values().toArray(new Element[providerRegistrations.size()]));
            try (PrintWriter out = new PrintWriter(new OutputStreamWriter(file.openOutputStream(), "UTF-8"))) {
                for (String providerClassName : providerClassNames) {
                    out.println(providerClassName);
                }
            }
        } catch (IOException e) {
            handleIOError(e, env, providerRegistrations.values().iterator().next());
        }
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) TypeElement(javax.lang.model.element.TypeElement) CodeExecutableElement(com.oracle.truffle.dsl.processor.java.model.CodeExecutableElement) CodeTypeElement(com.oracle.truffle.dsl.processor.java.model.CodeTypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) ArrayList(java.util.ArrayList) OutputStreamWriter(java.io.OutputStreamWriter) FileObject(javax.tools.FileObject) IOException(java.io.IOException) Elements(javax.lang.model.util.Elements) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) PrintWriter(java.io.PrintWriter)

Example 17 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project error-prone by google.

the class DataFlow method methodDataflow.

/**
 * Run the {@code transfer} dataflow analysis over the method or lambda which is the leaf of the
 * {@code methodPath}.
 *
 * <p>For caching, we make the following assumptions: - if two paths to methods are {@code equal},
 * their control flow graph is the same. - if two transfer functions are {@code equal}, and are
 * run over the same control flow graph, the analysis result is the same. - for all contexts, the
 * analysis result is the same.
 */
private static <A extends AbstractValue<A>, S extends Store<S>, T extends ForwardTransferFunction<A, S>> Result<A, S, T> methodDataflow(TreePath methodPath, Context context, T transfer) {
    ProcessingEnvironment env = JavacProcessingEnvironment.instance(context);
    ControlFlowGraph cfg;
    try {
        cfg = cfgCache.getUnchecked(CfgParams.create(methodPath, env));
    } catch (UncheckedExecutionException e) {
        throw e.getCause() instanceof CompletionFailure ? (CompletionFailure) e.getCause() : e;
    }
    AnalysisParams aparams = AnalysisParams.create(transfer, cfg, env);
    @SuppressWarnings("unchecked") Analysis<A, S, T> analysis = (Analysis<A, S, T>) analysisCache.getUnchecked(aparams);
    return new Result<A, S, T>() {

        @Override
        public Analysis<A, S, T> getAnalysis() {
            return analysis;
        }

        @Override
        public ControlFlowGraph getControlFlowGraph() {
            return cfg;
        }
    };
}
Also used : UncheckedExecutionException(com.google.common.util.concurrent.UncheckedExecutionException) UnderlyingAST(org.checkerframework.errorprone.dataflow.cfg.UnderlyingAST) CompletionFailure(com.sun.tools.javac.code.Symbol.CompletionFailure) Analysis(org.checkerframework.errorprone.dataflow.analysis.Analysis) ControlFlowGraph(org.checkerframework.errorprone.dataflow.cfg.ControlFlowGraph) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment)

Example 18 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project vue-gwt by Axellience.

the class ComponentTemplateProcessor method validateRefs.

private void validateRefs(Set<RefInfo> templateRefs, TypeElement component) {
    RefFieldValidator refFieldValidator = new RefFieldValidator(component, templateRefs, processingEnvironment);
    ElementFilter.fieldsIn(component.getEnclosedElements()).stream().filter(field -> hasAnnotation(field, Ref.class)).forEach(refFieldValidator::validateRefField);
}
Also used : Modifier(javax.lang.model.element.Modifier) Builder(com.squareup.javapoet.TypeSpec.Builder) GeneratorsUtil.hasAnnotation(com.axellience.vuegwt.processors.utils.GeneratorsUtil.hasAnnotation) ClassName(com.squareup.javapoet.ClassName) TypeElement(javax.lang.model.element.TypeElement) ComponentGeneratorsUtil.getSuperComponentType(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getSuperComponentType) Ref(com.axellience.vuegwt.core.annotations.component.Ref) Elements(javax.lang.model.util.Elements) HashSet(java.util.HashSet) FileObject(javax.tools.FileObject) ComponentGeneratorsUtil.getComponentLocalComponents(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil.getComponentLocalComponents) Kind(javax.tools.Diagnostic.Kind) RefFieldValidator(com.axellience.vuegwt.processors.component.template.parser.refs.RefFieldValidator) ComponentGeneratorsUtil(com.axellience.vuegwt.processors.utils.ComponentGeneratorsUtil) Computed(com.axellience.vuegwt.core.annotations.component.Computed) DeclaredType(javax.lang.model.type.DeclaredType) GeneratorsNameUtil.computedPropertyNameToFieldName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.computedPropertyNameToFieldName) Prop(com.axellience.vuegwt.core.annotations.component.Prop) URI(java.net.URI) ElementFilter(javax.lang.model.util.ElementFilter) IsVueComponent(com.axellience.vuegwt.core.client.component.IsVueComponent) Messager(javax.annotation.processing.Messager) TemplateMethodsBuilder(com.axellience.vuegwt.processors.component.template.builder.TemplateMethodsBuilder) StandardLocation(javax.tools.StandardLocation) Component(com.axellience.vuegwt.core.annotations.component.Component) Data(com.axellience.vuegwt.core.annotations.component.Data) TemplateParser(com.axellience.vuegwt.processors.component.template.parser.TemplateParser) MethodSpec(com.squareup.javapoet.MethodSpec) ExecutableElement(javax.lang.model.element.ExecutableElement) LocalComponents(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponents) TemplateParserResult(com.axellience.vuegwt.processors.component.template.parser.result.TemplateParserResult) Set(java.util.Set) ParameterizedTypeName(com.squareup.javapoet.ParameterizedTypeName) IOException(java.io.IOException) LocalComponent(com.axellience.vuegwt.processors.component.template.parser.context.localcomponents.LocalComponent) TypeMirror(javax.lang.model.type.TypeMirror) Filer(javax.annotation.processing.Filer) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) GeneratorsUtil.getComputedPropertyName(com.axellience.vuegwt.processors.utils.GeneratorsUtil.getComputedPropertyName) ComponentExposedTypeGenerator(com.axellience.vuegwt.processors.component.ComponentExposedTypeGenerator) MissingComponentAnnotationException(com.axellience.vuegwt.processors.utils.MissingComponentAnnotationException) TypeName(com.squareup.javapoet.TypeName) Optional(java.util.Optional) RefInfo(com.axellience.vuegwt.processors.component.template.parser.refs.RefInfo) TemplateParserContext(com.axellience.vuegwt.processors.component.template.parser.context.TemplateParserContext) GeneratorsNameUtil.componentToTagName(com.axellience.vuegwt.processors.utils.GeneratorsNameUtil.componentToTagName) RefFieldValidator(com.axellience.vuegwt.processors.component.template.parser.refs.RefFieldValidator)

Example 19 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project tikxml by Tickaroo.

the class TikXmlAutoValueExtension method applicable.

@Override
public boolean applicable(Context context) {
    ProcessingEnvironment environment = context.processingEnvironment();
    try {
        Xml xmlAnnotation = context.autoValueClass().getAnnotation(Xml.class);
        if (xmlAnnotation == null) {
            // Auto value class not annotated with @Xml annotation
            return false;
        }
        if (!xmlAnnotation.inheritance()) {
            throw new ProcessingException(context.autoValueClass(), "Inheritance in TikXml can't be disabled via @" + Xml.class.getSimpleName() + "(inheritance = false) in class " + context.autoValueClass().getQualifiedName());
        }
        List<AnnotatedMethod<?>> annotatedMethods = AutoValueScannerKt.extractAutoValueProperties(context.autoValueClass(), context.properties(), context.processingEnvironment().getTypeUtils(), context.processingEnvironment().getElementUtils());
        // generate code
        AutoValueAnnotatedClass annotatedClass = new AutoValueAnnotatedClass(context.packageName(), context.autoValueClass(), xmlAnnotation, annotatedMethods);
        try {
            Filer filer = context.processingEnvironment().getFiler();
            JavaFile.builder(context.packageName(), AutoValueTypeAdapterCodeGeneratorKt.generateValueHolder(annotatedClass, context.processingEnvironment().getElementUtils())).build().writeTo(filer);
            JavaFile.builder(context.packageName(), AutoValueTypeAdapterCodeGeneratorKt.generateTypeAdapter(annotatedClass)).build().writeTo(filer);
        } catch (IOException e) {
            throw new ProcessingException(annotatedClass.getAutoValueClass(), "Error while generating code for " + annotatedClass.getAutoValueClass().getQualifiedName() + ": " + e.getMessage());
        }
    } catch (ProcessingException exception) {
        environment.getMessager().printMessage(Diagnostic.Kind.ERROR, exception.getMessage(), exception.getElement());
    }
    // We don't generate code as an autovalue extension
    return false;
}
Also used : Xml(com.tickaroo.tikxml.annotation.Xml) IOException(java.io.IOException) ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment) Filer(javax.annotation.processing.Filer) ProcessingException(com.tickaroo.tikxml.processor.ProcessingException)

Example 20 with ProcessingEnvironment

use of javax.annotation.processing.ProcessingEnvironment in project linkki by linkki-framework.

the class TestProcessor method init.

@Override
public void init(ProcessingEnvironment processingEnv) {
    ProcessingEnvironment testProcessingEnvironment = new TestProcessingEnvironment(processingEnv, messager);
    delegate.init(testProcessingEnvironment);
}
Also used : ProcessingEnvironment(javax.annotation.processing.ProcessingEnvironment)

Aggregations

ProcessingEnvironment (javax.annotation.processing.ProcessingEnvironment)54 TypeElement (javax.lang.model.element.TypeElement)21 TypeMirror (javax.lang.model.type.TypeMirror)13 IOException (java.io.IOException)9 ExecutableElement (javax.lang.model.element.ExecutableElement)9 ArrayList (java.util.ArrayList)8 Set (java.util.Set)8 Element (javax.lang.model.element.Element)8 JavacProcessingEnvironment (com.sun.tools.javac.processing.JavacProcessingEnvironment)7 Collectors (java.util.stream.Collectors)7 AnnotatedTypeMirror (org.checkerframework.framework.type.AnnotatedTypeMirror)7 List (java.util.List)6 Map (java.util.Map)6 Modifier (javax.lang.model.element.Modifier)6 Elements (javax.lang.model.util.Elements)6 Types (javax.lang.model.util.Types)6 VariableElement (javax.lang.model.element.VariableElement)5 DeclaredType (javax.lang.model.type.DeclaredType)5 Annotation (java.lang.annotation.Annotation)4 Field (java.lang.reflect.Field)4