Skip to content

Commit 288c1a5

Browse files
chenlushunbeiwei30
authored andcommitted
polish code (#3823)
* polish code and fix some documentation errors * polish code * polish code * polish code
1 parent 2bfe25e commit 288c1a5

File tree

8 files changed

+46
-56
lines changed

8 files changed

+46
-56
lines changed

dubbo-bom/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
<version>2.7.2-SNAPSHOT</version>
2626
</parent>
2727

28-
<groupId>org.apache.dubbo</groupId>
2928
<artifactId>dubbo-bom</artifactId>
3029
<version>2.7.2-SNAPSHOT</version>
3130
<packaging>pom</packaging>

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/AnnotationInjectedBeanPostProcessor.java

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public abstract class AnnotationInjectedBeanPostProcessor<A extends Annotation>
8282
private final ConcurrentMap<String, AnnotationInjectedBeanPostProcessor.AnnotatedInjectionMetadata> injectionMetadataCache =
8383
new ConcurrentHashMap<String, AnnotationInjectedBeanPostProcessor.AnnotatedInjectionMetadata>(CACHE_SIZE);
8484

85-
private final ConcurrentMap<String, Object> injectedObjectsCache = new ConcurrentHashMap<String, Object>(CACHE_SIZE);
85+
private final ConcurrentMap<String, Object> injectedObjectsCache = new ConcurrentHashMap<>(CACHE_SIZE);
8686

8787
private ConfigurableListableBeanFactory beanFactory;
8888

@@ -96,8 +96,9 @@ public AnnotationInjectedBeanPostProcessor() {
9696
this.annotationType = resolveGenericType(getClass());
9797
}
9898

99+
@SafeVarargs
99100
private static <T> Collection<T> combine(Collection<? extends T>... elements) {
100-
List<T> allElements = new ArrayList<T>();
101+
List<T> allElements = new ArrayList<>();
101102
for (Collection<? extends T> e : elements) {
102103
allElements.addAll(e);
103104
}
@@ -147,25 +148,22 @@ private List<AnnotationInjectedBeanPostProcessor.AnnotatedFieldElement> findFiel
147148

148149
final List<AnnotationInjectedBeanPostProcessor.AnnotatedFieldElement> elements = new LinkedList<AnnotationInjectedBeanPostProcessor.AnnotatedFieldElement>();
149150

150-
ReflectionUtils.doWithFields(beanClass, new ReflectionUtils.FieldCallback() {
151-
@Override
152-
public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
151+
ReflectionUtils.doWithFields(beanClass, field -> {
153152

154-
A annotation = getAnnotation(field, getAnnotationType());
153+
A annotation = getAnnotation(field, getAnnotationType());
155154

156-
if (annotation != null) {
155+
if (annotation != null) {
157156

158-
if (Modifier.isStatic(field.getModifiers())) {
159-
if (logger.isWarnEnabled()) {
160-
logger.warn("@" + getAnnotationType().getName() + " is not supported on static fields: " + field);
161-
}
162-
return;
157+
if (Modifier.isStatic(field.getModifiers())) {
158+
if (logger.isWarnEnabled()) {
159+
logger.warn("@" + getAnnotationType().getName() + " is not supported on static fields: " + field);
163160
}
164-
165-
elements.add(new AnnotationInjectedBeanPostProcessor.AnnotatedFieldElement(field, annotation));
161+
return;
166162
}
167163

164+
elements.add(new AnnotatedFieldElement(field, annotation));
168165
}
166+
169167
});
170168

171169
return elements;
@@ -182,34 +180,31 @@ private List<AnnotationInjectedBeanPostProcessor.AnnotatedMethodElement> findAnn
182180

183181
final List<AnnotationInjectedBeanPostProcessor.AnnotatedMethodElement> elements = new LinkedList<AnnotationInjectedBeanPostProcessor.AnnotatedMethodElement>();
184182

185-
ReflectionUtils.doWithMethods(beanClass, new ReflectionUtils.MethodCallback() {
186-
@Override
187-
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
183+
ReflectionUtils.doWithMethods(beanClass, method -> {
188184

189-
Method bridgedMethod = findBridgedMethod(method);
185+
Method bridgedMethod = findBridgedMethod(method);
190186

191-
if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) {
192-
return;
193-
}
187+
if (!isVisibilityBridgeMethodPair(method, bridgedMethod)) {
188+
return;
189+
}
194190

195-
A annotation = findAnnotation(bridgedMethod, getAnnotationType());
191+
A annotation = findAnnotation(bridgedMethod, getAnnotationType());
196192

197-
if (annotation != null && method.equals(ClassUtils.getMostSpecificMethod(method, beanClass))) {
198-
if (Modifier.isStatic(method.getModifiers())) {
199-
if (logger.isWarnEnabled()) {
200-
logger.warn("@" + getAnnotationType().getSimpleName() + " annotation is not supported on static methods: " + method);
201-
}
202-
return;
193+
if (annotation != null && method.equals(ClassUtils.getMostSpecificMethod(method, beanClass))) {
194+
if (Modifier.isStatic(method.getModifiers())) {
195+
if (logger.isWarnEnabled()) {
196+
logger.warn("@" + getAnnotationType().getSimpleName() + " annotation is not supported on static methods: " + method);
203197
}
204-
if (method.getParameterTypes().length == 0) {
205-
if (logger.isWarnEnabled()) {
206-
logger.warn("@" + getAnnotationType().getSimpleName() + " annotation should only be used on methods with parameters: " +
207-
method);
208-
}
198+
return;
199+
}
200+
if (method.getParameterTypes().length == 0) {
201+
if (logger.isWarnEnabled()) {
202+
logger.warn("@" + getAnnotationType().getSimpleName() + " annotation should only be used on methods with parameters: " +
203+
method);
209204
}
210-
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, beanClass);
211-
elements.add(new AnnotationInjectedBeanPostProcessor.AnnotatedMethodElement(method, pd, annotation));
212205
}
206+
PropertyDescriptor pd = BeanUtils.findPropertyForMethod(bridgedMethod, beanClass);
207+
elements.add(new AnnotatedMethodElement(method, pd, annotation));
213208
}
214209
});
215210

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/DubboConfigBindingBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private void initConfigBeanCustomizers() {
186186
Collection<DubboConfigBeanCustomizer> configBeanCustomizers =
187187
beansOfTypeIncludingAncestors(applicationContext, DubboConfigBeanCustomizer.class).values();
188188

189-
this.configBeanCustomizers = new ArrayList<DubboConfigBeanCustomizer>(configBeanCustomizers);
189+
this.configBeanCustomizers = new ArrayList<>(configBeanCustomizers);
190190

191191
AnnotationAwareOrderComparator.sort(this.configBeanCustomizers);
192192
}

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ReferenceAnnotationBeanPostProcessor.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ public class ReferenceAnnotationBeanPostProcessor extends AnnotationInjectedBean
6161
private static final int CACHE_SIZE = Integer.getInteger(BEAN_NAME + ".cache.size", 32);
6262

6363
private final ConcurrentMap<String, ReferenceBean<?>> referenceBeanCache =
64-
new ConcurrentHashMap<String, ReferenceBean<?>>(CACHE_SIZE);
64+
new ConcurrentHashMap<>(CACHE_SIZE);
6565

6666
private final ConcurrentHashMap<String, ReferenceBeanInvocationHandler> localReferenceBeanInvocationHandlerCache =
67-
new ConcurrentHashMap<String, ReferenceBeanInvocationHandler>(CACHE_SIZE);
67+
new ConcurrentHashMap<>(CACHE_SIZE);
6868

6969
private final ConcurrentMap<InjectionMetadata.InjectedElement, ReferenceBean<?>> injectedFieldReferenceBeanCache =
70-
new ConcurrentHashMap<InjectionMetadata.InjectedElement, ReferenceBean<?>>(CACHE_SIZE);
70+
new ConcurrentHashMap<>(CACHE_SIZE);
7171

7272
private final ConcurrentMap<InjectionMetadata.InjectedElement, ReferenceBean<?>> injectedMethodReferenceBeanCache =
73-
new ConcurrentHashMap<InjectionMetadata.InjectedElement, ReferenceBean<?>>(CACHE_SIZE);
73+
new ConcurrentHashMap<>(CACHE_SIZE);
7474

7575
private ApplicationContext applicationContext;
7676

@@ -114,15 +114,12 @@ protected Object doGetInjectedBean(Reference reference, Object bean, String bean
114114

115115
cacheInjectedReferenceBean(referenceBean, injectedElement);
116116

117-
Object proxy = buildProxy(referencedBeanName, referenceBean, injectedType);
118-
119-
return proxy;
117+
return buildProxy(referencedBeanName, referenceBean, injectedType);
120118
}
121119

122120
private Object buildProxy(String referencedBeanName, ReferenceBean referenceBean, Class<?> injectedType) {
123121
InvocationHandler handler = buildInvocationHandler(referencedBeanName, referenceBean);
124-
Object proxy = Proxy.newProxyInstance(getClassLoader(), new Class[]{injectedType}, handler);
125-
return proxy;
122+
return Proxy.newProxyInstance(getClassLoader(), new Class[]{injectedType}, handler);
126123
}
127124

128125
private InvocationHandler buildInvocationHandler(String referencedBeanName, ReferenceBean referenceBean) {
@@ -156,7 +153,7 @@ private ReferenceBeanInvocationHandler(ReferenceBean referenceBean) {
156153

157154
@Override
158155
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
159-
Object result = null;
156+
Object result;
160157
try {
161158
if (bean == null) { // If the bean is not initialized, invoke init()
162159
// issue: https://github.com/apache/incubator-dubbo/issues/3429
@@ -179,11 +176,9 @@ private void init() {
179176
protected String buildInjectedObjectCacheKey(Reference reference, Object bean, String beanName,
180177
Class<?> injectedType, InjectionMetadata.InjectedElement injectedElement) {
181178

182-
String key = buildReferencedBeanName(reference, injectedType) +
179+
return buildReferencedBeanName(reference, injectedType) +
183180
"#source=" + (injectedElement.getMember()) +
184181
"#attributes=" + AnnotationUtils.getAttributes(reference,getEnvironment(),true);
185-
186-
return key;
187182
}
188183

189184
private String buildReferencedBeanName(Reference reference, Class<?> injectedType) {

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/beans/factory/annotation/ServiceAnnotationBeanPostProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public ServiceAnnotationBeanPostProcessor(String... packagesToScan) {
8888
}
8989

9090
public ServiceAnnotationBeanPostProcessor(Collection<String> packagesToScan) {
91-
this(new LinkedHashSet<String>(packagesToScan));
91+
this(new LinkedHashSet<>(packagesToScan));
9292
}
9393

9494
public ServiceAnnotationBeanPostProcessor(Set<String> packagesToScan) {
@@ -218,7 +218,7 @@ private Set<BeanDefinitionHolder> findServiceBeanDefinitionHolders(
218218

219219
Set<BeanDefinition> beanDefinitions = scanner.findCandidateComponents(packageToScan);
220220

221-
Set<BeanDefinitionHolder> beanDefinitionHolders = new LinkedHashSet<BeanDefinitionHolder>(beanDefinitions.size());
221+
Set<BeanDefinitionHolder> beanDefinitionHolders = new LinkedHashSet<>(beanDefinitions.size());
222222

223223
for (BeanDefinition beanDefinition : beanDefinitions) {
224224

@@ -443,7 +443,7 @@ private AbstractBeanDefinition buildServiceBeanDefinition(Service service, Class
443443

444444
private ManagedList<RuntimeBeanReference> toRuntimeBeanReferences(String... beanNames) {
445445

446-
ManagedList<RuntimeBeanReference> runtimeBeanReferences = new ManagedList<RuntimeBeanReference>();
446+
ManagedList<RuntimeBeanReference> runtimeBeanReferences = new ManagedList<>();
447447

448448
if (!ObjectUtils.isEmpty(beanNames)) {
449449

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/config/NamePropertyDefaultValueDubboConfigBeanCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void customize(String beanName, AbstractConfig dubboConfigBean) {
6767
}
6868

6969
Method setNameMethod = propertyDescriptor.getWriteMethod();
70-
if (setNameMethod != null && getNameMethod != null) { // "setName" and "getName" methods are present
70+
if (setNameMethod != null) { // "setName" and "getName" methods are present
7171
if (Arrays.equals(of(String.class), setNameMethod.getParameterTypes())) { // the param type is String
7272
// set bean name to the value of the "name" property
7373
ReflectionUtils.invokeMethod(setNameMethod, dubboConfigBean, beanName);

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/schema/DubboBeanDefinitionParser.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private static BeanDefinition parse(Element element, ParserContext parserContext
125125
} else if (ConsumerConfig.class.equals(beanClass)) {
126126
parseNested(element, parserContext, ReferenceBean.class, false, "reference", "consumer", id, beanDefinition);
127127
}
128-
Set<String> props = new HashSet<String>();
128+
Set<String> props = new HashSet<>();
129129
ManagedMap parameters = null;
130130
for (Method setter : beanClass.getMethods()) {
131131
String name = setter.getName();
@@ -143,6 +143,7 @@ private static BeanDefinition parse(Element element, ParserContext parserContext
143143
try {
144144
getter = beanClass.getMethod("is" + name.substring(3), new Class<?>[0]);
145145
} catch (NoSuchMethodException e2) {
146+
logger.error("Method " + name + " parse error, cause: " + e2.getMessage(), e2);
146147
}
147148
}
148149
if (getter == null

dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/util/PropertySourcesUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Map<String, Object> getSubProperties(Iterable<PropertySource<?>> p
7272
*/
7373
public static Map<String, Object> getSubProperties(ConfigurableEnvironment environment, String prefix) {
7474

75-
Map<String, Object> subProperties = new LinkedHashMap<String, Object>();
75+
Map<String, Object> subProperties = new LinkedHashMap<>();
7676

7777
MutablePropertySources propertySources = environment.getPropertySources();
7878

0 commit comments

Comments
 (0)