gson-compile/gson-compile-processor-core/src/main/java/io/gitlab/jfronny/gson/compile/processor/core/AbstractProcessor2.java

45 lines
1.6 KiB
Java
Raw Normal View History

package io.gitlab.jfronny.gson.compile.processor.core;
2022-10-31 20:52:48 +01:00
2022-12-14 14:55:45 +01:00
import io.gitlab.jfronny.gson.compile.processor.core.value.ValueCreator;
import javax.annotation.processing.*;
import javax.lang.model.util.Elements;
2022-10-31 20:52:48 +01:00
import java.util.*;
import java.util.stream.Collectors;
public abstract class AbstractProcessor2 extends AbstractProcessor {
2022-12-14 14:55:45 +01:00
protected Messager message;
protected Filer filer;
protected ValueCreator valueCreator;
protected Elements elements;
protected boolean hasManifold = false;
@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
try {
Class.forName("manifold.ext.Model");
System.out.println("Detected manifold!");
hasManifold = true;
} catch (ClassNotFoundException e) {
hasManifold = false;
}
message = processingEnv.messager;
filer = processingEnv.filer;
elements = processingEnv.elementUtils;
valueCreator = new ValueCreator(processingEnv);
}
2022-10-31 20:52:48 +01:00
@Override
public Set<String> getSupportedAnnotationTypes() {
return Optional.ofNullable(this.getClass().getAnnotation(SupportedAnnotationTypes.class))
.map(SupportedAnnotationTypes::value)
.map(Set::of)
.or(() -> Optional.ofNullable(this.getClass().getAnnotation(SupportedAnnotationTypes2.class))
.map(SupportedAnnotationTypes2::value)
.map(Arrays::stream)
.map(s -> s.map(Class::getCanonicalName).collect(Collectors.toSet()))
).orElse(Set.of());
}
}