Skip to content

Commit 91b557e

Browse files
committed
Polishing
1 parent 567c769 commit 91b557e

File tree

2 files changed

+28
-38
lines changed

2 files changed

+28
-38
lines changed

spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,8 +41,8 @@
4141

4242
/**
4343
* Decorator for a standard {@link BeanInfo} object, e.g. as created by
44-
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register static
45-
* and/or non-void returning setter methods. For example:
44+
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register
45+
* static and/or non-void returning setter methods. For example:
4646
*
4747
* <pre class="code">
4848
* public class Bean {
@@ -487,7 +487,7 @@ public void setPropertyEditorClass(@Nullable Class<?> propertyEditorClass) {
487487
}
488488

489489
/*
490-
* See java.beans.IndexedPropertyDescriptor#equals(java.lang.Object)
490+
* See java.beans.IndexedPropertyDescriptor#equals
491491
*/
492492
@Override
493493
public boolean equals(@Nullable Object other) {

spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,6 @@ public int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreExce
232232
* @return the number of bean definitions found
233233
* @throws BeanDefinitionStoreException in case of loading or parsing errors
234234
*/
235-
@SuppressWarnings("rawtypes")
236235
public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefinitionStoreException {
237236
// Check for XML files and redirect them to the "standard" XmlBeanDefinitionReader
238237
String filename = encodedResource.getResource().getFilename();
@@ -245,10 +244,10 @@ public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefin
245244
}
246245

247246
@SuppressWarnings("serial")
248-
Closure beans = new Closure(this) {
247+
Closure<Object> beans = new Closure<Object>(this) {
249248
@Override
250249
public Object call(Object... args) {
251-
invokeBeanDefiningClosure((Closure) args[0]);
250+
invokeBeanDefiningClosure((Closure<?>) args[0]);
252251
return null;
253252
}
254253
};
@@ -290,8 +289,7 @@ public void setVariable(String name, Object value) {
290289
* @param closure the block or closure
291290
* @return this {@code GroovyBeanDefinitionReader} instance
292291
*/
293-
@SuppressWarnings("rawtypes")
294-
public GroovyBeanDefinitionReader beans(Closure closure) {
292+
public GroovyBeanDefinitionReader beans(Closure<?> closure) {
295293
return invokeBeanDefiningClosure(closure);
296294
}
297295

@@ -312,29 +310,25 @@ public GenericBeanDefinition bean(Class<?> type) {
312310
* @param args the constructors arguments and closure configurer
313311
* @return the bean definition
314312
*/
315-
@SuppressWarnings("rawtypes")
316313
public AbstractBeanDefinition bean(Class<?> type, Object...args) {
317314
GroovyBeanDefinitionWrapper current = this.currentBeanDefinition;
318315
try {
319-
Closure callable = null;
320-
Collection constructorArgs = null;
316+
Closure<?> callable = null;
317+
Collection<Object> constructorArgs = null;
321318
if (!ObjectUtils.isEmpty(args)) {
322319
int index = args.length;
323320
Object lastArg = args[index - 1];
324-
if (lastArg instanceof Closure) {
325-
callable = (Closure) lastArg;
321+
if (lastArg instanceof Closure<?>) {
322+
callable = (Closure<?>) lastArg;
326323
index--;
327324
}
328-
if (index > -1) {
329-
constructorArgs = resolveConstructorArguments(args, 0, index);
330-
}
325+
constructorArgs = resolveConstructorArguments(args, 0, index);
331326
}
332327
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(null, type, constructorArgs);
333328
if (callable != null) {
334329
callable.call(this.currentBeanDefinition);
335330
}
336331
return this.currentBeanDefinition.getBeanDefinition();
337-
338332
}
339333
finally {
340334
this.currentBeanDefinition = current;
@@ -381,11 +375,10 @@ public void importBeans(String resourcePattern) throws IOException {
381375
* takes a class argument.
382376
*/
383377
@Override
384-
@SuppressWarnings("rawtypes")
385378
public Object invokeMethod(String name, Object arg) {
386379
Object[] args = (Object[])arg;
387380
if ("beans".equals(name) && args.length == 1 && args[0] instanceof Closure) {
388-
return beans((Closure) args[0]);
381+
return beans((Closure<?>) args[0]);
389382
}
390383
else if ("ref".equals(name)) {
391384
String refName;
@@ -435,14 +428,13 @@ private boolean addDeferredProperty(String property, Object newValue) {
435428
return false;
436429
}
437430

438-
@SuppressWarnings("rawtypes")
439431
private void finalizeDeferredProperties() {
440432
for (DeferredProperty dp : this.deferredProperties.values()) {
441433
if (dp.value instanceof List) {
442-
dp.value = manageListIfNecessary((List) dp.value);
434+
dp.value = manageListIfNecessary((List<?>) dp.value);
443435
}
444436
else if (dp.value instanceof Map) {
445-
dp.value = manageMapIfNecessary((Map) dp.value);
437+
dp.value = manageMapIfNecessary((Map<?, ?>) dp.value);
446438
}
447439
dp.apply();
448440
}
@@ -454,8 +446,7 @@ else if (dp.value instanceof Map) {
454446
* @param callable the closure argument
455447
* @return this {@code GroovyBeanDefinitionReader} instance
456448
*/
457-
@SuppressWarnings("rawtypes")
458-
protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable) {
449+
protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure<?> callable) {
459450
callable.setDelegate(this);
460451
callable.call();
461452
finalizeDeferredProperties();
@@ -469,7 +460,6 @@ protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable)
469460
* argument is sometimes a closure. All the arguments in between are constructor arguments.
470461
* @return the bean definition wrapper
471462
*/
472-
@SuppressWarnings("rawtypes")
473463
private GroovyBeanDefinitionWrapper invokeBeanDefiningMethod(String beanName, Object[] args) {
474464
boolean hasClosureArgument = (args[args.length - 1] instanceof Closure);
475465
if (args[0] instanceof Class) {
@@ -495,9 +485,10 @@ else if (args[0] instanceof RuntimeBeanReference) {
495485
else if (args[0] instanceof Map) {
496486
// named constructor arguments
497487
if (args.length > 1 && args[1] instanceof Class) {
498-
List<Object> constructorArgs = resolveConstructorArguments(args, 2, hasClosureArgument ? args.length - 1 : args.length);
488+
List<Object> constructorArgs =
489+
resolveConstructorArguments(args, 2, hasClosureArgument ? args.length - 1 : args.length);
499490
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, (Class<?>) args[1], constructorArgs);
500-
Map namedArgs = (Map) args[0];
491+
Map<?, ?> namedArgs = (Map<?, ?>) args[0];
501492
for (Object o : namedArgs.keySet()) {
502493
String propName = (String) o;
503494
setProperty(propName, namedArgs.get(propName));
@@ -507,7 +498,7 @@ else if (args[0] instanceof Map) {
507498
else {
508499
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName);
509500
// First arg is the map containing factoryBean : factoryMethod
510-
Map.Entry factoryBeanEntry = (Map.Entry) ((Map) args[0]).entrySet().iterator().next();
501+
Map.Entry<?, ?> factoryBeanEntry = ((Map<?, ?>) args[0]).entrySet().iterator().next();
511502
// If we have a closure body, that will be the last argument.
512503
// In between are the constructor args
513504
int constructorArgsTest = (hasClosureArgument ? 2 : 1);
@@ -531,12 +522,13 @@ else if (args[0] instanceof Closure) {
531522
this.currentBeanDefinition.getBeanDefinition().setAbstract(true);
532523
}
533524
else {
534-
List constructorArgs = resolveConstructorArguments(args, 0, hasClosureArgument ? args.length - 1 : args.length);
525+
List<Object> constructorArgs =
526+
resolveConstructorArguments(args, 0, hasClosureArgument ? args.length - 1 : args.length);
535527
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, null, constructorArgs);
536528
}
537529

538530
if (hasClosureArgument) {
539-
Closure callable = (Closure) args[args.length - 1];
531+
Closure<?> callable = (Closure<?>) args[args.length - 1];
540532
callable.setDelegate(this);
541533
callable.setResolveStrategy(Closure.DELEGATE_FIRST);
542534
callable.call(this.currentBeanDefinition);
@@ -549,18 +541,17 @@ else if (args[0] instanceof Closure) {
549541
return beanDefinition;
550542
}
551543

552-
@SuppressWarnings("rawtypes")
553544
protected List<Object> resolveConstructorArguments(Object[] args, int start, int end) {
554545
Object[] constructorArgs = Arrays.copyOfRange(args, start, end);
555546
for (int i = 0; i < constructorArgs.length; i++) {
556547
if (constructorArgs[i] instanceof GString) {
557548
constructorArgs[i] = constructorArgs[i].toString();
558549
}
559550
else if (constructorArgs[i] instanceof List) {
560-
constructorArgs[i] = manageListIfNecessary((List) constructorArgs[i]);
551+
constructorArgs[i] = manageListIfNecessary((List<?>) constructorArgs[i]);
561552
}
562553
else if (constructorArgs[i] instanceof Map){
563-
constructorArgs[i] = manageMapIfNecessary((Map) constructorArgs[i]);
554+
constructorArgs[i] = manageMapIfNecessary((Map<?, ?>) constructorArgs[i]);
564555
}
565556
}
566557
return Arrays.asList(constructorArgs);
@@ -621,7 +612,6 @@ public void setProperty(String name, Object value) {
621612
}
622613
}
623614

624-
@SuppressWarnings("rawtypes")
625615
protected void applyPropertyToBeanDefinition(String name, Object value) {
626616
if (value instanceof GString) {
627617
value = value.toString();
@@ -632,7 +622,7 @@ protected void applyPropertyToBeanDefinition(String name, Object value) {
632622
else if (value instanceof Closure) {
633623
GroovyBeanDefinitionWrapper current = this.currentBeanDefinition;
634624
try {
635-
Closure callable = (Closure) value;
625+
Closure<?> callable = (Closure<?>) value;
636626
Class<?> parameterType = callable.getParameterTypes()[0];
637627
if (Object.class == parameterType) {
638628
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper("");
@@ -833,8 +823,8 @@ public boolean add(Object value) {
833823
return retVal;
834824
}
835825

836-
@SuppressWarnings({ "rawtypes", "unused" })
837-
public boolean addAll(Collection values) {
826+
@SuppressWarnings("unused")
827+
public boolean addAll(Collection<?> values) {
838828
boolean retVal = (Boolean) InvokerHelper.invokeMethod(this.propertyValue, "addAll", values);
839829
for (Object value : values) {
840830
updateDeferredProperties(value);

0 commit comments

Comments
 (0)