Skip to content

Commit

Permalink
Revert "Introduce isSynthesizable in MergedAnnotation"
Browse files Browse the repository at this point in the history
This reverts commit 32346b8.

Closes gh-29093
  • Loading branch information
sbrannen committed Sep 8, 2022
1 parent 75dfd47 commit 8a0e196
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -477,15 +477,6 @@ <T extends Annotation> MergedAnnotation<T>[] getAnnotationArray(String attribute
*/
<T extends Map<String, Object>> T asMap(Function<MergedAnnotation<?>, T> factory, Adapt... adaptations);

/**
* Determine if this merged annotation is <em>synthesizable</em>.
* <p>Consult the documentation for {@link #synthesize()} for an explanation
* of what is considered synthesizable.
* @return {@code true} if the mapped annotation is synthesizable
* @since 6.0
*/
boolean isSynthesizable();

/**
* Create a type-safe synthesized version of this merged annotation that can
* be used directly in code.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -134,11 +134,6 @@ public <T extends Map<String, Object>> T asMap(Function<MergedAnnotation<?>, T>
return factory.apply(this);
}

@Override
public boolean isSynthesizable() {
return false;
}

@Override
public String toString() {
return "(missing)";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,6 @@ private <T extends Map<String, Object>> Object adaptValueForMapOptions(Method at
return value;
}

@Override
public boolean isSynthesizable() {
// Is this a mapped annotation for a composed annotation, and are there
// annotation attributes (mirrors) that need to be merged?
if (getDistance() > 0 && this.resolvedMirrors.length > 0) {
return true;
}
// Is the mapped annotation itself synthesizable?
return this.mapping.isSynthesizable();
}

@Override
@SuppressWarnings("unchecked")
protected A createSynthesizedAnnotation() {
Expand Down Expand Up @@ -358,15 +347,22 @@ private boolean isTargetAnnotation(@Nullable Object obj) {
* Determine if the supplied annotation has not already been synthesized
* <strong>and</strong> whether the mapped annotation is a composed annotation
* that needs to have its attributes merged or the mapped annotation is
* {@linkplain #isSynthesizable() synthesizable} in general.
* {@linkplain AnnotationTypeMapping#isSynthesizable() synthesizable} in general.
* @param annotation the annotation to check
* @since 5.3.22
*/
private boolean isSynthesizable(Annotation annotation) {
// Already synthesized?
if (AnnotationUtils.isSynthesizedAnnotation(annotation)) {
return false;
}
return isSynthesizable();
// Is this a mapped annotation for a composed annotation, and are there
// annotation attributes (mirrors) that need to be merged?
if (getDistance() > 0 && this.resolvedMirrors.length > 0) {
return true;
}
// Is the mapped annotation itself synthesizable?
return this.mapping.isSynthesizable();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1504,13 +1504,6 @@ void synthesizeWithoutAttributeAliases() throws Exception {
assertThat(synthesizedComponent.value()).isEqualTo("webController");
}

@Test
void isSynthesizableWithoutAttributeAliases() throws Exception {
Component component = WebController.class.getAnnotation(Component.class);
assertThat(component).isNotNull();
assertThat(MergedAnnotation.from(component).isSynthesizable()).isFalse();
}

/**
* @since 6.0
*/
Expand Down Expand Up @@ -1595,16 +1588,10 @@ void synthesizeWhenUsingMergedAnnotationsFromApi() {
void synthesizeShouldNotSynthesizeNonsynthesizableAnnotationsWhenUsingMergedAnnotationsFromApi() {
MergedAnnotations mergedAnnotations = MergedAnnotations.from(SecurityConfig.class);

MergedAnnotation<EnableWebSecurity> enableWebSecurityAnnotation =
mergedAnnotations.get(EnableWebSecurity.class);
assertThat(enableWebSecurityAnnotation.isSynthesizable()).isFalse();
EnableWebSecurity enableWebSecurity = enableWebSecurityAnnotation.synthesize();
EnableWebSecurity enableWebSecurity = mergedAnnotations.get(EnableWebSecurity.class).synthesize();
assertNotSynthesized(enableWebSecurity);

MergedAnnotation<EnableGlobalAuthentication> enableGlobalAuthenticationMergedAnnotation =
mergedAnnotations.get(EnableGlobalAuthentication.class);
assertThat(enableGlobalAuthenticationMergedAnnotation.isSynthesizable()).isFalse();
EnableGlobalAuthentication enableGlobalAuthentication = enableGlobalAuthenticationMergedAnnotation.synthesize();
EnableGlobalAuthentication enableGlobalAuthentication = mergedAnnotations.get(EnableGlobalAuthentication.class).synthesize();
assertNotSynthesized(enableGlobalAuthentication);
}

Expand Down Expand Up @@ -1750,9 +1737,7 @@ void synthesizeWithImplicitAliases() throws Exception {
private void testSynthesisWithImplicitAliases(Class<?> clazz, String expected) throws Exception {
ImplicitAliasesTestConfiguration config = clazz.getAnnotation(ImplicitAliasesTestConfiguration.class);
assertThat(config).isNotNull();
MergedAnnotation<ImplicitAliasesTestConfiguration> mergedAnnotation = MergedAnnotation.from(config);
assertThat(mergedAnnotation.isSynthesizable()).isTrue();
ImplicitAliasesTestConfiguration synthesized = mergedAnnotation.synthesize();
ImplicitAliasesTestConfiguration synthesized = MergedAnnotation.from(config).synthesize();
assertSynthesized(synthesized);
assertThat(synthesized.value()).isEqualTo(expected);
assertThat(synthesized.location1()).isEqualTo(expected);
Expand All @@ -1779,11 +1764,8 @@ private void testSynthesisWithImplicitAliasesWithImpliedAliasNamesOmitted(
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration config = clazz.getAnnotation(
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration.class);
assertThat(config).isNotNull();
MergedAnnotation<ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration> mergedAnnotation =
MergedAnnotation.from(config);
assertThat(mergedAnnotation.isSynthesizable()).isTrue();
ImplicitAliasesWithImpliedAliasNamesOmittedTestConfiguration synthesized =
mergedAnnotation.synthesize();
MergedAnnotation.from(config).synthesize();
assertSynthesized(synthesized);
assertThat(synthesized.value()).isEqualTo(expected);
assertThat(synthesized.location()).isEqualTo(expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ void getDefaultValueReturnsEmpty() {
assertThat(this.missing.getDefaultValue("value", Integer.class)).isEmpty();
}

@Test
void isSynthesizableReturnsFalse() {
assertThat(this.missing.isSynthesizable()).isFalse();
}

@Test
void synthesizeThrowsNoSuchElementException() {
assertThatNoSuchElementException().isThrownBy(this.missing::synthesize);
Expand Down

0 comments on commit 8a0e196

Please sign in to comment.