@Test public void testToString() { assertEquals("a#b()", new MethodHandle("a", "b").toString()); assertEquals("a#b(c)", new MethodHandle("a", "b", "c").toString()); assertEquals("a#b(c,d)", new MethodHandle("a", "b", "c", "d").toString()); }
@Test public void testParse() { assertEquals(new MethodHandle("a", "b"), MethodHandle.parse("a#b()")); assertEquals(new MethodHandle("a", "b", "c"), MethodHandle.parse("a#b(c)")); assertEquals(new MethodHandle("a", "b", "c", "d"), MethodHandle.parse("a#b(c,d)")); }
private void format(Type type, StringBuilder sb) { if (type instanceof Class) { Class classType = (Class)type; if (classType.isArray()) { format(classType.getComponentType(), sb); sb.append("[]"); } else { sb.append(classType.getName()); } } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType)type; format(parameterizedType.getRawType(), sb); sb.append('<'); Type[] typeArguments = parameterizedType.getActualTypeArguments(); for (int i = 0;i < typeArguments.length;i++) { if (i > 0) { sb.append(','); } format(typeArguments[i], sb); } sb.append('>'); } else if (type instanceof GenericArrayType) { GenericArrayType arrayType = (GenericArrayType)type; format(arrayType.getGenericComponentType(), sb); sb.append("[]"); } else { throw new UnsupportedOperationException("todo " + type); } }
private static void assertParameterTypes(Method m, String... parameterTypes) { MethodHandle handle = new MethodHandle(m); assertEquals(parameterTypes.length, handle.getParameterSize()); for (int i = 0;i < parameterTypes.length;i++) { assertEquals(parameterTypes[i], handle.getParameterAt(i)); } }
String handle = method.getMethod().getMethodHandle().toString(); RouteMetaModel route = new RouteMetaModel(path, handle, priority != null ? priority : 0, parameters); router.routes.add(route);
public MethodHandle getMethodHandle() { return new MethodHandle(type.name.toString(), name, parameterTypes.toArray(new String[parameterTypes.size()])); }
@Test public void testInvalid() { String[] a = { "a", "a#", "a#b", "a#b(", "a#b(c", "a#b(,)", }; for (String s : a) { try { MethodHandle.parse(s); fail(); } catch (IllegalArgumentException ignore) { } } }
String handle = method.getMethod().getMethodHandle().toString(); RouteMetaModel route = new RouteMetaModel(path, handle, priority != null ? priority : 0, parameters); router.routes.add(route);
private static void assertParameterTypes(Method m, String... parameterTypes) { MethodHandle handle = new MethodHandle(m); assertEquals(parameterTypes.length, handle.getParameterSize()); for (int i = 0;i < parameterTypes.length;i++) { assertEquals(parameterTypes[i], handle.getParameterAt(i)); } }
public MethodHandle getMethodHandle() { return new MethodHandle(type.name.toString(), name, parameterTypes.toArray(new String[parameterTypes.size()])); }
@Test public void testInvalid() { String[] a = { "a", "a#", "a#b", "a#b(", "a#b(c", "a#b(,)", }; for (String s : a) { try { MethodHandle.parse(s); fail(); } catch (IllegalArgumentException ignore) { } } }
public Response invoke(Stage.Handler stage) { String methodId = stage.getRequest().getHandler().getHandle().toString(); String controllerId = methodId.substring(0, methodId.indexOf('#')); methodId = methodId.substring(controllerId.length() + 1);
@Test public void testToString() { assertEquals("a#b()", new MethodHandle("a", "b").toString()); assertEquals("a#b(c)", new MethodHandle("a", "b", "c").toString()); assertEquals("a#b(c,d)", new MethodHandle("a", "b", "c", "d").toString()); }
@Test public void testParse() { assertEquals(new MethodHandle("a", "b"), MethodHandle.parse("a#b()")); assertEquals(new MethodHandle("a", "b", "c"), MethodHandle.parse("a#b(c)")); assertEquals(new MethodHandle("a", "b", "c", "d"), MethodHandle.parse("a#b(c,d)")); }
public static MethodHandle parse(String s) throws NullPointerException, IllegalArgumentException { int method = s.indexOf('#'); if (method == -1) { throw new IllegalArgumentException("Invalid method handle " + s); } int leftParenthesis = s.indexOf('(', method + 1); if (leftParenthesis == -1 || leftParenthesis > s.length() - 2) { throw new IllegalArgumentException("Invalid method handle " + s); } if (s.charAt(s.length() - 1) != ')') { throw new IllegalArgumentException("Invalid method handle " + s); } // String type = s.substring(0, method); String name = s.substring(method + 1, leftParenthesis); // if (s.length() - leftParenthesis == 2) { return new MethodHandle(type, name); } else { String[] list = EMPTY_STRINGS; for (String parameter : Spliterator.split(s, leftParenthesis + 1, s.length() - 1, ',', new ArrayList<String>())) { if (parameter.length() == 0) { throw new IllegalArgumentException(); } list = Tools.appendTo(list, parameter); } return new MethodHandle(type, name, list); } }
public RouteDescriptor(JSON config) { HashMap<String, ParamDescriptor> parameters = null; JSON foo = config.getJSON("parameters"); if (foo != null) { parameters = new HashMap<String, ParamDescriptor>(); for (String name : foo.names()) { String pattern = foo.getJSON(name).getString("pattern"); Boolean preservePath = foo.getJSON(name).getBoolean("preserve-path"); Boolean captureGroup = foo.getJSON(name).getBoolean("capture-group"); parameters.put(name, new ParamDescriptor(pattern, preservePath, captureGroup)); } } // this.path = config.getString("path"); this.handle = MethodHandle.parse(config.getString("handle")); this.parameters = parameters; }
private void format(Type type, StringBuilder sb) { if (type instanceof Class) { Class classType = (Class)type; if (classType.isArray()) { format(classType.getComponentType(), sb); sb.append("[]"); } else { sb.append(classType.getName()); } } else if (type instanceof ParameterizedType) { ParameterizedType parameterizedType = (ParameterizedType)type; format(parameterizedType.getRawType(), sb); sb.append('<'); Type[] typeArguments = parameterizedType.getActualTypeArguments(); for (int i = 0;i < typeArguments.length;i++) { if (i > 0) { sb.append(','); } format(typeArguments[i], sb); } sb.append('>'); } else if (type instanceof GenericArrayType) { GenericArrayType arrayType = (GenericArrayType)type; format(arrayType.getGenericComponentType(), sb); sb.append("[]"); } else { throw new UnsupportedOperationException("todo " + type); } }
String methodId = handler.getMethod().getMethodHandle().toString();
public static MethodHandle parse(String s) throws NullPointerException, IllegalArgumentException { int method = s.indexOf('#'); if (method == -1) { throw new IllegalArgumentException("Invalid method handle " + s); } int leftParenthesis = s.indexOf('(', method + 1); if (leftParenthesis == -1 || leftParenthesis > s.length() - 2) { throw new IllegalArgumentException("Invalid method handle " + s); } if (s.charAt(s.length() - 1) != ')') { throw new IllegalArgumentException("Invalid method handle " + s); } // String type = s.substring(0, method); String name = s.substring(method + 1, leftParenthesis); // if (s.length() - leftParenthesis == 2) { return new MethodHandle(type, name); } else { String[] list = EMPTY_STRINGS; for (String parameter : Spliterator.split(s, leftParenthesis + 1, s.length() - 1, ',', new ArrayList<String>())) { if (parameter.length() == 0) { throw new IllegalArgumentException(); } list = Tools.appendTo(list, parameter); } return new MethodHandle(type, name, list); } }
public RouteDescriptor(JSON config) { HashMap<String, ParamDescriptor> parameters = null; JSON foo = config.getJSON("parameters"); if (foo != null) { parameters = new HashMap<String, ParamDescriptor>(); for (String name : foo.names()) { String pattern = foo.getJSON(name).getString("pattern"); Boolean preservePath = foo.getJSON(name).getBoolean("preserve-path"); Boolean captureGroup = foo.getJSON(name).getBoolean("capture-group"); parameters.put(name, new ParamDescriptor(pattern, preservePath, captureGroup)); } } // this.path = config.getString("path"); this.handle = MethodHandle.parse(config.getString("handle")); this.parameters = parameters; }