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