Skip to content

Commit e50346a

Browse files
committed
Add @Contract and @CheckReturnValue annotations.
Closes: #3195 Original pull request: #3210
1 parent 6ac6de2 commit e50346a

File tree

177 files changed

+948
-795
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

177 files changed

+948
-795
lines changed

src/main/java/org/springframework/data/annotation/AccessType.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434

3535
/**
3636
* The access type to be used.
37-
*
38-
* @return
3937
*/
4038
Type value();
4139

src/main/java/org/springframework/data/annotation/PersistenceCreator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
*/
3030
@Retention(RetentionPolicy.RUNTIME)
3131
@Target({ ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.ANNOTATION_TYPE })
32-
public @interface PersistenceCreator {}
32+
public @interface PersistenceCreator {
33+
}

src/main/java/org/springframework/data/annotation/Reference.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@
3636
/**
3737
* Explicitly define the target type of the reference. Used in case the annotated property is not the target type but
3838
* rather an identifier and/or if that identifier type is not uniquely identifying the target entity.
39-
*
40-
* @return
4139
*/
4240
@AliasFor(attribute = "to")
4341
Class<?> value() default Class.class;
4442

4543
/**
4644
* Explicitly define the target type of the reference. Used in case the annotated property is not the target type but
4745
* rather an identifier and/or if that identifier type is not uniquely identifying the target entity.
48-
*
49-
* @return
5046
*/
5147
@AliasFor(attribute = "value")
5248
Class<?> to() default Class.class;

src/main/java/org/springframework/data/annotation/TypeAlias.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* {@link PersistentEntity}s.
3030
*
3131
* @author Oliver Gierke
32+
* @see org.springframework.data.mapping.Alias
3233
*/
3334
@Documented
3435
@Inherited
@@ -38,9 +39,7 @@
3839
public @interface TypeAlias {
3940

4041
/**
41-
* The type alias to be used when persisting
42-
*
43-
* @return
42+
* The type alias to be used when persisting.
4443
*/
4544
String value();
4645
}

src/main/java/org/springframework/data/annotation/Version.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,4 @@
3333
@Retention(RUNTIME)
3434
@Target(value = { FIELD, METHOD, ANNOTATION_TYPE })
3535
public @interface Version {
36-
3736
}

src/main/java/org/springframework/data/aot/AotContext.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ default Set<Class<?>> scanPackageForTypes(Collection<Class<? extends Annotation>
140140
}
141141

142142
/**
143-
* Returns a {@link IntrospectedBeanDefinition} to obtain further detail about the underlying bean definition. A
143+
* Returns a {@link IntrospectedBeanDefinition} to obtain further detail about the underlying bean definition. An
144144
* introspected bean definition can also point to an absent bean definition.
145145
*
146146
* @param reference {@link BeanReference} to the managed bean.
@@ -151,7 +151,7 @@ default IntrospectedBeanDefinition introspectBeanDefinition(BeanReference refere
151151
}
152152

153153
/**
154-
* Returns a {@link IntrospectedBeanDefinition} to obtain further detail about the underlying bean definition. A
154+
* Returns a {@link IntrospectedBeanDefinition} to obtain further detail about the underlying bean definition. An
155155
* introspected bean definition can also point to an absent bean definition.
156156
*
157157
* @param beanName {@link String} containing the {@literal name} of the bean to evaluate; must not be {@literal null}.
@@ -251,7 +251,6 @@ interface IntrospectedBeanDefinition {
251251
* bean}.
252252
* @see BeanDefinition
253253
*/
254-
255254
BeanDefinition getBeanDefinition() throws NoSuchBeanDefinitionException;
256255

