use of org.infinispan.protostream.annotations.AutoProtoSchemaBuilder in project protostream by infinispan.
the class AutoProtoSchemaBuilderAnnotationProcessor method processDependencies.
// todo [anistor] we do not support yet dependencies on packages, only on types
private ProcessorContext processDependencies(RoundEnvironment roundEnv, SerializationContext serCtx, Element annotatedElement, AutoProtoSchemaBuilder builderAnnotation) throws IOException {
List<? extends TypeMirror> dependencies = DangerousActions.getTypeMirrors(builderAnnotation, AutoProtoSchemaBuilder::dependsOn);
ProcessorContext processorContext = new ProcessorContext();
// register internal known types
processorContext.marshalledClasses.put(typeFactory.fromClass(WrappedMessage.class), WrappedMessage.PROTO_FILE);
for (TypeMirror dependencyType : dependencies) {
TypeElement dependencyElement = (TypeElement) types.asElement(dependencyType);
String dependencyFQN = dependencyElement.getQualifiedName().toString();
AutoProtoSchemaBuilder dependencyAnnotation = getBuilderAnnotation(dependencyElement);
if (dependencyAnnotation == null) {
throw new AnnotationProcessingException(annotatedElement, "Dependency %s is not annotated with @AutoProtoSchemaBuilder annotation", dependencyFQN);
}
if (!processedElementsFQN.add(dependencyFQN)) {
throw new AnnotationProcessingException(annotatedElement, "Illegal recursive dependency on %s", dependencyFQN);
}
// disable source file emission for dependencies because they are already compiled
boolean wasGenerationEnabled = generatedFilesWriter.isEnabled();
generatedFilesWriter.setEnabled(false);
processElement(roundEnv, serCtx, dependencyElement, dependencyAnnotation, processorContext);
// restore previous state of source file emission
generatedFilesWriter.setEnabled(wasGenerationEnabled);
processedElementsFQN.remove(dependencyFQN);
}
return processorContext;
}
use of org.infinispan.protostream.annotations.AutoProtoSchemaBuilder in project protostream by infinispan.
the class AutoProtoSchemaBuilderAnnotationProcessor method process.
// todo [anistor] check RoundEnvironment.errorRaised() and do not write any more output files if errors are present
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (isDebugEnabled) {
logDebug("AutoProtoSchemaBuilderAnnotationProcessor annotations=%s, rootElements=%s", annotations, roundEnv.getRootElements());
}
Optional<? extends TypeElement> claimedAnnotation = annotations.stream().filter(a -> a.getQualifiedName().contentEquals(ANNOTATION_NAME)).findAny();
try {
if (claimedAnnotation.isPresent()) {
for (Element annotatedElement : roundEnv.getElementsAnnotatedWith(claimedAnnotation.get())) {
AutoProtoSchemaBuilder builderAnnotation = getBuilderAnnotation(annotatedElement);
SerializationContext serCtx = ProtobufUtil.newSerializationContext();
try {
processElement(roundEnv, serCtx, annotatedElement, builderAnnotation, new ProcessorContext());
} catch (ProtoSchemaBuilderException | DescriptorParserException e) {
throw new AnnotationProcessingException(e, annotatedElement, "%s", getStackTraceAsString(e));
}
}
}
if (roundEnv.processingOver()) {
serviceLoaderFileGenerator.writeServiceFile(filer);
}
} catch (AnnotationProcessingException e) {
// this is caused by the user supplying incorrect data in the annotation or related classes
if (isDebugEnabled) {
logDebug("@AutoProtoSchemaBuilder processor threw an exception: %s", getStackTraceAsString(e));
}
reportError(e);
} catch (Exception e) {
// this may be a fatal programming error in the annotation processor itself
reportError(null, "@AutoProtoSchemaBuilder processor threw a fatal exception: %s", getStackTraceAsString(e));
}
return claimedAnnotation.isPresent();
}
Aggregations