Skip to content

Commit

Permalink
Complete removal of local variable support in SpEL
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Dec 15, 2024
1 parent af83a15 commit dd094b5
Showing 1 changed file with 0 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.function.Supplier;

Expand Down Expand Up @@ -64,9 +62,6 @@ public class ExpressionState {
@Nullable
private Deque<TypedValue> contextObjects;

@Nullable
private Deque<VariableScope> variableScopes;

// When entering a new scope there is a new base object which should be used
// for '#this' references (or to act as a target for unqualified references).
// This ArrayDeque captures those objects at each nested scope level.
Expand Down Expand Up @@ -207,12 +202,10 @@ public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor
* context object} and a new local variable scope.
*/
public void enterScope() {
initVariableScopes().push(new VariableScope());
initScopeRootObjects().push(getActiveContextObject());
}

public void exitScope() {
initVariableScopes().pop();
initScopeRootObjects().pop();
}

Expand All @@ -231,15 +224,6 @@ private Deque<TypedValue> initScopeRootObjects() {
return this.scopeRootObjects;
}

private Deque<VariableScope> initVariableScopes() {
if (this.variableScopes == null) {
this.variableScopes = new ArrayDeque<>();
// top-level empty variable scope
this.variableScopes.add(new VariableScope());
}
return this.variableScopes;
}

public TypedValue operate(Operation op, @Nullable Object left, @Nullable Object right) throws EvaluationException {
OperatorOverloader overloader = this.relatedContext.getOperatorOverloader();
if (overloader.overridesOperation(op, left, right)) {
Expand All @@ -265,43 +249,4 @@ public SpelParserConfiguration getConfiguration() {
return this.configuration;
}


/**
* A new local variable scope is entered when a new expression scope is
* entered and exited when the corresponding expression scope is exited.
*
* <p>If variable names clash with those in a higher level scope, those in
* the higher level scope will not be accessible within the current scope.
*/
private static class VariableScope {

private final Map<String, Object> variables = new HashMap<>();

VariableScope() {
}

VariableScope(String name, Object value) {
this.variables.put(name, value);
}

VariableScope(@Nullable Map<String, Object> variables) {
if (variables != null) {
this.variables.putAll(variables);
}
}

@Nullable
Object lookupVariable(String name) {
return this.variables.get(name);
}

void setVariable(String name, Object value) {
this.variables.put(name,value);
}

boolean definesVariable(String name) {
return this.variables.containsKey(name);
}
}

}

0 comments on commit dd094b5

Please sign in to comment.