diff -Nru invokebinder-1.5/debian/changelog invokebinder-1.7/debian/changelog --- invokebinder-1.5/debian/changelog 2015-01-22 21:07:35.000000000 +0000 +++ invokebinder-1.7/debian/changelog 2017-07-16 19:37:57.000000000 +0000 @@ -1,3 +1,22 @@ +invokebinder (1.7-2) unstable; urgency=medium + + * Upload to unstable. + + -- Miguel Landaeta Sun, 16 Jul 2017 20:37:42 +0100 + +invokebinder (1.7-1) experimental; urgency=medium + + * New upstream release. (Closes: #851328). + * Bump debhelper compat level to 10. + * Wrap and sort dependencies in d/control file. + * Add B-D on libmaven-bundle-plugin-java. + * Replace cdbs with debhelper. + * Bump Standards-Version to 3.9.8. No changes were required. + * Update copyright dates. + * Switch Vcs-Git URL to https. + + -- Miguel Landaeta Sun, 15 Jan 2017 12:19:43 +0000 + invokebinder (1.5-1) unstable; urgency=medium * Initial release. (Closes: #776020). diff -Nru invokebinder-1.5/debian/compat invokebinder-1.7/debian/compat --- invokebinder-1.5/debian/compat 2015-01-22 21:08:59.000000000 +0000 +++ invokebinder-1.7/debian/compat 2017-07-16 19:37:00.000000000 +0000 @@ -1 +1 @@ -9 +10 diff -Nru invokebinder-1.5/debian/control invokebinder-1.7/debian/control --- invokebinder-1.5/debian/control 2015-01-22 21:14:42.000000000 +0000 +++ invokebinder-1.7/debian/control 2017-07-16 19:37:00.000000000 +0000 @@ -3,17 +3,24 @@ Priority: optional Maintainer: Debian Java Maintainers Uploaders: Miguel Landaeta -Build-Depends: debhelper (>= 9), cdbs, default-jdk, maven-debian-helper (>= 1.5) -Build-Depends-Indep: junit4, default-jdk-doc, libmaven-javadoc-plugin-java -Standards-Version: 3.9.6 -Vcs-Git: git://anonscm.debian.org/pkg-java/invokebinder.git +Build-Depends: debhelper (>= 10~), + default-jdk, + maven-debian-helper +Build-Depends-Indep: junit4, + default-jdk-doc, + libmaven-bundle-plugin-java, + libmaven-javadoc-plugin-java +Standards-Version: 3.9.8 +Vcs-Git: https://anonscm.debian.org/git/pkg-java/invokebinder.git Vcs-Browser: https://anonscm.debian.org/cgit/pkg-java/invokebinder.git Homepage: https://github.com/headius/invokebinder Package: libinvokebinder-java Architecture: all -Depends: ${misc:Depends}, ${maven:Depends} -Suggests: ${maven:OptionalDepends}, libinvokebinder-java-doc +Depends: ${misc:Depends}, + ${maven:Depends} +Suggests: ${maven:OptionalDepends}, + libinvokebinder-java-doc Description: Java DSL for binding method handles This Java library hopes to provide a more friendly DSL for binding method handles. @@ -30,7 +37,8 @@ Architecture: all Section: doc Depends: ${misc:Depends} -Recommends: ${maven:DocDepends}, ${maven:DocOptionalDepends} +Recommends: ${maven:DocDepends}, + ${maven:DocOptionalDepends} Suggests: libinvokebinder-java Description: Documentation for invokebinder This Java library hopes to provide a more friendly DSL for binding diff -Nru invokebinder-1.5/debian/copyright invokebinder-1.7/debian/copyright --- invokebinder-1.5/debian/copyright 2015-01-22 21:13:54.000000000 +0000 +++ invokebinder-1.7/debian/copyright 2017-07-16 19:37:00.000000000 +0000 @@ -3,11 +3,11 @@ Source: https://github.com/headius/invokebinder Files: * -Copyright: 2012-2014, Charles Oliver Nutter +Copyright: 2012-2016, Charles Oliver Nutter License: Apache-2.0 Files: debian/* -Copyright: 2015, Miguel Landaeta +Copyright: 2015-2017, Miguel Landaeta License: Apache-2.0 License: Apache-2.0 diff -Nru invokebinder-1.5/debian/rules invokebinder-1.7/debian/rules --- invokebinder-1.5/debian/rules 2015-01-22 21:08:59.000000000 +0000 +++ invokebinder-1.7/debian/rules 2017-07-16 19:37:00.000000000 +0000 @@ -1,9 +1,6 @@ #!/usr/bin/make -f - -include /usr/share/cdbs/1/rules/debhelper.mk -include /usr/share/cdbs/1/class/maven.mk - -JAVA_HOME := /usr/lib/jvm/default-java +%: + dh $@ --buildsystem=maven get-orig-source: uscan --download-current-version --force-download --no-symlink diff -Nru invokebinder-1.5/.gitignore invokebinder-1.7/.gitignore --- invokebinder-1.5/.gitignore 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/.gitignore 2016-01-14 15:50:40.000000000 +0000 @@ -1,2 +1,3 @@ /target/ /.idea/ +*.iml diff -Nru invokebinder-1.5/pom.xml invokebinder-1.7/pom.xml --- invokebinder-1.5/pom.xml 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/pom.xml 2016-01-14 15:50:40.000000000 +0000 @@ -2,8 +2,8 @@ 4.0.0 com.headius invokebinder - jar - 1.5 + bundle + 1.7 invokebinder http://maven.apache.org @@ -42,6 +42,17 @@ + org.apache.felix + maven-bundle-plugin + true + + + com.headius.invokebinder + com.headius.invokebinder.* + + + + org.apache.maven.plugins maven-compiler-plugin 2.0.2 diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/Binder.java invokebinder-1.7/src/main/java/com/headius/invokebinder/Binder.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/Binder.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/Binder.java 2016-01-14 15:50:40.000000000 +0000 @@ -68,8 +68,8 @@ public class Binder { private final Logger logger = Logger.getLogger("Invoke Binder"); - private final List transforms = new ArrayList(); - private final List types = new ArrayList(); + private final List transforms = new ArrayList<>(); + private final List types = new ArrayList<>(); private final MethodType start; private final MethodHandles.Lookup lookup; @@ -178,7 +178,7 @@ * @param returnType the return type of the incoming signature * @return the Binder object */ - public static Binder from(Class returnType) { + public static Binder from(Class returnType) { return from(MethodType.methodType(returnType)); } @@ -189,7 +189,7 @@ * @param returnType the return type of the incoming signature * @return the Binder object */ - public static Binder from(MethodHandles.Lookup lookup, Class returnType) { + public static Binder from(MethodHandles.Lookup lookup, Class returnType) { return from(lookup, MethodType.methodType(returnType)); } @@ -200,7 +200,7 @@ * @param argTypes the argument types of the incoming signature * @return the Binder object */ - public static Binder from(Class returnType, Class[] argTypes) { + public static Binder from(Class returnType, Class[] argTypes) { return from(MethodType.methodType(returnType, argTypes)); } @@ -212,7 +212,7 @@ * @param argTypes the argument types of the incoming signature * @return the Binder object */ - public static Binder from(MethodHandles.Lookup lookup, Class returnType, Class[] argTypes) { + public static Binder from(MethodHandles.Lookup lookup, Class returnType, Class[] argTypes) { return from(lookup, MethodType.methodType(returnType, argTypes)); } @@ -224,7 +224,7 @@ * @param argTypes the remaining argument types of the incoming signature * @return the Binder object */ - public static Binder from(Class returnType, Class argType0, Class... argTypes) { + public static Binder from(Class returnType, Class argType0, Class... argTypes) { return from(MethodType.methodType(returnType, argType0, argTypes)); } @@ -237,7 +237,7 @@ * @param argTypes the remaining argument types of the incoming signature * @return the Binder object */ - public static Binder from(MethodHandles.Lookup lookup, Class returnType, Class argType0, Class... argTypes) { + public static Binder from(MethodHandles.Lookup lookup, Class returnType, Class argType0, Class... argTypes) { return from(lookup, MethodType.methodType(returnType, argType0, argTypes)); } @@ -461,7 +461,7 @@ * @param value the value to insert * @return a new Binder */ - public Binder insert(int index, Class type, Object value) { + public Binder insert(int index, Class type, Object value) { return new Binder(this, new Insert(index, new Class[]{type}, value)); } @@ -473,7 +473,7 @@ * @param values the value(s) to insert * @return a new Binder */ - public Binder insert(int index, Class[] types, Object... values) { + public Binder insert(int index, Class[] types, Object... values) { return new Binder(this, new Insert(index, types, values)); } @@ -664,7 +664,7 @@ * @param value the value to append * @return a new Binder */ - public Binder append(Class type, Object value) { + public Binder append(Class type, Object value) { return new Binder(this, new Insert(type().parameterCount(), new Class[]{type}, value)); } @@ -675,7 +675,7 @@ * @param values the value(s) to append * @return a new Binder */ - public Binder append(Class[] types, Object... values) { + public Binder append(Class[] types, Object... values) { return new Binder(this, new Insert(type().parameterCount(), types, values)); } @@ -686,7 +686,7 @@ * @param value the value(s) to prepend * @return a new Binder */ - public Binder prepend(Class type, Object value) { + public Binder prepend(Class type, Object value) { return new Binder(this, new Insert(0, new Class[]{type}, value)); } @@ -697,7 +697,7 @@ * @param values the value(s) to prepend * @return a new Binder */ - public Binder prepend(Class[] types, Object... values) { + public Binder prepend(Class[] types, Object... values) { return new Binder(this, new Insert(0, types, values)); } @@ -792,7 +792,7 @@ * @param argTypes the target argument types * @return a new Binder */ - public Binder convert(Class returnType, Class... argTypes) { + public Binder convert(Class returnType, Class... argTypes) { return new Binder(this, new Convert(type()), MethodType.methodType(returnType, argTypes)); } @@ -815,7 +815,7 @@ * @param argTypes the target argument types * @return a new Binder */ - public Binder cast(Class returnType, Class... argTypes) { + public Binder cast(Class returnType, Class... argTypes) { return new Binder(this, new Cast(type()), MethodType.methodType(returnType, argTypes)); } @@ -828,7 +828,7 @@ * @param restTypes the remaining target argument types * @return a new Binder */ - public Binder castVirtual(Class returnType, Class firstType, Class... restTypes) { + public Binder castVirtual(Class returnType, Class firstType, Class... restTypes) { return new Binder(this, new Cast(type()), MethodType.methodType(returnType, firstType, restTypes)); } @@ -838,7 +838,7 @@ * @param spreadTypes the types into which to spread the incoming Object[] * @return a new Binder */ - public Binder spread(Class... spreadTypes) { + public Binder spread(Class... spreadTypes) { if (spreadTypes.length == 0) { return dropLast(); } @@ -858,11 +858,11 @@ return dropLast(); } - Class aryType = type().parameterType(type().parameterCount() - 1); + Class aryType = type().parameterType(type().parameterCount() - 1); assert aryType.isArray(); - Class[] spreadTypes = new Class[count]; + Class[] spreadTypes = new Class[count]; Arrays.fill(spreadTypes, aryType.getComponentType()); return spread(spreadTypes); @@ -875,7 +875,7 @@ * @param type the array type into which the args will be boxed * @return a new Binder */ - public Binder collect(int index, Class type) { + public Binder collect(int index, Class type) { return new Binder(this, new Collect(type(), index, type)); } @@ -887,7 +887,7 @@ * @param type the array type into which the args will be boxed * @return a new Binder */ - public Binder collect(int index, int count, Class type) { + public Binder collect(int index, int count, Class type) { return new Binder(this, new Collect(type(), index, count, type)); } @@ -899,7 +899,7 @@ * @param type the array type into which the args will be boxed * @return a new Binder */ - public Binder varargs(int index, Class type) { + public Binder varargs(int index, Class type) { return new Binder(this, new Varargs(type(), index, type)); } @@ -944,7 +944,7 @@ * @param method the method to invoke on the first argument * @return a new Binder */ - public Binder foldStatic(MethodHandles.Lookup lookup, Class target, String method) { + public Binder foldStatic(MethodHandles.Lookup lookup, Class target, String method) { return fold(Binder.from(type()).invokeStaticQuiet(lookup, target, method)); } @@ -956,7 +956,7 @@ * @param method the method to invoke on the first argument * @return a new Binder */ - public Binder foldStatic(Class target, String method) { + public Binder foldStatic(Class target, String method) { return foldStatic(lookup, target, method); } @@ -969,7 +969,7 @@ * @return a new Binder */ public Binder foldVirtual(MethodHandles.Lookup lookup, String method) { - return fold(Binder.from(type()).printType().invokeVirtualQuiet(lookup, method)); + return fold(Binder.from(type()).invokeVirtualQuiet(lookup, method)); } /** @@ -1068,7 +1068,7 @@ if (type().parameterCount() != 1 || !Throwable.class.isAssignableFrom(type().parameterType(0))) { throw new InvalidTransformException("incoming signature must have one Throwable type as its sole argument: " + type()); } - return invoke(MethodHandles.throwException(type().returnType(), (Class)type().parameterType(0))); + return invoke(MethodHandles.throwException(type().returnType(), type().parameterType(0).asSubclass(Throwable.class))); } /** @@ -1174,7 +1174,7 @@ * @throws java.lang.NoSuchMethodException if the method does not exist * @throws java.lang.IllegalAccessException if the method is not accessible */ - public MethodHandle invokeStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchMethodException, IllegalAccessException { + public MethodHandle invokeStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchMethodException, IllegalAccessException { return invoke(lookup.findStatic(target, name, type())); } @@ -1195,13 +1195,11 @@ * @param name the name of the method to invoke * @return the full handle chain, bound to the given method */ - public MethodHandle invokeStaticQuiet(MethodHandles.Lookup lookup, Class target, String name) { + public MethodHandle invokeStaticQuiet(MethodHandles.Lookup lookup, Class target, String name) { try { return invokeStatic(lookup, target, name); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchMethodException nsme) { - throw new InvalidTransformException(nsme); + } catch (IllegalAccessException | NoSuchMethodException e) { + throw new InvalidTransformException(e); } } @@ -1243,10 +1241,8 @@ public MethodHandle invokeVirtualQuiet(MethodHandles.Lookup lookup, String name) { try { return invokeVirtual(lookup, name); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchMethodException nsme) { - throw new InvalidTransformException(nsme); + } catch (IllegalAccessException | NoSuchMethodException e) { + throw new InvalidTransformException(e); } } @@ -1266,7 +1262,7 @@ * @throws java.lang.NoSuchMethodException if the method does not exist * @throws java.lang.IllegalAccessException if the method is not accessible */ - public MethodHandle invokeSpecial(MethodHandles.Lookup lookup, String name, Class caller) throws NoSuchMethodException, IllegalAccessException { + public MethodHandle invokeSpecial(MethodHandles.Lookup lookup, String name, Class caller) throws NoSuchMethodException, IllegalAccessException { return invoke(lookup.findSpecial(type().parameterType(0), name, type().dropParameterTypes(0, 1), caller)); } @@ -1287,13 +1283,11 @@ * @param caller the calling class * @return the full handle chain, bound to the given method */ - public MethodHandle invokeSpecialQuiet(MethodHandles.Lookup lookup, String name, Class caller) { + public MethodHandle invokeSpecialQuiet(MethodHandles.Lookup lookup, String name, Class caller) { try { return invokeSpecial(lookup, name, caller); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchMethodException nsme) { - throw new InvalidTransformException(nsme); + } catch (IllegalAccessException | NoSuchMethodException e) { + throw new InvalidTransformException(e); } } @@ -1312,7 +1306,7 @@ * @throws java.lang.NoSuchMethodException if the constructor does not exist * @throws java.lang.IllegalAccessException if the constructor is not accessible */ - public MethodHandle invokeConstructor(MethodHandles.Lookup lookup, Class target) throws NoSuchMethodException, IllegalAccessException { + public MethodHandle invokeConstructor(MethodHandles.Lookup lookup, Class target) throws NoSuchMethodException, IllegalAccessException { return invoke(lookup.findConstructor(target, type().changeReturnType(void.class))); } @@ -1332,13 +1326,11 @@ * @param target the constructor's class * @return the full handle chain, bound to the given constructor */ - public MethodHandle invokeConstructorQuiet(MethodHandles.Lookup lookup, Class target) { + public MethodHandle invokeConstructorQuiet(MethodHandles.Lookup lookup, Class target) { try { return invokeConstructor(lookup, target); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchMethodException nsme) { - throw new InvalidTransformException(nsme); + } catch (IllegalAccessException | NoSuchMethodException e) { + throw new InvalidTransformException(e); } } @@ -1382,10 +1374,8 @@ public MethodHandle getFieldQuiet(MethodHandles.Lookup lookup, String name) { try { return getField(lookup, name); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchFieldException nsfe) { - throw new InvalidTransformException(nsfe); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new InvalidTransformException(e); } } @@ -1405,7 +1395,7 @@ * @throws java.lang.NoSuchFieldException if the field does not exist * @throws java.lang.IllegalAccessException if the field is not accessible or cannot be modified */ - public MethodHandle getStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchFieldException, IllegalAccessException { + public MethodHandle getStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchFieldException, IllegalAccessException { return invoke(lookup.findStaticGetter(target, name, type().returnType())); } @@ -1426,13 +1416,11 @@ * @param name the field's name * @return the full handle chain, bound to the given field access */ - public MethodHandle getStaticQuiet(MethodHandles.Lookup lookup, Class target, String name) { + public MethodHandle getStaticQuiet(MethodHandles.Lookup lookup, Class target, String name) { try { return getStatic(lookup, target, name); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchFieldException nsfe) { - throw new InvalidTransformException(nsfe); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new InvalidTransformException(e); } } @@ -1474,10 +1462,8 @@ public MethodHandle setFieldQuiet(MethodHandles.Lookup lookup, String name) { try { return setField(lookup, name); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchFieldException nsfe) { - throw new InvalidTransformException(nsfe); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new InvalidTransformException(e); } } @@ -1497,7 +1483,7 @@ * @throws java.lang.NoSuchFieldException if the field does not exist * @throws java.lang.IllegalAccessException if the field is not accessible or cannot be modified */ - public MethodHandle setStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchFieldException, IllegalAccessException { + public MethodHandle setStatic(MethodHandles.Lookup lookup, Class target, String name) throws NoSuchFieldException, IllegalAccessException { return invoke(lookup.findStaticSetter(target, name, type().parameterType(0))); } @@ -1518,13 +1504,11 @@ * @param name the field's name * @return the full handle chain, bound to the given field assignment */ - public MethodHandle setStaticQuiet(MethodHandles.Lookup lookup, Class target, String name) { + public MethodHandle setStaticQuiet(MethodHandles.Lookup lookup, Class target, String name) { try { return setStatic(lookup, target, name); - } catch (IllegalAccessException iae) { - throw new InvalidTransformException(iae); - } catch (NoSuchFieldException nsfe) { - throw new InvalidTransformException(nsfe); + } catch (IllegalAccessException | NoSuchFieldException e) { + throw new InvalidTransformException(e); } } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/Signature.java invokebinder-1.7/src/main/java/com/headius/invokebinder/Signature.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/Signature.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/Signature.java 2016-01-14 15:50:40.000000000 +0000 @@ -56,7 +56,7 @@ * * @param retval the return value for the new signature */ - Signature(Class retval) { + Signature(Class retval) { this(MethodType.methodType(retval)); } @@ -68,7 +68,7 @@ * @param argTypes the argument types for the new signature * @param argNames the argument names for the new signature */ - Signature(Class retval, Class[] argTypes, String... argNames) { + Signature(Class retval, Class[] argTypes, String... argNames) { this(MethodType.methodType(retval, argTypes), argNames); } @@ -81,7 +81,7 @@ * @param restArgs the remaining argument types for the new signature * @param argNames the argument names for the new signature */ - Signature(Class retval, Class firstArg, Class[] restArgs, String... argNames) { + Signature(Class retval, Class firstArg, Class[] restArgs, String... argNames) { this(MethodType.methodType(retval, firstArg, restArgs), argNames); } @@ -138,7 +138,7 @@ * @param retval the return type for the new signature * @return the new signature */ - public static Signature returning(Class retval) { + public static Signature returning(Class retval) { Signature sig = new Signature(retval); return sig; } @@ -151,7 +151,7 @@ * @param argNames the names of the arguments * @return a new Signature */ - public static Signature from(Class retval, Class[] argTypes, String... argNames) { + public static Signature from(Class retval, Class[] argTypes, String... argNames) { assert argTypes.length == argNames.length; return new Signature(retval, argTypes, argNames); @@ -163,7 +163,7 @@ * @param retval the class for the new signature's return type * @return the new signature with modified return value */ - public Signature changeReturn(Class retval) { + public Signature changeReturn(Class retval) { return new Signature(methodType.changeReturnType(retval), argNames); } @@ -173,7 +173,7 @@ * @param retval the new return type for the new signature * @return a new signature with the added argument */ - public Signature asFold(Class retval) { + public Signature asFold(Class retval) { return new Signature(methodType.changeReturnType(retval), argNames); } @@ -184,7 +184,7 @@ * @param type the type of the argument * @return a new signature with the added arguments */ - public Signature appendArg(String name, Class type) { + public Signature appendArg(String name, Class type) { String[] newArgNames = new String[argNames.length + 1]; System.arraycopy(argNames, 0, newArgNames, 0, argNames.length); newArgNames[argNames.length] = name; @@ -199,7 +199,7 @@ * @param types the types of the argument * @return a new signature with the added arguments */ - public Signature appendArgs(String[] names, Class... types) { + public Signature appendArgs(String[] names, Class... types) { assert names.length == types.length : "names and types must be of the same length"; String[] newArgNames = new String[argNames.length + names.length]; @@ -216,7 +216,7 @@ * @param type the type of the argument * @return a new signature with the added arguments */ - public Signature prependArg(String name, Class type) { + public Signature prependArg(String name, Class type) { String[] newArgNames = new String[argNames.length + 1]; System.arraycopy(argNames, 0, newArgNames, 1, argNames.length); newArgNames[0] = name; @@ -231,7 +231,7 @@ * @param types the types of the arguments * @return a new signature with the added arguments */ - public Signature prependArgs(String[] names, Class... types) { + public Signature prependArgs(String[] names, Class... types) { String[] newArgNames = new String[argNames.length + names.length]; System.arraycopy(argNames, 0, newArgNames, names.length, argNames.length); System.arraycopy(names, 0, newArgNames, 0, names.length); @@ -247,8 +247,8 @@ * @param type the type of the new argument * @return a new signature with the added arguments */ - public Signature insertArg(int index, String name, Class type) { - return insertArgs(index, new String[]{name}, new Class[]{type}); + public Signature insertArg(int index, String name, Class type) { + return insertArgs(index, new String[]{name}, new Class[]{type}); } /** @@ -260,8 +260,8 @@ * @param type the type of the new argument * @return a new signature with the added arguments */ - public Signature insertArg(String beforeName, String name, Class type) { - return insertArgs(argOffset(beforeName), new String[]{name}, new Class[]{type}); + public Signature insertArg(String beforeName, String name, Class type) { + return insertArgs(argOffset(beforeName), new String[]{name}, new Class[]{type}); } /** @@ -272,7 +272,7 @@ * @param types the types of the new arguments * @return a new signature with the added arguments */ - public Signature insertArgs(int index, String[] names, Class... types) { + public Signature insertArgs(int index, String[] names, Class... types) { assert names.length == types.length : "names and types must be of the same length"; String[] newArgNames = new String[argNames.length + names.length]; @@ -295,7 +295,7 @@ * @param types the types of the new arguments * @return a new Signature with the added arguments */ - public Signature insertArgs(String beforeName, String[] names, Class... types) { + public Signature insertArgs(String beforeName, String[] names, Class... types) { return insertArgs(argOffset(beforeName), names, types); } @@ -394,7 +394,7 @@ * @param newType the new type of the argument; can be the same as old * @return a new signature with the modified argument */ - public Signature replaceArg(String oldName, String newName, Class newType) { + public Signature replaceArg(String oldName, String newName, Class newType) { int offset = argOffset(oldName); String[] newArgNames = argNames; @@ -403,7 +403,7 @@ newArgNames[offset] = newName; } - Class oldType = methodType.parameterType(offset); + Class oldType = methodType.parameterType(offset); MethodType newMethodType = methodType; if (!oldType.equals(newType)) newMethodType = methodType.changeParameterType(offset, newType); @@ -418,7 +418,7 @@ * @param types types to use for the decomposed arguments * @return a new signature with decomposed arguments in place of the trailing array */ - public Signature spread(String[] names, Class... types) { + public Signature spread(String[] names, Class... types) { assert names.length == types.length : "names and types must be of the same length"; String[] newArgNames = new String[argNames.length - 1 + names.length]; @@ -439,11 +439,11 @@ * @return a new signature with decomposed arguments in place of the trailing array */ public Signature spread(String... names) { - Class aryType = lastArgType(); + Class aryType = lastArgType(); assert lastArgType().isArray(); - Class[] newTypes = new Class[names.length]; + Class[] newTypes = new Class[names.length]; Arrays.fill(newTypes, aryType.getComponentType()); return spread(names, newTypes); @@ -475,7 +475,7 @@ int start = -1; int newCount = 0; int gatherCount = 0; - Class type = null; + Class type = null; Pattern pattern = Pattern.compile(oldPattern); MethodType newType = type(); @@ -484,7 +484,7 @@ if (pattern.matcher(argName(i)).matches()) { gatherCount++; newType = newType.dropParameterTypes(newCount, newCount + 1); - Class argType = argType(i); + Class argType = argType(i); if (start == -1) start = i; if (type == null) { type = argType; @@ -621,7 +621,7 @@ * @param index the index from which to get the argument type * @return the argument type */ - public Class argType(int index) { + public Class argType(int index) { return methodType.parameterType(index); } @@ -630,7 +630,7 @@ * * @return the first argument type */ - public Class firstArgType() { + public Class firstArgType() { return methodType.parameterType(0); } @@ -639,7 +639,7 @@ * * @return the last argument type */ - public Class lastArgType() { + public Class lastArgType() { return argType(methodType.parameterCount() - 1); } @@ -650,7 +650,7 @@ * @param type the type to set * @return a new signature with the given type at the given index */ - public Signature argType(int index, Class type) { + public Signature argType(int index, Class type) { return new Signature(type().changeParameterType(index, type), argNames()); } @@ -665,8 +665,8 @@ Pattern[] patterns = new Pattern[permuteArgs.length]; for (int i = 0; i < permuteArgs.length; i++) patterns[i] = Pattern.compile(permuteArgs[i]); - List types = new ArrayList(argNames.length); - List names = new ArrayList(argNames.length); + List> types = new ArrayList<>(argNames.length); + List names = new ArrayList<>(argNames.length); for (Pattern pattern : patterns) { for (int argOffset = 0; argOffset < argNames.length; argOffset++) { @@ -678,7 +678,7 @@ } } } - return new Signature(MethodType.methodType(methodType.returnType(), types.toArray(new Class[0])), names.toArray(new String[0])); + return new Signature(MethodType.methodType(methodType.returnType(), types.toArray(new Class[0])), names.toArray(new String[0])); } /** @@ -692,8 +692,8 @@ Pattern[] patterns = new Pattern[excludeArgs.length]; for (int i = 0; i < excludeArgs.length; i++) patterns[i] = Pattern.compile(excludeArgs[i]); - List types = new ArrayList(argNames.length); - List names = new ArrayList(argNames.length); + List> types = new ArrayList<>(argNames.length); + List names = new ArrayList<>(argNames.length); OUTER: for (int argOffset = 0; argOffset < argNames.length; argOffset++) { @@ -707,7 +707,7 @@ types.add(methodType.parameterType(argOffset)); names.add(arg); } - return new Signature(MethodType.methodType(methodType.returnType(), types.toArray(new Class[0])), names.toArray(new String[0])); + return new Signature(MethodType.methodType(methodType.returnType(), types.toArray(new Class[0])), names.toArray(new String[0])); } /** diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/SmartBinder.java invokebinder-1.7/src/main/java/com/headius/invokebinder/SmartBinder.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/SmartBinder.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/SmartBinder.java 2016-01-14 15:50:40.000000000 +0000 @@ -15,6 +15,7 @@ */ package com.headius.invokebinder; +import java.io.PrintStream; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles.Lookup; import java.lang.reflect.Array; @@ -35,7 +36,7 @@ */ public class SmartBinder { private final Signature start; - private final List signatures = new ArrayList(); + private final List signatures = new ArrayList<>(); private final Binder binder; private SmartBinder(Signature start, Binder binder) { @@ -61,6 +62,15 @@ } /** + * Get the signature this binder started with. + * + * @return the signature this binder started with. + */ + public Signature baseSignature() { + return signatures.get(signatures.size() - 1); + } + + /** * Get the Binder instance associated with this SmartBinder. * * @return this SmartBinder's Binder instance @@ -87,7 +97,7 @@ * @param types the argument types * @return a new SmartBinder */ - public static SmartBinder from(Class retType, String[] names, Class... types) { + public static SmartBinder from(Class retType, String[] names, Class... types) { return from(Signature.returning(retType).appendArgs(names, types)); } @@ -99,7 +109,7 @@ * @param type the sole argument's type * @return a new SmartBinder */ - public static SmartBinder from(Class retType, String name, Class type) { + public static SmartBinder from(Class retType, String name, Class type) { return from(Signature.returning(retType).appendArg(name, type)); } @@ -125,7 +135,7 @@ * @param types the argument types * @return a new SmartBinder */ - public static SmartBinder from(Lookup lookup, Class retType, String[] names, Class... types) { + public static SmartBinder from(Lookup lookup, Class retType, String[] names, Class... types) { return from(lookup, Signature.returning(retType).appendArgs(names, types)); } @@ -139,7 +149,7 @@ * @param type the sole argument's type * @return a new SmartBinder */ - public static SmartBinder from(Lookup lookup, Class retType, String name, Class type) { + public static SmartBinder from(Lookup lookup, Class retType, String name, Class type) { return from(lookup, Signature.returning(retType).appendArg(name, type)); } @@ -217,7 +227,7 @@ * @param method the name of the method to become a folding function * @return a new SmartBinder with the fold applied */ - public SmartBinder foldStatic(String newName, Lookup lookup, Class target, String method) { + public SmartBinder foldStatic(String newName, Lookup lookup, Class target, String method) { Binder newBinder = binder.foldStatic(lookup, target, method); return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), binder); } @@ -233,9 +243,9 @@ * @param method the name of the method to become a folding function * @return a new SmartBinder with the fold applied */ - public SmartBinder foldStatic(String newName, Class target, String method) { + public SmartBinder foldStatic(String newName, Class target, String method) { Binder newBinder = binder.foldStatic(target, method); - return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), binder); + return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), newBinder); } /** @@ -251,7 +261,7 @@ */ public SmartBinder foldVirtual(String newName, Lookup lookup, String method) { Binder newBinder = binder.foldVirtual(lookup, method); - return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), binder); + return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), newBinder); } /** @@ -267,7 +277,7 @@ */ public SmartBinder foldVirtual(String newName, String method) { Binder newBinder = binder.foldVirtual(method); - return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), binder); + return new SmartBinder(this, signature().prependArg(newName, newBinder.type().parameterType(0)), newBinder); } /////////////////////////////////////////////////////////////////////////// @@ -323,7 +333,7 @@ * @param spreadTypes the types as which to spread the incoming array * @return a new SmartBinder with the spread applied */ - public SmartBinder spread(String[] spreadNames, Class... spreadTypes) { + public SmartBinder spread(String[] spreadNames, Class... spreadTypes) { return new SmartBinder(this, signature().spread(spreadNames, spreadTypes), binder.spread(spreadTypes)); } @@ -480,7 +490,7 @@ * @param value the value of the new argument * @return a new SmartBinder with the insert applied */ - public SmartBinder insert(int index, String name, Class type, Object value) { + public SmartBinder insert(int index, String name, Class type, Object value) { return new SmartBinder(this, signature().insertArg(index, name, type), binder.insert(index, type, value)); } @@ -494,7 +504,7 @@ * @param values the values of the new arguments * @return a new SmartBinder with the insert applied */ - public SmartBinder insert(int index, String[] names, Class[] types, Object... values) { + public SmartBinder insert(int index, String[] names, Class[] types, Object... values) { return new SmartBinder(this, signature().insertArgs(index, names, types), binder.insert(index, types, values)); } @@ -615,8 +625,8 @@ * @param value the value of the new argument * @return a new SmartBinder with the append applied */ - public SmartBinder append(String name, Class type, Object value) { - return new SmartBinder(this, signature().appendArg(name, type), binder.append(new Class[]{type}, value)); + public SmartBinder append(String name, Class type, Object value) { + return new SmartBinder(this, signature().appendArg(name, type), binder.append(new Class[]{type}, value)); } /** @@ -628,7 +638,7 @@ * @param values the values of the new arguments * @return a new SmartBinder with the append applied */ - public SmartBinder append(String[] names, Class[] types, Object... values) { + public SmartBinder append(String[] names, Class[] types, Object... values) { return new SmartBinder(this, signature().appendArgs(names, types), binder.append(types, values)); } @@ -749,7 +759,7 @@ * @param value the value of the new argument * @return a new SmartBinder with the prepend applied */ - public SmartBinder prepend(String name, Class type, Object value) { + public SmartBinder prepend(String name, Class type, Object value) { return new SmartBinder(this, signature().prependArg(name, type), binder.prepend(type, value)); } @@ -762,7 +772,7 @@ * @param values the values of the new arguments * @return a new SmartBinder with the prepend applied */ - public SmartBinder prepend(String[] names, Class[] types, Object... values) { + public SmartBinder prepend(String[] names, Class[] types, Object... values) { return new SmartBinder(this, signature().prependArgs(names, types), binder.prepend(types, values)); } @@ -867,7 +877,7 @@ * @param argTypes the types of the arguments for the casted signature * @return a new SmartBinder with the cast applied */ - public SmartBinder cast(Class returnType, Class... argTypes) { + public SmartBinder cast(Class returnType, Class... argTypes) { return new SmartBinder(this, new Signature(returnType, argTypes, signature().argNames()), binder.cast(returnType, argTypes)); } @@ -882,7 +892,7 @@ * @param restArgs the types of the remaining arguments for the casted signature * @return a new SmartBinder with the cast applied. */ - public SmartBinder castVirtual(Class returnType, Class firstArg, Class... restArgs) { + public SmartBinder castVirtual(Class returnType, Class firstArg, Class... restArgs) { return new SmartBinder(this, new Signature(returnType, firstArg, restArgs, signature().argNames()), binder.castVirtual(returnType, firstArg, restArgs)); } @@ -893,7 +903,7 @@ * @param type the type to which that argument will be cast * @return a new SmartBinder with the cast applied */ - public SmartBinder castArg(String name, Class type) { + public SmartBinder castArg(String name, Class type) { Signature newSig = signature().replaceArg(name, name, type); return new SmartBinder(this, newSig, binder.cast(newSig.type())); } @@ -912,7 +922,7 @@ * @param type the new type for the return value * @return a new SmartBinder */ - public SmartBinder castReturn(Class type) { + public SmartBinder castReturn(Class type) { return new SmartBinder(this, signature().changeReturn(type), binder.cast(type, binder.type().parameterArray())); } @@ -1005,7 +1015,7 @@ * @throws NoSuchMethodException if the named method with current signature's types does not exist * @throws IllegalAccessException if the named method is not accessible to the given Lookup */ - public SmartHandle invokeStatic(Lookup lookup, Class target, String name) throws NoSuchMethodException, IllegalAccessException { + public SmartHandle invokeStatic(Lookup lookup, Class target, String name) throws NoSuchMethodException, IllegalAccessException { return new SmartHandle(start, binder.invokeStatic(lookup, target, name)); } @@ -1026,7 +1036,7 @@ * @return a SmartHandle with this binder's starting signature, bound * to the target method */ - public SmartHandle invokeStaticQuiet(Lookup lookup, Class target, String name) { + public SmartHandle invokeStaticQuiet(Lookup lookup, Class target, String name) { return new SmartHandle(start, binder.invokeStaticQuiet(lookup, target, name)); } @@ -1105,12 +1115,21 @@ /////////////////////////////////////////////////////////////////////////// /** - * Print this binder's current signature to stdout. + * Print this binder's current signature to System.out. * * @return this SmartBinder */ public SmartBinder printSignature() { - System.out.println(signature().toString()); + return printSignature(System.out); + } + + /** + * Print this binder's current signature to the give PrintStream. + * + * @return this SmartBinder + */ + public SmartBinder printSignature(PrintStream ps) { + ps.println(signature().toString()); return this; } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/SmartHandle.java invokebinder-1.7/src/main/java/com/headius/invokebinder/SmartHandle.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/SmartHandle.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/SmartHandle.java 2016-01-14 15:50:40.000000000 +0000 @@ -100,13 +100,11 @@ * @param signature the signature of the method * @return a new SmartHandle based on the signature and looked-up MethodHandle */ - public static SmartHandle findStaticQuiet(Lookup lookup, Class target, String name, Signature signature) { + public static SmartHandle findStaticQuiet(Lookup lookup, Class target, String name, Signature signature) { try { return new SmartHandle(signature, lookup.findStatic(target, name, signature.type())); - } catch (NoSuchMethodException nsme) { - throw new RuntimeException(nsme); - } catch (IllegalAccessException nae) { - throw new RuntimeException(nae); + } catch (NoSuchMethodException | IllegalAccessException e) { + throw new RuntimeException(e); } } @@ -178,7 +176,7 @@ * @param type type of the argument * @return a new SmartHandle with the additional argument */ - public SmartHandle drop(String beforeName, String newName, Class type) { + public SmartHandle drop(String beforeName, String newName, Class type) { return new SmartHandle(signature.insertArg(beforeName, newName, type), MethodHandles.dropArguments(handle, signature.argOffset(beforeName), type)); } @@ -191,7 +189,7 @@ * @param type type of the argument * @return a new SmartHandle with the additional argument */ - public SmartHandle drop(int index, String newName, Class type) { + public SmartHandle drop(int index, String newName, Class type) { return new SmartHandle(signature.insertArg(index, newName, type), MethodHandles.dropArguments(handle, index, type)); } @@ -203,7 +201,7 @@ * @param type type of the argument * @return a new SmartHandle with the additional argument */ - public SmartHandle dropLast(String newName, Class type) { + public SmartHandle dropLast(String newName, Class type) { return new SmartHandle(signature.appendArg(newName, type), MethodHandles.dropArguments(handle, signature.argOffset(newName), type)); } @@ -261,7 +259,7 @@ * @param argTypes the argument types of the new handle * @return a new SmartHandle that accepts the given argument types */ - public SmartHandle convert(Class returnType, Class... argTypes) { + public SmartHandle convert(Class returnType, Class... argTypes) { return convert(MethodType.methodType(returnType, argTypes)); } @@ -310,7 +308,7 @@ * @param argTypes the argument types of the new handle * @return a new SmartHandle that accepts the given argument types */ - public SmartHandle cast(Class returnType, Class... argTypes) { + public SmartHandle cast(Class returnType, Class... argTypes) { return cast(MethodType.methodType(returnType, argTypes)); } @@ -322,7 +320,7 @@ * @param value the new value to return * @return a new SmartHandle that returns the given value */ - public SmartHandle returnValue(Class type, Object value) { + public SmartHandle returnValue(Class type, Object value) { return new SmartHandle(signature.changeReturn(type), MethodHandles.filterReturnValue(handle, MethodHandles.constant(type, value))); } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Catch.java invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Catch.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Catch.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Catch.java 2016-01-14 15:50:40.000000000 +0000 @@ -26,10 +26,10 @@ */ public class Catch extends Transform { - private final Class throwable; + private final Class throwable; private final MethodHandle function; - public Catch(Class throwable, MethodHandle function) { + public Catch(Class throwable, MethodHandle function) { this.throwable = throwable; this.function = function; } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Collect.java invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Collect.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Collect.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Collect.java 2016-01-14 15:50:40.000000000 +0000 @@ -30,16 +30,16 @@ private final MethodType source; private final int index; private final int count; - private final Class arrayType; + private final Class arrayType; - public Collect(MethodType source, int index, Class arrayType) { + public Collect(MethodType source, int index, Class arrayType) { this.source = source; this.index = index; this.count = source.parameterCount() - index; this.arrayType = arrayType; } - public Collect(MethodType source, int index, int count, Class arrayType) { + public Collect(MethodType source, int index, int count, Class arrayType) { this.source = source; this.index = index; this.count = count; @@ -85,9 +85,9 @@ } private void assertTypesAreCompatible() { - Class componentType = arrayType.getComponentType(); + Class componentType = arrayType.getComponentType(); for (int i = index; i < index + count; i++) { - Class in = source.parameterType(i); + Class in = source.parameterType(i); assert in.isAssignableFrom(componentType) : "incoming type " + in.getName() + " not compatible with " + componentType.getName() + "[]"; } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Drop.java invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Drop.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Drop.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Drop.java 2016-01-14 15:50:40.000000000 +0000 @@ -28,9 +28,9 @@ public class Drop extends Transform { private final int position; - private final Class[] types; + private final Class[] types; - public Drop(int position, Class... types) { + public Drop(int position, Class... types) { this.position = position; this.types = types; } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Insert.java invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Insert.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Insert.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Insert.java 2016-01-14 15:50:40.000000000 +0000 @@ -28,13 +28,13 @@ public class Insert extends Transform { private final int position; - private final Class[] types; + private final Class[] types; private final Object[] values; public Insert(int position, Object... values) { this.position = position; this.values = values; - Class[] types = new Class[values.length]; + Class[] types = new Class[values.length]; for (int i = 0; i < values.length; i++) { types[i] = values[i].getClass(); } @@ -89,7 +89,7 @@ this.types = new Class[]{double.class}; } - public Insert(int position, Class[] types, Object... values) { + public Insert(int position, Class[] types, Object... values) { this.position = position; this.values = values; this.types = types; @@ -107,8 +107,8 @@ return "insert " + Arrays.toString(types()) + " at " + position; } - private Class[] types() { - Class[] types = new Class[values.length]; + private Class[] types() { + Class[] types = new Class[values.length]; for (int i = 0; i < types.length; i++) { types[i] = values[i].getClass(); } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Permute.java invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Permute.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Permute.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Permute.java 2016-01-14 15:50:40.000000000 +0000 @@ -42,7 +42,7 @@ } public MethodType down(MethodType type) { - Class[] types = new Class[reorder.length]; + Class[] types = new Class[reorder.length]; for (int i = 0; i < reorder.length; i++) { int typeIndex = reorder[i]; if (typeIndex < 0 || typeIndex >= type.parameterCount()) { diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Spread.java invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Spread.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Spread.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Spread.java 2016-01-14 15:50:40.000000000 +0000 @@ -28,9 +28,9 @@ public class Spread extends Transform { private final MethodType source; - private final Class[] spreadTypes; + private final Class[] spreadTypes; - public Spread(MethodType source, Class... spreadTypes) { + public Spread(MethodType source, Class... spreadTypes) { this.source = source; this.spreadTypes = spreadTypes; } diff -Nru invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Varargs.java invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Varargs.java --- invokebinder-1.5/src/main/java/com/headius/invokebinder/transform/Varargs.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/main/java/com/headius/invokebinder/transform/Varargs.java 2016-01-14 15:50:40.000000000 +0000 @@ -27,9 +27,9 @@ private final MethodType source; private int index; - private final Class arrayType; + private final Class arrayType; - public Varargs(MethodType source, int index, Class arrayType) { + public Varargs(MethodType source, int index, Class arrayType) { this.source = source; this.index = index; this.arrayType = arrayType; @@ -48,10 +48,10 @@ } private void assertTypesAreCompatible() { - Class componentType = arrayType.getComponentType(); + Class componentType = arrayType.getComponentType(); for (int i = index; i < source.parameterCount(); i++) { - Class in = source.parameterType(i); - assert in.isAssignableFrom(componentType) + Class in = source.parameterType(i); + assert componentType.isAssignableFrom(in) : "incoming type " + in.getName() + " not compatible with " + componentType.getName() + "[]"; } } diff -Nru invokebinder-1.5/src/test/java/com/headius/invokebinder/BinderTest.java invokebinder-1.7/src/test/java/com/headius/invokebinder/BinderTest.java --- invokebinder-1.5/src/test/java/com/headius/invokebinder/BinderTest.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/test/java/com/headius/invokebinder/BinderTest.java 2016-01-14 15:50:40.000000000 +0000 @@ -390,6 +390,13 @@ assertEquals(2, ary.length); assertEquals("two", ary[0]); assertEquals("three", ary[1]); + + // from #2 + MethodHandle foo = Binder.from(MethodType.methodType(String.class, String.class)) + .varargs(0, Object[].class) + .invokeStatic(MethodHandles.publicLookup(), getClass(), "varargs"); + + assertEquals(foo.invokeWithArguments("value"), "value"); } @Test @@ -916,6 +923,11 @@ return args; } + public static String varargs(Object... args) + { + return (String) args[0]; + } + public static String intLong(int a, long b) { return "intLong ok"; } diff -Nru invokebinder-1.5/src/test/java/com/headius/invokebinder/SmartBinderTest.java invokebinder-1.7/src/test/java/com/headius/invokebinder/SmartBinderTest.java --- invokebinder-1.5/src/test/java/com/headius/invokebinder/SmartBinderTest.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/test/java/com/headius/invokebinder/SmartBinderTest.java 2016-01-14 15:50:40.000000000 +0000 @@ -15,6 +15,8 @@ */ package com.headius.invokebinder; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; @@ -257,7 +259,7 @@ assertEquals("foogoodbyebargoodbye", (String)handle.invokeExact("foo", "bar")); } - @Test + @Test public void testIdentity() throws Throwable { MethodHandle handle = SmartBinder .from(String.class, "i", int.class) @@ -269,7 +271,83 @@ assertEquals(MethodType.methodType(String.class, int.class), handle.type()); assertEquals("15", (String)handle.invokeExact(15)); } - + + + @Test + public void testFoldStatic() throws Throwable { + MethodHandle handle = SmartBinder + .from(Subjects.StringIntegerIntegerInteger) + .foldStatic("x", Subjects.class, "foldStringIntegerIntegerInteger") + .drop("a") + .drop("b1") + .drop("b2") + .drop("b3") + .invokeStatic(MethodHandles.lookup(), Subjects.class, "upperCase") + .handle(); + + assertEquals("FORTY_TWO", (String)handle.invokeExact("foo", + Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3))); + } + + @Test + public void testFoldVirtual() throws Throwable { + MethodHandle handle = SmartBinder + .from(Subjects.StringIntegerIntegerInteger) + .prepend("this", new Subjects()) + .foldVirtual("x", "foldVirtualStringIntegerIntegerInteger") + .drop("this") + .drop("a") + .drop("b1") + .drop("b2") + .drop("b3") + .invokeStatic(MethodHandles.lookup(), Subjects.class, "upperCase") + .handle(); + + assertEquals("FORTY_TWO", (String)handle.invokeExact("foo", + Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3))); + } + + @Test + public void testFoldVirtualWithLookup() throws Throwable { + MethodHandle handle = SmartBinder + .from(Subjects.StringIntegerIntegerInteger) + .prepend("this", new Subjects()) + .foldVirtual("x", MethodHandles.lookup(), "foldVirtualStringIntegerIntegerInteger") + .drop("this") + .drop("a") + .drop("b1") + .drop("b2") + .drop("b3") + .invokeStatic(MethodHandles.lookup(), Subjects.class, "upperCase") + .handle(); + + assertEquals("FORTY_TWO", (String)handle.invokeExact("foo", + Integer.valueOf(1), Integer.valueOf(2), Integer.valueOf(3))); + } + + @Test + public void testPrintSignature() throws Throwable { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + MethodHandle handle = SmartBinder + .from(Subjects.StringIntegerIntegerInteger) + .foldStatic("x", Subjects.class, "foldStringIntegerIntegerInteger") + .drop("a").printSignature(ps) + .drop("b1") + .drop("b2") + .drop("b3").printSignature(ps) + .invokeStatic(MethodHandles.lookup(), Subjects.class, "upperCase") + .handle(); + + String result = baos.toString(); + + assertEquals( + "(String x, Integer b1, Integer b2, Integer b3)String\n" + + "(String x)String\n", + result); + } + + private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup(); private static final MethodHandle stringInt = Binder diff -Nru invokebinder-1.5/src/test/java/com/headius/invokebinder/Subjects.java invokebinder-1.7/src/test/java/com/headius/invokebinder/Subjects.java --- invokebinder-1.5/src/test/java/com/headius/invokebinder/Subjects.java 2014-12-11 17:34:03.000000000 +0000 +++ invokebinder-1.7/src/test/java/com/headius/invokebinder/Subjects.java 2016-01-14 15:50:40.000000000 +0000 @@ -67,4 +67,18 @@ public String stringIntegersString2(String a, Integer[] bs, String c) { return Arrays.deepToString(new Object[]{a, bs, c}); } + + public static String foldStringIntegerIntegerInteger(String a, Integer b1, Integer b2, Integer b3) { + return "forty_two"; + } + + public String foldVirtualStringIntegerIntegerInteger(String a, Integer b1, Integer b2, Integer b3) { + return "forty_two"; + } + + + public static String upperCase(String x) { + return x.toUpperCase(); + } + }