private static List<MethodParameterModel> parametersForInstanceFields(final ClassModelBuilder builder, final TypeElement typeElement) { return builder.build().getFields().stream() .filter(f -> !f.getModifiers().contains("static")) .sorted(Comparator.comparing(fieldModel -> unescapeJavaKeyword(fieldModel.getName()))) .map(f -> { final MethodParameterModel p = new MethodParameterModel(); p.setModifiers(asList("final")); p.setType(f.getType()); p.setName(f.getName()); if (f.getType().endsWith("Boolean")) { final Element element = elementStreamIncludingInterfaces(typeElement) .filter(t -> t.getSimpleName().toString().equals("is" + capitalize(unescapeJavaKeyword(f.getName())))) .filter(t -> t.getAnnotation(JsonProperty.class) != null) .findFirst() .orElseThrow(() -> new RuntimeException("Boolean getter '" + f.getName() + "' for " + typeElement + " needs @JsonProperty annotation to find the right name")); final JsonProperty jsonProperty = element.getAnnotation(JsonProperty.class); final AnnotationModel annotationModel = new AnnotationModel(); annotationModel.setName(jsonProperty.annotationType().getName()); annotationModel.setValue(jsonProperty.value()); p.setAnnotations(singletonList(annotationModel)); } return p; }) .collect(Collectors.toList()); }
private static List<MethodParameterModel> parametersForInstanceFields(final ClassModelBuilder builder, final TypeElement typeElement) { return builder.build().getFields().stream() .filter(f -> !f.getModifiers().contains("static")) .sorted(Comparator.comparing(fieldModel -> unescapeJavaKeyword(fieldModel.getName()))) .map(f -> { final MethodParameterModel p = new MethodParameterModel(); p.setModifiers(asList("final")); p.setType(f.getType()); p.setName(f.getName()); if (f.getType().endsWith("Boolean")) { final Element element = elementStreamIncludingInterfaces(typeElement) .filter(t -> t.getSimpleName().toString().equals("is" + capitalize(unescapeJavaKeyword(f.getName())))) .filter(t -> t.getAnnotation(JsonProperty.class) != null) .findFirst() .orElseThrow(() -> new RuntimeException("Boolean getter '" + f.getName() + "' for " + typeElement + " needs @JsonProperty annotation to find the right name")); final JsonProperty jsonProperty = element.getAnnotation(JsonProperty.class); final AnnotationModel annotationModel = new AnnotationModel(); annotationModel.setName(jsonProperty.annotationType().getName()); annotationModel.setValue(jsonProperty.value()); p.setAnnotations(singletonList(annotationModel)); } return p; }) .collect(Collectors.toList()); }