public boolean test(ReflectMethod object) { return object.getName().equals(name); } }).toArray(new ReflectMethod[]{});
void add(ReflectMethod method) { Integer size = method.getParameters().length; if(methods.containsKey(size)) { throw new IllegalStateException("Found duplicated method '" + method.getName() + "' with " + size + " args at '" + cls.getName() + "'"); } if(size > maxArgs) { maxArgs = size; } methods.put(size, method); }
@Override public Object invoke(ElEvalContext context, Object[] args) throws Throwable { if(null == instance){ throw new IllegalStateException("Instance is null,cannot invoke method '" + m.getName() + "'"); } return m.invoke(instance, args); } }
protected Doc searchUp(ReflectMethod m) { Class<?> c = m.getReflectedMethod().getDeclaringClass(); for(Class<?> ic : c.getInterfaces()) { try { Method im = ic.getMethod(m.getName(), m.getReflectedMethod().getParameterTypes()); return im.getAnnotation(Doc.class); } catch (NoSuchMethodException e) { //do nothing. } } return null; }
public ElInstanceMethods add(ReflectMethod m) { if(!m.getName().equals(name)){ throw new IllegalArgumentException("Method name '" + m.getName() + "' must be '" + name + "'"); } if(m.getReflectedMethod().isVarArgs()){ defaultMethod = m; }else{ Integer i = m.getParameters().length; if(!methods().containsKey(i)){ methods().put(i, m); } } return this; }
protected Doc searchUp(ReflectMethod m, ReflectParameter p) { Class<?> c = m.getReflectedMethod().getDeclaringClass(); for(Class<?> ic : c.getInterfaces()) { try { Method im = ic.getMethod(m.getName(), m.getReflectedMethod().getParameterTypes()); return im.getParameters()[p.getIndex()-1].getAnnotation(Doc.class); } catch (NoSuchMethodException e) { //do nothing. } } return null; }
private String getTranditionalPropertyName(ReflectField field) { String name = null; if(field.hasSetter()){ name = field.getSetter().getName().substring(SETTER_PREFIX.length()); }else if(field.hasGetter()){ name = field.getGetter().getName(); if(name.startsWith(IS_PREFIX)){ name = name.substring(IS_PREFIX.length()); }else{ name = name.substring(GETTER_PREFIX.length()); } }else{ name = field.getName().startsWith("_") ? field.getName().substring(1) : field.getName(); } return name.length() == 1 ? name.toLowerCase() : Character.toLowerCase(name.charAt(0)) + name.substring(1); }
public ReflectMethod getMethod(final String name,final Class<?>... argumentTypes){ for(ReflectMethod rm : methods){ if(rm.getName().equals(name)){ Method m = rm.getReflectedMethod();
public Object invokeStatic(Object... args) { try { if(parameters.length != args.length){ throw new IllegalArgumentException("argument's length must be " + parameters.length); } for(int i=0;i<args.length;i++){ if(null == args[i]) { args[i] = Classes.getDefaultValue(parameters[i].getType()); } } return reflectedMethod.invoke(null, args); // if(index == -1){ // return javaMethod.invoke(null, args); // }else{ // return accessor.invokeMethod(null, index, args); // } } catch (Throwable e) { if(e instanceof InvocationTargetException){ e = e.getCause(); } if(e instanceof RuntimeException){ throw (RuntimeException)e; } throw new ReflectException(Strings.format("Error invoking method '{0}'",getName()),e); } }
throw (RuntimeException)e; throw new ReflectException(Strings.format("Error invoking method '{0}'",getName()),e);
@Override public ElMethod resolveMethod(Class<?> cls, String name, Object[] args) { ReflectClass rc = ReflectClass.of(cls); int len = args.length; for(ReflectMethod rm : rc.getMethods()){ if(rm.getName().equals(name) && rm.getParameters().length == len){ boolean ok = true; for(int i=0;i<len;i++){ Object v = args[i]; if(null != v && !rm.getParameters()[i].getType().isAssignableFrom(v.getClass())){ ok = false; break; } } if(ok){ return rm.isStatic() ? new ElStaticMethod(rm) : new ElInstanceMethod(rm); } } } return null; }
String name = m.getName(); if(bt.hasProperty(name)) { log.warn("Method '{}' conflict with property at '{}', ignore it", name, cls.getName());
String methodName = rm.getName();
protected void processOperation(ApiMetadataContext context, Map<Class<?>, ClassDoc> docs, MApiOperationBuilder o) { ReflectMethod method = o.getRoute().getAction().getMethod(); //operation if(null != method) { ClassDoc cdoc = resolveClassDoc(docs, method.getDeclaringClass(), false); MethodDoc mdoc = cdoc.methods.get(method.getName()); if(null != mdoc) { if(!Strings.isEmpty(mdoc.description)) { o.setDescription(mdoc.description); } if(!Strings.isEmpty(mdoc.response)) { for(MApiResponseBuilder resp : o.getResponses()) { if(resp.getStatus() >= 200 && resp.getStatus() < 300) { resp.setDescription(mdoc.response); break; } } } //parameters o.getParameters().forEach((param) -> processParameter(context, docs, mdoc, param, method)); } } }