Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化if判断逻辑,使开发者只需关心boolean变量本身 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,8 @@ protected Object[] scanAndProxyForTarget(Class<?> targetClass, String beanName,
if (StringUtils.isNotEmpty(targetClassName) && !targetClassName.startsWith("java.")) {
// 避免对同一个接口或者类扫描多次
Boolean proxied = proxyMap.get(targetClassName);
if (proxied != null) {
if (proxied) {
if (proxied != null && proxied) {
return interceptors;
}
} else {
Object[] proxyInterceptors = null;
switch (proxyMode) {
Expand Down Expand Up @@ -353,13 +351,14 @@ protected boolean scanPackagesContained(Class<?> beanClass) {
if (StringUtils.isNotEmpty(scanPackage)) {
// beanClassName有时候会为null...
String beanClassName = beanClass.getCanonicalName();
if (StringUtils.isNotEmpty(beanClassName)) {
if (beanClassName.startsWith(scanPackage) || beanClassName.contains(ProxyConstant.JDK_PROXY_NAME_KEY) || beanClassName.contains(ProxyConstant.CGLIB_PROXY_NAME_KEY)) {
return true;
}
} else {
return false;
boolean isBeanClassName = StringUtils.isNotEmpty(beanClassName) && beanClassName.startsWith(scanPackage)
|| beanClassName.contains(ProxyConstant.JDK_PROXY_NAME_KEY)
|| beanClassName.contains(ProxyConstant.CGLIB_PROXY_NAME_KEY);
if (isBeanClassName) {
return true;
}
return false;

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ protected ClassPathScanningCandidateComponentProvider getScanner() {
@Override
protected boolean isCandidateComponent(AnnotatedBeanDefinition beanDefinition) {
if (beanDefinition.getMetadata().isIndependent()) {
if (beanDefinition.getMetadata().isInterface() && beanDefinition.getMetadata().getInterfaceNames().length == 1 && Annotation.class.getName().equals(beanDefinition.getMetadata().getInterfaceNames()[0])) {
boolean isInterface = beanDefinition.getMetadata().isInterface() &&
beanDefinition.getMetadata().getInterfaceNames().length == 1 &&
Annotation.class.getName().equals(beanDefinition.getMetadata().getInterfaceNames()[0]);
if (isInterface) {
try {
Class<?> target = ClassUtils.forName(beanDefinition.getMetadata().getClassName(), AbstractRegistrar.this.classLoader);

Expand Down