This is an automated email from the ASF dual-hosted git repository.

iluo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git


The following commit(s) were added to refs/heads/master by this push:
     new 288c1a5  polish code (#3823)
288c1a5 is described below

commit 288c1a582c819c2c70f58ef41840915b5c407e7a
Author: Alex <[email protected]>
AuthorDate: Tue Apr 9 10:20:27 2019 +0800

    polish code (#3823)
    
    * polish code and fix some documentation errors
    
    * polish code
    
    * polish code
    
    * polish code
---
 dubbo-bom/pom.xml                                  |  1 -
 .../AnnotationInjectedBeanPostProcessor.java       | 65 ++++++++++------------
 .../DubboConfigBindingBeanPostProcessor.java       |  2 +-
 .../ReferenceAnnotationBeanPostProcessor.java      | 21 +++----
 .../ServiceAnnotationBeanPostProcessor.java        |  6 +-
 ...pertyDefaultValueDubboConfigBeanCustomizer.java |  2 +-
 .../spring/schema/DubboBeanDefinitionParser.java   |  3 +-
 .../config/spring/util/PropertySourcesUtils.java   |  2 +-
 8 files changed, 46 insertions(+), 56 deletions(-)

diff --git a/dubbo-bom/pom.xml b/dubbo-bom/pom.xml
index 3d28b43..058a198 100644
--- a/dubbo-bom/pom.xml
+++ b/dubbo-bom/pom.xml
@@ -25,7 +25,6 @@
         <version>2.7.2-SNAPSHOT</version>
     </parent>
 
-    <groupId>org.apache.dubbo</groupId>
     <artifactId>dubbo-bom</artifactId>
     <version>2.7.2-SNAPSHOT</version>
     <packaging>pom</packaging>
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java
index 30592a1..53ff695 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java
@@ -82,7 +82,7 @@ public abstract class AnnotationInjectedBeanPostProcessor<A 
extends Annotation>
     private final ConcurrentMap<String, 
AnnotationInjectedBeanPostProcessor.AnnotatedInjectionMetadata> 
injectionMetadataCache =
             new ConcurrentHashMap<String, 
AnnotationInjectedBeanPostProcessor.AnnotatedInjectionMetadata>(CACHE_SIZE);
 
-    private final ConcurrentMap<String, Object> injectedObjectsCache = new 
ConcurrentHashMap<String, Object>(CACHE_SIZE);
+    private final ConcurrentMap<String, Object> injectedObjectsCache = new 
ConcurrentHashMap<>(CACHE_SIZE);
 
     private ConfigurableListableBeanFactory beanFactory;
 
@@ -96,8 +96,9 @@ public abstract class AnnotationInjectedBeanPostProcessor<A 
extends Annotation>
         this.annotationType = resolveGenericType(getClass());
     }
 
+    @SafeVarargs
     private static <T> Collection<T> combine(Collection<? extends T>... 
elements) {
-        List<T> allElements = new ArrayList<T>();
+        List<T> allElements = new ArrayList<>();
         for (Collection<? extends T> e : elements) {
             allElements.addAll(e);
         }
@@ -147,25 +148,22 @@ public abstract class 
AnnotationInjectedBeanPostProcessor<A extends Annotation>
 
         final List<AnnotationInjectedBeanPostProcessor.AnnotatedFieldElement> 
elements = new 
LinkedList<AnnotationInjectedBeanPostProcessor.AnnotatedFieldElement>();
 
-        ReflectionUtils.doWithFields(beanClass, new 
ReflectionUtils.FieldCallback() {
-            @Override
-            public void doWith(Field field) throws IllegalArgumentException, 
IllegalAccessException {
+        ReflectionUtils.doWithFields(beanClass, field -> {
 
-                A annotation = getAnnotation(field, getAnnotationType());
+            A annotation = getAnnotation(field, getAnnotationType());
 
-                if (annotation != null) {
+            if (annotation != null) {
 
-                    if (Modifier.isStatic(field.getModifiers())) {
-                        if (logger.isWarnEnabled()) {
-                            logger.warn("@" + getAnnotationType().getName() + 
" is not supported on static fields: " + field);
-                        }
-                        return;
+                if (Modifier.isStatic(field.getModifiers())) {
+                    if (logger.isWarnEnabled()) {
+                        logger.warn("@" + getAnnotationType().getName() + " is 
not supported on static fields: " + field);
                     }
-
-                    elements.add(new 
AnnotationInjectedBeanPostProcessor.AnnotatedFieldElement(field, annotation));
+                    return;
                 }
 
+                elements.add(new AnnotatedFieldElement(field, annotation));
             }
+
         });
 
         return elements;
@@ -182,34 +180,31 @@ public abstract class 
AnnotationInjectedBeanPostProcessor<A extends Annotation>
 
         final List<AnnotationInjectedBeanPostProcessor.AnnotatedMethodElement> 
elements = new 
LinkedList<AnnotationInjectedBeanPostProcessor.AnnotatedMethodElement>();
 
-        ReflectionUtils.doWithMethods(beanClass, new 
ReflectionUtils.MethodCallback() {
-            @Override
-            public void doWith(Method method) throws IllegalArgumentException, 
IllegalAccessException {
+        ReflectionUtils.doWithMethods(beanClass, method -> {
 
-                Method bridgedMethod = findBridgedMethod(method);
+            Method bridgedMethod = findBridgedMethod(method);
 
-                if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) {
-                    return;
-                }
+            if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) {
+                return;
+            }
 
-                A annotation = findAnnotation(bridgedMethod, 
getAnnotationType());
+            A annotation = findAnnotation(bridgedMethod, getAnnotationType());
 
-                if (annotation != null && 
method.equals(ClassUtils.getMostSpecificMethod(method, beanClass))) {
-                    if (Modifier.isStatic(method.getModifiers())) {
-                        if (logger.isWarnEnabled()) {
-                            logger.warn("@" + 
getAnnotationType().getSimpleName() + " annotation is not supported on static 
methods: " + method);
-                        }
-                        return;
+            if (annotation != null && 
method.equals(ClassUtils.getMostSpecificMethod(method, beanClass))) {
+                if (Modifier.isStatic(method.getModifiers())) {
+                    if (logger.isWarnEnabled()) {
+                        logger.warn("@" + getAnnotationType().getSimpleName() 
+ " annotation is not supported on static methods: " + method);
                     }
-                    if (method.getParameterTypes().length == 0) {
-                        if (logger.isWarnEnabled()) {
-                            logger.warn("@" + 
getAnnotationType().getSimpleName() + " annotation should only be used on 
methods with parameters: " +
-                                    method);
-                        }
+                    return;
+                }
+                if (method.getParameterTypes().length == 0) {
+                    if (logger.isWarnEnabled()) {
+                        logger.warn("@" + getAnnotationType().getSimpleName() 
+ " annotation should only be used on methods with parameters: " +
+                                method);
                     }
-                    PropertyDescriptor pd = 
BeanUtils.findPropertyForMethod(bridgedMethod, beanClass);
-                    elements.add(new 
AnnotationInjectedBeanPostProcessor.AnnotatedMethodElement(method, pd, 
annotation));
                 }
+                PropertyDescriptor pd = 
BeanUtils.findPropertyForMethod(bridgedMethod, beanClass);
+                elements.add(new AnnotatedMethodElement(method, pd, 
annotation));
             }
         });
 
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/DubboConfigBindingBeanPostProcessor.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/DubboConfigBindingBeanPostProcessor.java
index 4430c9f..ad2218f 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/DubboConfigBindingBeanPostProcessor.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/DubboConfigBindingBeanPostProcessor.java
@@ -186,7 +186,7 @@ public class DubboConfigBindingBeanPostProcessor implements 
BeanPostProcessor, A
         Collection<DubboConfigBeanCustomizer> configBeanCustomizers =
                 beansOfTypeIncludingAncestors(applicationContext, 
DubboConfigBeanCustomizer.class).values();
 
-        this.configBeanCustomizers = new 
ArrayList<DubboConfigBeanCustomizer>(configBeanCustomizers);
+        this.configBeanCustomizers = new ArrayList<>(configBeanCustomizers);
 
         AnnotationAwareOrderComparator.sort(this.configBeanCustomizers);
     }
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
index 94bf9e8..7c3a6b9 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java
@@ -61,16 +61,16 @@ public class ReferenceAnnotationBeanPostProcessor extends 
AnnotationInjectedBean
     private static final int CACHE_SIZE = Integer.getInteger(BEAN_NAME + 
".cache.size", 32);
 
     private final ConcurrentMap<String, ReferenceBean<?>> referenceBeanCache =
-            new ConcurrentHashMap<String, ReferenceBean<?>>(CACHE_SIZE);
+            new ConcurrentHashMap<>(CACHE_SIZE);
 
     private final ConcurrentHashMap<String, ReferenceBeanInvocationHandler> 
localReferenceBeanInvocationHandlerCache =
-            new ConcurrentHashMap<String, 
ReferenceBeanInvocationHandler>(CACHE_SIZE);
+            new ConcurrentHashMap<>(CACHE_SIZE);
 
     private final ConcurrentMap<InjectionMetadata.InjectedElement, 
ReferenceBean<?>> injectedFieldReferenceBeanCache =
-            new ConcurrentHashMap<InjectionMetadata.InjectedElement, 
ReferenceBean<?>>(CACHE_SIZE);
+            new ConcurrentHashMap<>(CACHE_SIZE);
 
     private final ConcurrentMap<InjectionMetadata.InjectedElement, 
ReferenceBean<?>> injectedMethodReferenceBeanCache =
-            new ConcurrentHashMap<InjectionMetadata.InjectedElement, 
ReferenceBean<?>>(CACHE_SIZE);
+            new ConcurrentHashMap<>(CACHE_SIZE);
 
     private ApplicationContext applicationContext;
 
@@ -114,15 +114,12 @@ public class ReferenceAnnotationBeanPostProcessor extends 
AnnotationInjectedBean
 
         cacheInjectedReferenceBean(referenceBean, injectedElement);
 
-        Object proxy = buildProxy(referencedBeanName, referenceBean, 
injectedType);
-
-        return proxy;
+        return buildProxy(referencedBeanName, referenceBean, injectedType);
     }
 
     private Object buildProxy(String referencedBeanName, ReferenceBean 
referenceBean, Class<?> injectedType) {
         InvocationHandler handler = buildInvocationHandler(referencedBeanName, 
referenceBean);
-        Object proxy = Proxy.newProxyInstance(getClassLoader(), new 
Class[]{injectedType}, handler);
-        return proxy;
+        return Proxy.newProxyInstance(getClassLoader(), new 
Class[]{injectedType}, handler);
     }
 
     private InvocationHandler buildInvocationHandler(String 
referencedBeanName, ReferenceBean referenceBean) {
@@ -156,7 +153,7 @@ public class ReferenceAnnotationBeanPostProcessor extends 
AnnotationInjectedBean
 
         @Override
         public Object invoke(Object proxy, Method method, Object[] args) 
throws Throwable {
-            Object result = null;
+            Object result;
             try {
                 if (bean == null) { // If the bean is not initialized, invoke 
init()
                     // issue: 
https://github.com/apache/incubator-dubbo/issues/3429
@@ -179,11 +176,9 @@ public class ReferenceAnnotationBeanPostProcessor extends 
AnnotationInjectedBean
     protected String buildInjectedObjectCacheKey(Reference reference, Object 
bean, String beanName,
                                                  Class<?> injectedType, 
InjectionMetadata.InjectedElement injectedElement) {
 
-        String key = buildReferencedBeanName(reference, injectedType) +
+        return buildReferencedBeanName(reference, injectedType) +
                 "#source=" + (injectedElement.getMember()) +
                 "#attributes=" + 
AnnotationUtils.getAttributes(reference,getEnvironment(),true);
-
-        return key;
     }
 
     private String buildReferencedBeanName(Reference reference, Class<?> 
injectedType) {
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
index 532026d..8a07fee 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java
@@ -88,7 +88,7 @@ public class ServiceAnnotationBeanPostProcessor implements 
BeanDefinitionRegistr
     }
 
     public ServiceAnnotationBeanPostProcessor(Collection<String> 
packagesToScan) {
-        this(new LinkedHashSet<String>(packagesToScan));
+        this(new LinkedHashSet<>(packagesToScan));
     }
 
     public ServiceAnnotationBeanPostProcessor(Set<String> packagesToScan) {
@@ -218,7 +218,7 @@ public class ServiceAnnotationBeanPostProcessor implements 
BeanDefinitionRegistr
 
         Set<BeanDefinition> beanDefinitions = 
scanner.findCandidateComponents(packageToScan);
 
-        Set<BeanDefinitionHolder> beanDefinitionHolders = new 
LinkedHashSet<BeanDefinitionHolder>(beanDefinitions.size());
+        Set<BeanDefinitionHolder> beanDefinitionHolders = new 
LinkedHashSet<>(beanDefinitions.size());
 
         for (BeanDefinition beanDefinition : beanDefinitions) {
 
@@ -443,7 +443,7 @@ public class ServiceAnnotationBeanPostProcessor implements 
BeanDefinitionRegistr
 
     private ManagedList<RuntimeBeanReference> 
toRuntimeBeanReferences(String... beanNames) {
 
-        ManagedList<RuntimeBeanReference> runtimeBeanReferences = new 
ManagedList<RuntimeBeanReference>();
+        ManagedList<RuntimeBeanReference> runtimeBeanReferences = new 
ManagedList<>();
 
         if (!ObjectUtils.isEmpty(beanNames)) {
 
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java
index fcd053d..2f8c446 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java
@@ -67,7 +67,7 @@ public class 
NamePropertyDefaultValueDubboConfigBeanCustomizer implements DubboC
             }
 
             Method setNameMethod = propertyDescriptor.getWriteMethod();
-            if (setNameMethod != null && getNameMethod != null) { // "setName" 
and "getName" methods are present
+            if (setNameMethod != null) { // "setName" and "getName" methods 
are present
                 if (Arrays.equals(of(String.class), 
setNameMethod.getParameterTypes())) { // the param type is String
                     // set bean name to the value of the "name" property
                     ReflectionUtils.invokeMethod(setNameMethod, 
dubboConfigBean, beanName);
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
index 9272b7f..3c69294 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java
@@ -125,7 +125,7 @@ public class DubboBeanDefinitionParser implements 
BeanDefinitionParser {
         } else if (ConsumerConfig.class.equals(beanClass)) {
             parseNested(element, parserContext, ReferenceBean.class, false, 
"reference", "consumer", id, beanDefinition);
         }
-        Set<String> props = new HashSet<String>();
+        Set<String> props = new HashSet<>();
         ManagedMap parameters = null;
         for (Method setter : beanClass.getMethods()) {
             String name = setter.getName();
@@ -143,6 +143,7 @@ public class DubboBeanDefinitionParser implements 
BeanDefinitionParser {
                     try {
                         getter = beanClass.getMethod("is" + name.substring(3), 
new Class<?>[0]);
                     } catch (NoSuchMethodException e2) {
+                        logger.error("Method " + name + " parse error,  cause: 
" + e2.getMessage(), e2);
                     }
                 }
                 if (getter == null
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/PropertySourcesUtils.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/PropertySourcesUtils.java
index 8a07057..119a1f8 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/PropertySourcesUtils.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/PropertySourcesUtils.java
@@ -72,7 +72,7 @@ public abstract class PropertySourcesUtils {
      */
     public static Map<String, Object> getSubProperties(ConfigurableEnvironment 
environment, String prefix) {
 
-        Map<String, Object> subProperties = new LinkedHashMap<String, 
Object>();
+        Map<String, Object> subProperties = new LinkedHashMap<>();
 
         MutablePropertySources propertySources = 
environment.getPropertySources();
 

Reply via email to