Polishing
This commit is contained in:
parent
6030e62766
commit
0cb4043aac
|
|
@ -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
|
* @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) {
|
public static boolean isPrimitive(@Nullable String descriptor) {
|
||||||
return (descriptor != null && descriptor.length() == 1);
|
return (descriptor != null && descriptor.length() == 1);
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ public class MethodReference extends SpelNodeImpl {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private String originalPrimitiveExitTypeDescriptor;
|
private Character originalPrimitiveExitTypeDescriptor;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private volatile CachedMethodExecutor cachedExecutor;
|
private volatile CachedMethodExecutor cachedExecutor;
|
||||||
|
|
@ -260,7 +260,7 @@ public class MethodReference extends SpelNodeImpl {
|
||||||
Method method = reflectiveMethodExecutor.getMethod();
|
Method method = reflectiveMethodExecutor.getMethod();
|
||||||
String descriptor = CodeFlow.toDescriptor(method.getReturnType());
|
String descriptor = CodeFlow.toDescriptor(method.getReturnType());
|
||||||
if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) {
|
if (this.nullSafe && CodeFlow.isPrimitive(descriptor)) {
|
||||||
this.originalPrimitiveExitTypeDescriptor = descriptor;
|
this.originalPrimitiveExitTypeDescriptor = descriptor.charAt(0);
|
||||||
this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
|
this.exitTypeDescriptor = CodeFlow.toBoxedDescriptor(descriptor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
||||||
|
|
@ -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");
|
* 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.
|
||||||
|
|
@ -184,8 +184,9 @@ public final class SpelCompiler implements Opcodes {
|
||||||
cf.finish();
|
cf.finish();
|
||||||
|
|
||||||
byte[] data = cw.toByteArray();
|
byte[] data = cw.toByteArray();
|
||||||
// TODO need to make this conditionally occur based on a debug flag
|
// TODO Save generated class files conditionally based on a debug flag.
|
||||||
// dump(expressionToCompile.toStringAST(), clazzName, data);
|
// Source code for the following method resides in SpelCompilationCoverageTests.
|
||||||
|
// saveGeneratedClassFile(expressionToCompile.toStringAST(), className, data);
|
||||||
return loadClass(StringUtils.replace(className, "/", "."), data);
|
return loadClass(StringUtils.replace(className, "/", "."), data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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…
Reference in New Issue