| 4065 | } |
| 4066 | |
| 4067 | public static Expr parse(Var v, ISeq args, Object tag, boolean tailPosition) { |
| 4068 | if(!v.isBound() || v.get() == null) |
| 4069 | { |
| 4070 | // System.out.println("Not bound: " + v); |
| 4071 | return null; |
| 4072 | } |
| 4073 | Class c = v.get().getClass(); |
| 4074 | String cname = c.getName(); |
| 4075 | // System.out.println("Class: " + cname); |
| 4076 | |
| 4077 | java.lang.reflect.Method[] allmethods = c.getMethods(); |
| 4078 | |
| 4079 | boolean variadic = false; |
| 4080 | int argcount = RT.count(args); |
| 4081 | java.lang.reflect.Method method = null; |
| 4082 | for(java.lang.reflect.Method m : allmethods) |
| 4083 | { |
| 4084 | //System.out.println(m); |
| 4085 | if(Modifier.isStatic(m.getModifiers()) && m.getName().equals("invokeStatic")) |
| 4086 | { |
| 4087 | Class[] params = m.getParameterTypes(); |
| 4088 | if(argcount == params.length) |
| 4089 | { |
| 4090 | method = m; |
| 4091 | variadic = argcount > 0 && params[params.length-1] == ISeq.class; |
| 4092 | break; |
| 4093 | } |
| 4094 | else if(argcount > params.length |
| 4095 | && params.length > 0 |
| 4096 | && params[params.length-1] == ISeq.class) |
| 4097 | { |
| 4098 | method = m; |
| 4099 | variadic = true; |
| 4100 | break; |
| 4101 | } |
| 4102 | } |
| 4103 | } |
| 4104 | if(method == null) |
| 4105 | return null; |
| 4106 | |
| 4107 | Class retClass = method.getReturnType(); |
| 4108 | |
| 4109 | Class[] paramClasses = method.getParameterTypes(); |
| 4110 | Type[] paramTypes = new Type[paramClasses.length]; |
| 4111 | |
| 4112 | for(int i = 0;i<paramClasses.length;i++) |
| 4113 | { |
| 4114 | paramTypes[i] = Type.getType(paramClasses[i]); |
| 4115 | } |
| 4116 | |
| 4117 | Type target = Type.getType(c); |
| 4118 | |
| 4119 | PersistentVector argv = PersistentVector.EMPTY; |
| 4120 | for(ISeq s = RT.seq(args); s != null; s = s.next()) |
| 4121 | argv = argv.cons(analyze(C.EXPRESSION, s.first())); |
| 4122 | |
| 4123 | return new StaticInvokeExpr(target,retClass,paramClasses, paramTypes,variadic, argv, tag, tailPosition); |
| 4124 | } |