257256
/**

src/main/java/org/springframework/data/aot/AuditingBeanRegistrationAotProcessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
*/
4040
class AuditingBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor {
4141

42-
4342
@Nullable
4443
@Override
4544
public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) {

src/main/java/org/springframework/data/aot/ManagedTypesBeanFactoryInitializationAotProcessor.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
3030
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
3131
import org.springframework.data.domain.ManagedTypes;
32+
import org.springframework.lang.Contract;
3233
import org.springframework.lang.Nullable;
3334
import org.springframework.util.CollectionUtils;
3435
import org.springframework.util.ObjectUtils;
@@ -44,10 +45,11 @@
4445
*/
4546
public class ManagedTypesBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor {
4647

47-
private static final Log logger = LogFactory.getLog(BeanFactoryInitializationAotProcessor.class);
48+
private static final Log logger = LogFactory.getLog(ManagedTypesBeanFactoryInitializationAotProcessor.class);
4849

49-
@Nullable
5050
@Override
51+
@Nullable
52+
@Contract("_ -> null")
5153
public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) {
5254

5355
processManagedTypes(beanFactory);
@@ -71,9 +73,9 @@ private void postProcessManagedTypes(ConfigurableListableBeanFactory beanFactory
7173

7274
if (hasConstructorArguments(beanDefinition)) {
7375

74-
ValueHolder argumentValue = beanDefinition.getConstructorArgumentValues().getArgumentValue(0, null, null, null);
76+
ValueHolder holder = beanDefinition.getConstructorArgumentValues().getArgumentValue(0, null, null, null);
7577

76-
if (argumentValue.getValue()instanceof Supplier supplier) {
78+
if (holder != null && holder.getValue() instanceof Supplier<?> supplier) {
7779

7880
if (logger.isDebugEnabled()) {
7981
logger.info(String.format("Replacing ManagedType bean definition %s.", beanName));

src/main/java/org/springframework/data/aot/ManagedTypesBeanRegistrationAotProcessor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ private ManagedTypes resolveManagedTypes(RegisteredBean registeredBean) {
7878
if (beanDefinition.hasConstructorArgumentValues()) {
7979

8080
ValueHolder indexedArgumentValue = beanDefinition.getConstructorArgumentValues().getIndexedArgumentValue(0, null);
81-
Object value = indexedArgumentValue.getValue();
8281

83-
if (value instanceof Collection<?> values && values.stream().allMatch(it -> it instanceof Class)) {
82+
if (indexedArgumentValue != null && indexedArgumentValue.getValue() instanceof Collection<?> values
83+
&& values.stream().allMatch(it -> it instanceof Class)) {
8484
return ManagedTypes.fromIterable((Collection<Class<?>>) values);
8585
}
8686
}
@@ -115,7 +115,6 @@ private ManagedTypes resolveManagedTypes(RegisteredBean registeredBean) {
115115
* @param managedTypes never {@literal null}.
116116
* @return new instance of {@link BeanRegistrationAotContribution} or {@literal null} if nothing to do.
117117
*/
118-
@Nullable
119118
protected BeanRegistrationAotContribution contribute(AotContext aotContext, ManagedTypes managedTypes,
120119
RegisteredBean registeredBean) {
121120
return new ManagedTypesRegistrationAotContribution(managedTypes, registeredBean, this::contributeType);

src/main/java/org/springframework/data/aot/ManagedTypesRegistrationAotContribution.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package org.springframework.data.aot;
1717

18-
import java.lang.reflect.Executable;
1918
import java.lang.reflect.Method;
2019
import java.util.Collections;
2120
import java.util.List;
@@ -69,8 +68,8 @@
6968
* @author John Blum
7069
* @author Christoph Strobl
7170
* @author Mark Paluch
72-
* @see org.springframework.beans.factory.aot.BeanRegistrationAotContribution
7371
* @since 3.0
72+
* @see org.springframework.beans.factory.aot.BeanRegistrationAotContribution
7473
*/
7574
class ManagedTypesRegistrationAotContribution implements RegisteredBeanAotContribution {
7675

@@ -126,7 +125,7 @@ static class ManagedTypesInstanceCodeFragment extends BeanRegistrationCodeFragme
126125
public static final ResolvableType MANAGED_TYPES_TYPE = ResolvableType.forType(ManagedTypes.class);
127126
private final List<Class<?>> sourceTypes;
128127
private final RegisteredBean source;
129-
private final Lazy<Method> instanceMethod = Lazy.of(this::findInstanceFactory);
128+
private final Lazy<Method> instanceMethod;
130129

131130
private static final TypeName WILDCARD = WildcardTypeName.subtypeOf(Object.class);
132131
private static final TypeName CLASS_OF_ANY = ParameterizedTypeName.get(ClassName.get(Class.class), WILDCARD);
@@ -139,6 +138,7 @@ protected ManagedTypesInstanceCodeFragment(List<Class<?>> sourceTypes, Registere
139138

140139
this.sourceTypes = sourceTypes;
141140
this.source = source;
141+
this.instanceMethod = Lazy.of(() -> findInstanceFactory(source.getBeanClass()));
142142
}
143143

144144
@Override
@@ -230,15 +230,15 @@ private CodeBlock toCodeBlock(List<Class<?>> values, boolean allPublic) {
230230
}
231231

232232
@Nullable
233-
private Method findInstanceFactory() {
233+
private static Method findInstanceFactory(Class<?> beanClass) {
234234

235-
for (Method beanMethod : ReflectionUtils.getDeclaredMethods(source.getBeanClass())) {
235+
for (Method beanMethod : ReflectionUtils.getDeclaredMethods(beanClass)) {
236236

237237
if (!isInstanceFactory(beanMethod)) {
238238
continue;
239239
}
240240

241-
ResolvableType parameterType = ResolvableType.forMethodParameter(beanMethod, 0, source.getBeanClass());
241+
ResolvableType parameterType = ResolvableType.forMethodParameter(beanMethod, 0, beanClass);
242242

243243
if (parameterType.isAssignableFrom(LIST_TYPE) || parameterType.isAssignableFrom(MANAGED_TYPES_TYPE)) {
244244
return beanMethod;

0 commit comments

Comments
 (0)