Search in sources :

Example 1 with MirrorTypeFactory

use of org.infinispan.protostream.annotations.impl.processor.types.MirrorTypeFactory in project protostream by infinispan.

the class CompileTimeProtoSchemaGenerator method getAdapterFor.

@Override
protected XClass getAdapterFor(XClass annotatedClass) {
    ProtoAdapter protoAdapter;
    try {
        protoAdapter = annotatedClass.getAnnotation(ProtoAdapter.class);
        if (protoAdapter == null) {
            return null;
        }
    } catch (ClassCastException e) {
        // javac soiling pants
        throw new ProtoSchemaBuilderException("The class referenced by the ProtoAdapter annotation " + "does not exist, possibly due to compilation errors in your source code or due to " + "incremental compilation issues caused by your build system. Please try a clean rebuild.");
    }
    // TODO [anistor] also ensure that typeMirror is not part of current serCtxInit and is not scanned for @ProtoXyz annotations even if present
    TypeMirror typeMirror = DangerousActions.getTypeMirror(protoAdapter, ProtoAdapter::value);
    XClass target = ((MirrorTypeFactory) typeFactory).fromTypeMirror(typeMirror);
    if (target == annotatedClass) {
        throw new ProtoSchemaBuilderException(annotatedClass.getName() + " has an invalid @ProtoAdapter annotation pointing to self");
    }
    return target;
}
Also used : ProtoSchemaBuilderException(org.infinispan.protostream.annotations.ProtoSchemaBuilderException) TypeMirror(javax.lang.model.type.TypeMirror) ProtoAdapter(org.infinispan.protostream.annotations.ProtoAdapter) XClass(org.infinispan.protostream.annotations.impl.types.XClass) MirrorTypeFactory(org.infinispan.protostream.annotations.impl.processor.types.MirrorTypeFactory)

Example 2 with MirrorTypeFactory

use of org.infinispan.protostream.annotations.impl.processor.types.MirrorTypeFactory in project protostream by infinispan.

the class AutoProtoSchemaBuilderAnnotationProcessor method init.

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    isDebugEnabled = Boolean.parseBoolean(processingEnv.getOptions().get(DEBUG_OPTION));
    typeFactory = new MirrorTypeFactory(processingEnv);
    types = processingEnv.getTypeUtils();
    elements = processingEnv.getElementUtils();
    filer = processingEnv.getFiler();
    messager = processingEnv.getMessager();
    generatedFilesWriter = new GeneratedFilesWriter(filer);
    ensureRequiredEnv();
}
Also used : MirrorTypeFactory(org.infinispan.protostream.annotations.impl.processor.types.MirrorTypeFactory)

Aggregations

MirrorTypeFactory (org.infinispan.protostream.annotations.impl.processor.types.MirrorTypeFactory)2 TypeMirror (javax.lang.model.type.TypeMirror)1 ProtoAdapter (org.infinispan.protostream.annotations.ProtoAdapter)1 ProtoSchemaBuilderException (org.infinispan.protostream.annotations.ProtoSchemaBuilderException)1 XClass (org.infinispan.protostream.annotations.impl.types.XClass)1