Skip to content

Commit 4f86282

Browse files
committed
Polishing
1 parent b3237f3 commit 4f86282

File tree

10 files changed

+63
-30
lines changed

10 files changed

+63
-30
lines changed

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

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,12 @@ public GroovyBeanDefinitionReader(XmlBeanDefinitionReader xmlBeanDefinitionReade
182182
}
183183

184184

185+
@Override
185186
public void setMetaClass(MetaClass metaClass) {
186187
this.metaClass = metaClass;
187188
}
188189

190+
@Override
189191
public MetaClass getMetaClass() {
190192
return this.metaClass;
191193
}
@@ -216,6 +218,7 @@ public Binding getBinding() {
216218
* @return the number of bean definitions found
217219
* @throws BeanDefinitionStoreException in case of loading or parsing errors
218220
*/
221+
@Override
219222
public int loadBeanDefinitions(Resource resource) throws BeanDefinitionStoreException {
220223
return loadBeanDefinitions(new EncodedResource(resource));
221224
}
@@ -240,10 +243,11 @@ public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefin
240243
logger.trace("Loading Groovy bean definitions from " + encodedResource);
241244
}
242245

243-
Closure beans = new Closure(this) {
246+
@SuppressWarnings("serial")
247+
Closure<Object> beans = new Closure<Object>(this) {
244248
@Override
245-
public Object call(Object[] args) {
246-
invokeBeanDefiningClosure((Closure) args[0]);
249+
public Object call(Object... args) {
250+
invokeBeanDefiningClosure((Closure<?>) args[0]);
247251
return null;
248252
}
249253
};
@@ -285,7 +289,7 @@ public void setVariable(String name, Object value) {
285289
* @param closure the block or closure
286290
* @return this {@code GroovyBeanDefinitionReader} instance
287291
*/
288-
public GroovyBeanDefinitionReader beans(Closure closure) {
292+
public GroovyBeanDefinitionReader beans(Closure<?> closure) {
289293
return invokeBeanDefiningClosure(closure);
290294
}
291295

@@ -309,13 +313,13 @@ public GenericBeanDefinition bean(Class<?> type) {
309313
public AbstractBeanDefinition bean(Class<?> type, Object...args) {
310314
GroovyBeanDefinitionWrapper current = this.currentBeanDefinition;
311315
try {
312-
Closure callable = null;
316+
Closure<?> callable = null;
313317
Collection<Object> constructorArgs = null;
314318
if (!ObjectUtils.isEmpty(args)) {
315319
int index = args.length;
316320
Object lastArg = args[index - 1];
317-
if (lastArg instanceof Closure) {
318-
callable = (Closure) lastArg;
321+
if (lastArg instanceof Closure<?>) {
322+
callable = (Closure<?>) lastArg;
319323
index--;
320324
}
321325
constructorArgs = resolveConstructorArguments(args, 0, index);
@@ -370,10 +374,11 @@ public void importBeans(String resourcePattern) throws IOException {
370374
* This method overrides method invocation to create beans for each method name that
371375
* takes a class argument.
372376
*/
377+
@Override
373378
public Object invokeMethod(String name, Object arg) {
374379
Object[] args = (Object[])arg;
375380
if ("beans".equals(name) && args.length == 1 && args[0] instanceof Closure) {
376-
return beans((Closure) args[0]);
381+
return beans((Closure<?>) args[0]);
377382
}
378383
else if ("ref".equals(name)) {
379384
String refName;
@@ -426,10 +431,10 @@ private boolean addDeferredProperty(String property, Object newValue) {
426431
private void finalizeDeferredProperties() {
427432
for (DeferredProperty dp : this.deferredProperties.values()) {
428433
if (dp.value instanceof List) {
429-
dp.value = manageListIfNecessary((List) dp.value);
434+
dp.value = manageListIfNecessary((List<?>) dp.value);
430435
}
431436
else if (dp.value instanceof Map) {
432-
dp.value = manageMapIfNecessary((Map) dp.value);
437+
dp.value = manageMapIfNecessary((Map<?, ?>) dp.value);
433438
}
434439
dp.apply();
435440
}
@@ -441,7 +446,7 @@ else if (dp.value instanceof Map) {
441446
* @param callable the closure argument
442447
* @return this {@code GroovyBeanDefinitionReader} instance
443448
*/
444-
protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure callable) {
449+
protected GroovyBeanDefinitionReader invokeBeanDefiningClosure(Closure<?> callable) {
445450
callable.setDelegate(this);
446451
callable.call();
447452
finalizeDeferredProperties();
@@ -480,9 +485,10 @@ else if (args[0] instanceof RuntimeBeanReference) {
480485
else if (args[0] instanceof Map) {
481486
// named constructor arguments
482487
if (args.length > 1 && args[1] instanceof Class) {
483-
List constructorArgs = resolveConstructorArguments(args, 2, hasClosureArgument ? args.length - 1 : args.length);
484-
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, (Class)args[1], constructorArgs);
485-
Map namedArgs = (Map)args[0];
488+
List<Object> constructorArgs =
489+
resolveConstructorArguments(args, 2, hasClosureArgument ? args.length - 1 : args.length);
490+
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, (Class<?>) args[1], constructorArgs);
491+
Map<?, ?> namedArgs = (Map<?, ?>) args[0];
486492
for (Object o : namedArgs.keySet()) {
487493
String propName = (String) o;
488494
setProperty(propName, namedArgs.get(propName));
@@ -491,8 +497,8 @@ else if (args[0] instanceof Map) {
491497
// factory method syntax
492498
else {
493499
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName);
494-
//First arg is the map containing factoryBean : factoryMethod
495-
Map.Entry factoryBeanEntry = (Map.Entry) ((Map) args[0]).entrySet().iterator().next();
500+
// First arg is the map containing factoryBean : factoryMethod
501+
Map.Entry<?, ?> factoryBeanEntry = ((Map<?, ?>) args[0]).entrySet().iterator().next();
496502
// If we have a closure body, that will be the last argument.
497503
// In between are the constructor args
498504
int constructorArgsTest = (hasClosureArgument ? 2 : 1);
@@ -516,12 +522,13 @@ else if (args[0] instanceof Closure) {
516522
this.currentBeanDefinition.getBeanDefinition().setAbstract(true);
517523
}
518524
else {
519-
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);
520527
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, null, constructorArgs);
521528
}
522529

523530
if (hasClosureArgument) {
524-
Closure callable = (Closure) args[args.length - 1];
531+
Closure<?> callable = (Closure<?>) args[args.length - 1];
525532
callable.setDelegate(this);
526533
callable.setResolveStrategy(Closure.DELEGATE_FIRST);
527534
callable.call(this.currentBeanDefinition);
@@ -541,10 +548,10 @@ protected List<Object> resolveConstructorArguments(Object[] args, int start, int
541548
constructorArgs[i] = constructorArgs[i].toString();
542549
}
543550
else if (constructorArgs[i] instanceof List) {
544-
constructorArgs[i] = manageListIfNecessary((List) constructorArgs[i]);
551+
constructorArgs[i] = manageListIfNecessary((List<?>) constructorArgs[i]);
545552
}
546553
else if (constructorArgs[i] instanceof Map){
547-
constructorArgs[i] = manageMapIfNecessary((Map) constructorArgs[i]);
554+
constructorArgs[i] = manageMapIfNecessary((Map<?, ?>) constructorArgs[i]);
548555
}
549556
}
550557
return Arrays.asList(constructorArgs);
@@ -598,6 +605,7 @@ private Object manageListIfNecessary(List<?> list) {
598605
* This method overrides property setting in the scope of the {@code GroovyBeanDefinitionReader}
599606
* to set properties on the current bean definition.
600607
*/
608+
@Override
601609
public void setProperty(String name, Object value) {
602610
if (this.currentBeanDefinition != null) {
603611
applyPropertyToBeanDefinition(name, value);
@@ -614,7 +622,7 @@ protected void applyPropertyToBeanDefinition(String name, Object value) {
614622
else if (value instanceof Closure) {
615623
GroovyBeanDefinitionWrapper current = this.currentBeanDefinition;
616624
try {
617-
Closure callable = (Closure) value;
625+
Closure<?> callable = (Closure<?>) value;
618626
Class<?> parameterType = callable.getParameterTypes()[0];
619627
if (Object.class == parameterType) {
620628
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper("");
@@ -644,6 +652,7 @@ else if (value instanceof Closure) {
644652
* properties from the {@code GroovyBeanDefinitionReader} itself
645653
* </ul>
646654
*/
655+
@Override
647656
public Object getProperty(String name) {
648657
Binding binding = getBinding();
649658
if (binding != null && binding.hasVariable(name)) {
@@ -687,8 +696,8 @@ else if (this.currentBeanDefinition != null) {
687696
}
688697

689698
private GroovyDynamicElementReader createDynamicElementReader(String namespace) {
690-
XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(new DescriptiveResource(
691-
"Groovy"));
699+
XmlReaderContext readerContext = this.groovyDslXmlBeanDefinitionReader.createReaderContext(
700+
new DescriptiveResource("Groovy"));
692701
BeanDefinitionParserDelegate delegate = new BeanDefinitionParserDelegate(readerContext);
693702
boolean decorating = (this.currentBeanDefinition != null);
694703
if (!decorating) {
@@ -746,10 +755,12 @@ public GroovyRuntimeBeanReference(String beanName, GroovyBeanDefinitionWrapper b
746755
this.metaClass = InvokerHelper.getMetaClass(this);
747756
}
748757

758+
@Override
749759
public MetaClass getMetaClass() {
750760
return this.metaClass;
751761
}
752762

763+
@Override
753764
public Object getProperty(String property) {
754765
if (property.equals("beanName")) {
755766
return getBeanName();
@@ -766,14 +777,17 @@ else if (this.beanDefinition != null) {
766777
}
767778
}
768779

780+
@Override
769781
public Object invokeMethod(String name, Object args) {
770782
return this.metaClass.invokeMethod(this, name, args);
771783
}
772784

785+
@Override
773786
public void setMetaClass(MetaClass metaClass) {
774787
this.metaClass = metaClass;
775788
}
776789

790+
@Override
777791
public void setProperty(String property, Object newValue) {
778792
if (!addDeferredProperty(property, newValue)) {
779793
this.beanDefinition.getBeanDefinition().getPropertyValues().add(property, newValue);
@@ -782,7 +796,7 @@ public void setProperty(String property, Object newValue) {
782796

783797

784798
/**
785-
* Wraps a bean definition property an ensures that any RuntimeBeanReference
799+
* Wraps a bean definition property and ensures that any RuntimeBeanReference
786800
* additions to it are deferred for resolution later.
787801
*/
788802
private class GroovyPropertyValue extends GroovyObjectSupport {
@@ -796,17 +810,20 @@ public GroovyPropertyValue(String propertyName, Object propertyValue) {
796810
this.propertyValue = propertyValue;
797811
}
798812

813+
@SuppressWarnings("unused")
799814
public void leftShift(Object value) {
800815
InvokerHelper.invokeMethod(this.propertyValue, "leftShift", value);
801816
updateDeferredProperties(value);
802817
}
803818

819+
@SuppressWarnings("unused")
804820
public boolean add(Object value) {
805821
boolean retVal = (Boolean) InvokerHelper.invokeMethod(this.propertyValue, "add", value);
806822
updateDeferredProperties(value);
807823
return retVal;
808824
}
809825

826+
@SuppressWarnings("unused")
810827
public boolean addAll(Collection<?> values) {
811828
boolean retVal = (Boolean) InvokerHelper.invokeMethod(this.propertyValue, "addAll", values);
812829
for (Object value : values) {

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

Lines changed: 2 additions & 2 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.
@@ -196,7 +196,7 @@ else if (Boolean.TRUE.equals(newValue)) {
196196
// constructorArgs
197197
else if (CONSTRUCTOR_ARGS.equals(property) && newValue instanceof List) {
198198
ConstructorArgumentValues cav = new ConstructorArgumentValues();
199-
List args = (List) newValue;
199+
List<?> args = (List<?>) newValue;
200200
for (Object arg : args) {
201201
cav.addGenericArgumentValue(arg);
202202
}

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ protected void destroyBean(String beanName, @Nullable DisposableBean bean) {
612612
* should <i>not</i> have their own mutexes involved in singleton creation,
613613
* to avoid the potential for deadlocks in lazy-init situations.
614614
*/
615+
@Override
615616
public final Object getSingletonMutex() {
616617
return this.singletonObjects;
617618
}

spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public JCacheOperationSource getCacheOperationSource() {
8888
return this.cacheOperationSource;
8989
}
9090

91+
@Override
9192
public void afterPropertiesSet() {
9293
getCacheOperationSource();
9394

spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java

Lines changed: 3 additions & 3 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.
@@ -110,7 +110,7 @@ public Connection getConnection() throws SQLException {
110110
public void shutdown() {
111111
// Do nothing - a Spring-managed DataSource has its own lifecycle.
112112
}
113-
/* Quartz 2.2 initialize method */
113+
@Override
114114
public void initialize() {
115115
// Do nothing - a Spring-managed DataSource has its own lifecycle.
116116
}
@@ -138,7 +138,7 @@ public Connection getConnection() throws SQLException {
138138
public void shutdown() {
139139
// Do nothing - a Spring-managed DataSource has its own lifecycle.
140140
}
141-
/* Quartz 2.2 initialize method */
141+
@Override
142142
public void initialize() {
143143
// Do nothing - a Spring-managed DataSource has its own lifecycle.
144144
}

spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 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.
@@ -82,6 +82,7 @@ public Class<?> loadClass(String name) throws ClassNotFoundException {
8282
}
8383

8484
@SuppressWarnings("unchecked")
85+
@Override
8586
public <T> Class<? extends T> loadClass(String name, Class<T> clazz) throws ClassNotFoundException {
8687
return (Class<? extends T>) loadClass(name);
8788
}

spring-context/src/main/java/org/springframework/context/support/GenericGroovyApplicationContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,18 +225,22 @@ public void load(Class<?> relativeClass, String... resourceNames) {
225225

226226
// Implementation of the GroovyObject interface
227227

228+
@Override
228229
public void setMetaClass(MetaClass metaClass) {
229230
this.metaClass = metaClass;
230231
}
231232

233+
@Override
232234
public MetaClass getMetaClass() {
233235
return this.metaClass;
234236
}
235237

238+
@Override
236239
public Object invokeMethod(String name, Object args) {
237240
return this.metaClass.invokeMethod(this, name, args);
238241
}
239242

243+
@Override
240244
public void setProperty(String property, Object newValue) {
241245
if (newValue instanceof BeanDefinition) {
242246
registerBeanDefinition(property, (BeanDefinition) newValue);
@@ -246,6 +250,7 @@ public void setProperty(String property, Object newValue) {
246250
}
247251
}
248252

253+
@Override
249254
@Nullable
250255
public Object getProperty(String property) {
251256
if (containsBean(property)) {

spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageProducer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ public boolean getDisableMessageTimestamp() throws JMSException {
8989
return this.target.getDisableMessageTimestamp();
9090
}
9191

92+
@Override
9293
public void setDeliveryDelay(long deliveryDelay) throws JMSException {
9394
if (this.originalDeliveryDelay == null) {
9495
this.originalDeliveryDelay = this.target.getDeliveryDelay();
9596
}
9697
this.target.setDeliveryDelay(deliveryDelay);
9798
}
9899

100+
@Override
99101
public long getDeliveryDelay() throws JMSException {
100102
return this.target.getDeliveryDelay();
101103
}

spring-web/src/main/java/org/springframework/web/context/support/GroovyWebApplicationContext.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,27 @@ protected String[] getDefaultConfigLocations() {
154154

155155
// Implementation of the GroovyObject interface
156156

157+
@Override
157158
public void setMetaClass(MetaClass metaClass) {
158159
this.metaClass = metaClass;
159160
}
160161

162+
@Override
161163
public MetaClass getMetaClass() {
162164
return this.metaClass;
163165
}
164166

167+
@Override
165168
public Object invokeMethod(String name, Object args) {
166169
return this.metaClass.invokeMethod(this, name, args);
167170
}
168171

172+
@Override
169173
public void setProperty(String property, Object newValue) {
170174
this.metaClass.setProperty(this, property, newValue);
171175
}
172176

177+
@Override
173178
@Nullable
174179
public Object getProperty(String property) {
175180
if (containsBean(property)) {

0 commit comments

Comments
 (0)