type) {
+ ClassLoader classLoader = type.getClassLoader();
+ InvocationHandler handler = new SynthesizedMergedAnnotationInvocationHandler<>(
+ annotation, type);
+ Class>[] interfaces = isVisible(classLoader, SynthesizedAnnotation.class)
+ ? new Class>[] { type, SynthesizedAnnotation.class }
+ : new Class>[] { type };
+ return (A) Proxy.newProxyInstance(classLoader, interfaces, handler);
+ }
+
+ private static boolean isVisible(ClassLoader classLoader, Class> interfaceClass) {
+ try {
+ return Class.forName(interfaceClass.getName(), false,
+ classLoader) == interfaceClass;
+ }
+ catch (ClassNotFoundException ex) {
+ return false;
+ }
+ }
+
+}
diff --git a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java
new file mode 100644
index 000000000000..3eaef51cb72f
--- /dev/null
+++ b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java
@@ -0,0 +1,614 @@
+/*
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.core.annotation;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Optional;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+import java.util.function.Predicate;
+
+import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
+import org.springframework.util.ClassUtils;
+import org.springframework.util.ReflectionUtils;
+
+/**
+ * {@link MergedAnnotation} that adapts attributes from a root annotation by
+ * applying the mapping and mirroring rules of an {@link AnnotationTypeMapping}.
+ *
+ * Root attribute values are extracted from a source object using a supplied
+ * {@code BiFunction}. This allows various different annotation models to be
+ * supported by the same class. For example, the attributes source might be an
+ * actual {@link Annotation} instance where methods on the annotation instance
+ * are {@link ReflectionUtils#invokeMethod(Method, Object) invoked} to extract
+ * values. Equally, the source could be a simple {@link Map} with values
+ * extracted using {@link Map#get(Object)}.
+ *
+ *
Extracted root attribute values must be compatible with the attribute
+ * return type, namely:
+ *
+ *