@Override public boolean getAsBoolean() { try { return Reflection.toClass("javafx.beans.Observable") != null; } catch (ClassNotFoundException e) { return false; } } }
protected ConstructorComparator(final Class<?> beanClass) { for (final Constructor<?> c : Reflection.getDeclaredConstructors(beanClass)) { constructors.put(c, Arrays.hashCode(c.getParameterTypes())); } }
protected MethodComparator(final Class<?> beanClass) { Class<?> clazz = beanClass; while (clazz != null && clazz != Object.class) { for (final Method m : Reflection.getDeclaredMethods(clazz)) { methods.put(m, Arrays.hashCode(m.getParameterTypes())); } clazz = clazz.getSuperclass(); } }
public static Class<?> toClass(String className) throws ClassNotFoundException { ClassLoader cl = getClassLoader(Reflection.class); return toClass(className, cl); }
public static Class<?> toClass(String className) throws ClassNotFoundException { return toClass(className, loaderFromClassOrThread(Reflection.class)); }
public static Class<?> toClass(String className) throws ClassNotFoundException { return toClass(className, loaderFromThreadOrClass(Reflection.class)); }
cls = Reflection.primitiveToWrapper(cls); if (cls == null) { return false; cls = Reflection.wrapperToPrimitive(cls); if (cls == null) { return false;
@Override public Map<String, MetadataBuilder.ForContainer<Field>> getFields(Meta<Class<T>> meta) { return merge(b -> b.getFields(meta), (f, l) -> { final Field fld = Reflection.find(meta.getHost(), t -> Reflection.getDeclaredField(t, f)); if (fld == null) { Exceptions.raise(IllegalStateException::new, "Could not find field %s of %s", f, meta.getHost()); } return forContainer(l, new Meta.ForField(fld), ElementKind.PROPERTY); }); }
/** * Get the named value from the specified {@link Annotation}. * @param annotation * @param name * @return Object value * @throws IllegalAccessException * @throws InvocationTargetException */ public static Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException { final Method valueMethod; try { valueMethod = annotation.annotationType().getDeclaredMethod(name); } catch (final NoSuchMethodException ex) { // do nothing return null; } final boolean mustUnset = setAccessible(valueMethod, true); try { return valueMethod.invoke(annotation); } finally { if (mustUnset) { setAccessible(valueMethod, false); } } }
private <T> T newInstance(final Class<T> cls) { final Constructor<T> cons = Reflection.getDeclaredConstructor(cls, ApacheFactoryContext.class); if (cons == null) { throw new ValidationException("Cannot instantiate " + cls); } final boolean mustUnset = Reflection.setAccessible(cons, true); try { return cons.newInstance(validatorContext); } catch (final Exception ex) { throw new ValidationException("Cannot instantiate " + cls, ex); } finally { if (mustUnset) { Reflection.setAccessible(cons, false); } } } }
Map<Signature, MethodD> getMethods(BeanD<T> parent) { final Map<Signature, MetadataBuilder.ForExecutable<Method>> methodBuilders = beanBuilder.getMethods(meta); if (methodBuilders.isEmpty()) { return Collections.emptyMap(); } final Map<Signature, MethodD> result = new LinkedHashMap<>(); methodBuilders.forEach((sig, builder) -> { final Method m = Reflection.find(meta.getHost(), t -> Reflection.getDeclaredMethod(t, sig.getName(), sig.getParameterTypes())); final MethodD descriptor = new MethodD(new MetadataReader.ForMethod(new Meta.ForMethod(m), builder), parent); if (DescriptorManager.isConstrained(descriptor)) { result.put(sig, descriptor); } }); return Collections.unmodifiableMap(result); }
protected FieldComparator(final Class<?> beanClass) { int i = 0; Class<?> clazz = beanClass; while (clazz != null && clazz != Object.class) { for (final Field f : Reflection.getDeclaredFields(clazz)) { final String name = f.getName(); if (!fields.containsKey(name)) { fields.put(name, Integer.valueOf(++i)); } } for (final Method m : clazz.getDeclaredMethods()) { final String name = getPropertyName(m); if (name != null && !name.isEmpty()) { if (!fields.containsKey(name)) { fields.put(name, Integer.valueOf(++i)); } } } clazz = clazz.getSuperclass(); } }
cls = Reflection.primitiveToWrapper(cls);
@Override public Map<String, MetadataBuilder.ForContainer<Field>> getFields(Meta<Class<T>> meta) { final Map<String, MetadataBuilder.ForContainer<Field>> fields = delegate.getFields(hierarchyElement); if (fields.isEmpty()) { return fields; } final Map<String, MetadataBuilder.ForContainer<Field>> result = new LinkedHashMap<>(); fields.forEach((k, v) -> { final Field fld = Reflection.getDeclaredField(hierarchyElement.getHost(), k); Exceptions.raiseIf(fld == null, IllegalStateException::new, "delegate builder specified unknown field"); result.put(k, new ContainerDelegate<Field>(v, new Meta.ForField(fld))); }); return result; }
Map<Signature, ConstructorD<T>> getConstructors(BeanD<T> parent) { final Map<Signature, MetadataBuilder.ForExecutable<Constructor<? extends T>>> ctorBuilders = beanBuilder.getConstructors(meta); if (ctorBuilders.isEmpty()) { return Collections.emptyMap(); } final Map<Signature, ConstructorD<T>> result = new LinkedHashMap<>(); ctorBuilders.forEach((sig, builder) -> { final Constructor<?> c = Reflection.getDeclaredConstructor(meta.getHost(), sig.getParameterTypes()); @SuppressWarnings({ "unchecked", "rawtypes" }) final Meta.ForConstructor<T> metaCtor = (Meta.ForConstructor) new Meta.ForConstructor<>(c); final ConstructorD<T> descriptor = new ConstructorD<>(new MetadataReader.ForConstructor<T>(metaCtor, builder), parent); if (DescriptorManager.isConstrained(descriptor)) { result.put(sig, descriptor); } }); return Collections.unmodifiableMap(result); }
cls = Reflection.primitiveToWrapper(cls); if (cls == null) { return false; cls = Reflection.wrapperToPrimitive(cls); if (cls == null) { return false;
@Override public Map<String, MetadataBuilder.ForContainer<Field>> getFields(Meta<Class<T>> meta) { return merge(b -> b.getFields(meta), (f, l) -> { final Field fld = Reflection.find(meta.getHost(), t -> Reflection.getDeclaredField(t, f)); if (fld == null) { Exceptions.raise(IllegalStateException::new, "Could not find field %s of %s", f, meta.getHost()); } return forContainer(l, new Meta.ForField(fld), ElementKind.PROPERTY); }); }
/** * Get the named value from the specified {@link Annotation}. * @param annotation * @param name * @return Object value * @throws IllegalAccessException * @throws InvocationTargetException */ public static Object getAnnotationValue(final Annotation annotation, final String name) throws IllegalAccessException, InvocationTargetException { final Method valueMethod; try { valueMethod = annotation.annotationType().getDeclaredMethod(name); } catch (final NoSuchMethodException ex) { // do nothing return null; } final boolean mustUnset = setAccessible(valueMethod, true); try { return valueMethod.invoke(annotation); } finally { if (mustUnset) { setAccessible(valueMethod, false); } } }
private <T> T newInstance(final Class<T> cls) { final Constructor<T> cons = Reflection.getDeclaredConstructor(cls, ApacheFactoryContext.class); if (cons == null) { throw new ValidationException("Cannot instantiate " + cls); } final boolean mustUnset = Reflection.setAccessible(cons, true); try { return cons.newInstance(validatorContext); } catch (final Exception ex) { throw new ValidationException("Cannot instantiate " + cls, ex); } finally { if (mustUnset) { Reflection.setAccessible(cons, false); } } } }
Map<Signature, MethodD> getMethods(BeanD<T> parent) { final Map<Signature, MetadataBuilder.ForExecutable<Method>> methodBuilders = beanBuilder.getMethods(meta); if (methodBuilders.isEmpty()) { return Collections.emptyMap(); } final Map<Signature, MethodD> result = new LinkedHashMap<>(); methodBuilders.forEach((sig, builder) -> { final Method m = Reflection.find(meta.getHost(), t -> Reflection.getDeclaredMethod(t, sig.getName(), sig.getParameterTypes())); final MethodD descriptor = new MethodD(new MetadataReader.ForMethod(new Meta.ForMethod(m), builder), parent); if (DescriptorManager.isConstrained(descriptor)) { result.put(sig, descriptor); } }); return Collections.unmodifiableMap(result); }