/** * Factory method to create a transforming map. * <p> * If there are any elements already in the map being decorated, they * are NOT transformed. * Constrast this with {@link #decorateTransform}. * * @param map the map to decorate, must not be null * @param keyTransformer the transformer to use for key conversion, null means no transformation * @param valueTransformer the transformer to use for value conversion, null means no transformation * @throws IllegalArgumentException if map is null */ publicstatic Map decorate(Map map, Transformer keyTransformer, Transformer valueTransformer) { returnnewTransformedMap(map, keyTransformer, valueTransformer); }
// If there are annotation members without values, that // situation is handled by the invoke method. for (Map.Entry<String, Object> memberValue : memberValues.entrySet()) { Stringname= memberValue.getKey(); Class<?> memberType = memberTypes.get(name); if (memberType != null) { // i.e. member still exists Objectvalue= memberValue.getValue(); if (!(memberType.isInstance(value) || value instanceof ExceptionProxy)) { memberValue.setValue( // 这里调用了setValue newAnnotationTypeMismatchExceptionProxy( value.getClass() + "[" + value + "]").setMember( annotationType.members().get(name))); } } }
它是通过new AnnotationTypeMismatchExceptionProxy(value.getClass() + "[" + value +"]").setMember(annotationType.members().get(name)));来控制的,我们继续跟进
// If there are annotation members without values, that // situation is handled by the invoke method. for (Map.Entry<String, Object> memberValue : memberValues.entrySet()) { Stringname= memberValue.getKey(); Class<?> memberType = memberTypes.get(name); if (memberType != null) { // i.e. member still exists Objectvalue= memberValue.getValue(); if (!(memberType.isInstance(value) || value instanceof ExceptionProxy)) { memberValue.setValue( // 这里调用了setValue newAnnotationTypeMismatchExceptionProxy( value.getClass() + "[" + value + "]").setMember( annotationType.members().get(name))); } } }
// Runtime r = Runtime.getRuntime(); // Class c = Runtime.class; // Method execMethod = c.getMethod("exec", String.class); // execMethod.invoke(r, "calc"); // Class c = Runtime.class; // Method grt = c.getMethod("getRuntime", null); // Runtime r = (Runtime) grt.invoke(null, null); // r.exec("calc"); // Method execMethod = c.getMethod("exec", String.class); // execMethod.invoke(r, "calc");
// 我觉得这样写就好理解多了 // InvokerTransformer(methodname, argstype, args).transform(object) <==> method.invoke(object, args) <==> object.method(args) Classc= Runtime.class; // Method grt = (Method) new InvokerTransformer("getMethod", new Class[]{String.class, Class[].class}, new Object[]{"getRuntime", null}).transform(c); // Runtime r = (Runtime) new InvokerTransformer("invoke", new Class[]{Object.class, Object[].class}, new Object[]{null, null}).transform(grt); // new InvokerTransformer("exec", new Class[]{String.class}, new Object[]{"calc"}).transform(r);