Search in sources :

Example 1 with Patterns

use of javaslang.match.annotation.Patterns 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;
}
Also used : AbstractProcessor(javax.annotation.processing.AbstractProcessor) Patterns(javaslang.match.annotation.Patterns) Set(java.util.Set) TypeElement(javax.lang.model.element.TypeElement) IOException(java.io.IOException) Unapply(javaslang.match.annotation.Unapply) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) SourceVersion(javax.lang.model.SourceVersion) MethodModel(javaslang.match.model.MethodModel) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) RoundEnvironment(javax.annotation.processing.RoundEnvironment) Diagnostic(javax.tools.Diagnostic) Filer(javax.annotation.processing.Filer) Writer(java.io.Writer) Collections(java.util.Collections) Generator(javaslang.match.generator.Generator) Messager(javax.annotation.processing.Messager) ClassModel(javaslang.match.model.ClassModel) MethodModel(javaslang.match.model.MethodModel) Messager(javax.annotation.processing.Messager) ClassModel(javaslang.match.model.ClassModel) TypeElement(javax.lang.model.element.TypeElement) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 Writer (java.io.Writer)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 Patterns (javaslang.match.annotation.Patterns)1 Unapply (javaslang.match.annotation.Unapply)1 Generator (javaslang.match.generator.Generator)1 ClassModel (javaslang.match.model.ClassModel)1 MethodModel (javaslang.match.model.MethodModel)1 AbstractProcessor (javax.annotation.processing.AbstractProcessor)1 Filer (javax.annotation.processing.Filer)1 Messager (javax.annotation.processing.Messager)1 RoundEnvironment (javax.annotation.processing.RoundEnvironment)1 SourceVersion (javax.lang.model.SourceVersion)1 TypeElement (javax.lang.model.element.TypeElement)1 Diagnostic (javax.tools.Diagnostic)1