Skip to content

Commit 529f311

Browse files
committed
Polish and harmonize implementations of SpEL components in spring-context
1 parent ea8f8f7 commit 529f311

File tree

6 files changed

+33
-34
lines changed

6 files changed

+33
-34
lines changed

spring-context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -25,15 +25,20 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
* EL property accessor that knows how to traverse the beans and contextual objects
29-
* of a Spring {@link org.springframework.beans.factory.config.BeanExpressionContext}.
28+
* SpEL {@link PropertyAccessor} that knows how to access the beans and contextual
29+
* objects of a Spring {@link BeanExpressionContext}.
3030
*
3131
* @author Juergen Hoeller
3232
* @author Andy Clement
3333
* @since 3.0
3434
*/
3535
public class BeanExpressionContextAccessor implements PropertyAccessor {
3636

37+
@Override
38+
public Class<?>[] getSpecificTargetClasses() {
39+
return new Class<?>[] {BeanExpressionContext.class};
40+
}
41+
3742
@Override
3843
public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
3944
return (target instanceof BeanExpressionContext bec && bec.containsObject(name));
@@ -57,9 +62,4 @@ public void write(EvaluationContext context, @Nullable Object target, String nam
5762
throw new AccessException("Beans in a BeanFactory are read-only");
5863
}
5964

60-
@Override
61-
public Class<?>[] getSpecificTargetClasses() {
62-
return new Class<?>[] {BeanExpressionContext.class};
63-
}
64-
6565
}

spring-context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -25,8 +25,8 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
* EL property accessor that knows how to traverse the beans of a
29-
* Spring {@link org.springframework.beans.factory.BeanFactory}.
28+
* SpEL {@link PropertyAccessor} that knows how to access the beans of a
29+
* Spring {@link BeanFactory}.
3030
*
3131
* @author Juergen Hoeller
3232
* @author Andy Clement

spring-context/src/main/java/org/springframework/context/expression/BeanFactoryResolver.java

Lines changed: 4 additions & 5 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-2024 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.
@@ -24,8 +24,7 @@
2424
import org.springframework.util.Assert;
2525

