private void setIJ1CompilerDebugFlag(final boolean b) { final Field field = getCompilerField("generateDebuggingInfo"); if (field == null) return; ClassUtils.setValue(field, null, b); }
private static String classNameAndLocation(final Object o) { if (o == null) return null; final Class<?> c = o.getClass(); return c.getName() + " [" + ClassUtils.getLocation(c) + "]"; }
private boolean getIJ1CompilerDebugFlag() { final Field field = getCompilerField("generateDebuggingInfo"); if (field == null) return false; return (Boolean) ClassUtils.getValue(field, null); }
/** Helper method of {@link #getName} and {@link #getAliases}. */ private <T> T getFieldValue(final Class<T> fieldType, final String fieldName) { final Class<? extends Op> opType = getType(); final Field nameField = ClassUtils.getField(opType, fieldName); if (nameField == null) return null; if (!fieldType.isAssignableFrom(nameField.getType())) return null; @SuppressWarnings("unchecked") final T value = (T) ClassUtils.getValue(nameField, null); return value; }
@Override public void populate(final Object metadata, final Map<String, Object> map) { final List<java.lang.reflect.Field> fields = ClassUtils.getAnnotatedFields(metadata.getClass(), Field.class); for (final java.lang.reflect.Field field : fields) { final String name = field.getName(); if (!map.containsKey(name)) { // no value given for this field continue; } final Object value = map.get(name); // TEMP: Until bug is fixed; see // https://github.com/scijava/scijava-common/issues/31 if (value == null) continue; ClassUtils.setValue(field, metadata, value); } } }
ClassUtils.getAnnotatedFields(c, Parameter.class); for (final Field f : fields) { f.setAccessible(true); // expose private fields if (type.isAssignableFrom(context().getClass())) { ClassUtils.setValue(f, service, getContext()); continue; ClassUtils.setValue(f, service, s); if (!ClassUtils.getAnnotatedMethods(c, EventHandler.class).isEmpty()) {
final Service existingService = (Service) ClassUtils.getValue(f, o); if (strict && existingService != null) { throw new IllegalStateException("Context already injected: " + // f.getDeclaringClass().getName() + "#" + f.getName()); ClassUtils.setValue(f, o, service); final Context existingContext = (Context) ClassUtils.getValue(f, o); if (strict && existingContext != null) { throw new IllegalStateException("Context already injected: " + // ClassUtils.setValue(f, o, this); final Object value = ClassUtils.getValue(f, o); if (value != null) inject(value);
@Override public int compare(final Class<?> c1, final Class<?> c2) { return ClassUtils.compare(c1, c2); }
private List<Field> getParameterFields(final Object o) { try { return ClassUtils.getAnnotatedFields(o.getClass(), Parameter.class); } catch (final Throwable t) { handleSafely(t); } return Collections.emptyList(); }
/** * Gets the given class's {@link Method}s marked with the annotation of the * specified class. * <p> * Unlike {@link Class#getMethods()}, the result will include any non-public * methods, including methods defined in supertypes of the given class. * </p> * * @param c The class to scan for annotated methods. * @param annotationClass The type of annotation for which to scan. * @return A list containing all methods with the requested annotation. Note * that for performance reasons, lists may be cached and reused, so it * is best to make a copy of the result if you need to modify it. */ public static <A extends Annotation> List<Method> getAnnotatedMethods( final Class<?> c, final Class<A> annotationClass) { List<Method> methods = methodCache.getList(c, annotationClass); if (methods == null) { methods = new ArrayList<>(); getAnnotatedMethods(c, annotationClass, methods); } return methods; }
/** Extracts the event type associated with a given tree node. */ private Class<? extends SciJavaEvent> getEventType( final DefaultMutableTreeNode node) { final CheckBoxNodeData data = getData(node); if (data == null) return null; final String className = data.getText(); @SuppressWarnings({ "rawtypes", "unchecked" }) final Class<? extends SciJavaEvent> eventType = (Class) ClassUtils.loadClass(className); if (eventType == null) { throw new IllegalStateException("Invalid class: " + className); } return eventType; }
ClassUtils.getAnnotatedFields(c, Parameter.class); for (final Field f : fields) { f.setAccessible(true); // expose private fields if (type.isAssignableFrom(context().getClass())) { ClassUtils.setValue(f, service, getContext()); continue; ClassUtils.setValue(f, service, s); if (!ClassUtils.getAnnotatedMethods(c, EventHandler.class).isEmpty()) {
final Service existingService = (Service) ClassUtils.getValue(f, o); if (strict && existingService != null) { throw new IllegalStateException("Context already injected: " + // f.getDeclaringClass().getName() + "#" + f.getName()); ClassUtils.setValue(f, o, service); final Context existingContext = (Context) ClassUtils.getValue(f, o); if (strict && existingContext != null) { throw new IllegalStateException("Context already injected: " + // ClassUtils.setValue(f, o, this); final Object value = ClassUtils.getValue(f, o); if (value != null) inject(value);
@Override public void populate(final Object metadata, final Map<String, Object> map) { final List<java.lang.reflect.Field> fields = ClassUtils.getAnnotatedFields(metadata.getClass(), Field.class); for (final java.lang.reflect.Field field : fields) { final String name = field.getName(); if (!map.containsKey(name)) { // no value given for this field continue; } final Object value = map.get(name); // TEMP: Until bug is fixed; see // https://github.com/scijava/scijava-common/issues/31 if (value == null) continue; ClassUtils.setValue(field, metadata, value); } } }
@Override public int compare(final Class<?> c1, final Class<?> c2) { return ClassUtils.compare(c1, c2); }
private List<Field> getParameterFields(final Object o) { try { return ClassUtils.getAnnotatedFields(o.getClass(), Parameter.class); } catch (final Throwable t) { handleSafely(t); } return Collections.emptyList(); }
/** * Gets the given class's {@link Method}s marked with the annotation of the * specified class. * <p> * Unlike {@link Class#getMethods()}, the result will include any non-public * methods, including methods defined in supertypes of the given class. * </p> * * @param c The class to scan for annotated methods. * @param annotationClass The type of annotation for which to scan. * @return A list containing all methods with the requested annotation. Note * that for performance reasons, lists may be cached and reused, so it * is best to make a copy of the result if you need to modify it. */ public static <A extends Annotation> List<Method> getAnnotatedMethods( final Class<?> c, final Class<A> annotationClass) { List<Method> methods = methodCache.getList(c, annotationClass); if (methods == null) { methods = new ArrayList<>(); getAnnotatedMethods(c, annotationClass, methods); } return methods; }
final String packageName = objectClass.getPackage().getName(); final Class<?> wrapperClass = ClassUtils.loadClass(packageName + ".Wrapper"); if (wrapperClass == null || !wrapperClass.isAssignableFrom(objectClass)) { return object;
private void setIJ1WandMode(final String mode) { final Field field = Types.field(WandToolOptions.class, "mode"); ClassUtils.setValue(field, null, mode); }