use of org.infinispan.protostream.annotations.impl.types.XClass in project protostream by infinispan.
the class ReservedProcessorTest method testDuplicateReservedName.
@Test
public void testDuplicateReservedName() {
expectedException.expect(ProtoSchemaBuilderException.class);
expectedException.expectMessage("Found duplicate @ProtoReserved name \"triceratops\" in org.infinispan.protostream.annotations.impl.ReservedProcessorTest.DuplicateName");
XClass classToTest = new ReflectionTypeFactory().fromClass(DuplicateName.class);
new ReservedProcessor().scan(classToTest);
}
use of org.infinispan.protostream.annotations.impl.types.XClass in project protostream by infinispan.
the class ReservedProcessorTest method testReservedNumbers.
@Test
public void testReservedNumbers() {
XClass classToTest = new ReflectionTypeFactory().fromClass(TestingReserved.class);
ReservedProcessor rp = new ReservedProcessor();
rp.scan(classToTest);
IndentWriter iw = new IndentWriter();
rp.generate(iw);
assertEquals("//reserved 1 to 7;\n//reserved \"a\", \"b\";\n", iw.toString());
}
use of org.infinispan.protostream.annotations.impl.types.XClass in project protostream by infinispan.
the class AutoProtoSchemaBuilderAnnotationProcessor method processClass.
private void processClass(RoundEnvironment roundEnv, SerializationContext serCtx, TypeElement typeElement, AutoProtoSchemaBuilder builderAnnotation, AnnotatedClassScanner classScanner, ProcessorContext processorContext) throws IOException {
if (typeElement.getNestingKind() == NestingKind.LOCAL || typeElement.getNestingKind() == NestingKind.ANONYMOUS) {
throw new AnnotationProcessingException(typeElement, "Classes or interfaces annotated with @AutoProtoSchemaBuilder must not be local or anonymous.");
}
if (typeElement.getNestingKind() == NestingKind.MEMBER && !typeElement.getModifiers().contains(Modifier.STATIC)) {
throw new AnnotationProcessingException(typeElement, "Nested classes or interfaces annotated with @AutoProtoSchemaBuilder must be static.");
}
if (typeElement.getModifiers().contains(Modifier.FINAL)) {
throw new AnnotationProcessingException(typeElement, "Classes annotated with @AutoProtoSchemaBuilder must not be final.");
}
if (!builderAnnotation.className().isEmpty() && (!SourceVersion.isIdentifier(builderAnnotation.className()) || SourceVersion.isKeyword(builderAnnotation.className()))) {
throw new AnnotationProcessingException(typeElement, "@AutoProtoSchemaBuilder.className annotation attribute must be a valid Java identifier and must not be fully qualified.");
}
TypeMirror serializationContextInitializerTypeMirror = elements.getTypeElement(SerializationContextInitializer.class.getName()).asType();
if (!types.isSubtype(typeElement.asType(), serializationContextInitializerTypeMirror)) {
throw new AnnotationProcessingException(typeElement, "Classes or interfaces annotated with @AutoProtoSchemaBuilder must implement/extend %s", SerializationContextInitializer.class.getName());
}
PackageElement packageElement = elements.getPackageOf(typeElement);
String initializerPackageName = packageElement.isUnnamed() ? null : packageElement.getQualifiedName().toString();
String initializerClassName = classScanner.getInitializerClassName();
String initializerFQN = classScanner.getInitializerFQClassName();
String protobufPackageName = builderAnnotation.schemaPackageName().isEmpty() ? null : builderAnnotation.schemaPackageName();
String protobufFileName = getProtobufFileName(typeElement, builderAnnotation);
ProcessorContext dependencies = processDependencies(roundEnv, serCtx, typeElement, builderAnnotation);
warnOverrideExistingMethods(typeElement);
Set<XClass> xclasses = classScanner.getXClasses();
CompileTimeProtoSchemaGenerator protoSchemaGenerator = new CompileTimeProtoSchemaGenerator(typeFactory, generatedFilesWriter, serCtx, typeElement.getQualifiedName().toString(), protobufFileName, protobufPackageName, dependencies.marshalledClasses, xclasses, builderAnnotation.autoImportClasses(), classScanner);
String schemaSrc = protoSchemaGenerator.generateAndRegister();
writeSerializationContextInitializer(typeElement, typeElement.getQualifiedName().toString(), builderAnnotation, dependencies.initializerClassNames, classScanner.getClasses(), protoSchemaGenerator.getGeneratedMarshallerClasses(), initializerPackageName, initializerClassName, initializerFQN, protobufFileName, protobufPackageName, schemaSrc);
processorContext.add(classScanner.getInitializerFQClassName(), protobufFileName, protoSchemaGenerator.getMarshalledClasses());
}
use of org.infinispan.protostream.annotations.impl.types.XClass in project protostream by infinispan.
the class AutoProtoSchemaBuilderAnnotationProcessor method warnOverrideExistingMethods.
private void warnOverrideExistingMethods(TypeElement typeElement) {
XClass annotatedType = typeFactory.fromTypeMirror(typeElement.asType());
warnOverrideExistingMethod(annotatedType, "getProtoFileName");
warnOverrideExistingMethod(annotatedType, "getProtoFile");
XClass serializationContextClass = typeFactory.fromClass(SerializationContext.class);
warnOverrideExistingMethod(annotatedType, "registerSchema", serializationContextClass);
warnOverrideExistingMethod(annotatedType, "registerMarshallers", serializationContextClass);
}
Aggregations