Skip to content

Commit

Permalink
fieldgenerator: Update AccessLevel detection, Fix #82
Browse files Browse the repository at this point in the history
  • Loading branch information
julgus committed Sep 10, 2020
1 parent 098ff23 commit f5e6c4c
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment

void generateFields(final Element annotatedElement, final Writer writer) throws IOException {




final String entityName = shortName(annotatedElement.asType().toString());
final String genEntityName = entityName + "$";

Expand Down Expand Up @@ -174,6 +171,7 @@ private String findGetter(final Element field,
final Set<String> isGetters,
final String entityName,
boolean lombokGetterAvailable) {

final String fieldName = field.getSimpleName().toString();
final String getterPrefix = isGetters.contains(fieldName)
? IS_PREFIX
Expand Down Expand Up @@ -395,9 +393,15 @@ private Optional<String> getterAccessLevel(final Element fieldElement) {

return map.values().stream()
.map(AnnotationValue::toString)
.filter(v -> v.contains("AccessLevel"))
.map(v -> v.substring(v.lastIndexOf(".") + 1)) // Format as simple name
.filter(this::isAccessLevel)
.findFirst();
}

private boolean isAccessLevel(String s) {
Set<String> validAccessLevels = Stream.of("PACKAGE", "NONE", "PRIVATE", "MODULE", "PROTECTED", "PUBLIC")
.collect(Collectors.collectingAndThen(toSet(), Collections::unmodifiableSet));
return validAccessLevels.contains(s);
}

}

0 comments on commit f5e6c4c

Please sign in to comment.