Java Code Examples for org.springframework.expression.spel.CodeFlow#insertNewArrayCode()
The following examples show how to use
org.springframework.expression.spel.CodeFlow#insertNewArrayCode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SpelNodeImpl.java From spring-analysis-note with MIT License | 4 votes |
/** * Generate code that handles building the argument values for the specified method. * This method will take account of whether the invoked method is a varargs method * and if it is then the argument values will be appropriately packaged into an array. * @param mv the method visitor where code should be generated * @param cf the current codeflow * @param member the method or constructor for which arguments are being setup * @param arguments the expression nodes for the expression supplied argument values */ protected static void generateCodeForArguments(MethodVisitor mv, CodeFlow cf, Member member, SpelNodeImpl[] arguments) { String[] paramDescriptors = null; boolean isVarargs = false; if (member instanceof Constructor) { Constructor<?> ctor = (Constructor<?>) member; paramDescriptors = CodeFlow.toDescriptors(ctor.getParameterTypes()); isVarargs = ctor.isVarArgs(); } else { // Method Method method = (Method)member; paramDescriptors = CodeFlow.toDescriptors(method.getParameterTypes()); isVarargs = method.isVarArgs(); } if (isVarargs) { // The final parameter may or may not need packaging into an array, or nothing may // have been passed to satisfy the varargs and so something needs to be built. int p = 0; // Current supplied argument being processed int childCount = arguments.length; // Fulfill all the parameter requirements except the last one for (p = 0; p < paramDescriptors.length - 1; p++) { generateCodeForArgument(mv, cf, arguments[p], paramDescriptors[p]); } SpelNodeImpl lastChild = (childCount == 0 ? null : arguments[childCount - 1]); String arrayType = paramDescriptors[paramDescriptors.length - 1]; // Determine if the final passed argument is already suitably packaged in array // form to be passed to the method if (lastChild != null && arrayType.equals(lastChild.getExitDescriptor())) { generateCodeForArgument(mv, cf, lastChild, paramDescriptors[p]); } else { arrayType = arrayType.substring(1); // trim the leading '[', may leave other '[' // build array big enough to hold remaining arguments CodeFlow.insertNewArrayCode(mv, childCount - p, arrayType); // Package up the remaining arguments into the array int arrayindex = 0; while (p < childCount) { SpelNodeImpl child = arguments[p]; mv.visitInsn(DUP); CodeFlow.insertOptimalLoad(mv, arrayindex++); generateCodeForArgument(mv, cf, child, arrayType); CodeFlow.insertArrayStore(mv, arrayType); p++; } } } else { for (int i = 0; i < paramDescriptors.length;i++) { generateCodeForArgument(mv, cf, arguments[i], paramDescriptors[i]); } } }
Example 2
Source File: SpelNodeImpl.java From java-technology-stack with MIT License | 4 votes |
/** * Generate code that handles building the argument values for the specified method. * This method will take account of whether the invoked method is a varargs method * and if it is then the argument values will be appropriately packaged into an array. * @param mv the method visitor where code should be generated * @param cf the current codeflow * @param member the method or constructor for which arguments are being setup * @param arguments the expression nodes for the expression supplied argument values */ protected static void generateCodeForArguments(MethodVisitor mv, CodeFlow cf, Member member, SpelNodeImpl[] arguments) { String[] paramDescriptors = null; boolean isVarargs = false; if (member instanceof Constructor) { Constructor<?> ctor = (Constructor<?>) member; paramDescriptors = CodeFlow.toDescriptors(ctor.getParameterTypes()); isVarargs = ctor.isVarArgs(); } else { // Method Method method = (Method)member; paramDescriptors = CodeFlow.toDescriptors(method.getParameterTypes()); isVarargs = method.isVarArgs(); } if (isVarargs) { // The final parameter may or may not need packaging into an array, or nothing may // have been passed to satisfy the varargs and so something needs to be built. int p = 0; // Current supplied argument being processed int childCount = arguments.length; // Fulfill all the parameter requirements except the last one for (p = 0; p < paramDescriptors.length - 1; p++) { generateCodeForArgument(mv, cf, arguments[p], paramDescriptors[p]); } SpelNodeImpl lastChild = (childCount == 0 ? null : arguments[childCount - 1]); String arrayType = paramDescriptors[paramDescriptors.length - 1]; // Determine if the final passed argument is already suitably packaged in array // form to be passed to the method if (lastChild != null && arrayType.equals(lastChild.getExitDescriptor())) { generateCodeForArgument(mv, cf, lastChild, paramDescriptors[p]); } else { arrayType = arrayType.substring(1); // trim the leading '[', may leave other '[' // build array big enough to hold remaining arguments CodeFlow.insertNewArrayCode(mv, childCount - p, arrayType); // Package up the remaining arguments into the array int arrayindex = 0; while (p < childCount) { SpelNodeImpl child = arguments[p]; mv.visitInsn(DUP); CodeFlow.insertOptimalLoad(mv, arrayindex++); generateCodeForArgument(mv, cf, child, arrayType); CodeFlow.insertArrayStore(mv, arrayType); p++; } } } else { for (int i = 0; i < paramDescriptors.length;i++) { generateCodeForArgument(mv, cf, arguments[i], paramDescriptors[i]); } } }
Example 3
Source File: SpelNodeImpl.java From lams with GNU General Public License v2.0 | 4 votes |
/** * Generate code that handles building the argument values for the specified method. * This method will take account of whether the invoked method is a varargs method * and if it is then the argument values will be appropriately packaged into an array. * @param mv the method visitor where code should be generated * @param cf the current codeflow * @param member the method or constructor for which arguments are being setup * @param arguments the expression nodes for the expression supplied argument values */ protected static void generateCodeForArguments(MethodVisitor mv, CodeFlow cf, Member member, SpelNodeImpl[] arguments) { String[] paramDescriptors = null; boolean isVarargs = false; if (member instanceof Constructor) { Constructor<?> ctor = (Constructor<?>) member; paramDescriptors = CodeFlow.toDescriptors(ctor.getParameterTypes()); isVarargs = ctor.isVarArgs(); } else { // Method Method method = (Method)member; paramDescriptors = CodeFlow.toDescriptors(method.getParameterTypes()); isVarargs = method.isVarArgs(); } if (isVarargs) { // The final parameter may or may not need packaging into an array, or nothing may // have been passed to satisfy the varargs and so something needs to be built. int p = 0; // Current supplied argument being processed int childCount = arguments.length; // Fulfill all the parameter requirements except the last one for (p = 0; p < paramDescriptors.length - 1; p++) { generateCodeForArgument(mv, cf, arguments[p], paramDescriptors[p]); } SpelNodeImpl lastChild = (childCount == 0 ? null : arguments[childCount - 1]); String arrayType = paramDescriptors[paramDescriptors.length - 1]; // Determine if the final passed argument is already suitably packaged in array // form to be passed to the method if (lastChild != null && arrayType.equals(lastChild.getExitDescriptor())) { generateCodeForArgument(mv, cf, lastChild, paramDescriptors[p]); } else { arrayType = arrayType.substring(1); // trim the leading '[', may leave other '[' // build array big enough to hold remaining arguments CodeFlow.insertNewArrayCode(mv, childCount - p, arrayType); // Package up the remaining arguments into the array int arrayindex = 0; while (p < childCount) { SpelNodeImpl child = arguments[p]; mv.visitInsn(DUP); CodeFlow.insertOptimalLoad(mv, arrayindex++); generateCodeForArgument(mv, cf, child, arrayType); CodeFlow.insertArrayStore(mv, arrayType); p++; } } } else { for (int i = 0; i < paramDescriptors.length;i++) { generateCodeForArgument(mv, cf, arguments[i], paramDescriptors[i]); } } }
Example 4
Source File: SpelNodeImpl.java From spring4-understanding with Apache License 2.0 | 4 votes |
/** * Generate code that handles building the argument values for the specified method. This method will take account * of whether the invoked method is a varargs method and if it is then the argument values will be appropriately * packaged into an array. * @param mv the method visitor where code should be generated * @param cf the current codeflow * @param member the method or constructor for which arguments are being setup * @param arguments the expression nodes for the expression supplied argument values */ protected static void generateCodeForArguments(MethodVisitor mv, CodeFlow cf, Member member, SpelNodeImpl[] arguments) { String[] paramDescriptors = null; boolean isVarargs = false; if (member instanceof Constructor) { Constructor<?> ctor = (Constructor<?>)member; paramDescriptors = CodeFlow.toDescriptors(ctor.getParameterTypes()); isVarargs = ctor.isVarArgs(); } else { // Method Method method = (Method)member; paramDescriptors = CodeFlow.toDescriptors(method.getParameterTypes()); isVarargs = method.isVarArgs(); } if (isVarargs) { // The final parameter may or may not need packaging into an array, or nothing may // have been passed to satisfy the varargs and so something needs to be built. int p = 0; // Current supplied argument being processed int childCount = arguments.length; // Fulfill all the parameter requirements except the last one for (p = 0; p < paramDescriptors.length - 1; p++) { generateCodeForArgument(mv, cf, arguments[p], paramDescriptors[p]); } SpelNodeImpl lastchild = (childCount == 0 ? null : arguments[childCount - 1]); String arraytype = paramDescriptors[paramDescriptors.length - 1]; // Determine if the final passed argument is already suitably packaged in array // form to be passed to the method if (lastchild != null && lastchild.getExitDescriptor().equals(arraytype)) { generateCodeForArgument(mv, cf, lastchild, paramDescriptors[p]); } else { arraytype = arraytype.substring(1); // trim the leading '[', may leave other '[' // build array big enough to hold remaining arguments CodeFlow.insertNewArrayCode(mv, childCount - p, arraytype); // Package up the remaining arguments into the array int arrayindex = 0; while (p < childCount) { SpelNodeImpl child = arguments[p]; mv.visitInsn(DUP); CodeFlow.insertOptimalLoad(mv, arrayindex++); generateCodeForArgument(mv, cf, child, arraytype); CodeFlow.insertArrayStore(mv, arraytype); p++; } } } else { for (int i = 0; i < paramDescriptors.length;i++) { generateCodeForArgument(mv, cf, arguments[i], paramDescriptors[i]); } } }