diff --git a/spring-core/src/main/java/org/springframework/util/MimeType.java b/spring-core/src/main/java/org/springframework/util/MimeType.java index 640f8e51155..bc2d996ab82 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeType.java +++ b/spring-core/src/main/java/org/springframework/util/MimeType.java @@ -31,15 +31,15 @@ import java.util.TreeSet; import org.springframework.lang.Nullable; /** - * Represents a MIME Type, as originally defined in RFC 2046 and subsequently used in - * other Internet protocols including HTTP. + * Represents a MIME Type, as originally defined in RFC 2046 and subsequently + * used in other Internet protocols including HTTP. * *

This class, however, does not contain support for the q-parameters used - * in HTTP content negotiation. Those can be found in the sub-class + * in HTTP content negotiation. Those can be found in the subclass * {@code org.springframework.http.MediaType} in the {@code spring-web} module. * *

Consists of a {@linkplain #getType() type} and a {@linkplain #getSubtype() subtype}. - * Also has functionality to parse media types from a string using + * Also has functionality to parse MIME Type values from a {@code String} using * {@link #valueOf(String)}. For more parsing options see {@link MimeTypeUtils}. * * @author Arjen Poutsma @@ -139,7 +139,7 @@ public class MimeType implements Comparable, Serializable { /** * Copy-constructor that copies the type, subtype, parameters of the given {@code MimeType}, * and allows to set the specified character set. - * @param other the other media type + * @param other the other MimeType * @param charset the character set * @throws IllegalArgumentException if any of the parameters contains illegal characters * @since 4.3 @@ -151,8 +151,8 @@ public class MimeType implements Comparable, Serializable { /** * Copy-constructor that copies the type and subtype of the given {@code MimeType}, * and allows for different parameter. - * @param other the other media type - * @param parameters the parameters, may be {@code null} + * @param other the other MimeType + * @param parameters the parameters (may be {@code null}) * @throws IllegalArgumentException if any of the parameters contains illegal characters */ public MimeType(MimeType other, @Nullable Map parameters) { @@ -163,7 +163,7 @@ public class MimeType implements Comparable, Serializable { * Create a new {@code MimeType} for the given type, subtype, and parameters. * @param type the primary type * @param subtype the subtype - * @param parameters the parameters, may be {@code null} + * @param parameters the parameters (may be {@code null}) * @throws IllegalArgumentException if any of the parameters contains illegal characters */ public MimeType(String type, String subtype, @Nullable Map parameters) { @@ -246,9 +246,9 @@ public class MimeType implements Comparable, Serializable { } /** - * Indicates whether this media type is concrete, i.e. whether neither the type + * Indicates whether this MIME Type is concrete, i.e. whether neither the type * nor the subtype is a wildcard character *. - * @return whether this media type is concrete + * @return whether this MIME Type is concrete */ public boolean isConcrete() { return !isWildcardType() && !isWildcardSubtype(); @@ -298,12 +298,12 @@ public class MimeType implements Comparable, Serializable { } /** - * Indicate whether this {@code MediaType} includes the given media type. + * Indicate whether this MIME Type includes the given MIME Type. *

For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, - * and {@code application/*+xml} includes {@code application/soap+xml}, etc. This - * method is not symmetric. - * @param other the reference media type with which to compare - * @return {@code true} if this media type includes the given media type; + * and {@code application/*+xml} includes {@code application/soap+xml}, etc. + * This method is not symmetric. + * @param other the reference MIME Type with which to compare + * @return {@code true} if this MIME Type includes the given MIME Type; * {@code false} otherwise */ public boolean includes(@Nullable MimeType other) { @@ -342,12 +342,12 @@ public class MimeType implements Comparable, Serializable { } /** - * Indicate whether this {@code MediaType} is compatible with the given media type. + * Indicate whether this MIME Type is compatible with the given MIME Type. *

For instance, {@code text/*} is compatible with {@code text/plain}, * {@code text/html}, and vice versa. In effect, this method is similar to * {@link #includes}, except that it is symmetric. - * @param other the reference media type with which to compare - * @return {@code true} if this media type is compatible with the given media type; + * @param other the reference MIME Type with which to compare + * @return {@code true} if this MIME Type is compatible with the given MIME Type; * {@code false} otherwise */ public boolean isCompatibleWith(@Nullable MimeType other) { @@ -458,8 +458,8 @@ public class MimeType implements Comparable, Serializable { } /** - * Compares this {@code MediaType} to another alphabetically. - * @param other media type to compare to + * Compares this MIME Type to another alphabetically. + * @param other the MIME Type to compare to * @see MimeTypeUtils#sortBySpecificity(List) */ @Override diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java index dd0b1e6888c..a6e753fea70 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/EvaluationTests.java @@ -60,14 +60,15 @@ public class EvaluationTests extends AbstractExpressionTests { @Test public void testCreateListsOnAttemptToIndexNull01() throws EvaluationException, ParseException { ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression expression = parser.parseExpression("list[0]"); + Expression e = parser.parseExpression("list[0]"); TestClass testClass = new TestClass(); - Object o = null; - o = expression.getValue(new StandardEvaluationContext(testClass)); + + Object o = e.getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); o = parser.parseExpression("list[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.list.size()); + try { o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass)); fail(); @@ -76,18 +77,19 @@ public class EvaluationTests extends AbstractExpressionTests { ee.printStackTrace(); // success! } + o = parser.parseExpression("foo[3]").getValue(new StandardEvaluationContext(testClass)); assertEquals("", o); assertEquals(4, testClass.getFoo().size()); } @Test(expected = SpelEvaluationException.class) - public void testCreateMapsOnAttemptToIndexNull01() throws Exception { + public void testCreateMapsOnAttemptToIndexNull01() { TestClass testClass = new TestClass(); StandardEvaluationContext ctx = new StandardEvaluationContext(testClass); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Object o = null; - o = parser.parseExpression("map['a']").getValue(ctx); + + Object o = parser.parseExpression("map['a']").getValue(ctx); assertNull(o); o = parser.parseExpression("map").getValue(ctx); assertNotNull(o); @@ -98,12 +100,12 @@ public class EvaluationTests extends AbstractExpressionTests { // wibble2 should be null (cannot be initialized dynamically), there is no setter @Test(expected = SpelEvaluationException.class) - public void testCreateObjectsOnAttemptToReferenceNull() throws Exception { + public void testCreateObjectsOnAttemptToReferenceNull() { TestClass testClass = new TestClass(); StandardEvaluationContext ctx = new StandardEvaluationContext(testClass); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Object o = null; - o = parser.parseExpression("wibble.bar").getValue(ctx); + + Object o = parser.parseExpression("wibble.bar").getValue(ctx); assertEquals("hello", o); o = parser.parseExpression("wibble").getValue(ctx); assertNotNull(o); @@ -189,7 +191,7 @@ public class EvaluationTests extends AbstractExpressionTests { @Test public void testRelOperatorsMatches05() { - evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int>string + evaluate("27 matches '^.*2.*$'", true, Boolean.class); // conversion int>string } // mixing operators @@ -204,7 +206,7 @@ public class EvaluationTests extends AbstractExpressionTests { evaluate("name", "Nikola Tesla", String.class, false); // not writable because (1) name is private (2) there is no setter, only a getter evaluateAndCheckError("madeup", SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE, 0, "madeup", - "org.springframework.expression.spel.testresources.Inventor"); + "org.springframework.expression.spel.testresources.Inventor"); } @Test @@ -219,12 +221,9 @@ public class EvaluationTests extends AbstractExpressionTests { new SpelExpressionParser().parseExpression("placeOfBirth.foo."); fail("Should have failed to parse"); } - catch (ParseException e) { - e.printStackTrace(); - assertTrue(e instanceof SpelParseException); - SpelParseException spe = (SpelParseException) e; - assertEquals(SpelMessage.OOD, spe.getMessageCode()); - assertEquals(16, spe.getPosition()); + catch (SpelParseException ex) { + assertEquals(SpelMessage.OOD, ex.getMessageCode()); + assertEquals(16, ex.getPosition()); } } @@ -274,19 +273,19 @@ public class EvaluationTests extends AbstractExpressionTests { } @Test - public void testConstructorInvocation06() throws Exception { + public void testConstructorInvocation06() { // repeated evaluation to drive use of cached executor - SpelExpression expr = (SpelExpression) parser.parseExpression("new String('wibble')"); - String newString = expr.getValue(String.class); + SpelExpression e = (SpelExpression) parser.parseExpression("new String('wibble')"); + String newString = e.getValue(String.class); assertEquals("wibble", newString); - newString = expr.getValue(String.class); + newString = e.getValue(String.class); assertEquals("wibble", newString); // not writable - assertFalse(expr.isWritable(new StandardEvaluationContext())); + assertFalse(e.isWritable(new StandardEvaluationContext())); // ast - assertEquals("new String('wibble')", expr.toStringAST()); + assertEquals("new String('wibble')", e.toStringAST()); } // unary expressions @@ -358,9 +357,9 @@ public class EvaluationTests extends AbstractExpressionTests { } @Test - public void testTernaryOperator04() throws Exception { - Expression expr = parser.parseExpression("1>2?3:4"); - assertFalse(expr.isWritable(eContext)); + public void testTernaryOperator04() { + Expression e = parser.parseExpression("1>2?3:4"); + assertFalse(e.isWritable(eContext)); } @Test @@ -384,7 +383,7 @@ public class EvaluationTests extends AbstractExpressionTests { @Test public void ctorCallWithRootReferenceThroughParameter() { evaluate("new org.springframework.expression.spel.testresources.PlaceOfBirth(inventions[0].toString()).city", - "Telephone repeater", String.class); + "Telephone repeater", String.class); } @Test @@ -405,7 +404,7 @@ public class EvaluationTests extends AbstractExpressionTests { @Test public void testIndexerError() { evaluateAndCheckError("new org.springframework.expression.spel.testresources.Inventor().inventions[1]", - SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE); + SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE); } @Test @@ -436,43 +435,43 @@ public class EvaluationTests extends AbstractExpressionTests { } @Test - public void testTypeReferencesAndQualifiedIdentifierCaching() throws Exception { - SpelExpression expr = (SpelExpression) parser.parseExpression("T(java.lang.String)"); - assertFalse(expr.isWritable(new StandardEvaluationContext())); - assertEquals("T(java.lang.String)", expr.toStringAST()); - assertEquals(String.class, expr.getValue(Class.class)); + public void testTypeReferencesAndQualifiedIdentifierCaching() { + SpelExpression e = (SpelExpression) parser.parseExpression("T(java.lang.String)"); + assertFalse(e.isWritable(new StandardEvaluationContext())); + assertEquals("T(java.lang.String)", e.toStringAST()); + assertEquals(String.class, e.getValue(Class.class)); // use cached QualifiedIdentifier: - assertEquals("T(java.lang.String)", expr.toStringAST()); - assertEquals(String.class, expr.getValue(Class.class)); + assertEquals("T(java.lang.String)", e.toStringAST()); + assertEquals(String.class, e.getValue(Class.class)); } @Test - public void operatorVariants() throws Exception { - SpelExpression expr = (SpelExpression)parser.parseExpression("#a < #b"); + public void operatorVariants() { + SpelExpression e = (SpelExpression)parser.parseExpression("#a < #b"); EvaluationContext ctx = new StandardEvaluationContext(); - ctx.setVariable("a", (short)3); - ctx.setVariable("b", (short)6); - assertTrue(expr.getValue(ctx, Boolean.class)); - ctx.setVariable("b", (byte)6); - assertTrue(expr.getValue(ctx, Boolean.class)); - ctx.setVariable("a", (byte)9); - ctx.setVariable("b", (byte)6); - assertFalse(expr.getValue(ctx, Boolean.class)); + ctx.setVariable("a", (short) 3); + ctx.setVariable("b", (short) 6); + assertTrue(e.getValue(ctx, Boolean.class)); + ctx.setVariable("b", (byte) 6); + assertTrue(e.getValue(ctx, Boolean.class)); + ctx.setVariable("a", (byte) 9); + ctx.setVariable("b", (byte) 6); + assertFalse(e.getValue(ctx, Boolean.class)); ctx.setVariable("a", 10L); - ctx.setVariable("b", (short)30); - assertTrue(expr.getValue(ctx, Boolean.class)); - ctx.setVariable("a", (byte)3); - ctx.setVariable("b", (short)30); - assertTrue(expr.getValue(ctx, Boolean.class)); - ctx.setVariable("a", (byte)3); + ctx.setVariable("b", (short) 30); + assertTrue(e.getValue(ctx, Boolean.class)); + ctx.setVariable("a", (byte) 3); + ctx.setVariable("b", (short) 30); + assertTrue(e.getValue(ctx, Boolean.class)); + ctx.setVariable("a", (byte) 3); ctx.setVariable("b", 30L); - assertTrue(expr.getValue(ctx, Boolean.class)); - ctx.setVariable("a", (byte)3); + assertTrue(e.getValue(ctx, Boolean.class)); + ctx.setVariable("a", (byte) 3); ctx.setVariable("b", 30f); - assertTrue(expr.getValue(ctx, Boolean.class)); + assertTrue(e.getValue(ctx, Boolean.class)); ctx.setVariable("a", new BigInteger("10")); ctx.setVariable("b", new BigInteger("20")); - assertTrue(expr.getValue(ctx, Boolean.class)); + assertTrue(e.getValue(ctx, Boolean.class)); } @Test @@ -507,7 +506,7 @@ public class EvaluationTests extends AbstractExpressionTests { } @Test - public void testAdvancedNumerics() throws Exception { + public void testAdvancedNumerics() { int twentyFour = parser.parseExpression("2.0 * 3e0 * 4").getValue(Integer.class); assertEquals(24, twentyFour); double one = parser.parseExpression("8.0 / 5e0 % 2").getValue(Double.class); @@ -521,15 +520,15 @@ public class EvaluationTests extends AbstractExpressionTests { } @Test - public void testComparison() throws Exception { + public void testComparison() { EvaluationContext context = TestScenarioCreator.getTestEvaluationContext(); - boolean trueValue = parser.parseExpression("T(java.util.Date) == Birthdate.Class").getValue(context, - Boolean.class); + boolean trueValue = parser.parseExpression("T(java.util.Date) == Birthdate.Class").getValue( + context, Boolean.class); assertTrue(trueValue); } @Test - public void testResolvingList() throws Exception { + public void testResolvingList() { StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext(); try { assertFalse(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class)); @@ -543,7 +542,7 @@ public class EvaluationTests extends AbstractExpressionTests { } @Test - public void testResolvingString() throws Exception { + public void testResolvingString() { Class stringClass = parser.parseExpression("T(String)").getValue(Class.class); assertEquals(String.class, stringClass); } @@ -553,25 +552,25 @@ public class EvaluationTests extends AbstractExpressionTests { * doesn't currently exist in the collection (address.crossStreets[0] below) */ @Test - public void initializingCollectionElementsOnWrite() throws Exception { + public void initializingCollectionElementsOnWrite() { TestPerson person = new TestPerson(); EvaluationContext context = new StandardEvaluationContext(person); SpelParserConfiguration config = new SpelParserConfiguration(true, true); ExpressionParser parser = new SpelExpressionParser(config); - Expression expression = parser.parseExpression("name"); - expression.setValue(context, "Oleg"); + Expression e = parser.parseExpression("name"); + e.setValue(context, "Oleg"); assertEquals("Oleg", person.getName()); - expression = parser.parseExpression("address.street"); - expression.setValue(context, "123 High St"); + e = parser.parseExpression("address.street"); + e.setValue(context, "123 High St"); assertEquals("123 High St", person.getAddress().getStreet()); - expression = parser.parseExpression("address.crossStreets[0]"); - expression.setValue(context, "Blah"); + e = parser.parseExpression("address.crossStreets[0]"); + e.setValue(context, "Blah"); assertEquals("Blah", person.getAddress().getCrossStreets().get(0)); - expression = parser.parseExpression("address.crossStreets[3]"); - expression.setValue(context, "Wibble"); + e = parser.parseExpression("address.crossStreets[3]"); + e.setValue(context, "Wibble"); assertEquals("Blah", person.getAddress().getCrossStreets().get(0)); assertEquals("Wibble", person.getAddress().getCrossStreets().get(3)); } @@ -582,23 +581,22 @@ public class EvaluationTests extends AbstractExpressionTests { @Test public void caseInsensitiveNullLiterals() { ExpressionParser parser = new SpelExpressionParser(); - Expression exp; - exp = parser.parseExpression("null"); - assertNull(exp.getValue()); + Expression e = parser.parseExpression("null"); + assertNull(e.getValue()); - exp = parser.parseExpression("NULL"); - assertNull(exp.getValue()); + e = parser.parseExpression("NULL"); + assertNull(e.getValue()); - exp = parser.parseExpression("NuLl"); - assertNull(exp.getValue()); + e = parser.parseExpression("NuLl"); + assertNull(e.getValue()); } /** * Verifies behavior requested in SPR-9621. */ @Test - public void customMethodFilter() throws Exception { + public void customMethodFilter() { StandardEvaluationContext context = new StandardEvaluationContext(); // Register a custom MethodResolver... @@ -622,68 +620,6 @@ public class EvaluationTests extends AbstractExpressionTests { } } - static class CustomMethodResolver implements MethodResolver { - - @Override - public MethodExecutor resolve(EvaluationContext context, - Object targetObject, String name, - List argumentTypes) throws AccessException { - return null; - } - } - - static class CustomMethodFilter implements MethodFilter { - - @Override - public List filter(List methods) { - return null; - } - - } - - // increment/decrement operators - SPR-9751 - - static class Spr9751 { - public String type = "hello"; - public BigDecimal bd = new BigDecimal("2"); - public double ddd = 2.0d; - public float fff = 3.0f; - public long lll = 66666L; - public int iii = 42; - public short sss = (short)15; - public Spr9751_2 foo = new Spr9751_2(); - - public void m() {} - - public int[] intArray = new int[]{1,2,3,4,5}; - public int index1 = 2; - - public Integer[] integerArray; - public int index2 = 2; - - public List listOfStrings; - public int index3 = 0; - - public Spr9751() { - integerArray = new Integer[5]; - integerArray[0] = 1; - integerArray[1] = 2; - integerArray[2] = 3; - integerArray[3] = 4; - integerArray[4] = 5; - listOfStrings = new ArrayList<>(); - listOfStrings.add("abc"); - } - - public static boolean isEven(int i) { - return (i%2)==0; - } - } - - static class Spr9751_2 { - public int iii = 99; - } - /** * This test is checking that with the changes for 9751 that the refactoring in Indexer is * coping correctly for references beyond collection boundaries. @@ -704,13 +640,13 @@ public class EvaluationTests extends AbstractExpressionTests { ctx = new StandardEvaluationContext(instance); parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); e = parser.parseExpression("listOfStrings[0]"); - String value = e.getValue(ctx,String.class); + String value = e.getValue(ctx, String.class); assertEquals("abc",value); e = parser.parseExpression("listOfStrings[1]"); - value = e.getValue(ctx,String.class); + value = e.getValue(ctx, String.class); assertEquals("def",value); e = parser.parseExpression("listOfStrings[2]"); - value = e.getValue(ctx,String.class); + value = e.getValue(ctx, String.class); assertEquals("",value); // Now turn off growing and reference off the end @@ -718,25 +654,25 @@ public class EvaluationTests extends AbstractExpressionTests { parser = new SpelExpressionParser(new SpelParserConfiguration(false, false)); e = parser.parseExpression("listOfStrings[3]"); try { - e.getValue(ctx,String.class); + e.getValue(ctx, String.class); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS,see.getMessageCode()); + assertEquals(SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS, see.getMessageCode()); } } @Test - public void limitCollectionGrowing() throws Exception { + public void limitCollectionGrowing() { TestClass instance = new TestClass(); StandardEvaluationContext ctx = new StandardEvaluationContext(instance); SpelExpressionParser parser = new SpelExpressionParser( new SpelParserConfiguration(true, true, 3)); - Expression expression = parser.parseExpression("foo[2]"); - expression.setValue(ctx, "2"); + Expression e = parser.parseExpression("foo[2]"); + e.setValue(ctx, "2"); assertThat(instance.getFoo().size(), equalTo(3)); - expression = parser.parseExpression("foo[3]"); + e = parser.parseExpression("foo[3]"); try { - expression.setValue(ctx, "3"); + e.setValue(ctx, "3"); } catch (SpelEvaluationException see) { assertEquals(SpelMessage.UNABLE_TO_GROW_COLLECTION, see.getMessageCode()); @@ -753,11 +689,11 @@ public class EvaluationTests extends AbstractExpressionTests { Expression e = parser.parseExpression("#this++"); assertEquals(42,i.intValue()); try { - e.getValue(ctx,Integer.class); + e.getValue(ctx, Integer.class); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode()); + assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode()); } } @@ -766,52 +702,52 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; // BigDecimal e = parser.parseExpression("bd++"); assertTrue(new BigDecimal("2").equals(helper.bd)); - BigDecimal return_bd = e.getValue(ctx,BigDecimal.class); + BigDecimal return_bd = e.getValue(ctx, BigDecimal.class); assertTrue(new BigDecimal("2").equals(return_bd)); assertTrue(new BigDecimal("3").equals(helper.bd)); // double e = parser.parseExpression("ddd++"); - assertEquals(2.0d,helper.ddd,0d); - double return_ddd = e.getValue(ctx,Double.TYPE); - assertEquals(2.0d,return_ddd,0d); - assertEquals(3.0d,helper.ddd,0d); + assertEquals(2.0d, helper.ddd,0d); + double return_ddd = e.getValue(ctx, Double.TYPE); + assertEquals(2.0d, return_ddd,0d); + assertEquals(3.0d, helper.ddd,0d); // float e = parser.parseExpression("fff++"); - assertEquals(3.0f,helper.fff,0d); - float return_fff = e.getValue(ctx,Float.TYPE); - assertEquals(3.0f,return_fff,0d); - assertEquals(4.0f,helper.fff,0d); + assertEquals(3.0f, helper.fff,0d); + float return_fff = e.getValue(ctx, Float.TYPE); + assertEquals(3.0f, return_fff,0d); + assertEquals(4.0f, helper.fff,0d); // long e = parser.parseExpression("lll++"); - assertEquals(66666L,helper.lll); - long return_lll = e.getValue(ctx,Long.TYPE); - assertEquals(66666L,return_lll); - assertEquals(66667L,helper.lll); + assertEquals(66666L, helper.lll); + long return_lll = e.getValue(ctx, Long.TYPE); + assertEquals(66666L, return_lll); + assertEquals(66667L, helper.lll); // int e = parser.parseExpression("iii++"); - assertEquals(42,helper.iii); - int return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(42,return_iii); - assertEquals(43,helper.iii); - return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(43,return_iii); - assertEquals(44,helper.iii); + assertEquals(42, helper.iii); + int return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(42, return_iii); + assertEquals(43, helper.iii); + return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(43, return_iii); + assertEquals(44, helper.iii); // short e = parser.parseExpression("sss++"); - assertEquals(15,helper.sss); - short return_sss = e.getValue(ctx,Short.TYPE); - assertEquals(15,return_sss); - assertEquals(16,helper.sss); + assertEquals(15, helper.sss); + short return_sss = e.getValue(ctx, Short.TYPE); + assertEquals(15, return_sss); + assertEquals(16, helper.sss); } @Test @@ -819,53 +755,53 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; // BigDecimal e = parser.parseExpression("++bd"); assertTrue(new BigDecimal("2").equals(helper.bd)); - BigDecimal return_bd = e.getValue(ctx,BigDecimal.class); + BigDecimal return_bd = e.getValue(ctx, BigDecimal.class); assertTrue(new BigDecimal("3").equals(return_bd)); assertTrue(new BigDecimal("3").equals(helper.bd)); // double e = parser.parseExpression("++ddd"); - assertEquals(2.0d,helper.ddd,0d); - double return_ddd = e.getValue(ctx,Double.TYPE); - assertEquals(3.0d,return_ddd,0d); - assertEquals(3.0d,helper.ddd,0d); + assertEquals(2.0d, helper.ddd ,0d); + double return_ddd = e.getValue(ctx, Double.TYPE); + assertEquals(3.0d, return_ddd, 0d); + assertEquals(3.0d, helper.ddd, 0d); // float e = parser.parseExpression("++fff"); - assertEquals(3.0f,helper.fff,0d); - float return_fff = e.getValue(ctx,Float.TYPE); - assertEquals(4.0f,return_fff,0d); - assertEquals(4.0f,helper.fff,0d); + assertEquals(3.0f, helper.fff, 0d); + float return_fff = e.getValue(ctx, Float.TYPE); + assertEquals(4.0f, return_fff, 0d); + assertEquals(4.0f, helper.fff, 0d); // long e = parser.parseExpression("++lll"); - assertEquals(66666L,helper.lll); - long return_lll = e.getValue(ctx,Long.TYPE); - assertEquals(66667L,return_lll); - assertEquals(66667L,helper.lll); + assertEquals(66666L, helper.lll); + long return_lll = e.getValue(ctx, Long.TYPE); + assertEquals(66667L, return_lll); + assertEquals(66667L, helper.lll); // int e = parser.parseExpression("++iii"); - assertEquals(42,helper.iii); - int return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(43,return_iii); - assertEquals(43,helper.iii); - return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(44,return_iii); - assertEquals(44,helper.iii); + assertEquals(42, helper.iii); + int return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(43, return_iii); + assertEquals(43, helper.iii); + return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(44, return_iii); + assertEquals(44, helper.iii); // short e = parser.parseExpression("++sss"); - assertEquals(15,helper.sss); - int return_sss = (Integer)e.getValue(ctx); - assertEquals(16,return_sss); - assertEquals(16,helper.sss); + assertEquals(15, helper.sss); + int return_sss = (Integer) e.getValue(ctx); + assertEquals(16, return_sss); + assertEquals(16, helper.sss); } @Test @@ -873,28 +809,27 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; e = parser.parseExpression("m()++"); try { - e.getValue(ctx,Double.TYPE); + e.getValue(ctx, Double.TYPE); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.OPERAND_NOT_INCREMENTABLE,see.getMessageCode()); + assertEquals(SpelMessage.OPERAND_NOT_INCREMENTABLE, see.getMessageCode()); } e = parser.parseExpression("++m()"); try { - e.getValue(ctx,Double.TYPE); + e.getValue(ctx, Double.TYPE); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.OPERAND_NOT_INCREMENTABLE,see.getMessageCode()); + assertEquals(SpelMessage.OPERAND_NOT_INCREMENTABLE, see.getMessageCode()); } } - @Test public void increment04() { Integer i = 42; @@ -902,34 +837,35 @@ public class EvaluationTests extends AbstractExpressionTests { ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); try { Expression e = parser.parseExpression("++1"); - e.getValue(ctx,Integer.class); + e.getValue(ctx, Integer.class); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode()); + assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode()); } try { Expression e = parser.parseExpression("1++"); - e.getValue(ctx,Integer.class); + e.getValue(ctx, Integer.class); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode()); + assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode()); } } + @Test public void decrement01root() { Integer i = 42; StandardEvaluationContext ctx = new StandardEvaluationContext(i); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); Expression e = parser.parseExpression("#this--"); - assertEquals(42,i.intValue()); + assertEquals(42, i.intValue()); try { - e.getValue(ctx,Integer.class); + e.getValue(ctx, Integer.class); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode()); + assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode()); } } @@ -938,7 +874,7 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; // BigDecimal e = parser.parseExpression("bd--"); @@ -949,41 +885,41 @@ public class EvaluationTests extends AbstractExpressionTests { // double e = parser.parseExpression("ddd--"); - assertEquals(2.0d,helper.ddd,0d); - double return_ddd = e.getValue(ctx,Double.TYPE); - assertEquals(2.0d,return_ddd,0d); - assertEquals(1.0d,helper.ddd,0d); + assertEquals(2.0d, helper.ddd,0d); + double return_ddd = e.getValue(ctx, Double.TYPE); + assertEquals(2.0d, return_ddd,0d); + assertEquals(1.0d, helper.ddd,0d); // float e = parser.parseExpression("fff--"); - assertEquals(3.0f,helper.fff,0d); - float return_fff = e.getValue(ctx,Float.TYPE); - assertEquals(3.0f,return_fff,0d); - assertEquals(2.0f,helper.fff,0d); + assertEquals(3.0f, helper.fff,0d); + float return_fff = e.getValue(ctx, Float.TYPE); + assertEquals(3.0f, return_fff,0d); + assertEquals(2.0f, helper.fff,0d); // long e = parser.parseExpression("lll--"); - assertEquals(66666L,helper.lll); - long return_lll = e.getValue(ctx,Long.TYPE); - assertEquals(66666L,return_lll); - assertEquals(66665L,helper.lll); + assertEquals(66666L, helper.lll); + long return_lll = e.getValue(ctx, Long.TYPE); + assertEquals(66666L, return_lll); + assertEquals(66665L, helper.lll); // int e = parser.parseExpression("iii--"); - assertEquals(42,helper.iii); - int return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(42,return_iii); - assertEquals(41,helper.iii); - return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(41,return_iii); - assertEquals(40,helper.iii); + assertEquals(42, helper.iii); + int return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(42, return_iii); + assertEquals(41, helper.iii); + return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(41, return_iii); + assertEquals(40, helper.iii); // short e = parser.parseExpression("sss--"); - assertEquals(15,helper.sss); - short return_sss = e.getValue(ctx,Short.TYPE); - assertEquals(15,return_sss); - assertEquals(14,helper.sss); + assertEquals(15, helper.sss); + short return_sss = e.getValue(ctx, Short.TYPE); + assertEquals(15, return_sss); + assertEquals(14, helper.sss); } @Test @@ -991,7 +927,7 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; // BigDecimal e = parser.parseExpression("--bd"); @@ -1002,41 +938,41 @@ public class EvaluationTests extends AbstractExpressionTests { // double e = parser.parseExpression("--ddd"); - assertEquals(2.0d,helper.ddd,0d); - double return_ddd = e.getValue(ctx,Double.TYPE); - assertEquals(1.0d,return_ddd,0d); - assertEquals(1.0d,helper.ddd,0d); + assertEquals(2.0d, helper.ddd,0d); + double return_ddd = e.getValue(ctx, Double.TYPE); + assertEquals(1.0d, return_ddd,0d); + assertEquals(1.0d, helper.ddd,0d); // float e = parser.parseExpression("--fff"); - assertEquals(3.0f,helper.fff,0d); - float return_fff = e.getValue(ctx,Float.TYPE); - assertEquals(2.0f,return_fff,0d); - assertEquals(2.0f,helper.fff,0d); + assertEquals(3.0f, helper.fff,0d); + float return_fff = e.getValue(ctx, Float.TYPE); + assertEquals(2.0f, return_fff,0d); + assertEquals(2.0f, helper.fff,0d); // long e = parser.parseExpression("--lll"); - assertEquals(66666L,helper.lll); - long return_lll = e.getValue(ctx,Long.TYPE); - assertEquals(66665L,return_lll); - assertEquals(66665L,helper.lll); + assertEquals(66666L, helper.lll); + long return_lll = e.getValue(ctx, Long.TYPE); + assertEquals(66665L, return_lll); + assertEquals(66665L, helper.lll); // int e = parser.parseExpression("--iii"); - assertEquals(42,helper.iii); - int return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(41,return_iii); - assertEquals(41,helper.iii); - return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(40,return_iii); - assertEquals(40,helper.iii); + assertEquals(42, helper.iii); + int return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(41, return_iii); + assertEquals(41, helper.iii); + return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(40, return_iii); + assertEquals(40, helper.iii); // short e = parser.parseExpression("--sss"); - assertEquals(15,helper.sss); + assertEquals(15, helper.sss); int return_sss = (Integer)e.getValue(ctx); - assertEquals(14,return_sss); - assertEquals(14,helper.sss); + assertEquals(14, return_sss); + assertEquals(14, helper.sss); } @Test @@ -1044,24 +980,24 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; e = parser.parseExpression("m()--"); try { - e.getValue(ctx,Double.TYPE); + e.getValue(ctx, Double.TYPE); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.OPERAND_NOT_DECREMENTABLE,see.getMessageCode()); + assertEquals(SpelMessage.OPERAND_NOT_DECREMENTABLE, see.getMessageCode()); } e = parser.parseExpression("--m()"); try { - e.getValue(ctx,Double.TYPE); + e.getValue(ctx, Double.TYPE); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.OPERAND_NOT_DECREMENTABLE,see.getMessageCode()); + assertEquals(SpelMessage.OPERAND_NOT_DECREMENTABLE, see.getMessageCode()); } } @@ -1072,20 +1008,20 @@ public class EvaluationTests extends AbstractExpressionTests { StandardEvaluationContext ctx = new StandardEvaluationContext(i); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); try { - Expression e = parser.parseExpression("--1"); - e.getValue(ctx,Integer.class); + Expression e = parser.parseExpression("--1"); + e.getValue(ctx, Integer.class); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode()); + assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode()); } try { - Expression e = parser.parseExpression("1--"); - e.getValue(ctx,Integer.class); + Expression e = parser.parseExpression("1--"); + e.getValue(ctx, Integer.class); fail(); } catch (SpelEvaluationException see) { - assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode()); + assertEquals(SpelMessage.NOT_ASSIGNABLE, see.getMessageCode()); } } @@ -1094,26 +1030,26 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; // index1 is 2 at the start - the 'intArray[#root.index1++]' should not be evaluated twice! // intArray[2] is 3 e = parser.parseExpression("intArray[#root.index1++]++"); - e.getValue(ctx,Integer.class); - assertEquals(3,helper.index1); - assertEquals(4,helper.intArray[2]); + e.getValue(ctx, Integer.class); + assertEquals(3, helper.index1); + assertEquals(4, helper.intArray[2]); // index1 is 3 intArray[3] is 4 e = parser.parseExpression("intArray[#root.index1++]--"); - assertEquals(4,e.getValue(ctx,Integer.class).intValue()); - assertEquals(4,helper.index1); - assertEquals(3,helper.intArray[3]); + assertEquals(4, e.getValue(ctx, Integer.class).intValue()); + assertEquals(4, helper.index1); + assertEquals(3, helper.intArray[3]); // index1 is 4, intArray[3] is 3 e = parser.parseExpression("intArray[--#root.index1]++"); - assertEquals(3,e.getValue(ctx,Integer.class).intValue()); - assertEquals(3,helper.index1); - assertEquals(4,helper.intArray[3]); + assertEquals(3, e.getValue(ctx, Integer.class).intValue()); + assertEquals(3, helper.index1); + assertEquals(4, helper.intArray[3]); } @@ -1123,7 +1059,7 @@ public class EvaluationTests extends AbstractExpressionTests { Spr9751 helper = new Spr9751(); StandardEvaluationContext ctx = new StandardEvaluationContext(helper); ExpressionParser parser = new SpelExpressionParser(new SpelParserConfiguration(true, true)); - Expression e = null; + Expression e; // BooleanLiteral expectFailNotAssignable(parser, ctx, "true++"); @@ -1272,49 +1208,49 @@ public class EvaluationTests extends AbstractExpressionTests { // Assign // iii=42 e = parser.parseExpression("iii=iii++"); - assertEquals(42,helper.iii); - int return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(42,helper.iii); - assertEquals(42,return_iii); + assertEquals(42, helper.iii); + int return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(42, helper.iii); + assertEquals(42, return_iii); // Identifier e = parser.parseExpression("iii++"); - assertEquals(42,helper.iii); - return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(42,return_iii); - assertEquals(43,helper.iii); + assertEquals(42, helper.iii); + return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(42, return_iii); + assertEquals(43, helper.iii); e = parser.parseExpression("--iii"); - assertEquals(43,helper.iii); - return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(42,return_iii); - assertEquals(42,helper.iii); + assertEquals(43, helper.iii); + return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(42, return_iii); + assertEquals(42, helper.iii); e = parser.parseExpression("iii=99"); - assertEquals(42,helper.iii); - return_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(99,return_iii); - assertEquals(99,helper.iii); + assertEquals(42, helper.iii); + return_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(99, return_iii); + assertEquals(99, helper.iii); // CompoundExpression // foo.iii == 99 e = parser.parseExpression("foo.iii++"); - assertEquals(99,helper.foo.iii); - int return_foo_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(99,return_foo_iii); - assertEquals(100,helper.foo.iii); + assertEquals(99, helper.foo.iii); + int return_foo_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(99, return_foo_iii); + assertEquals(100, helper.foo.iii); e = parser.parseExpression("--foo.iii"); - assertEquals(100,helper.foo.iii); - return_foo_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(99,return_foo_iii); - assertEquals(99,helper.foo.iii); + assertEquals(100, helper.foo.iii); + return_foo_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(99, return_foo_iii); + assertEquals(99, helper.foo.iii); e = parser.parseExpression("foo.iii=999"); - assertEquals(99,helper.foo.iii); - return_foo_iii = e.getValue(ctx,Integer.TYPE); - assertEquals(999,return_foo_iii); - assertEquals(999,helper.foo.iii); + assertEquals(99, helper.foo.iii); + return_foo_iii = e.getValue(ctx, Integer.TYPE); + assertEquals(999, return_foo_iii); + assertEquals(999, helper.foo.iii); // ConstructorReference expectFailNotAssignable(parser, ctx, "(new String('abc'))++"); @@ -1357,32 +1293,32 @@ public class EvaluationTests extends AbstractExpressionTests { expectFailNotIncrementable(parser, ctx, "#wibble++"); expectFailNotDecrementable(parser, ctx, "--#wibble"); e = parser.parseExpression("#wibble=#wibble+#wibble"); - String s = e.getValue(ctx,String.class); - assertEquals("hello worldhello world",s); + String s = e.getValue(ctx, String.class); + assertEquals("hello worldhello world", s); assertEquals("hello worldhello world",ctx.lookupVariable("wibble")); ctx.setVariable("wobble", 3); e = parser.parseExpression("#wobble++"); - assertEquals(3,((Integer)ctx.lookupVariable("wobble")).intValue()); - int r = e.getValue(ctx,Integer.TYPE); - assertEquals(3,r); - assertEquals(4,((Integer)ctx.lookupVariable("wobble")).intValue()); + assertEquals(3, ((Integer) ctx.lookupVariable("wobble")).intValue()); + int r = e.getValue(ctx, Integer.TYPE); + assertEquals(3, r); + assertEquals(4, ((Integer) ctx.lookupVariable("wobble")).intValue()); e = parser.parseExpression("--#wobble"); - assertEquals(4,((Integer)ctx.lookupVariable("wobble")).intValue()); - r = e.getValue(ctx,Integer.TYPE); - assertEquals(3,r); - assertEquals(3,((Integer)ctx.lookupVariable("wobble")).intValue()); + assertEquals(4, ((Integer) ctx.lookupVariable("wobble")).intValue()); + r = e.getValue(ctx, Integer.TYPE); + assertEquals(3, r); + assertEquals(3, ((Integer) ctx.lookupVariable("wobble")).intValue()); e = parser.parseExpression("#wobble=34"); - assertEquals(3,((Integer)ctx.lookupVariable("wobble")).intValue()); - r = e.getValue(ctx,Integer.TYPE); - assertEquals(34,r); - assertEquals(34,((Integer)ctx.lookupVariable("wobble")).intValue()); + assertEquals(3, ((Integer) ctx.lookupVariable("wobble")).intValue()); + r = e.getValue(ctx, Integer.TYPE); + assertEquals(34, r); + assertEquals(34, ((Integer) ctx.lookupVariable("wobble")).intValue()); // Projection - expectFailNotIncrementable(parser, ctx, "({1,2,3}.![#isEven(#this)])++"); // projection would be {false,true,false} - expectFailNotDecrementable(parser, ctx, "--({1,2,3}.![#isEven(#this)])"); // projection would be {false,true,false} + expectFailNotIncrementable(parser, ctx, "({1,2,3}.![#isEven(#this)])++"); // projection would be {false,true,false} + expectFailNotDecrementable(parser, ctx, "--({1,2,3}.![#isEven(#this)])"); // projection would be {false,true,false} expectFailNotAssignable(parser, ctx, "({1,2,3}.![#isEven(#this)])=({1,2,3}.![#isEven(#this)])"); // InlineList @@ -1404,52 +1340,71 @@ public class EvaluationTests extends AbstractExpressionTests { // PropertyOrFieldReference helper.iii = 42; e = parser.parseExpression("iii++"); - assertEquals(42,helper.iii); - r = e.getValue(ctx,Integer.TYPE); - assertEquals(42,r); - assertEquals(43,helper.iii); + assertEquals(42, helper.iii); + r = e.getValue(ctx, Integer.TYPE); + assertEquals(42, r); + assertEquals(43, helper.iii); e = parser.parseExpression("--iii"); - assertEquals(43,helper.iii); - r = e.getValue(ctx,Integer.TYPE); - assertEquals(42,r); - assertEquals(42,helper.iii); + assertEquals(43, helper.iii); + r = e.getValue(ctx, Integer.TYPE); + assertEquals(42, r); + assertEquals(42, helper.iii); e = parser.parseExpression("iii=100"); - assertEquals(42,helper.iii); - r = e.getValue(ctx,Integer.TYPE); - assertEquals(100,r); - assertEquals(100,helper.iii); + assertEquals(42, helper.iii); + r = e.getValue(ctx, Integer.TYPE); + assertEquals(100, r); + assertEquals(100, helper.iii); } private void expectFail(ExpressionParser parser, EvaluationContext eContext, String expressionString, SpelMessage messageCode) { try { Expression e = parser.parseExpression(expressionString); - SpelUtilities.printAbstractSyntaxTree(System.out, e); + SpelUtilities.printAbstractSyntaxTree(System.out, e); e.getValue(eContext); fail(); } catch (SpelEvaluationException see) { - see.printStackTrace(); - assertEquals(messageCode,see.getMessageCode()); + assertEquals(messageCode, see.getMessageCode()); } } private void expectFailNotAssignable(ExpressionParser parser, EvaluationContext eContext, String expressionString) { - expectFail(parser,eContext,expressionString,SpelMessage.NOT_ASSIGNABLE); + expectFail(parser, eContext, expressionString, SpelMessage.NOT_ASSIGNABLE); } private void expectFailSetValueNotSupported(ExpressionParser parser, EvaluationContext eContext, String expressionString) { - expectFail(parser,eContext,expressionString,SpelMessage.SETVALUE_NOT_SUPPORTED); + expectFail(parser, eContext, expressionString, SpelMessage.SETVALUE_NOT_SUPPORTED); } private void expectFailNotIncrementable(ExpressionParser parser, EvaluationContext eContext, String expressionString) { - expectFail(parser,eContext,expressionString,SpelMessage.OPERAND_NOT_INCREMENTABLE); + expectFail(parser, eContext, expressionString, SpelMessage.OPERAND_NOT_INCREMENTABLE); } private void expectFailNotDecrementable(ExpressionParser parser, EvaluationContext eContext, String expressionString) { - expectFail(parser,eContext,expressionString,SpelMessage.OPERAND_NOT_DECREMENTABLE); + expectFail(parser, eContext, expressionString, SpelMessage.OPERAND_NOT_DECREMENTABLE); + } + + + static class CustomMethodResolver implements MethodResolver { + + @Override + public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, + List argumentTypes) throws AccessException { + return null; + } + } + + + static class CustomMethodFilter implements MethodFilter { + + @Override + public List filter(List methods) { + return null; + } + } @@ -1471,6 +1426,7 @@ public class EvaluationTests extends AbstractExpressionTests { public void setFoo(List newfoo) { this.foo = newfoo; } } + public static class Foo { public String bar = "hello"; @@ -1479,15 +1435,60 @@ public class EvaluationTests extends AbstractExpressionTests { } + // increment/decrement operators - SPR-9751 + static class Spr9751 { + + public String type = "hello"; + public BigDecimal bd = new BigDecimal("2"); + public double ddd = 2.0d; + public float fff = 3.0f; + public long lll = 66666L; + public int iii = 42; + public short sss = (short)15; + public Spr9751_2 foo = new Spr9751_2(); + + public int[] intArray = new int[]{1,2,3,4,5}; + public int index1 = 2; + + public Integer[] integerArray; + public int index2 = 2; + + public List listOfStrings; + public int index3 = 0; + + public Spr9751() { + integerArray = new Integer[5]; + integerArray[0] = 1; + integerArray[1] = 2; + integerArray[2] = 3; + integerArray[3] = 4; + integerArray[4] = 5; + listOfStrings = new ArrayList<>(); + listOfStrings.add("abc"); + } + + public void m() {} + + public static boolean isEven(int i) { + return (i%2)==0; + } + } + + + static class Spr9751_2 { + + public int iii = 99; + } + + static class MyBeanResolver implements BeanResolver { @Override - public Object resolve(EvaluationContext context, String beanName) - throws AccessException { + public Object resolve(EvaluationContext context, String beanName) throws AccessException { if (beanName.equals("foo") || beanName.equals("bar")) { return new Spr9751_2(); } - throw new AccessException("not heard of "+beanName); + throw new AccessException("not heard of " + beanName); } } diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index 5e0aa4d362b..bc8ae26ab49 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -36,8 +36,8 @@ import org.springframework.util.MimeTypeUtils; import org.springframework.util.StringUtils; /** - * A sub-class of {@link MimeType} that adds support for quality parameters as defined - * in the HTTP specification. + * A subclass of {@link MimeType} that adds support for quality parameters + * as defined in the HTTP specification. * * @author Arjen Poutsma * @author Juergen Hoeller @@ -427,21 +427,25 @@ public class MediaType extends MimeType implements Serializable { } /** - * Return the quality value, as indicated by a {@code q} parameter, if any. + * Return the quality factor, as indicated by a {@code q} parameter, if any. * Defaults to {@code 1.0}. - * @return the quality factory + * @return the quality factor as double value */ public double getQualityValue() { - String qualityFactory = getParameter(PARAM_QUALITY_FACTOR); - return (qualityFactory != null ? Double.parseDouble(unquote(qualityFactory)) : 1D); + String qualityFactor = getParameter(PARAM_QUALITY_FACTOR); + return (qualityFactor != null ? Double.parseDouble(unquote(qualityFactor)) : 1D); } /** * Indicate whether this {@code MediaType} includes the given media type. - *

For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, and {@code application/*+xml} - * includes {@code application/soap+xml}, etc. This method is not symmetric. + *

For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, + * and {@code application/*+xml} includes {@code application/soap+xml}, etc. + * This method is not symmetric. + *

Simply calls {@link #includes(MimeType)} but declared with a + * {@code MediaType} parameter for binary backwards compatibility. * @param other the reference media type with which to compare - * @return {@code true} if this media type includes the given media type; {@code false} otherwise + * @return {@code true} if this media type includes the given media type; + * {@code false} otherwise */ public boolean includes(@Nullable MediaType other) { return super.includes(other); @@ -449,18 +453,23 @@ public class MediaType extends MimeType implements Serializable { /** * Indicate whether this {@code MediaType} is compatible with the given media type. - *

For instance, {@code text/*} is compatible with {@code text/plain}, {@code text/html}, and vice versa. - * In effect, this method is similar to {@link #includes(MediaType)}, except that it is symmetric. + *

For instance, {@code text/*} is compatible with {@code text/plain}, + * {@code text/html}, and vice versa. In effect, this method is similar to + * {@link #includes}, except that it is symmetric. + *

Simply calls {@link #isCompatibleWith(MimeType)} but declared with a + * {@code MediaType} parameter for binary backwards compatibility. * @param other the reference media type with which to compare - * @return {@code true} if this media type is compatible with the given media type; {@code false} otherwise + * @return {@code true} if this media type is compatible with the given media type; + * {@code false} otherwise */ public boolean isCompatibleWith(@Nullable MediaType other) { return super.isCompatibleWith(other); } /** - * Return a replica of this instance with the quality value of the given MediaType. - * @return the same instance if the given MediaType doesn't have a quality value, or a new one otherwise + * Return a replica of this instance with the quality value of the given {@code MediaType}. + * @return the same instance if the given MediaType doesn't have a quality value, + * or a new one otherwise */ public MediaType copyQualityValue(MediaType mediaType) { if (!mediaType.getParameters().containsKey(PARAM_QUALITY_FACTOR)) { @@ -473,7 +482,8 @@ public class MediaType extends MimeType implements Serializable { /** * Return a replica of this instance with its quality value removed. - * @return the same instance if the media type doesn't contain a quality value, or a new one otherwise + * @return the same instance if the media type doesn't contain a quality value, + * or a new one otherwise */ public MediaType removeQualityValue() { if (!getParameters().containsKey(PARAM_QUALITY_FACTOR)) { @@ -677,30 +687,29 @@ public class MediaType extends MimeType implements Serializable { if (qualityComparison != 0) { return qualityComparison; // audio/*;q=0.7 < audio/*;q=0.3 } - else if (mediaType1.isWildcardType() && !mediaType2.isWildcardType()) { // */* < audio/* + else if (mediaType1.isWildcardType() && !mediaType2.isWildcardType()) { // */* < audio/* return 1; } - else if (mediaType2.isWildcardType() && !mediaType1.isWildcardType()) { // audio/* > */* + else if (mediaType2.isWildcardType() && !mediaType1.isWildcardType()) { // audio/* > */* return -1; } - else if (!mediaType1.getType().equals(mediaType2.getType())) { // audio/basic == text/html + else if (!mediaType1.getType().equals(mediaType2.getType())) { // audio/basic == text/html return 0; } - else { // mediaType1.getType().equals(mediaType2.getType()) - if (mediaType1.isWildcardSubtype() && !mediaType2.isWildcardSubtype()) { // audio/* < audio/basic + else { // mediaType1.getType().equals(mediaType2.getType()) + if (mediaType1.isWildcardSubtype() && !mediaType2.isWildcardSubtype()) { // audio/* < audio/basic return 1; } - else if (mediaType2.isWildcardSubtype() && !mediaType1.isWildcardSubtype()) { // audio/basic > audio/* + else if (mediaType2.isWildcardSubtype() && !mediaType1.isWildcardSubtype()) { // audio/basic > audio/* return -1; } - else if (!mediaType1.getSubtype().equals(mediaType2.getSubtype())) { // audio/basic == audio/wave + else if (!mediaType1.getSubtype().equals(mediaType2.getSubtype())) { // audio/basic == audio/wave return 0; } else { int paramsSize1 = mediaType1.getParameters().size(); int paramsSize2 = mediaType2.getParameters().size(); - // audio/basic;level=1 < audio/basic - return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); + return Integer.compare(paramsSize2, paramsSize1); // audio/basic;level=1 < audio/basic } } };