Skip to content

Commit

Permalink
Merge pull request #42 from mercyblitz/1.0.11
Browse files Browse the repository at this point in the history
1.0.11
  • Loading branch information
mercyblitz authored Oct 13, 2020
2 parents b9967aa + 749cd29 commit ed713c9
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Current project that extends `spring-context` is based on Spring Framework 3.2.x
<dependency>
<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>1.0.10</version>
<version>1.0.11</version>
</dependency>

......
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>com.alibaba.spring</groupId>
<artifactId>spring-context-support</artifactId>
<version>1.0.10</version>
<version>1.0.11</version>

<properties>
<maven.compiler.source>1.6</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@

import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -60,6 +60,7 @@
import java.util.concurrent.ConcurrentMap;

import static com.alibaba.spring.util.AnnotationUtils.getAnnotationAttributes;
import static java.util.Collections.unmodifiableMap;
import static org.springframework.aop.support.AopUtils.getTargetClass;
import static org.springframework.core.BridgeMethodResolver.findBridgedMethod;
import static org.springframework.core.BridgeMethodResolver.isVisibilityBridgeMethodPair;
Expand Down Expand Up @@ -98,6 +99,39 @@ public abstract class AbstractAnnotationBeanPostProcessor extends
*/
private int order = Ordered.LOWEST_PRECEDENCE - 3;

/**
* whether to turn Class references into Strings (for
* compatibility with {@link org.springframework.core.type.AnnotationMetadata} or to
* preserve them as Class references
*
* @since 1.0.11
*/
private boolean classValuesAsString = true;

/**
* whether to turn nested Annotation instances into
* {@link AnnotationAttributes} maps (for compatibility with
* {@link org.springframework.core.type.AnnotationMetadata} or to preserve them as
* Annotation instances
*
* @since 1.0.11
*/
private boolean nestedAnnotationsAsMap = true;

/**
* whether ignore default value or not
*
* @since 1.0.11
*/
private boolean ignoreDefaultValue = true;

/**
* whether try merged annotation or not
*
* @since 1.0.11
*/
private boolean tryMergedAnnotation = true;

/**
* @param annotationTypes the multiple types of {@link Annotation annotations}
*/
Expand Down Expand Up @@ -169,7 +203,7 @@ public void doWith(Field field) throws IllegalArgumentException, IllegalAccessEx

for (Class<? extends Annotation> annotationType : getAnnotationTypes()) {

AnnotationAttributes attributes = getAnnotationAttributes(field, annotationType, getEnvironment(), true, true);
AnnotationAttributes attributes = doGetAnnotationAttributes(field, annotationType);

if (attributes != null) {

Expand Down Expand Up @@ -213,7 +247,7 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess

for (Class<? extends Annotation> annotationType : getAnnotationTypes()) {

AnnotationAttributes attributes = getAnnotationAttributes(bridgedMethod, annotationType, getEnvironment(), true, true);
AnnotationAttributes attributes = doGetAnnotationAttributes(bridgedMethod, annotationType);

if (attributes != null && method.equals(ClassUtils.getMostSpecificMethod(method, beanClass))) {
if (Modifier.isStatic(method.getModifiers())) {
Expand All @@ -238,6 +272,19 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
return elements;
}

/**
* Get {@link AnnotationAttributes}
*
* @param annotatedElement {@link AnnotatedElement the annotated element}
* @param annotationType the {@link Class tyoe} pf {@link Annotation annotation}
* @return if <code>annotatedElement</code> can't be found in <code>annotatedElement</code>, return <code>null</code>
* @since 1.0.11
*/
protected AnnotationAttributes doGetAnnotationAttributes(AnnotatedElement annotatedElement,
Class<? extends Annotation> annotationType) {
return getAnnotationAttributes(annotatedElement, annotationType, getEnvironment(),
classValuesAsString, nestedAnnotationsAsMap, ignoreDefaultValue, tryMergedAnnotation);
}

private AbstractAnnotationBeanPostProcessor.AnnotatedInjectionMetadata buildAnnotatedMetadata(final Class<?> beanClass) {
Collection<AbstractAnnotationBeanPostProcessor.AnnotatedFieldElement> fieldElements = findFieldAnnotationMetadata(beanClass);
Expand Down Expand Up @@ -430,7 +477,7 @@ protected Map<InjectionMetadata.InjectedElement, Object> getInjectedFieldObjects

}

return Collections.unmodifiableMap(injectedElementBeanMap);
return unmodifiableMap(injectedElementBeanMap);

}

Expand All @@ -456,8 +503,45 @@ protected Map<InjectionMetadata.InjectedElement, Object> getInjectedMethodObject

}

return Collections.unmodifiableMap(injectedElementBeanMap);
return unmodifiableMap(injectedElementBeanMap);

}

/**
* @param classValuesAsString whether to turn Class references into Strings (for
* compatibility with {@link org.springframework.core.type.AnnotationMetadata} or to
* preserve them as Class references
* @since 1.0.11
*/
public void setClassValuesAsString(boolean classValuesAsString) {
this.classValuesAsString = classValuesAsString;
}

/**
* @param nestedAnnotationsAsMap whether to turn nested Annotation instances into
* {@link AnnotationAttributes} maps (for compatibility with
* {@link org.springframework.core.type.AnnotationMetadata} or to preserve them as
* Annotation instances
* @since 1.0.11
*/
public void setNestedAnnotationsAsMap(boolean nestedAnnotationsAsMap) {
this.nestedAnnotationsAsMap = nestedAnnotationsAsMap;
}

/**
* @param ignoreDefaultValue whether ignore default value or not
* @since 1.0.11
*/
public void setIgnoreDefaultValue(boolean ignoreDefaultValue) {
this.ignoreDefaultValue = ignoreDefaultValue;
}

/**
* @param tryMergedAnnotation whether try merged annotation or not
* @since 1.0.11
*/
public void setTryMergedAnnotation(boolean tryMergedAnnotation) {
this.tryMergedAnnotation = tryMergedAnnotation;
}

/**
Expand Down
Loading

0 comments on commit ed713c9

Please sign in to comment.