Beispiel #1
0
 /** Creates a new instance of the specified type. */
 protected Object newInstance(Class<?> type) throws Exception {
   // find the most specific constructor that can take the last value
   if (_lvalue != null) {
     boolean inner = ReflectionUtil.isInner(type);
     _lvalue.getClass();
     Constructor cctor = null;
     Class<?> cptype = null;
     for (Constructor ctor : type.getConstructors()) {
       Class<?>[] ptypes = ctor.getParameterTypes();
       if (inner ? (ptypes.length != 2 || !ptypes[0].isInstance(_outer)) : (ptypes.length != 1)) {
         continue;
       }
       Class<?> ptype = ptypes[ptypes.length - 1];
       if (ptype.isInstance(_lvalue) && (cctor == null || cptype.isAssignableFrom(ptype))) {
         cctor = ctor;
         cptype = ptype;
       }
     }
     if (cctor != null) {
       return inner ? cctor.newInstance(_outer, _lvalue) : cctor.newInstance(_lvalue);
     }
   }
   // fall back on default constructor
   return ReflectionUtil.newInstance(type, _outer);
 }