Skip to content

Commit

Permalink
mapper-processor: record annotation warning fix
Browse files Browse the repository at this point in the history
Java duplicates the annotation on the record's field to the corresponding
getter method as well.

This results in generating the warning when using records and exclusive field annotations.
This commit fixes the issue, so the compilation warning message is
not printed for records.
  • Loading branch information
muzarski committed Oct 26, 2023
1 parent b97a4de commit f699942
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,18 @@ private Optional<PropertyStrategy> getPropertyStrategy(Set<TypeElement> typeHier

private void reportMultipleAnnotationError(
Element element, Class<? extends Annotation> a0, Class<? extends Annotation> a1) {
if (a0 == a1) {
// A hack to prevent displaying warning messages when annotating record's fields.
// See: https://github.com/scylladb/java-driver/issues/246
boolean isParentRecord = element.getEnclosingElement().getKind().name().equals("RECORD");
if (a0 == a1 && !isParentRecord) {
context
.getMessager()
.warn(
element,
"@%s should be used either on the field or the getter, but not both. "
+ "The annotation on this field will be ignored.",
a0.getSimpleName());
} else {
} else if (a0 != a1) {
context
.getMessager()
.error(
Expand Down

0 comments on commit f699942

Please sign in to comment.