Browse Source

Polishing

pull/31301/merge
Sam Brannen 12 months ago
parent
commit
0cb4043aac
  1. 4
      spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
  2. 4
      spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java
  3. 7
      spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java
  4. 15
      spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

4
spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java

@ -515,9 +515,9 @@ public class CodeFlow implements Opcodes { @@ -515,9 +515,9 @@ public class CodeFlow implements Opcodes {
}
/**
* Determine whether the descriptor is for a primitive type.
* Determine whether the descriptor is for a primitive type or {@code void}.
* @param descriptor type descriptor
* @return {@code true} if a primitive type
* @return {@code true} if a primitive type or {@code void}
*/
public static boolean isPrimitive(@Nullable String descriptor) {
return (descriptor != null && descriptor.length() == 1);

4
spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java

@ -60,7 +60,7 @@ public class MethodReference extends SpelNodeImpl { @@ -60,7 +60,7 @@ public class MethodReference extends SpelNodeImpl {
private final String name;
@Nullable
private String originalPrimitiveExitTypeDescriptor;
private Character originalPrimitiveExitTypeDescriptor;
@Nullable
private volatile CachedMethodExecutor cachedExecutor;
@ -260,7 +260,7 @@ public class MethodReference extends SpelNodeImpl { @@ -260,7 +260,7 @@ public class MethodReference extends SpelNodeImpl {
Method method = reflectiveMethodExecutor.getMethod();
String descriptor = CodeFlow.toDescriptor(method.getReturnType());
if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) {
this.originalPrimitiveExitTypeDescriptor = descriptor;
this.originalPrimitiveExitTypeDescriptor = descriptor.charAt(0);
this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
}
else {

7
spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelCompiler.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -184,8 +184,9 @@ public final class SpelCompiler implements Opcodes { @@ -184,8 +184,9 @@ public final class SpelCompiler implements Opcodes {
cf.finish();
byte[] data = cw.toByteArray();
// TODO need to make this conditionally occur based on a debug flag
// dump(expressionToCompile.toStringAST(), clazzName, data);
// TODO Save generated class files conditionally based on a debug flag.
// Source code for the following method resides in SpelCompilationCoverageTests.
// saveGeneratedClassFile(expressionToCompile.toStringAST(), className, data);
return loadClass(StringUtils.replace(className, "/", "."), data);
}

15
spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java

@ -6255,4 +6255,19 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { @@ -6255,4 +6255,19 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
}
}
// NOTE: saveGeneratedClassFile() can be copied to SpelCompiler and uncommented
// at the end of createExpressionClass(SpelNodeImpl) in order to review generated
// byte code for debugging purposes.
//
// private static void saveGeneratedClassFile(String stringAST, String className, byte[] data) {
// Path path = Path.of("build", StringUtils.replace(className, "/", ".") + ".class");
// System.out.println("Writing compiled SpEL expression [%s] to [%s]".formatted(stringAST, path.toAbsolutePath()));
// try {
// Files.copy(new ByteArrayInputStream(data), path);
// }
// catch (IOException ex) {
// throw new UncheckedIOException(ex);
// }
// }
}

Loading…
Cancel
Save