1
1
/*
2
- * Copyright 2002-2023 the original author or authors.
2
+ * Copyright 2002-2024 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
54
54
import org .springframework .core .io .Resource ;
55
55
import org .springframework .core .io .support .EncodedResource ;
56
56
import org .springframework .lang .Nullable ;
57
+ import org .springframework .util .Assert ;
57
58
import org .springframework .util .ObjectUtils ;
58
59
import org .springframework .util .StringUtils ;
59
60
@@ -250,6 +251,7 @@ public int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefin
250
251
@ SuppressWarnings ("serial" )
251
252
Closure <Object > beans = new Closure <>(this ) {
252
253
@ Override
254
+ @ Nullable
253
255
public Object call (Object ... args ) {
254
256
invokeBeanDefiningClosure ((Closure <?>) args [0 ]);
255
257
return null ;
@@ -425,6 +427,7 @@ else if (args.length > 1 && args[args.length -1] instanceof Closure) {
425
427
426
428
private boolean addDeferredProperty (String property , Object newValue ) {
427
429
if (newValue instanceof List || newValue instanceof Map ) {
430
+ Assert .state (this .currentBeanDefinition != null , "No current bean definition set" );
428
431
this .deferredProperties .put (this .currentBeanDefinition .getBeanName () + '.' + property ,
429
432
new DeferredProperty (this .currentBeanDefinition , property , newValue ));
430
433
return true ;
@@ -640,6 +643,7 @@ else if (value instanceof Closure<?> callable) {
640
643
this .currentBeanDefinition = current ;
641
644
}
642
645
}
646
+ Assert .state (this .currentBeanDefinition != null , "No current bean definition set" );
643
647
this .currentBeanDefinition .addProperty (name , value );
644
648
}
645
649
@@ -654,6 +658,7 @@ else if (value instanceof Closure<?> callable) {
654
658
* </ul>
655
659
*/
656
660
@ Override
661
+ @ Nullable
657
662
public Object getProperty (String name ) {
658
663
Binding binding = getBinding ();
659
664
if (binding != null && binding .hasVariable (name )) {
@@ -727,9 +732,10 @@ private static class DeferredProperty {
727
732
728
733
private final String name ;
729
734
735
+ @ Nullable
730
736
public Object value ;
731
737
732
- public DeferredProperty (GroovyBeanDefinitionWrapper beanDefinition , String name , Object value ) {
738
+ public DeferredProperty (GroovyBeanDefinitionWrapper beanDefinition , String name , @ Nullable Object value ) {
733
739
this .beanDefinition = beanDefinition ;
734
740
this .name = name ;
735
741
this .value = value ;
@@ -762,20 +768,18 @@ public MetaClass getMetaClass() {
762
768
}
763
769
764
770
@ Override
771
+ @ Nullable
765
772
public Object getProperty (String property ) {
766
773
if (property .equals ("beanName" )) {
767
774
return getBeanName ();
768
775
}
769
776
else if (property .equals ("source" )) {
770
777
return getSource ();
771
778
}
772
- else if ( this . beanDefinition != null ) {
779
+ else {
773
780
return new GroovyPropertyValue (
774
781
property , this .beanDefinition .getBeanDefinition ().getPropertyValues ().get (property ));
775
782
}
776
- else {
777
- return this .metaClass .getProperty (this , property );
778
- }
779
783
}
780
784
781
785
@ Override
@@ -804,9 +808,10 @@ private class GroovyPropertyValue extends GroovyObjectSupport {
804
808
805
809
private final String propertyName ;
806
810
811
+ @ Nullable
807
812
private final Object propertyValue ;
808
813
809
- public GroovyPropertyValue (String propertyName , Object propertyValue ) {
814
+ public GroovyPropertyValue (String propertyName , @ Nullable Object propertyValue ) {
810
815
this .propertyName = propertyName ;
811
816
this .propertyValue = propertyValue ;
812
817
}
0 commit comments