2626
/**
27-
* EL bean resolver that operates against a Spring
28-
* {@link org.springframework.beans.factory.BeanFactory}.
27+
* SpEL {@link BeanResolver} that operates against a Spring {@link BeanFactory}.
2928
*
3029
* @author Juergen Hoeller
3130
* @since 3.0.4
@@ -36,8 +35,8 @@ public class BeanFactoryResolver implements BeanResolver {
3635

3736

3837
/**
39-
* Create a new {@link BeanFactoryResolver} for the given factory.
40-
* @param beanFactory the {@link BeanFactory} to resolve bean names against
38+
* Create a new {@code BeanFactoryResolver} for the given factory.
39+
* @param beanFactory the {@code BeanFactory} to resolve bean names against
4140
*/
4241
public BeanFactoryResolver(BeanFactory beanFactory) {
4342
Assert.notNull(beanFactory, "BeanFactory must not be null");

spring-context/src/main/java/org/springframework/context/expression/EnvironmentAccessor.java

Lines changed: 7 additions & 12 deletions
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-2024 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.
@@ -25,7 +25,7 @@
2525
import org.springframework.util.Assert;
2626

2727
/**
28-
* Read-only EL property accessor that knows how to retrieve keys
28+
* Read-only SpEL {@link PropertyAccessor} that knows how to retrieve properties
2929
* of a Spring {@link Environment} instance.
3030
*
3131
* @author Chris Beams
@@ -38,18 +38,14 @@ public Class<?>[] getSpecificTargetClasses() {
3838
return new Class<?>[] {Environment.class};
3939
}
4040

41-
/**
42-
* Can read any {@link Environment}, thus always returns true.
43-
* @return true
44-
*/
4541
@Override
4642
public boolean canRead(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
47-
return true;
43+
return (target instanceof Environment);
4844
}
4945

5046
/**
51-
* Access the given target object by resolving the given property name against the given target
52-
* environment.
47+
* Access the given target object by resolving the given property name against
48+
* the given target environment.
5349
*/
5450
@Override
5551
public TypedValue read(EvaluationContext context, @Nullable Object target, String name) throws AccessException {
@@ -65,12 +61,11 @@ public boolean canWrite(EvaluationContext context, @Nullable Object target, Stri
6561
return false;
6662
}
6763

68-
/**
69-
* Read-only: no-op.
70-
*/
7164
@Override
7265
public void write(EvaluationContext context, @Nullable Object target, String name, @Nullable Object newValue)
7366
throws AccessException {
67+
68+
throw new AccessException("The Environment is read-only");
7469
}
7570

7671
}

spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,16 @@
2121
import org.springframework.asm.MethodVisitor;
2222
import org.springframework.expression.AccessException;
2323
import org.springframework.expression.EvaluationContext;
24+
import org.springframework.expression.PropertyAccessor;
2425
import org.springframework.expression.TypedValue;
2526
import org.springframework.expression.spel.CodeFlow;
2627
import org.springframework.expression.spel.CompilablePropertyAccessor;
2728
import org.springframework.lang.Nullable;
2829
import org.springframework.util.Assert;
2930

3031
/**
31-
* EL property accessor that knows how to traverse the keys
32-
* of a standard {@link java.util.Map}.
32+
* SpEL {@link PropertyAccessor} that knows how to access the keys of a standard
33+
* {@link java.util.Map}.
3334
*
3435
* @author Juergen Hoeller
3536
* @author Andy Clement
@@ -39,8 +40,9 @@ public class MapAccessor implements CompilablePropertyAccessor {
3940

4041
private final boolean allowWrite;
4142

43+
4244
/**
43-
* Create a new map accessor for reading as well as writing.
45+
* Create a new {@code MapAccessor} for reading as well as writing.
4446
* @since 6.2
4547
* @see #MapAccessor(boolean)
4648
*/
@@ -49,7 +51,7 @@ public MapAccessor() {
4951
}
5052

5153
/**
52-
* Create a new map accessor for reading and possibly also writing.
54+
* Create a new {@code MapAccessor} for reading and possibly also writing.
5355
* @param allowWrite whether to allow write operations on a target instance
5456
* @since 6.2
5557
* @see #canWrite
@@ -58,6 +60,7 @@ public MapAccessor(boolean allowWrite) {
5860
this.allowWrite = allowWrite;
5961
}
6062

63+
6164
@Override
6265
public Class<?>[] getSpecificTargetClasses() {
6366
return new Class<?>[] {Map.class};

spring-expression/src/test/java/org/springframework/expression/spel/CompilableMapAccessor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ public class CompilableMapAccessor implements CompilablePropertyAccessor {
3636

3737
private final boolean allowWrite;
3838

39+
3940
/**
40-
* Create a new map accessor for reading as well as writing.
41+
* Create a new {@code CompilableMapAccessor} for reading as well as writing.
4142
* @since 6.2
4243
* @see #CompilableMapAccessor(boolean)
4344
*/
@@ -46,7 +47,7 @@ public CompilableMapAccessor() {
4647
}
4748

4849
/**
49-
* Create a new map accessor for reading and possibly also writing.
50+
* Create a new {@code CompilableMapAccessor} for reading and possibly also writing.
5051
* @param allowWrite whether to allow write operations on a target instance
5152
* @since 6.2
5253
* @see #canWrite
@@ -55,6 +56,7 @@ public CompilableMapAccessor(boolean allowWrite) {
5556
this.allowWrite = allowWrite;
5657
}
5758

59+
5860
@Override
5961
public Class<?>[] getSpecificTargetClasses() {
6062
return new Class<?>[] {Map.class};

0 commit comments

Comments
 (0)