use of javaslang.match.model.ClassModel in project javaslang by javaslang.
the class PatternsProcessor method generate.
// Expands all @Patterns classes
private void generate(Set<ClassModel> classModels) {
final Filer filer = processingEnv.getFiler();
for (ClassModel classModel : classModels) {
final String derivedClassName = deriveClassName(classModel);
final String code = Generator.generate(derivedClassName, classModel);
final String fqn = (classModel.hasDefaultPackage() ? "" : classModel.getPackageName() + ".") + derivedClassName;
try (final Writer writer = filer.createSourceFile(fqn, classModel.typeElement()).openWriter()) {
writer.write(code);
} catch (IOException x) {
throw new Error("Error writing " + fqn, x);
}
}
}
use of javaslang.match.model.ClassModel in project javaslang by javaslang.
the class PatternsProcessor method transform.
// Verify correct usage of annotations @Patterns and @Unapply
private Set<ClassModel> transform(Set<TypeElement> typeElements) {
final Set<ClassModel> classModels = new HashSet<>();
final javax.lang.model.util.Elements elementUtils = processingEnv.getElementUtils();
final Messager messager = processingEnv.getMessager();
for (TypeElement typeElement : typeElements) {
final ClassModel classModel = ClassModel.of(elementUtils, typeElement);
final List<MethodModel> methodModels = classModel.getMethods().stream().filter(method -> method.isAnnotatedWith(Unapply.class)).collect(toList());
if (methodModels.isEmpty()) {
messager.printMessage(Diagnostic.Kind.WARNING, "No @Unapply methods found.", classModel.typeElement());
} else {
final boolean methodsValid = methodModels.stream().reduce(true, (bool, method) -> bool && UnapplyChecker.isValid(method.getExecutableElement(), messager), (b1, b2) -> b1 && b2);
if (methodsValid) {
classModels.add(classModel);
}
}
}
return classModels;
}
Aggregations