Here are the examples of the java api org.springframework.core.type.MethodMetadata taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
50 Examples
19
Source : AbstractConfigurationClassTests.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private boolean isPublic(MethodMetadata methodMetadata) {
int access = (Integer) new DirectFieldAccessor(methodMetadata).getPropertyValue("access");
return (access & Opcodes.ACC_PUBLIC) != 0;
}
19
Source : NoSuchBeanDefinitionFailureAnalyzer.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private void collectExcludedAutoConfiguration(NoSuchBeanDefinitionException cause, List<AutoConfigurationResult> results) {
for (String excludedClreplaced : this.report.getExclusions()) {
Source source = new Source(excludedClreplaced);
BeanMethods methods = new BeanMethods(source, cause);
for (MethodMetadata method : methods) {
String message = String.format("auto-configuration '%s' was excluded", ClreplacedUtils.getShortName(excludedClreplaced));
results.add(new AutoConfigurationResult(method, new ConditionOutcome(false, message)));
}
}
}
19
Source : NoSuchBeanDefinitionFailureAnalyzer.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause, Source source, ConditionAndOutcomes sourceOutcomes, List<AutoConfigurationResult> results) {
if (sourceOutcomes.isFullMatch()) {
return;
}
BeanMethods methods = new BeanMethods(source, cause);
for (ConditionAndOutcome conditionAndOutcome : sourceOutcomes) {
if (!conditionAndOutcome.getOutcome().isMatch()) {
for (MethodMetadata method : methods) {
results.add(new AutoConfigurationResult(method, conditionAndOutcome.getOutcome()));
}
}
}
}
19
Source : SpringBootCondition.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private static String getClreplacedOrMethodName(AnnotatedTypeMetadata metadata) {
// 如果metadata是类,则返回类名
if (metadata instanceof ClreplacedMetadata) {
ClreplacedMetadata clreplacedMetadata = (ClreplacedMetadata) metadata;
return clreplacedMetadata.getClreplacedName();
}
// 如果metadata是方法,则返回方法名,形式为"类名#方法名"
MethodMetadata methodMetadata = (MethodMetadata) metadata;
return methodMetadata.getDeclaringClreplacedName() + "#" + methodMetadata.getMethodName();
}
19
Source : OnEnabledEndpointCondition.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private Clreplaced<?> getEndpointType(ConditionContext context, MethodMetadata metadata) {
Map<String, Object> attributes = metadata.getAnnotationAttributes(ConditionalOnEnabledEndpoint.clreplaced.getName());
if (attributes != null && attributes.containsKey("endpoint")) {
Clreplaced<?> target = (Clreplaced<?>) attributes.get("endpoint");
if (target != Void.clreplaced) {
return target;
}
}
// We should be safe to load at this point since we are in the REGISTER_BEAN phase
try {
return ClreplacedUtils.forName(metadata.getReturnTypeName(), context.getClreplacedLoader());
} catch (Throwable ex) {
throw new IllegalStateException("Failed to extract endpoint id for " + metadata.getDeclaringClreplacedName() + "." + metadata.getMethodName(), ex);
}
}
19
Source : ConfigurationMethod.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Base clreplaced for a {@link Configuration @Configuration} clreplaced method.
*
* @author Chris Beams
* @since 3.1
*/
abstract clreplaced ConfigurationMethod {
protected final MethodMetadata metadata;
protected final ConfigurationClreplaced configurationClreplaced;
public ConfigurationMethod(MethodMetadata metadata, ConfigurationClreplaced configurationClreplaced) {
this.metadata = metadata;
this.configurationClreplaced = configurationClreplaced;
}
public MethodMetadata getMetadata() {
return this.metadata;
}
public ConfigurationClreplaced getConfigurationClreplaced() {
return this.configurationClreplaced;
}
public Location getResourceLocation() {
return new Location(this.configurationClreplaced.getResource(), this.metadata);
}
String getFullyQualifiedMethodName() {
return this.metadata.getDeclaringClreplacedName() + "#" + this.metadata.getMethodName();
}
static String getShortMethodName(String fullyQualifiedMethodName) {
return fullyQualifiedMethodName.substring(fullyQualifiedMethodName.indexOf('#') + 1);
}
public void validate(ProblemReporter problemReporter) {
}
@Override
public String toString() {
return String.format("[%s:name=%s,declaringClreplaced=%s]", getClreplaced().getSimpleName(), getMetadata().getMethodName(), getMetadata().getDeclaringClreplacedName());
}
}
19
Source : ConfigurationClassParser.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Register default methods on interfaces implemented by the configuration clreplaced.
*/
private void processInterfaces(ConfigurationClreplaced configClreplaced, SourceClreplaced sourceClreplaced) throws IOException {
for (SourceClreplaced ifc : sourceClreplaced.getInterfaces()) {
Set<MethodMetadata> beanMethods = retrieveBeanMethodMetadata(ifc);
for (MethodMetadata methodMetadata : beanMethods) {
if (!methodMetadata.isAbstract()) {
// A default method or other concrete method on a Java 8+ interface...
configClreplaced.addBeanMethod(new BeanMethod(methodMetadata, configClreplaced));
}
}
processInterfaces(configClreplaced, ifc);
}
}
19
Source : AnnotatedGenericBeanDefinition.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Extension of the {@link org.springframework.beans.factory.support.GenericBeanDefinition}
* clreplaced, adding support for annotation metadata exposed through the
* {@link AnnotatedBeanDefinition} interface.
*
* <p>This GenericBeanDefinition variant is mainly useful for testing code that expects
* to operate on an AnnotatedBeanDefinition, for example strategy implementations
* in Spring's component scanning support (where the default definition clreplaced is
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition},
* which also implements the AnnotatedBeanDefinition interface).
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.5
* @see AnnotatedBeanDefinition#getMetadata()
* @see org.springframework.core.type.StandardAnnotationMetadata
*/
@SuppressWarnings("serial")
public clreplaced AnnotatedGenericBeanDefinition extends GenericBeanDefinition implements AnnotatedBeanDefinition {
private final AnnotationMetadata metadata;
@Nullable
private MethodMetadata factoryMethodMetadata;
/**
* Create a new AnnotatedGenericBeanDefinition for the given bean clreplaced.
* @param beanClreplaced the loaded bean clreplaced
*/
public AnnotatedGenericBeanDefinition(Clreplaced<?> beanClreplaced) {
setBeanClreplaced(beanClreplaced);
this.metadata = AnnotationMetadata.introspect(beanClreplaced);
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* allowing for ASM-based processing and avoidance of early loading of the bean clreplaced.
* Note that this constructor is functionally equivalent to
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
* ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
* bean was discovered specifically via component-scanning as opposed to other means.
* @param metadata the annotation metadata for the bean clreplaced in question
* @since 3.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
replacedert.notNull(metadata, "AnnotationMetadata must not be null");
if (metadata instanceof StandardAnnotationMetadata) {
setBeanClreplaced(((StandardAnnotationMetadata) metadata).getIntrospectedClreplaced());
} else {
setBeanClreplacedName(metadata.getClreplacedName());
}
this.metadata = metadata;
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* based on an annotated clreplaced and a factory method on that clreplaced.
* @param metadata the annotation metadata for the bean clreplaced in question
* @param factoryMethodMetadata metadata for the selected factory method
* @since 4.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata, MethodMetadata factoryMethodMetadata) {
this(metadata);
replacedert.notNull(factoryMethodMetadata, "MethodMetadata must not be null");
setFactoryMethodName(factoryMethodMetadata.getMethodName());
this.factoryMethodMetadata = factoryMethodMetadata;
}
@Override
public final AnnotationMetadata getMetadata() {
return this.metadata;
}
@Override
@Nullable
public final MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}
}
19
Source : ConfigurationClassParser.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
/**
* Register default methods on interfaces implemented by the configuration clreplaced.
*/
private void processInterfaces(ConfigurationClreplaced configClreplaced, SourceClreplaced sourceClreplaced) throws IOException {
// 获取接口
for (SourceClreplaced ifc : sourceClreplaced.getInterfaces()) {
// 接口上获取方法元数据
Set<MethodMetadata> beanMethods = retrieveBeanMethodMetadata(ifc);
for (MethodMetadata methodMetadata : beanMethods) {
if (!methodMetadata.isAbstract()) {
// A default method or other concrete method on a Java 8+ interface...
configClreplaced.addBeanMethod(new BeanMethod(methodMetadata, configClreplaced));
}
}
processInterfaces(configClreplaced, ifc);
}
}
19
Source : AnnotatedGenericBeanDefinition.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
/**
* Extension of the {@link org.springframework.beans.factory.support.GenericBeanDefinition}
* clreplaced, adding support for annotation metadata exposed through the
* {@link AnnotatedBeanDefinition} interface.
*
* <p>This GenericBeanDefinition variant is mainly useful for testing code that expects
* to operate on an AnnotatedBeanDefinition, for example strategy implementations
* in Spring's component scanning support (where the default definition clreplaced is
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition},
* which also implements the AnnotatedBeanDefinition interface).
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.5
* @see AnnotatedBeanDefinition#getMetadata()
* @see org.springframework.core.type.StandardAnnotationMetadata
*/
@SuppressWarnings("serial")
public clreplaced AnnotatedGenericBeanDefinition extends GenericBeanDefinition implements AnnotatedBeanDefinition {
/**
* 注解元信息
*/
private final AnnotationMetadata metadata;
/**
* 方法元信息
*/
@Nullable
private MethodMetadata factoryMethodMetadata;
/**
* Create a new AnnotatedGenericBeanDefinition for the given bean clreplaced.
* @param beanClreplaced the loaded bean clreplaced
*/
public AnnotatedGenericBeanDefinition(Clreplaced<?> beanClreplaced) {
setBeanClreplaced(beanClreplaced);
this.metadata = AnnotationMetadata.introspect(beanClreplaced);
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* allowing for ASM-based processing and avoidance of early loading of the bean clreplaced.
* Note that this constructor is functionally equivalent to
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
* ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
* bean was discovered specifically via component-scanning as opposed to other means.
* @param metadata the annotation metadata for the bean clreplaced in question
* @since 3.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
replacedert.notNull(metadata, "AnnotationMetadata must not be null");
if (metadata instanceof StandardAnnotationMetadata) {
setBeanClreplaced(((StandardAnnotationMetadata) metadata).getIntrospectedClreplaced());
} else {
setBeanClreplacedName(metadata.getClreplacedName());
}
this.metadata = metadata;
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* based on an annotated clreplaced and a factory method on that clreplaced.
* @param metadata the annotation metadata for the bean clreplaced in question
* @param factoryMethodMetadata metadata for the selected factory method
* @since 4.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata, MethodMetadata factoryMethodMetadata) {
this(metadata);
replacedert.notNull(factoryMethodMetadata, "MethodMetadata must not be null");
setFactoryMethodName(factoryMethodMetadata.getMethodName());
this.factoryMethodMetadata = factoryMethodMetadata;
}
@Override
public final AnnotationMetadata getMetadata() {
return this.metadata;
}
@Override
@Nullable
public final MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}
}
19
Source : ProteusBeanDefinitionRegistryPostProcessor.java
with Apache License 2.0
from netifi-proteus
with Apache License 2.0
from netifi-proteus
public static Clreplaced<?> resolveClreplaced(BeanDefinition beanDefinition) throws ClreplacedNotFoundException {
Clreplaced<?> clazz = null;
if (beanDefinition.getBeanClreplacedName() != null) {
clazz = ClreplacedUtils.forName(beanDefinition.getBeanClreplacedName(), beanDefinition.getClreplaced().getClreplacedLoader());
} else if (beanDefinition instanceof AnnotatedBeanDefinition) {
MethodMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata();
if (metadata != null) {
clazz = ClreplacedUtils.forName(metadata.getReturnTypeName(), beanDefinition.getClreplaced().getClreplacedLoader());
}
}
return clazz;
}
19
Source : AnnotatedGenericBeanDefinition.java
with MIT License
from mindcarver
with MIT License
from mindcarver
/**
* Extension of the {@link org.springframework.beans.factory.support.GenericBeanDefinition}
* clreplaced, adding support for annotation metadata exposed through the
* {@link AnnotatedBeanDefinition} interface.
*
* <p>This GenericBeanDefinition variant is mainly useful for testing code that expects
* to operate on an AnnotatedBeanDefinition, for example strategy implementations
* in Spring's component scanning support (where the default definition clreplaced is
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition},
* which also implements the AnnotatedBeanDefinition interface).
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.5
* @see AnnotatedBeanDefinition#getMetadata()
* @see org.springframework.core.type.StandardAnnotationMetadata
*/
@SuppressWarnings("serial")
public clreplaced AnnotatedGenericBeanDefinition extends GenericBeanDefinition implements AnnotatedBeanDefinition {
private final AnnotationMetadata metadata;
@Nullable
private MethodMetadata factoryMethodMetadata;
/**
* Create a new AnnotatedGenericBeanDefinition for the given bean clreplaced.
* @param beanClreplaced the loaded bean clreplaced
*/
public AnnotatedGenericBeanDefinition(Clreplaced<?> beanClreplaced) {
setBeanClreplaced(beanClreplaced);
this.metadata = new StandardAnnotationMetadata(beanClreplaced, true);
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* allowing for ASM-based processing and avoidance of early loading of the bean clreplaced.
* Note that this constructor is functionally equivalent to
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
* ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
* bean was discovered specifically via component-scanning as opposed to other means.
* @param metadata the annotation metadata for the bean clreplaced in question
* @since 3.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
replacedert.notNull(metadata, "AnnotationMetadata must not be null");
if (metadata instanceof StandardAnnotationMetadata) {
setBeanClreplaced(((StandardAnnotationMetadata) metadata).getIntrospectedClreplaced());
} else {
setBeanClreplacedName(metadata.getClreplacedName());
}
this.metadata = metadata;
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* based on an annotated clreplaced and a factory method on that clreplaced.
* @param metadata the annotation metadata for the bean clreplaced in question
* @param factoryMethodMetadata metadata for the selected factory method
* @since 4.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata, MethodMetadata factoryMethodMetadata) {
this(metadata);
replacedert.notNull(factoryMethodMetadata, "MethodMetadata must not be null");
setFactoryMethodName(factoryMethodMetadata.getMethodName());
this.factoryMethodMetadata = factoryMethodMetadata;
}
@Override
public final AnnotationMetadata getMetadata() {
return this.metadata;
}
@Override
@Nullable
public final MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}
}
19
Source : ConfigurationMethod.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* @author Chris Beams
* @since 3.1
*/
abstract clreplaced ConfigurationMethod {
protected final MethodMetadata metadata;
protected final ConfigurationClreplaced configurationClreplaced;
public ConfigurationMethod(MethodMetadata metadata, ConfigurationClreplaced configurationClreplaced) {
this.metadata = metadata;
this.configurationClreplaced = configurationClreplaced;
}
public MethodMetadata getMetadata() {
return this.metadata;
}
public ConfigurationClreplaced getConfigurationClreplaced() {
return this.configurationClreplaced;
}
public Location getResourceLocation() {
return new Location(this.configurationClreplaced.getResource(), this.metadata);
}
String getFullyQualifiedMethodName() {
return this.metadata.getDeclaringClreplacedName() + "#" + this.metadata.getMethodName();
}
static String getShortMethodName(String fullyQualifiedMethodName) {
return fullyQualifiedMethodName.substring(fullyQualifiedMethodName.indexOf('#') + 1);
}
public void validate(ProblemReporter problemReporter) {
}
@Override
public String toString() {
return String.format("[%s:name=%s,declaringClreplaced=%s]", getClreplaced().getSimpleName(), getMetadata().getMethodName(), getMetadata().getDeclaringClreplacedName());
}
}
19
Source : AnnotatedGenericBeanDefinition.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Extension of the {@link org.springframework.beans.factory.support.GenericBeanDefinition}
* clreplaced, adding support for annotation metadata exposed through the
* {@link AnnotatedBeanDefinition} interface.
*
* <p>This GenericBeanDefinition variant is mainly useful for testing code that expects
* to operate on an AnnotatedBeanDefinition, for example strategy implementations
* in Spring's component scanning support (where the default definition clreplaced is
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition},
* which also implements the AnnotatedBeanDefinition interface).
*
* @author Juergen Hoeller
* @author Chris Beams
* @since 2.5
* @see AnnotatedBeanDefinition#getMetadata()
* @see org.springframework.core.type.StandardAnnotationMetadata
*/
@SuppressWarnings("serial")
public clreplaced AnnotatedGenericBeanDefinition extends GenericBeanDefinition implements AnnotatedBeanDefinition {
private final AnnotationMetadata metadata;
private MethodMetadata factoryMethodMetadata;
/**
* Create a new AnnotatedGenericBeanDefinition for the given bean clreplaced.
* @param beanClreplaced the loaded bean clreplaced
*/
public AnnotatedGenericBeanDefinition(Clreplaced<?> beanClreplaced) {
setBeanClreplaced(beanClreplaced);
this.metadata = new StandardAnnotationMetadata(beanClreplaced, true);
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* allowing for ASM-based processing and avoidance of early loading of the bean clreplaced.
* Note that this constructor is functionally equivalent to
* {@link org.springframework.context.annotation.ScannedGenericBeanDefinition
* ScannedGenericBeanDefinition}, however the semantics of the latter indicate that a
* bean was discovered specifically via component-scanning as opposed to other means.
* @param metadata the annotation metadata for the bean clreplaced in question
* @since 3.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata) {
replacedert.notNull(metadata, "AnnotationMetadata must not be null");
if (metadata instanceof StandardAnnotationMetadata) {
setBeanClreplaced(((StandardAnnotationMetadata) metadata).getIntrospectedClreplaced());
} else {
setBeanClreplacedName(metadata.getClreplacedName());
}
this.metadata = metadata;
}
/**
* Create a new AnnotatedGenericBeanDefinition for the given annotation metadata,
* based on an annotated clreplaced and a factory method on that clreplaced.
* @param metadata the annotation metadata for the bean clreplaced in question
* @param factoryMethodMetadata metadata for the selected factory method
* @since 4.1.1
*/
public AnnotatedGenericBeanDefinition(AnnotationMetadata metadata, MethodMetadata factoryMethodMetadata) {
this(metadata);
replacedert.notNull(factoryMethodMetadata, "MethodMetadata must not be null");
setFactoryMethodName(factoryMethodMetadata.getMethodName());
this.factoryMethodMetadata = factoryMethodMetadata;
}
@Override
public final AnnotationMetadata getMetadata() {
return this.metadata;
}
@Override
public final MethodMetadata getFactoryMethodMetadata() {
return this.factoryMethodMetadata;
}
}
19
Source : SpringBootCondition.java
with Apache License 2.0
from landy8530
with Apache License 2.0
from landy8530
private static String getClreplacedOrMethodName(AnnotatedTypeMetadata metadata) {
if (metadata instanceof ClreplacedMetadata) {
ClreplacedMetadata clreplacedMetadata = (ClreplacedMetadata) metadata;
return clreplacedMetadata.getClreplacedName();
}
MethodMetadata methodMetadata = (MethodMetadata) metadata;
return methodMetadata.getDeclaringClreplacedName() + "#" + methodMetadata.getMethodName();
}
19
Source : NoSuchBeanDefinitionFailureAnalyzer.java
with Apache License 2.0
from hello-shf
with Apache License 2.0
from hello-shf
private void collectReportedConditionOutcomes(NoSuchBeanDefinitionException cause, Source source, ConditionAndOutcomes sourceOutcomes, List<AutoConfigurationResult> results) {
if (sourceOutcomes.isFullMatch()) {
return;
}
BeanMethods methods = new BeanMethods(source, cause);
for (ConditionAndOutcome conditionAndOutcome : sourceOutcomes) {
if (!conditionAndOutcome.getOutcome().isMatch()) {
for (MethodMetadata method : methods) {
results.add(new AutoConfigurationResult(method, conditionAndOutcome.getOutcome(), source.isMethod()));
}
}
}
}
19
Source : NoSuchBeanDefinitionFailureAnalyzer.java
with Apache License 2.0
from hello-shf
with Apache License 2.0
from hello-shf
private void collectExcludedAutoConfiguration(NoSuchBeanDefinitionException cause, List<AutoConfigurationResult> results) {
for (String excludedClreplaced : this.report.getExclusions()) {
Source source = new Source(excludedClreplaced);
BeanMethods methods = new BeanMethods(source, cause);
for (MethodMetadata method : methods) {
String message = String.format("auto-configuration '%s' was excluded", ClreplacedUtils.getShortName(excludedClreplaced));
results.add(new AutoConfigurationResult(method, new ConditionOutcome(false, message), false));
}
}
}
19
Source : OnEnabledEndpointCondition.java
with Apache License 2.0
from hello-shf
with Apache License 2.0
from hello-shf
private AnnotationAttributes getEndpointAttributes(ConditionContext context, MethodMetadata metadata) {
// We should be safe to load at this point since we are in the REGISTER_BEAN phase
try {
Clreplaced<?> returnType = ClreplacedUtils.forName(metadata.getReturnTypeName(), context.getClreplacedLoader());
return getEndpointAttributes(returnType);
} catch (Throwable ex) {
throw new IllegalStateException("Failed to extract endpoint id for " + metadata.getDeclaringClreplacedName() + "." + metadata.getMethodName(), ex);
}
}
19
Source : AnnotationRelationshipDetectorEdgeCasesTest.java
with Apache License 2.0
from cereebro
with Apache License 2.0
from cereebro
@Test
public void detectUnknownClreplaced() {
ConsumerHintAnnotationRelationshipDetector detector = new ConsumerHintAnnotationRelationshipDetector();
MethodMetadata metadataMock = Mockito.mock(MethodMetadata.clreplaced);
Mockito.when(metadataMock.getReturnTypeName()).thenReturn("com.n0pe.ISwearThisClreplacedWontExist");
Optional<ConsumerHint> result = detector.getAnnotation(metadataMock);
replacedertions.replacedertThat(result.isPresent()).isFalse();
}
19
Source : AnnotationRelationshipDetector.java
with Apache License 2.0
from cereebro
with Apache License 2.0
from cereebro
protected Set<Relationship> detectMethodMetadata(final MethodMetadata metadata) {
/*
* ... get the metadata of the current definition bean for the
* annotation DependencyHint. In this case, we retrieve the annotation
* on the annotated method @Bean. The map can be null.
*/
Map<String, Object> hintData = metadata.getAnnotationAttributes(annotation.getName());
/*
* ... get the Hint directly from the clreplaced (Target = ElementType.TYPE)
*/
Optional<T> methodAnnotation = getAnnotation(metadata);
Set<Relationship> rel = new HashSet<>();
if (!CollectionUtils.isEmpty(hintData)) {
rel.addAll(extractFromAnnotationAttributes(hintData));
} else if (methodAnnotation.isPresent()) {
rel.addAll(extractFromAnnotation(methodAnnotation.get()));
}
return rel;
}
19
Source : AnnotationRelationshipDetector.java
with Apache License 2.0
from cereebro
with Apache License 2.0
from cereebro
/**
* Get the annotation from the clreplaced instead of the {@link Bean} method.
*
* @param metadata
* Method metadata.
* @return An optional target annotation.
*/
protected Optional<T> getAnnotation(MethodMetadata metadata) {
try {
return Optional.ofNullable(Clreplaced.forName(metadata.getReturnTypeName()).getDeclaredAnnotation(annotation));
} catch (ClreplacedNotFoundException e) {
LOGGER.error("Could not load clreplaced : " + metadata.getReturnTypeName(), e);
}
return Optional.empty();
}
18
Source : SpringBootCondition.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private String getName(AnnotatedTypeMetadata metadata) {
if (metadata instanceof AnnotationMetadata) {
return ((AnnotationMetadata) metadata).getClreplacedName();
}
if (metadata instanceof MethodMetadata) {
MethodMetadata methodMetadata = (MethodMetadata) metadata;
return methodMetadata.getDeclaringClreplacedName() + "." + methodMetadata.getMethodName();
}
return metadata.toString();
}
18
Source : SimpleAnnotationMetadataReadingVisitor.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
public void visitEnd() {
String[] memberClreplacedNames = StringUtils.toStringArray(this.memberClreplacedNames);
MethodMetadata[] annotatedMethods = this.annotatedMethods.toArray(new MethodMetadata[0]);
MergedAnnotations annotations = MergedAnnotations.of(this.annotations);
this.metadata = new SimpleAnnotationMetadata(this.clreplacedName, this.access, this.enclosingClreplacedName, this.superClreplacedName, this.independentInnerClreplaced, this.interfaceNames, memberClreplacedNames, annotatedMethods, annotations);
}
18
Source : SimpleAnnotationMetadata.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* {@link AnnotationMetadata} created from a
* {@link SimpleAnnotationMetadataReadingVisitor}.
*
* @author Phillip Webb
* @since 5.2
*/
final clreplaced SimpleAnnotationMetadata implements AnnotationMetadata {
private final String clreplacedName;
private final int access;
@Nullable
private final String enclosingClreplacedName;
@Nullable
private final String superClreplacedName;
private final boolean independentInnerClreplaced;
private final String[] interfaceNames;
private final String[] memberClreplacedNames;
private final MethodMetadata[] annotatedMethods;
private final MergedAnnotations annotations;
@Nullable
private Set<String> annotationTypes;
SimpleAnnotationMetadata(String clreplacedName, int access, @Nullable String enclosingClreplacedName, @Nullable String superClreplacedName, boolean independentInnerClreplaced, String[] interfaceNames, String[] memberClreplacedNames, MethodMetadata[] annotatedMethods, MergedAnnotations annotations) {
this.clreplacedName = clreplacedName;
this.access = access;
this.enclosingClreplacedName = enclosingClreplacedName;
this.superClreplacedName = superClreplacedName;
this.independentInnerClreplaced = independentInnerClreplaced;
this.interfaceNames = interfaceNames;
this.memberClreplacedNames = memberClreplacedNames;
this.annotatedMethods = annotatedMethods;
this.annotations = annotations;
}
@Override
public String getClreplacedName() {
return this.clreplacedName;
}
@Override
public boolean isInterface() {
return (this.access & Opcodes.ACC_INTERFACE) != 0;
}
@Override
public boolean isAnnotation() {
return (this.access & Opcodes.ACC_ANNOTATION) != 0;
}
@Override
public boolean isAbstract() {
return (this.access & Opcodes.ACC_ABSTRACT) != 0;
}
@Override
public boolean isFinal() {
return (this.access & Opcodes.ACC_FINAL) != 0;
}
@Override
public boolean isIndependent() {
return (this.enclosingClreplacedName == null || this.independentInnerClreplaced);
}
@Override
@Nullable
public String getEnclosingClreplacedName() {
return this.enclosingClreplacedName;
}
@Override
@Nullable
public String getSuperClreplacedName() {
return this.superClreplacedName;
}
@Override
public String[] getInterfaceNames() {
return this.interfaceNames.clone();
}
@Override
public String[] getMemberClreplacedNames() {
return this.memberClreplacedNames.clone();
}
@Override
public Set<String> getAnnotationTypes() {
Set<String> annotationTypes = this.annotationTypes;
if (annotationTypes == null) {
annotationTypes = Collections.unmodifiableSet(AnnotationMetadata.super.getAnnotationTypes());
this.annotationTypes = annotationTypes;
}
return annotationTypes;
}
@Override
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
Set<MethodMetadata> annotatedMethods = null;
for (int i = 0; i < this.annotatedMethods.length; i++) {
if (this.annotatedMethods[i].isAnnotated(annotationName)) {
if (annotatedMethods == null) {
annotatedMethods = new LinkedHashSet<>(4);
}
annotatedMethods.add(this.annotatedMethods[i]);
}
}
return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
}
@Override
public MergedAnnotations getAnnotations() {
return this.annotations;
}
}
18
Source : AnnotationMetadataReadingVisitor.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
public boolean hasAnnotatedMethods(String annotationName) {
for (MethodMetadata methodMetadata : this.methodMetadataSet) {
if (methodMetadata.isAnnotated(annotationName)) {
return true;
}
}
return false;
}
18
Source : AnnotationMetadataConditionService.java
with Apache License 2.0
from spring-projects-experimental
with Apache License 2.0
from spring-projects-experimental
@Override
public boolean matches(Clreplaced<?> factory, Clreplaced<?> type) {
AnnotationMetadata metadata = getMetadata(factory);
Set<MethodMetadata> replacedignable = new HashSet<>();
for (MethodMetadata method : metadata.getAnnotatedMethods(Bean.clreplaced.getName())) {
Clreplaced<?> candidate = types.getType(method.getReturnTypeName());
// Look for exact match first
if (type.equals(candidate)) {
return !this.evaluator.shouldSkip(method);
}
if (type.isreplacedignableFrom(candidate)) {
replacedignable.add(method);
}
}
if (replacedignable.size() == 1) {
return !this.evaluator.shouldSkip(replacedignable.iterator().next());
}
// TODO: fail if size() > 1
Clreplaced<?> base = factory.getSuperclreplaced();
if (base != Object.clreplaced) {
metadata = getMetadata(base);
if (metadata.hasAnnotation(Configuration.clreplaced.getName())) {
return matches(base, type);
}
}
return false;
}
18
Source : BeanDefinitionUtil.java
with Apache License 2.0
from sofastack
with Apache License 2.0
from sofastack
/**
* {@link AnnotatedGenericBeanDefinition}
* {@link ScannedGenericBeanDefinition}
* {@link GenericBeanDefinition}
* {@link org.springframework.beans.factory.support.ChildBeanDefinition}
* {@link org.springframework.beans.factory.support.RootBeanDefinition}
*
* @param beanDefinition resolve bean clreplaced type from bean definition
* @return
*/
public static Clreplaced<?> resolveBeanClreplacedType(BeanDefinition beanDefinition) {
Clreplaced<?> clazz = null;
if (beanDefinition instanceof AnnotatedBeanDefinition) {
String clreplacedName;
if (isFromConfigurationSource(beanDefinition)) {
MethodMetadata methodMetadata = ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata();
clreplacedName = methodMetadata.getReturnTypeName();
} else {
AnnotationMetadata annotationMetadata = ((AnnotatedBeanDefinition) beanDefinition).getMetadata();
clreplacedName = annotationMetadata.getClreplacedName();
}
try {
clazz = org.springframework.util.StringUtils.isEmpty(clreplacedName) ? null : ClreplacedUtils.forName(clreplacedName, null);
} catch (Throwable throwable) {
// ignore
}
}
if (clazz == null) {
try {
clazz = ((AbstractBeanDefinition) beanDefinition).getBeanClreplaced();
} catch (IllegalStateException ex) {
try {
String clreplacedName = beanDefinition.getBeanClreplacedName();
clazz = StringUtils.isEmpty(clreplacedName) ? null : ClreplacedUtils.forName(clreplacedName, null);
} catch (Throwable throwable) {
// ignore
}
}
}
if (ClreplacedUtils.isCglibProxyClreplaced(clazz)) {
return clazz.getSuperclreplaced();
} else {
return clazz;
}
}
18
Source : SoapClientRegistrar.java
with MIT License
from Salmondx
with MIT License
from Salmondx
private Map<String, List<SoapMethodData>> getAnnotatedMethods(AnnotationMetadata metadata) {
String annotationName = SoapMethod.clreplaced.getCanonicalName();
Map<String, List<SoapMethodData>> soapMethods = new HashMap<>();
Set<MethodMetadata> proxyInterfaceMethods = metadata.getAnnotatedMethods(annotationName);
for (MethodMetadata proxyInterfaceMethod : proxyInterfaceMethods) {
String soapMethodName = (String) proxyInterfaceMethod.getAnnotationAttributes(annotationName).get("value");
Clreplaced<?>[] autowiredFields = (Clreplaced<?>[]) proxyInterfaceMethod.getAnnotationAttributes(annotationName).get("autowired");
replacedert.hasText(soapMethodName, "Soap method name cannot be null or empty");
if (soapMethods.containsKey(soapMethodName)) {
soapMethods.get(soapMethodName).add(new SoapMethodData(proxyInterfaceMethod.getMethodName(), proxyInterfaceMethod.getReturnTypeName(), autowiredFields));
} else {
List<SoapMethodData> methodNames = new ArrayList<>();
methodNames.add(new SoapMethodData(proxyInterfaceMethod.getMethodName(), proxyInterfaceMethod.getReturnTypeName(), autowiredFields));
soapMethods.put(soapMethodName, methodNames);
}
}
return soapMethods;
}
18
Source : AnnotationMetadataReadingVisitor.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
public boolean hasAnnotatedMethods(String annotationType) {
for (MethodMetadata method : this.methodMetadataSet) {
if (method.isAnnotated(annotationType)) {
return true;
}
}
return false;
}
18
Source : LimitedResourceScanner.java
with Apache License 2.0
from jjj124
with Apache License 2.0
from jjj124
public void scanLimitedResource() {
try {
String packageSearchPath = ResourcePatternResolver.CLreplacedPATH_ALL_URL_PREFIX + ClreplacedUtils.convertClreplacedNameToResourcePath(basePackage) + '/' + this.resourcePattern;
Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
AnnotationMetadataReadingVisitor clreplacedVisitor = (AnnotationMetadataReadingVisitor) metadataReader.getClreplacedMetadata();
if (clreplacedVisitor.isInterface() || clreplacedVisitor.isAbstract()) {
continue;
}
for (LimiterAnnotationParser parser : limiterAnnotationParsers) {
Set<MethodMetadata> methodMetadata = clreplacedVisitor.getAnnotatedMethods(parser.getSupportAnnotation().getName());
if (CollectionUtils.isEmpty(methodMetadata)) {
continue;
}
for (MethodMetadata metadata : methodMetadata) {
MethodMetadataReadingVisitor methodVisitor = (MethodMetadataReadingVisitor) metadata;
AnnotationAttributes attributes = methodVisitor.getAnnotationAttributes(parser.getSupportAnnotation().getName());
if (attributes != null) {
Annotation annotation;
LimitedResource limitedResource = parser.parseLimiterAnnotation(attributes);
if (limitedResource != null) {
String key = methodVisitor.getDeclaringClreplacedName() + "#" + methodVisitor.getMethodName() + "@" + parser.getSupportAnnotation().getSimpleName();
limitedResourceMap.put(key, limitedResource);
// add to registry
String clreplacedMethod = methodVisitor.getDeclaringClreplacedName() + "#" + methodVisitor.getMethodName();
if (!limitedResourceRegistry.containsKey(clreplacedMethod)) {
List<LimitedResource> tempList = new ArrayList<>();
tempList.add(limitedResource);
limitedResourceRegistry.put(clreplacedMethod, tempList);
} else {
Collection<LimitedResource> tempList = limitedResourceRegistry.get(clreplacedMethod);
tempList.add(limitedResource);
}
}
}
}
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
18
Source : DubboLoadBalancedRestTemplateAutoConfiguration.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
/**
* Gets the annotation attributes {@link RestTemplate} bean being annotated
* {@link DubboTransported @DubboTransported}.
* @param beanName the bean name of {@link LoadBalanced @LoadBalanced}
* {@link RestTemplate}
* @param attributesResolver {@link DubboTransportedAttributesResolver}
* @return non-null {@link Map}
*/
private Map<String, Object> getDubboTranslatedAttributes(String beanName, DubboTransportedAttributesResolver attributesResolver) {
Map<String, Object> attributes = Collections.emptyMap();
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName);
if (beanDefinition instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition annotatedBeanDefinition = (AnnotatedBeanDefinition) beanDefinition;
MethodMetadata factoryMethodMetadata = annotatedBeanDefinition.getFactoryMethodMetadata();
attributes = factoryMethodMetadata != null ? Optional.ofNullable(factoryMethodMetadata.getAnnotationAttributes(DUBBO_TRANSPORTED_CLreplaced_NAME)).orElse(attributes) : Collections.emptyMap();
}
return attributesResolver.resolve(attributes);
}
17
Source : AbstractConfigurationClassTests.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Test
public void allBeanMethodsArePublic() throws IOException {
Set<String> nonPublicBeanMethods = new HashSet<>();
for (AnnotationMetadata configurationClreplaced : findConfigurationClreplacedes()) {
Set<MethodMetadata> beanMethods = configurationClreplaced.getAnnotatedMethods(Bean.clreplaced.getName());
for (MethodMetadata methodMetadata : beanMethods) {
if (!isPublic(methodMetadata)) {
nonPublicBeanMethods.add(methodMetadata.getDeclaringClreplacedName() + "." + methodMetadata.getMethodName());
}
}
}
replacedertThat(nonPublicBeanMethods).as("Found non-public @Bean methods").isEmpty();
}
17
Source : AnnotationMetadataReadingVisitor.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<>(4);
for (MethodMetadata methodMetadata : this.methodMetadataSet) {
if (methodMetadata.isAnnotated(annotationName)) {
annotatedMethods.add(methodMetadata);
}
}
return annotatedMethods;
}
17
Source : ConfigurationClassParser.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Retrieve the metadata for all <code>@Bean</code> methods.
*/
private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClreplaced sourceClreplaced) {
AnnotationMetadata original = sourceClreplaced.getMetadata();
Set<MethodMetadata> beanMethods = original.getAnnotatedMethods(Bean.clreplaced.getName());
if (beanMethods.size() > 1 && original instanceof StandardAnnotationMetadata) {
// Try reading the clreplaced file via ASM for deterministic declaration order...
// Unfortunately, the JVM's standard reflection returns methods in arbitrary
// order, even between different runs of the same application on the same JVM.
try {
AnnotationMetadata asm = this.metadataReaderFactory.getMetadataReader(original.getClreplacedName()).getAnnotationMetadata();
Set<MethodMetadata> asmMethods = asm.getAnnotatedMethods(Bean.clreplaced.getName());
if (asmMethods.size() >= beanMethods.size()) {
Set<MethodMetadata> selectedMethods = new LinkedHashSet<>(asmMethods.size());
for (MethodMetadata asmMethod : asmMethods) {
for (MethodMetadata beanMethod : beanMethods) {
if (beanMethod.getMethodName().equals(asmMethod.getMethodName())) {
selectedMethods.add(beanMethod);
break;
}
}
}
if (selectedMethods.size() == beanMethods.size()) {
// All reflection-detected methods found in ASM method set -> proceed
beanMethods = selectedMethods;
}
}
} catch (IOException ex) {
logger.debug("Failed to read clreplaced file via ASM for determining @Bean method order", ex);
// No worries, let's continue with the reflection metadata we started with...
}
}
return beanMethods;
}
17
Source : OnEnabledComponent.java
with Apache License 2.0
from spring-cloud
with Apache License 2.0
from spring-cloud
@SuppressWarnings("unchecked")
protected Clreplaced<? extends T> getComponentType(Clreplaced<?> annotationClreplaced, ConditionContext context, AnnotatedTypeMetadata metadata) {
Map<String, Object> attributes = metadata.getAnnotationAttributes(annotationClreplaced.getName());
if (attributes != null && attributes.containsKey("value")) {
Clreplaced<?> target = (Clreplaced<?>) attributes.get("value");
if (target != defaultValueClreplaced()) {
return (Clreplaced<? extends T>) target;
}
}
replacedert.state(metadata instanceof MethodMetadata && metadata.isAnnotated(Bean.clreplaced.getName()), getClreplaced().getSimpleName() + " must be used on @Bean methods when the value is not specified");
MethodMetadata methodMetadata = (MethodMetadata) metadata;
try {
return (Clreplaced<? extends T>) ClreplacedUtils.forName(methodMetadata.getReturnTypeName(), context.getClreplacedLoader());
} catch (Throwable ex) {
throw new IllegalStateException("Failed to extract component clreplaced for " + methodMetadata.getDeclaringClreplacedName() + "." + methodMetadata.getMethodName(), ex);
}
}
17
Source : ConfigurationClassParser.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
/**
* Retrieve the metadata for all <code>@Bean</code> methods.
*/
private Set<MethodMetadata> retrieveBeanMethodMetadata(SourceClreplaced sourceClreplaced) {
// 提取元数据
AnnotationMetadata original = sourceClreplaced.getMetadata();
// 提取带有 Bean 标签的数据
Set<MethodMetadata> beanMethods = original.getAnnotatedMethods(Bean.clreplaced.getName());
if (beanMethods.size() > 1 && original instanceof StandardAnnotationMetadata) {
// Try reading the clreplaced file via ASM for deterministic declaration order...
// Unfortunately, the JVM's standard reflection returns methods in arbitrary
// order, even between different runs of the same application on the same JVM.
try {
// 类的注解元数据
AnnotationMetadata asm = this.metadataReaderFactory.getMetadataReader(original.getClreplacedName()).getAnnotationMetadata();
// 提取带有 Bean 注解的方法元数据
Set<MethodMetadata> asmMethods = asm.getAnnotatedMethods(Bean.clreplaced.getName());
if (asmMethods.size() >= beanMethods.size()) {
// 选中的方法元数据
Set<MethodMetadata> selectedMethods = new LinkedHashSet<>(asmMethods.size());
// 循环两个方法元数据进行 methodName 比较如果相同会被加入到选中集合中
for (MethodMetadata asmMethod : asmMethods) {
for (MethodMetadata beanMethod : beanMethods) {
if (beanMethod.getMethodName().equals(asmMethod.getMethodName())) {
selectedMethods.add(beanMethod);
break;
}
}
}
if (selectedMethods.size() == beanMethods.size()) {
// All reflection-detected methods found in ASM method set -> proceed
beanMethods = selectedMethods;
}
}
} catch (IOException ex) {
logger.debug("Failed to read clreplaced file via ASM for determining @Bean method order", ex);
// No worries, let's continue with the reflection metadata we started with...
}
}
return beanMethods;
}
17
Source : AnnotationMetadataReadingVisitor.java
with Apache License 2.0
from mercyblitz
with Apache License 2.0
from mercyblitz
public Set<MethodMetadata> getAnnotatedMethods(String annotationType) {
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>();
for (MethodMetadata method : this.methodMetadataSet) {
if (method.isAnnotated(annotationType)) {
annotatedMethods.add(method);
}
}
return annotatedMethods;
}
17
Source : AnnotationMetadataReadingVisitor.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Override
public Set<MethodMetadata> getAnnotatedMethods(String annotationName) {
Set<MethodMetadata> annotatedMethods = new LinkedHashSet<MethodMetadata>(4);
for (MethodMetadata methodMetadata : this.methodMetadataSet) {
if (methodMetadata.isAnnotated(annotationName)) {
annotatedMethods.add(methodMetadata);
}
}
return annotatedMethods;
}
17
Source : LimitedResourceScanner.java
with MIT License
from aoju
with MIT License
from aoju
public void scanLimitedResource() {
try {
String packageSearchPath = ResourcePatternResolver.CLreplacedPATH_ALL_URL_PREFIX + ClreplacedKit.convertClreplacedNameToResourcePath(basePackage) + Symbol.C_SLASH + this.resourcePattern;
Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
AnnotationMetadataReadingVisitor clreplacedVisitor = (AnnotationMetadataReadingVisitor) metadataReader.getClreplacedMetadata();
if (clreplacedVisitor.isInterface() || clreplacedVisitor.isAbstract()) {
continue;
}
for (Parser parser : limiterAnnotationParsers) {
Set<MethodMetadata> methodMetadata = clreplacedVisitor.getAnnotatedMethods(parser.getSupportAnnotation().getName());
if (CollKit.isEmpty(methodMetadata)) {
continue;
}
for (MethodMetadata metadata : methodMetadata) {
AnnotationAttributes attributes = (AnnotationAttributes) metadata.getAnnotationAttributes(parser.getSupportAnnotation().getName());
if (attributes != null) {
LimitedResource limitedResource = parser.parseLimiterAnnotation(attributes);
if (limitedResource != null) {
String key = metadata.getDeclaringClreplacedName() + Symbol.SHAPE + metadata.getMethodName() + Symbol.AT + parser.getSupportAnnotation().getSimpleName();
limitedResourceMap.put(key, limitedResource);
// add to registry
String clreplacedMethod = metadata.getDeclaringClreplacedName() + Symbol.SHAPE + metadata.getMethodName();
if (!limitedResourceRegistry.containsKey(clreplacedMethod)) {
List<LimitedResource> tempList = new ArrayList<>();
tempList.add(limitedResource);
limitedResourceRegistry.put(clreplacedMethod, tempList);
} else {
Collection<LimitedResource> tempList = limitedResourceRegistry.get(clreplacedMethod);
tempList.add(limitedResource);
}
}
}
}
}
}
}
} catch (IOException e) {
throw new InstrumentException(e);
}
}
15
Source : ConfigurationClassParser.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Apply processing and build a complete {@link ConfigurationClreplaced} by reading the
* annotations, members and methods from the source clreplaced. This method can be called
* multiple times as relevant sources are discovered.
* @param configClreplaced the configuration clreplaced being build
* @param sourceClreplaced a source clreplaced
* @return the superclreplaced, or {@code null} if none found or previously processed
*/
protected final SourceClreplaced doProcessConfigurationClreplaced(ConfigurationClreplaced configClreplaced, SourceClreplaced sourceClreplaced) throws IOException {
// Recursively process any member (nested) clreplacedes first
processMemberClreplacedes(configClreplaced, sourceClreplaced);
// Process any @PropertySource annotations
for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(sourceClreplaced.getMetadata(), PropertySources.clreplaced, org.springframework.context.annotation.PropertySource.clreplaced)) {
if (this.environment instanceof ConfigurableEnvironment) {
processPropertySource(propertySource);
} else {
logger.warn("Ignoring @PropertySource annotation on [" + sourceClreplaced.getMetadata().getClreplacedName() + "]. Reason: Environment must implement ConfigurableEnvironment");
}
}
// Process any @ComponentScan annotations
AnnotationAttributes componentScan = AnnotationConfigUtils.attributesFor(sourceClreplaced.getMetadata(), ComponentScan.clreplaced);
if (componentScan != null && !this.conditionEvaluator.shouldSkip(sourceClreplaced.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
// The config clreplaced is annotated with @ComponentScan -> perform the scan immediately
Set<BeanDefinitionHolder> scannedBeanDefinitions = this.componentScanParser.parse(componentScan, sourceClreplaced.getMetadata().getClreplacedName());
// Check the set of scanned definitions for any further config clreplacedes and parse recursively if necessary
for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
if (ConfigurationClreplacedUtils.checkConfigurationClreplacedCandidate(holder.getBeanDefinition(), this.metadataReaderFactory)) {
parse(holder.getBeanDefinition().getBeanClreplacedName(), holder.getBeanName());
}
}
}
// Process any @Import annotations
processImports(configClreplaced, sourceClreplaced, getImports(sourceClreplaced), true);
// Process any @ImportResource annotations
if (sourceClreplaced.getMetadata().isAnnotated(ImportResource.clreplaced.getName())) {
AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClreplaced.getMetadata(), ImportResource.clreplaced);
String[] resources = importResource.getAliasedStringArray("locations", ImportResource.clreplaced, sourceClreplaced);
Clreplaced<? extends BeanDefinitionReader> readerClreplaced = importResource.getClreplaced("reader");
for (String resource : resources) {
String resolvedResource = this.environment.resolveRequiredPlaceholders(resource);
configClreplaced.addImportedResource(resolvedResource, readerClreplaced);
}
}
// Process individual @Bean methods
Set<MethodMetadata> beanMethods = sourceClreplaced.getMetadata().getAnnotatedMethods(Bean.clreplaced.getName());
for (MethodMetadata methodMetadata : beanMethods) {
configClreplaced.addBeanMethod(new BeanMethod(methodMetadata, configClreplaced));
}
// Process default methods on interfaces
for (SourceClreplaced ifc : sourceClreplaced.getInterfaces()) {
beanMethods = ifc.getMetadata().getAnnotatedMethods(Bean.clreplaced.getName());
for (MethodMetadata methodMetadata : beanMethods) {
if (!methodMetadata.isAbstract()) {
// A default method or other concrete method on a Java 8+ interface...
configClreplaced.addBeanMethod(new BeanMethod(methodMetadata, configClreplaced));
}
}
}
// Process superclreplaced, if any
if (sourceClreplaced.getMetadata().hreplaceduperClreplaced()) {
String superclreplaced = sourceClreplaced.getMetadata().getSuperClreplacedName();
if (!superclreplaced.startsWith("java") && !this.knownSuperclreplacedes.containsKey(superclreplaced)) {
this.knownSuperclreplacedes.put(superclreplaced, configClreplaced);
// Superclreplaced found, return its annotation metadata and recurse
return sourceClreplaced.getSuperClreplaced();
}
}
// No superclreplaced -> processing is complete
return null;
}
14
Source : BeanTypeRegistry.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
private Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory, BeanDefinition definition) throws Exception {
if (definition instanceof AnnotatedBeanDefinition) {
MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition).getFactoryMethodMetadata();
if (factoryMethodMetadata instanceof StandardMethodMetadata) {
return ((StandardMethodMetadata) factoryMethodMetadata).getIntrospectedMethod();
}
}
BeanDefinition factoryDefinition = beanFactory.getBeanDefinition(definition.getFactoryBeanName());
Clreplaced<?> factoryClreplaced = ClreplacedUtils.forName(factoryDefinition.getBeanClreplacedName(), beanFactory.getBeanClreplacedLoader());
return getFactoryMethod(definition, factoryClreplaced);
}
14
Source : ConfigurationClassParser.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Apply processing and build a complete {@link ConfigurationClreplaced} by reading the
* annotations, members and methods from the source clreplaced. This method can be called
* multiple times as relevant sources are discovered.
* @param configClreplaced the configuration clreplaced being build
* @param sourceClreplaced a source clreplaced
* @return the superclreplaced, or {@code null} if none found or previously processed
*/
@Nullable
protected final SourceClreplaced doProcessConfigurationClreplaced(ConfigurationClreplaced configClreplaced, SourceClreplaced sourceClreplaced) throws IOException {
if (configClreplaced.getMetadata().isAnnotated(Component.clreplaced.getName())) {
// Recursively process any member (nested) clreplacedes first
processMemberClreplacedes(configClreplaced, sourceClreplaced);
}
// Process any @PropertySource annotations
for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(sourceClreplaced.getMetadata(), PropertySources.clreplaced, org.springframework.context.annotation.PropertySource.clreplaced)) {
if (this.environment instanceof ConfigurableEnvironment) {
processPropertySource(propertySource);
} else {
logger.info("Ignoring @PropertySource annotation on [" + sourceClreplaced.getMetadata().getClreplacedName() + "]. Reason: Environment must implement ConfigurableEnvironment");
}
}
// Process any @ComponentScan annotations
Set<AnnotationAttributes> componentScans = AnnotationConfigUtils.attributesForRepeatable(sourceClreplaced.getMetadata(), ComponentScans.clreplaced, ComponentScan.clreplaced);
if (!componentScans.isEmpty() && !this.conditionEvaluator.shouldSkip(sourceClreplaced.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
for (AnnotationAttributes componentScan : componentScans) {
// The config clreplaced is annotated with @ComponentScan -> perform the scan immediately
Set<BeanDefinitionHolder> scannedBeanDefinitions = this.componentScanParser.parse(componentScan, sourceClreplaced.getMetadata().getClreplacedName());
// Check the set of scanned definitions for any further config clreplacedes and parse recursively if needed
for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
BeanDefinition bdCand = holder.getBeanDefinition().getOriginatingBeanDefinition();
if (bdCand == null) {
bdCand = holder.getBeanDefinition();
}
if (ConfigurationClreplacedUtils.checkConfigurationClreplacedCandidate(bdCand, this.metadataReaderFactory)) {
parse(bdCand.getBeanClreplacedName(), holder.getBeanName());
}
}
}
}
// Process any @Import annotations
processImports(configClreplaced, sourceClreplaced, getImports(sourceClreplaced), true);
// Process any @ImportResource annotations
AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClreplaced.getMetadata(), ImportResource.clreplaced);
if (importResource != null) {
String[] resources = importResource.getStringArray("locations");
Clreplaced<? extends BeanDefinitionReader> readerClreplaced = importResource.getClreplaced("reader");
for (String resource : resources) {
String resolvedResource = this.environment.resolveRequiredPlaceholders(resource);
configClreplaced.addImportedResource(resolvedResource, readerClreplaced);
}
}
// Process individual @Bean methods
Set<MethodMetadata> beanMethods = retrieveBeanMethodMetadata(sourceClreplaced);
for (MethodMetadata methodMetadata : beanMethods) {
configClreplaced.addBeanMethod(new BeanMethod(methodMetadata, configClreplaced));
}
// Process default methods on interfaces
processInterfaces(configClreplaced, sourceClreplaced);
// Process superclreplaced, if any
if (sourceClreplaced.getMetadata().hreplaceduperClreplaced()) {
String superclreplaced = sourceClreplaced.getMetadata().getSuperClreplacedName();
if (superclreplaced != null && !superclreplaced.startsWith("java") && !this.knownSuperclreplacedes.containsKey(superclreplaced)) {
this.knownSuperclreplacedes.put(superclreplaced, configClreplaced);
// Superclreplaced found, return its annotation metadata and recurse
return sourceClreplaced.getSuperClreplaced();
}
}
// No superclreplaced -> processing is complete
return null;
}
14
Source : ConfigurationClassParser.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
/**
* Apply processing and build a complete {@link ConfigurationClreplaced} by reading the
* annotations, members and methods from the source clreplaced. This method can be called
* multiple times as relevant sources are discovered.
* @param configClreplaced the configuration clreplaced being build
* @param sourceClreplaced a source clreplaced
* @return the superclreplaced, or {@code null} if none found or previously processed
*/
@Nullable
protected final SourceClreplaced doProcessConfigurationClreplaced(ConfigurationClreplaced configClreplaced, SourceClreplaced sourceClreplaced) throws IOException {
// 配置类是否存在 Component 注解
if (configClreplaced.getMetadata().isAnnotated(Component.clreplaced.getName())) {
// Recursively process any member (nested) clreplacedes first
processMemberClreplacedes(configClreplaced, sourceClreplaced);
}
// 处理 PropertySource 和 PropertySource 注解
// Process any @PropertySource annotations
for (AnnotationAttributes propertySource : AnnotationConfigUtils.attributesForRepeatable(sourceClreplaced.getMetadata(), PropertySources.clreplaced, org.springframework.context.annotation.PropertySource.clreplaced)) {
if (this.environment instanceof ConfigurableEnvironment) {
processPropertySource(propertySource);
} else {
logger.info("Ignoring @PropertySource annotation on [" + sourceClreplaced.getMetadata().getClreplacedName() + "]. Reason: Environment must implement ConfigurableEnvironment");
}
}
// 处理 ComponentScans ComponentScan 注解
// Process any @ComponentScan annotations
Set<AnnotationAttributes> componentScans = AnnotationConfigUtils.attributesForRepeatable(sourceClreplaced.getMetadata(), ComponentScans.clreplaced, ComponentScan.clreplaced);
// 如果 ComponentScan 数据解析结果不为空 并且通过条件解析,条件解析的阶段是注册阶段
if (!componentScans.isEmpty() && !this.conditionEvaluator.shouldSkip(sourceClreplaced.getMetadata(), ConfigurationPhase.REGISTER_BEAN)) {
// 处理单个 componentScan 数据
for (AnnotationAttributes componentScan : componentScans) {
// The config clreplaced is annotated with @ComponentScan -> perform the scan immediately
Set<BeanDefinitionHolder> scannedBeanDefinitions = this.componentScanParser.parse(componentScan, sourceClreplaced.getMetadata().getClreplacedName());
// Check the set of scanned definitions for any further config clreplacedes and parse recursively if needed
for (BeanDefinitionHolder holder : scannedBeanDefinitions) {
BeanDefinition bdCand = holder.getBeanDefinition().getOriginatingBeanDefinition();
if (bdCand == null) {
bdCand = holder.getBeanDefinition();
}
if (ConfigurationClreplacedUtils.checkConfigurationClreplacedCandidate(bdCand, this.metadataReaderFactory)) {
parse(bdCand.getBeanClreplacedName(), holder.getBeanName());
}
}
}
}
// 处理 Import 注解
// Process any @Import annotations
processImports(configClreplaced, sourceClreplaced, getImports(sourceClreplaced), true);
// 处理 ImportResource 注解
// Process any @ImportResource annotations
AnnotationAttributes importResource = AnnotationConfigUtils.attributesFor(sourceClreplaced.getMetadata(), ImportResource.clreplaced);
if (importResource != null) {
String[] resources = importResource.getStringArray("locations");
Clreplaced<? extends BeanDefinitionReader> readerClreplaced = importResource.getClreplaced("reader");
for (String resource : resources) {
String resolvedResource = this.environment.resolveRequiredPlaceholders(resource);
configClreplaced.addImportedResource(resolvedResource, readerClreplaced);
}
}
// 处理 Bean 注解
// Process individual @Bean methods
Set<MethodMetadata> beanMethods = retrieveBeanMethodMetadata(sourceClreplaced);
for (MethodMetadata methodMetadata : beanMethods) {
configClreplaced.addBeanMethod(new BeanMethod(methodMetadata, configClreplaced));
}
// 处理 Bean Method
// Process default methods on interfaces
processInterfaces(configClreplaced, sourceClreplaced);
// 父类配置处理
// Process superclreplaced, if any
if (sourceClreplaced.getMetadata().hreplaceduperClreplaced()) {
String superclreplaced = sourceClreplaced.getMetadata().getSuperClreplacedName();
if (superclreplaced != null && !superclreplaced.startsWith("java") && !this.knownSuperclreplacedes.containsKey(superclreplaced)) {
this.knownSuperclreplacedes.put(superclreplaced, configClreplaced);
// Superclreplaced found, return its annotation metadata and recurse
return sourceClreplaced.getSuperClreplaced();
}
}
// No superclreplaced -> processing is complete
return null;
}
13
Source : ServiceBeanFactoryPostProcessor.java
with Apache License 2.0
from sofastack
with Apache License 2.0
from sofastack
private void generateSofaServiceDefinitionOnMethod(String beanId, AnnotatedBeanDefinition beanDefinition, ConfigurableListableBeanFactory beanFactory) {
Clreplaced<?> returnType;
Clreplaced<?> declaringClreplaced;
List<Method> candidateMethods = new ArrayList<>();
MethodMetadata methodMetadata = beanDefinition.getFactoryMethodMetadata();
try {
returnType = ClreplacedUtils.forName(methodMetadata.getReturnTypeName(), null);
declaringClreplaced = ClreplacedUtils.forName(methodMetadata.getDeclaringClreplacedName(), null);
} catch (Throwable throwable) {
// it's impossible to catch throwable here
SofaLogger.error("Failed to parse factoryBeanMethod of BeanDefinition( {} )", beanId, throwable);
return;
}
if (methodMetadata instanceof StandardMethodMetadata) {
candidateMethods.add(((StandardMethodMetadata) methodMetadata).getIntrospectedMethod());
} else {
for (Method m : declaringClreplaced.getDeclaredMethods()) {
// check methodName and return type
if (!m.getName().equals(methodMetadata.getMethodName()) || !m.getReturnType().getTypeName().equals(methodMetadata.getReturnTypeName())) {
continue;
}
// check bean method
if (!AnnotatedElementUtils.hasAnnotation(m, Bean.clreplaced)) {
continue;
}
Bean bean = m.getAnnotation(Bean.clreplaced);
Set<String> beanNames = new HashSet<>();
beanNames.add(m.getName());
if (bean != null) {
beanNames.addAll(Arrays.asList(bean.name()));
beanNames.addAll(Arrays.asList(bean.value()));
}
// check bean name
if (!beanNames.contains(beanId)) {
continue;
}
candidateMethods.add(m);
}
}
if (candidateMethods.size() == 1) {
SofaService sofaServiceAnnotation = candidateMethods.get(0).getAnnotation(SofaService.clreplaced);
if (sofaServiceAnnotation == null) {
sofaServiceAnnotation = returnType.getAnnotation(SofaService.clreplaced);
}
generateSofaServiceDefinition(beanId, sofaServiceAnnotation, returnType, beanDefinition, beanFactory);
generateSofaReferenceDefinition(beanId, candidateMethods.get(0), beanFactory);
} else if (candidateMethods.size() > 1) {
for (Method m : candidateMethods) {
if (AnnotatedElementUtils.hasAnnotation(m, SofaService.clreplaced) || AnnotatedElementUtils.hasAnnotation(returnType, SofaService.clreplaced)) {
throw new FatalBeanException("multi @Bean-method with same name try to publish SofaService in " + declaringClreplaced.getCanonicalName());
}
if (Stream.of(m.getParameterAnnotations()).flatMap(Stream::of).anyMatch(annotation -> annotation instanceof SofaReference)) {
throw new FatalBeanException("multi @Bean-method with same name try to reference SofaService in" + declaringClreplaced.getCanonicalName());
}
}
}
}
7
Source : ConfigurationClassPostProcessor.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Post-processes a BeanFactory in search of Configuration clreplaced BeanDefinitions;
* any candidates are then enhanced by a {@link ConfigurationClreplacedEnhancer}.
* Candidate status is determined by BeanDefinition attribute metadata.
* @see ConfigurationClreplacedEnhancer
*/
public void enhanceConfigurationClreplacedes(ConfigurableListableBeanFactory beanFactory) {
Map<String, AbstractBeanDefinition> configBeanDefs = new LinkedHashMap<>();
for (String beanName : beanFactory.getBeanDefinitionNames()) {
BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
Object configClreplacedAttr = beanDef.getAttribute(ConfigurationClreplacedUtils.CONFIGURATION_CLreplaced_ATTRIBUTE);
MethodMetadata methodMetadata = null;
if (beanDef instanceof AnnotatedBeanDefinition) {
methodMetadata = ((AnnotatedBeanDefinition) beanDef).getFactoryMethodMetadata();
}
if ((configClreplacedAttr != null || methodMetadata != null) && beanDef instanceof AbstractBeanDefinition) {
// Configuration clreplaced (full or lite) or a configuration-derived @Bean method
// -> resolve bean clreplaced at this point...
AbstractBeanDefinition abd = (AbstractBeanDefinition) beanDef;
if (!abd.hasBeanClreplaced()) {
try {
abd.resolveBeanClreplaced(this.beanClreplacedLoader);
} catch (Throwable ex) {
throw new IllegalStateException("Cannot load configuration clreplaced: " + beanDef.getBeanClreplacedName(), ex);
}
}
}
if (ConfigurationClreplacedUtils.CONFIGURATION_CLreplaced_FULL.equals(configClreplacedAttr)) {
if (!(beanDef instanceof AbstractBeanDefinition)) {
throw new BeanDefinitionStoreException("Cannot enhance @Configuration bean definition '" + beanName + "' since it is not stored in an AbstractBeanDefinition subclreplaced");
} else if (logger.isInfoEnabled() && beanFactory.containsSingleton(beanName)) {
logger.info("Cannot enhance @Configuration bean definition '" + beanName + "' since its singleton instance has been created too early. The typical cause " + "is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " + "return type: Consider declaring such methods as 'static'.");
}
configBeanDefs.put(beanName, (AbstractBeanDefinition) beanDef);
}
}
if (configBeanDefs.isEmpty()) {
// nothing to enhance -> return immediately
return;
}
ConfigurationClreplacedEnhancer enhancer = new ConfigurationClreplacedEnhancer();
for (Map.Entry<String, AbstractBeanDefinition> entry : configBeanDefs.entrySet()) {
AbstractBeanDefinition beanDef = entry.getValue();
// If a @Configuration clreplaced gets proxied, always proxy the target clreplaced
beanDef.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLreplaced_ATTRIBUTE, Boolean.TRUE);
// Set enhanced subclreplaced of the user-specified bean clreplaced
Clreplaced<?> configClreplaced = beanDef.getBeanClreplaced();
Clreplaced<?> enhancedClreplaced = enhancer.enhance(configClreplaced, this.beanClreplacedLoader);
if (configClreplaced != enhancedClreplaced) {
if (logger.isTraceEnabled()) {
logger.trace(String.format("Replacing bean definition '%s' existing clreplaced '%s' with " + "enhanced clreplaced '%s'", entry.getKey(), configClreplaced.getName(), enhancedClreplaced.getName()));
}
beanDef.setBeanClreplaced(enhancedClreplaced);
}
}
}
7
Source : ConfigurationClassBeanDefinitionReader.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Read the given {@link BeanMethod}, registering bean definitions
* with the BeanDefinitionRegistry based on its contents.
*/
// for RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE
@SuppressWarnings("deprecation")
private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
ConfigurationClreplaced configClreplaced = beanMethod.getConfigurationClreplaced();
MethodMetadata metadata = beanMethod.getMetadata();
String methodName = metadata.getMethodName();
// Do we need to mark the bean as skipped by its condition?
if (this.conditionEvaluator.shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN)) {
configClreplaced.skippedBeanMethods.add(methodName);
return;
}
if (configClreplaced.skippedBeanMethods.contains(methodName)) {
return;
}
AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.clreplaced);
replacedert.state(bean != null, "No @Bean annotation attributes");
// Consider name and any aliases
List<String> names = new ArrayList<>(Arrays.asList(bean.getStringArray("name")));
String beanName = (!names.isEmpty() ? names.remove(0) : methodName);
// Register aliases even when overridden
for (String alias : names) {
this.registry.registerAlias(beanName, alias);
}
// Has this effectively been overridden before (e.g. via XML)?
if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
if (beanName.equals(beanMethod.getConfigurationClreplaced().getBeanName())) {
throw new BeanDefinitionStoreException(beanMethod.getConfigurationClreplaced().getResource().getDescription(), beanName, "Bean name derived from @Bean method '" + beanMethod.getMetadata().getMethodName() + "' clashes with bean name for containing configuration clreplaced; please make those names unique!");
}
return;
}
ConfigurationClreplacedBeanDefinition beanDef = new ConfigurationClreplacedBeanDefinition(configClreplaced, metadata);
beanDef.setResource(configClreplaced.getResource());
beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClreplaced.getResource()));
if (metadata.isStatic()) {
// static @Bean method
if (configClreplaced.getMetadata() instanceof StandardAnnotationMetadata) {
beanDef.setBeanClreplaced(((StandardAnnotationMetadata) configClreplaced.getMetadata()).getIntrospectedClreplaced());
} else {
beanDef.setBeanClreplacedName(configClreplaced.getMetadata().getClreplacedName());
}
beanDef.setUniqueFactoryMethodName(methodName);
} else {
// instance @Bean method
beanDef.setFactoryBeanName(configClreplaced.getBeanName());
beanDef.setUniqueFactoryMethodName(methodName);
}
if (metadata instanceof StandardMethodMetadata) {
beanDef.setResolvedFactoryMethod(((StandardMethodMetadata) metadata).getIntrospectedMethod());
}
beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
beanDef.setAttribute(org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);
AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata);
Autowire autowire = bean.getEnum("autowire");
if (autowire.isAutowire()) {
beanDef.setAutowireMode(autowire.value());
}
boolean autowireCandidate = bean.getBoolean("autowireCandidate");
if (!autowireCandidate) {
beanDef.setAutowireCandidate(false);
}
String initMethodName = bean.getString("initMethod");
if (StringUtils.hasText(initMethodName)) {
beanDef.setInitMethodName(initMethodName);
}
String destroyMethodName = bean.getString("destroyMethod");
beanDef.setDestroyMethodName(destroyMethodName);
// Consider scoping
ScopedProxyMode proxyMode = ScopedProxyMode.NO;
AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.clreplaced);
if (attributes != null) {
beanDef.setScope(attributes.getString("value"));
proxyMode = attributes.getEnum("proxyMode");
if (proxyMode == ScopedProxyMode.DEFAULT) {
proxyMode = ScopedProxyMode.NO;
}
}
// Replace the original bean definition with the target one, if necessary
BeanDefinition beanDefToRegister = beanDef;
if (proxyMode != ScopedProxyMode.NO) {
BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLreplaced);
beanDefToRegister = new ConfigurationClreplacedBeanDefinition((RootBeanDefinition) proxyDef.getBeanDefinition(), configClreplaced, metadata);
}
if (logger.isTraceEnabled()) {
logger.trace(String.format("Registering bean definition for @Bean method %s.%s()", configClreplaced.getMetadata().getClreplacedName(), beanName));
}
this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}
7
Source : ConfigurationClassPostProcessor.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
/**
* Post-processes a BeanFactory in search of Configuration clreplaced BeanDefinitions;
* any candidates are then enhanced by a {@link ConfigurationClreplacedEnhancer}.
* Candidate status is determined by BeanDefinition attribute metadata.
* @see ConfigurationClreplacedEnhancer
*/
public void enhanceConfigurationClreplacedes(ConfigurableListableBeanFactory beanFactory) {
// 存储 Spring Configuration Bean Definiton
Map<String, AbstractBeanDefinition> configBeanDefs = new LinkedHashMap<>();
// 容器中将符合条件的对象放入到 配置Bean 容器中
for (String beanName : beanFactory.getBeanDefinitionNames()) {
BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
Object configClreplacedAttr = beanDef.getAttribute(ConfigurationClreplacedUtils.CONFIGURATION_CLreplaced_ATTRIBUTE);
MethodMetadata methodMetadata = null;
if (beanDef instanceof AnnotatedBeanDefinition) {
methodMetadata = ((AnnotatedBeanDefinition) beanDef).getFactoryMethodMetadata();
}
if ((configClreplacedAttr != null || methodMetadata != null) && beanDef instanceof AbstractBeanDefinition) {
// Configuration clreplaced (full or lite) or a configuration-derived @Bean method
// -> resolve bean clreplaced at this point...
AbstractBeanDefinition abd = (AbstractBeanDefinition) beanDef;
if (!abd.hasBeanClreplaced()) {
try {
abd.resolveBeanClreplaced(this.beanClreplacedLoader);
} catch (Throwable ex) {
throw new IllegalStateException("Cannot load configuration clreplaced: " + beanDef.getBeanClreplacedName(), ex);
}
}
}
if (ConfigurationClreplacedUtils.CONFIGURATION_CLreplaced_FULL.equals(configClreplacedAttr)) {
if (!(beanDef instanceof AbstractBeanDefinition)) {
throw new BeanDefinitionStoreException("Cannot enhance @Configuration bean definition '" + beanName + "' since it is not stored in an AbstractBeanDefinition subclreplaced");
} else if (logger.isInfoEnabled() && beanFactory.containsSingleton(beanName)) {
logger.info("Cannot enhance @Configuration bean definition '" + beanName + "' since its singleton instance has been created too early. The typical cause " + "is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor " + "return type: Consider declaring such methods as 'static'.");
}
configBeanDefs.put(beanName, (AbstractBeanDefinition) beanDef);
}
}
// Spring Configuration Bean Definition 不存在
if (configBeanDefs.isEmpty()) {
// nothing to enhance -> return immediately
return;
}
// 对 Spring Configuration Bean Definition 进行增强处理
ConfigurationClreplacedEnhancer enhancer = new ConfigurationClreplacedEnhancer();
for (Map.Entry<String, AbstractBeanDefinition> entry : configBeanDefs.entrySet()) {
AbstractBeanDefinition beanDef = entry.getValue();
// If a @Configuration clreplaced gets proxied, always proxy the target clreplaced
beanDef.setAttribute(AutoProxyUtils.PRESERVE_TARGET_CLreplaced_ATTRIBUTE, Boolean.TRUE);
// Set enhanced subclreplaced of the user-specified bean clreplaced
Clreplaced<?> configClreplaced = beanDef.getBeanClreplaced();
Clreplaced<?> enhancedClreplaced = enhancer.enhance(configClreplaced, this.beanClreplacedLoader);
if (configClreplaced != enhancedClreplaced) {
if (logger.isTraceEnabled()) {
logger.trace(String.format("Replacing bean definition '%s' existing clreplaced '%s' with " + "enhanced clreplaced '%s'", entry.getKey(), configClreplaced.getName(), enhancedClreplaced.getName()));
}
beanDef.setBeanClreplaced(enhancedClreplaced);
}
}
}
7
Source : ConfigurationClassBeanDefinitionReader.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
/**
* Read the given {@link BeanMethod}, registering bean definitions
* with the BeanDefinitionRegistry based on its contents.
*/
// for RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE
@SuppressWarnings("deprecation")
private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
// 提取配置类
ConfigurationClreplaced configClreplaced = beanMethod.getConfigurationClreplaced();
// 提取方法元数据
MethodMetadata metadata = beanMethod.getMetadata();
// 提取方法名称
String methodName = metadata.getMethodName();
// 进行 Condition 注解处理
// Do we need to mark the bean as skipped by its condition?
if (this.conditionEvaluator.shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN)) {
configClreplaced.skippedBeanMethods.add(methodName);
return;
}
if (configClreplaced.skippedBeanMethods.contains(methodName)) {
return;
}
// 从注解元数据中提取 Bean 注解相关的注解属性对象
AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.clreplaced);
replacedert.state(bean != null, "No @Bean annotation attributes");
// 提取 Bean 属性中的 name 值
// Consider name and any aliases
List<String> names = new ArrayList<>(Arrays.asList(bean.getStringArray("name")));
String beanName = (!names.isEmpty() ? names.remove(0) : methodName);
// 别名处理
// 真名=方法名称
// 别名等于 @Bean 中的name属性
// Register aliases even when overridden
for (String alias : names) {
this.registry.registerAlias(beanName, alias);
}
// 检查是否存在覆盖的定义
// Has this effectively been overridden before (e.g. via XML)?
if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
if (beanName.equals(beanMethod.getConfigurationClreplaced().getBeanName())) {
throw new BeanDefinitionStoreException(beanMethod.getConfigurationClreplaced().getResource().getDescription(), beanName, "Bean name derived from @Bean method '" + beanMethod.getMetadata().getMethodName() + "' clashes with bean name for containing configuration clreplaced; please make those names unique!");
}
return;
}
// Bean Definition 的创建和属性设置
ConfigurationClreplacedBeanDefinition beanDef = new ConfigurationClreplacedBeanDefinition(configClreplaced, metadata);
beanDef.setResource(configClreplaced.getResource());
beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClreplaced.getResource()));
if (metadata.isStatic()) {
// static @Bean method
if (configClreplaced.getMetadata() instanceof StandardAnnotationMetadata) {
beanDef.setBeanClreplaced(((StandardAnnotationMetadata) configClreplaced.getMetadata()).getIntrospectedClreplaced());
} else {
beanDef.setBeanClreplacedName(configClreplaced.getMetadata().getClreplacedName());
}
beanDef.setUniqueFactoryMethodName(methodName);
} else {
// instance @Bean method
beanDef.setFactoryBeanName(configClreplaced.getBeanName());
beanDef.setUniqueFactoryMethodName(methodName);
}
if (metadata instanceof StandardMethodMetadata) {
beanDef.setResolvedFactoryMethod(((StandardMethodMetadata) metadata).getIntrospectedMethod());
}
beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
beanDef.setAttribute(org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);
// Lazy Primary DependsOn Role Description 注解数据设置
AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata);
Autowire autowire = bean.getEnum("autowire");
if (autowire.isAutowire()) {
beanDef.setAutowireMode(autowire.value());
}
boolean autowireCandidate = bean.getBoolean("autowireCandidate");
if (!autowireCandidate) {
beanDef.setAutowireCandidate(false);
}
String initMethodName = bean.getString("initMethod");
if (StringUtils.hasText(initMethodName)) {
beanDef.setInitMethodName(initMethodName);
}
String destroyMethodName = bean.getString("destroyMethod");
beanDef.setDestroyMethodName(destroyMethodName);
// scope 处理
// Consider scoping
ScopedProxyMode proxyMode = ScopedProxyMode.NO;
AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.clreplaced);
if (attributes != null) {
beanDef.setScope(attributes.getString("value"));
proxyMode = attributes.getEnum("proxyMode");
if (proxyMode == ScopedProxyMode.DEFAULT) {
proxyMode = ScopedProxyMode.NO;
}
}
// Replace the original bean definition with the target one, if necessary
BeanDefinition beanDefToRegister = beanDef;
if (proxyMode != ScopedProxyMode.NO) {
BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLreplaced);
beanDefToRegister = new ConfigurationClreplacedBeanDefinition((RootBeanDefinition) proxyDef.getBeanDefinition(), configClreplaced, metadata);
}
if (logger.isTraceEnabled()) {
logger.trace(String.format("Registering bean definition for @Bean method %s.%s()", configClreplaced.getMetadata().getClreplacedName(), beanName));
}
// 注册 Bean Definition
this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}
7
Source : ConfigurationClassBeanDefinitionReader.java
with MIT License
from mindcarver
with MIT License
from mindcarver
/**
* Read the given {@link BeanMethod}, registering bean definitions
* with the BeanDefinitionRegistry based on its contents.
*/
// for RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE
@SuppressWarnings("deprecation")
private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
ConfigurationClreplaced configClreplaced = beanMethod.getConfigurationClreplaced();
MethodMetadata metadata = beanMethod.getMetadata();
String methodName = metadata.getMethodName();
// Do we need to mark the bean as skipped by its condition?
if (this.conditionEvaluator.shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN)) {
configClreplaced.skippedBeanMethods.add(methodName);
return;
}
if (configClreplaced.skippedBeanMethods.contains(methodName)) {
return;
}
AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.clreplaced);
replacedert.state(bean != null, "No @Bean annotation attributes");
// Consider name and any aliases
List<String> names = new ArrayList<>(Arrays.asList(bean.getStringArray("name")));
String beanName = (!names.isEmpty() ? names.remove(0) : methodName);
// Register aliases even when overridden
for (String alias : names) {
this.registry.registerAlias(beanName, alias);
}
// Has this effectively been overridden before (e.g. via XML)?
if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
if (beanName.equals(beanMethod.getConfigurationClreplaced().getBeanName())) {
throw new BeanDefinitionStoreException(beanMethod.getConfigurationClreplaced().getResource().getDescription(), beanName, "Bean name derived from @Bean method '" + beanMethod.getMetadata().getMethodName() + "' clashes with bean name for containing configuration clreplaced; please make those names unique!");
}
return;
}
ConfigurationClreplacedBeanDefinition beanDef = new ConfigurationClreplacedBeanDefinition(configClreplaced, metadata);
beanDef.setResource(configClreplaced.getResource());
beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClreplaced.getResource()));
if (metadata.isStatic()) {
// static @Bean method
beanDef.setBeanClreplacedName(configClreplaced.getMetadata().getClreplacedName());
beanDef.setFactoryMethodName(methodName);
} else {
// instance @Bean method
beanDef.setFactoryBeanName(configClreplaced.getBeanName());
beanDef.setUniqueFactoryMethodName(methodName);
}
beanDef.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_CONSTRUCTOR);
beanDef.setAttribute(org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);
AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata);
Autowire autowire = bean.getEnum("autowire");
if (autowire.isAutowire()) {
beanDef.setAutowireMode(autowire.value());
}
boolean autowireCandidate = bean.getBoolean("autowireCandidate");
if (!autowireCandidate) {
beanDef.setAutowireCandidate(false);
}
String initMethodName = bean.getString("initMethod");
if (StringUtils.hasText(initMethodName)) {
beanDef.setInitMethodName(initMethodName);
}
String destroyMethodName = bean.getString("destroyMethod");
beanDef.setDestroyMethodName(destroyMethodName);
// Consider scoping
ScopedProxyMode proxyMode = ScopedProxyMode.NO;
AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.clreplaced);
if (attributes != null) {
beanDef.setScope(attributes.getString("value"));
proxyMode = attributes.getEnum("proxyMode");
if (proxyMode == ScopedProxyMode.DEFAULT) {
proxyMode = ScopedProxyMode.NO;
}
}
// Replace the original bean definition with the target one, if necessary
BeanDefinition beanDefToRegister = beanDef;
if (proxyMode != ScopedProxyMode.NO) {
BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLreplaced);
beanDefToRegister = new ConfigurationClreplacedBeanDefinition((RootBeanDefinition) proxyDef.getBeanDefinition(), configClreplaced, metadata);
}
if (logger.isTraceEnabled()) {
logger.trace(String.format("Registering bean definition for @Bean method %s.%s()", configClreplaced.getMetadata().getClreplacedName(), beanName));
}
this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}
6
Source : ConfigurationClassBeanDefinitionReader.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Read the given {@link BeanMethod}, registering bean definitions
* with the BeanDefinitionRegistry based on its contents.
*/
private void loadBeanDefinitionsForBeanMethod(BeanMethod beanMethod) {
ConfigurationClreplaced configClreplaced = beanMethod.getConfigurationClreplaced();
MethodMetadata metadata = beanMethod.getMetadata();
String methodName = metadata.getMethodName();
// Do we need to mark the bean as skipped by its condition?
if (this.conditionEvaluator.shouldSkip(metadata, ConfigurationPhase.REGISTER_BEAN)) {
configClreplaced.skippedBeanMethods.add(methodName);
return;
}
if (configClreplaced.skippedBeanMethods.contains(methodName)) {
return;
}
// Consider name and any aliases
AnnotationAttributes bean = AnnotationConfigUtils.attributesFor(metadata, Bean.clreplaced);
List<String> names = new ArrayList<String>(Arrays.asList(bean.getStringArray("name")));
String beanName = (names.size() > 0 ? names.remove(0) : methodName);
// Register aliases even when overridden
for (String alias : names) {
this.registry.registerAlias(beanName, alias);
}
// Has this effectively been overridden before (e.g. via XML)?
if (isOverriddenByExistingDefinition(beanMethod, beanName)) {
return;
}
ConfigurationClreplacedBeanDefinition beanDef = new ConfigurationClreplacedBeanDefinition(configClreplaced, metadata);
beanDef.setResource(configClreplaced.getResource());
beanDef.setSource(this.sourceExtractor.extractSource(metadata, configClreplaced.getResource()));
if (metadata.isStatic()) {
// static @Bean method
beanDef.setBeanClreplacedName(configClreplaced.getMetadata().getClreplacedName());
beanDef.setFactoryMethodName(methodName);
} else {
// instance @Bean method
beanDef.setFactoryBeanName(configClreplaced.getBeanName());
beanDef.setUniqueFactoryMethodName(methodName);
}
beanDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_CONSTRUCTOR);
beanDef.setAttribute(RequiredAnnotationBeanPostProcessor.SKIP_REQUIRED_CHECK_ATTRIBUTE, Boolean.TRUE);
AnnotationConfigUtils.processCommonDefinitionAnnotations(beanDef, metadata);
Autowire autowire = bean.getEnum("autowire");
if (autowire.isAutowire()) {
beanDef.setAutowireMode(autowire.value());
}
String initMethodName = bean.getString("initMethod");
if (StringUtils.hasText(initMethodName)) {
beanDef.setInitMethodName(initMethodName);
}
String destroyMethodName = bean.getString("destroyMethod");
if (destroyMethodName != null) {
beanDef.setDestroyMethodName(destroyMethodName);
}
// Consider scoping
ScopedProxyMode proxyMode = ScopedProxyMode.NO;
AnnotationAttributes attributes = AnnotationConfigUtils.attributesFor(metadata, Scope.clreplaced);
if (attributes != null) {
beanDef.setScope(attributes.getAliasedString("value", Scope.clreplaced, configClreplaced.getResource()));
proxyMode = attributes.getEnum("proxyMode");
if (proxyMode == ScopedProxyMode.DEFAULT) {
proxyMode = ScopedProxyMode.NO;
}
}
// Replace the original bean definition with the target one, if necessary
BeanDefinition beanDefToRegister = beanDef;
if (proxyMode != ScopedProxyMode.NO) {
BeanDefinitionHolder proxyDef = ScopedProxyCreator.createScopedProxy(new BeanDefinitionHolder(beanDef, beanName), this.registry, proxyMode == ScopedProxyMode.TARGET_CLreplaced);
beanDefToRegister = new ConfigurationClreplacedBeanDefinition((RootBeanDefinition) proxyDef.getBeanDefinition(), configClreplaced, metadata);
}
if (logger.isDebugEnabled()) {
logger.debug(String.format("Registering bean definition for @Bean method %s.%s()", configClreplaced.getMetadata().getClreplacedName(), beanName));
}
this.registry.registerBeanDefinition(beanName, beanDefToRegister);
}