Internal adaptation to Deque semantics
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -47,7 +47,7 @@ public final class ParserContext {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private BeanDefinition containingBeanDefinition;
|
private BeanDefinition containingBeanDefinition;
|
||||||
|
|
||||||
private final Deque<ComponentDefinition> containingComponents = new ArrayDeque<>();
|
private final Deque<CompositeComponentDefinition> containingComponents = new ArrayDeque<>();
|
||||||
|
|
||||||
|
|
||||||
public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate) {
|
public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate) {
|
||||||
@@ -96,8 +96,7 @@ public final class ParserContext {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public CompositeComponentDefinition getContainingComponent() {
|
public CompositeComponentDefinition getContainingComponent() {
|
||||||
return (!this.containingComponents.isEmpty() ?
|
return this.containingComponents.peek();
|
||||||
(CompositeComponentDefinition) this.containingComponents.getLast() : null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushContainingComponent(CompositeComponentDefinition containingComponent) {
|
public void pushContainingComponent(CompositeComponentDefinition containingComponent) {
|
||||||
@@ -105,7 +104,7 @@ public final class ParserContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public CompositeComponentDefinition popContainingComponent() {
|
public CompositeComponentDefinition popContainingComponent() {
|
||||||
return (CompositeComponentDefinition) this.containingComponents.pop();
|
return this.containingComponents.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void popAndRegisterContainingComponent() {
|
public void popAndRegisterContainingComponent() {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,9 +20,9 @@ import java.io.Serializable;
|
|||||||
import java.util.ArrayDeque;
|
import java.util.ArrayDeque;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Deque;
|
import java.util.Deque;
|
||||||
import java.util.EmptyStackException;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.springframework.lang.Nullable;
|
import org.springframework.lang.Nullable;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
@@ -62,12 +62,12 @@ public abstract class AbstractErrors implements Errors, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void popNestedPath() throws IllegalArgumentException {
|
public void popNestedPath() throws IllegalStateException {
|
||||||
try {
|
try {
|
||||||
String formerNestedPath = this.nestedPathStack.pop();
|
String formerNestedPath = this.nestedPathStack.pop();
|
||||||
doSetNestedPath(formerNestedPath);
|
doSetNestedPath(formerNestedPath);
|
||||||
}
|
}
|
||||||
catch (EmptyStackException ex) {
|
catch (NoSuchElementException ex) {
|
||||||
throw new IllegalStateException("Cannot pop nested path: no nested path on stack");
|
throw new IllegalStateException("Cannot pop nested path: no nested path on stack");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2017 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -23,6 +23,7 @@ import java.util.HashMap;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
import org.springframework.core.convert.TypeDescriptor;
|
import org.springframework.core.convert.TypeDescriptor;
|
||||||
import org.springframework.expression.EvaluationContext;
|
import org.springframework.expression.EvaluationContext;
|
||||||
@@ -49,6 +50,7 @@ import org.springframework.util.CollectionUtils;
|
|||||||
* nodes might need.
|
* nodes might need.
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
|
* @author Juergen Hoeller
|
||||||
* @since 3.0
|
* @since 3.0
|
||||||
*/
|
*/
|
||||||
public class ExpressionState {
|
public class ExpressionState {
|
||||||
@@ -118,8 +120,13 @@ public class ExpressionState {
|
|||||||
if (this.contextObjects == null) {
|
if (this.contextObjects == null) {
|
||||||
this.contextObjects = new ArrayDeque<>();
|
this.contextObjects = new ArrayDeque<>();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
this.contextObjects.pop();
|
this.contextObjects.pop();
|
||||||
}
|
}
|
||||||
|
catch (NoSuchElementException ex) {
|
||||||
|
throw new IllegalStateException("Cannot pop active context object: stack is empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public TypedValue getRootContextObject() {
|
public TypedValue getRootContextObject() {
|
||||||
return this.rootObject;
|
return this.rootObject;
|
||||||
@@ -197,9 +204,7 @@ public class ExpressionState {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Object lookupLocalVariable(String name) {
|
public Object lookupLocalVariable(String name) {
|
||||||
int scopeNumber = initVariableScopes().size() - 1;
|
for (VariableScope scope : initVariableScopes()) {
|
||||||
for (int i = scopeNumber; i >= 0; i--) {
|
|
||||||
VariableScope scope = initVariableScopes().get(i);
|
|
||||||
if (scope.definesVariable(name)) {
|
if (scope.definesVariable(name)) {
|
||||||
return scope.lookupVariable(name);
|
return scope.lookupVariable(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2018 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.springframework.expression.spel;
|
package org.springframework.expression.spel;
|
||||||
|
|
||||||
import java.util.EmptyStackException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@@ -36,6 +35,7 @@ import static org.junit.Assert.*;
|
|||||||
* Tests for the expression state object - some features are not yet exploited in the language (eg nested scopes)
|
* Tests for the expression state object - some features are not yet exploited in the language (eg nested scopes)
|
||||||
*
|
*
|
||||||
* @author Andy Clement
|
* @author Andy Clement
|
||||||
|
* @author Juergen Hoeller
|
||||||
*/
|
*/
|
||||||
public class ExpressionStateTests extends AbstractExpressionTests {
|
public class ExpressionStateTests extends AbstractExpressionTests {
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ public class ExpressionStateTests extends AbstractExpressionTests {
|
|||||||
state.popActiveContextObject();
|
state.popActiveContextObject();
|
||||||
fail("stack should be empty...");
|
fail("stack should be empty...");
|
||||||
}
|
}
|
||||||
catch (EmptyStackException ese) {
|
catch (IllegalStateException ese) {
|
||||||
// success
|
// success
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +217,7 @@ public class ExpressionStateTests extends AbstractExpressionTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOperators() throws Exception {
|
public void testOperators() {
|
||||||
ExpressionState state = getState();
|
ExpressionState state = getState();
|
||||||
try {
|
try {
|
||||||
state.operate(Operation.ADD,1,2);
|
state.operate(Operation.ADD,1,2);
|
||||||
|
|||||||
Reference in New Issue
Block a user