Parameterizer par = getParameterizer(c);
instantiable = instantiable || ClassGenericsUtil.getParameterizer(clazz) != null;
instantiable = instantiable || ClassGenericsUtil.getParameterizer(clazz) != null;
instantiable = instantiable || ClassGenericsUtil.getParameterizer(clazz) != null;
/** * Instantiate a parameterizable class. When using this, consider using * {@link Parameterization#descend}! * * @param <C> base type * @param r Base (restriction) class * @param c Class to instantiate * @param config Configuration to use for instantiation. * @return Instance * @throws ClassInstantiationException When a class cannot be instantiated. */ public static <C> C tryInstantiate(Class<C> r, Class<?> c, Parameterization config) throws ClassInstantiationException { if(c == null) { throw new ClassInstantiationException("Trying to instantiate 'null' class!"); } try { // Try a V3 parameterization class Parameterizer par = getParameterizer(c); if(par instanceof AbstractParameterizer) { return r.cast(((AbstractParameterizer) par).make(config)); } // Try a default constructor. return r.cast(c.getConstructor().newInstance()); } catch(InstantiationException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { throw new ClassInstantiationException(e); } }
/** * Instantiate a parameterizable class. When using this, consider using * {@link Parameterization#descend}! * * @param <C> base type * @param r Base (restriction) class * @param c Class to instantiate * @param config Configuration to use for instantiation. * @return Instance * @throws ClassInstantiationException When a class cannot be instantiated. */ public static <C> C tryInstantiate(Class<C> r, Class<?> c, Parameterization config) throws ClassInstantiationException { if(c == null) { throw new ClassInstantiationException("Trying to instantiate 'null' class!"); } try { // Try a V3 parameterization class Parameterizer par = getParameterizer(c); if(par instanceof AbstractParameterizer) { return r.cast(((AbstractParameterizer) par).make(config)); } // Try a default constructor. return r.cast(c.getConstructor().newInstance()); } catch(InstantiationException | InvocationTargetException | IllegalAccessException | NoSuchMethodException e) { throw new ClassInstantiationException(e); } }
instantiable = instantiable || ClassGenericsUtil.getParameterizer(cls) != null;
instantiable = instantiable || ClassGenericsUtil.getParameterizer(cls) != null;
@Override public void run() { // Only support V3 style parameterizers now: Parameterizer par = ClassGenericsUtil.getParameterizer(cls); if(par != null) { par.configure(track); for(TrackedParameter pair : track.getAllParameters()) { if(pair.getOwner() == null) { LOG.warning("No owner for parameter " + pair.getParameter() + " expected a " + cls.getName()); continue; } options.add(pair); } } // Not parameterizable. } }
instantiable = instantiable || ClassGenericsUtil.getParameterizer(cls) != null;
@Override public void run() { Parameterizer par = ClassGenericsUtil.getParameterizer(cls); if(par != null) { par.configure(track);
/** Check for a V3 constructor. */ private void checkV3Parameterization(Class<?> cls) throws NoClassDefFoundError { boolean first = true; for(Class<?> inner : cls.getDeclaredClasses()) { if(AbstractParameterizer.class.isAssignableFrom(inner)) { try { Class<? extends AbstractParameterizer> pcls = inner.asSubclass(AbstractParameterizer.class); pcls.newInstance(); assertTrue("More than one parameterization method in class " + cls.getName(), first); checkMakeInstance(cls, pcls); // Configure with missing values; must not throw an exception. Parameterizer par = ClassGenericsUtil.getParameterizer(cls); assertNotNull(par); par.configure(new UnParameterization()); par.configure(new EmptyParameterization()); } catch(Exception e) { fail(e.getMessage()); } first = false; } } }