Skip to content

Commit

Permalink
Internal change.
Browse files Browse the repository at this point in the history
RELNOTES=n/a
PiperOrigin-RevId: 540119503
  • Loading branch information
eamonnmcmanus authored and Google Java Core Libraries committed Jun 14, 2023
1 parent 15ac833 commit d37e51d
Showing 1 changed file with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -214,27 +215,17 @@ static boolean isValidIdentifier(String identifier) {
}

private ImmutableSet<AnnotationMirror> annotationsToAdd(Element element) {
ImmutableSet.Builder<AnnotationMirror> annotationsBuilder = ImmutableSet.builder();

ImmutableSet<? extends AnnotationMirror> containers =
AnnotationMirrors.getAnnotatedAnnotations(element, AnnotationsToApply.class);
switch (containers.size()) {
case 1:
annotationsBuilder.addAll(extractAnnotationsToApply(getOnlyElement(containers)));
break;
case 0:
break;
default:
messager.printMessage(
ERROR, "Multiple @AnnotationsToApply annotations are not supported", element);
if (containers.size() > 1) {
messager.printMessage(
ERROR, "Multiple @AnnotationsToApply annotations are not supported", element);
}

return annotationsBuilder.build();
}

private ImmutableSet<AnnotationMirror> extractAnnotationsToApply(
AnnotationMirror annotationsToApply) {
return elements.getElementValuesWithDefaults(annotationsToApply).values().stream()
return containers.stream()
.limit(1)
.map(elements::getElementValuesWithDefaults)
.map(Map::values)
.flatMap(Collection::stream)
.map(AnnotationValue::getValue)
.filter(AnnotationMirror.class::isInstance)
// Any non-annotation element should already have been flagged when processing
Expand Down

0 comments on commit d37e51d

Please sign in to comment.