/** get all fields of given {@code type}, up the super class hierarchy, optionally filtered by {@code predicates} */ public static Set<Field> getAllFields(final Class<?> type, Predicate<? super Field>... predicates) { Set<Field> result = Sets.newHashSet(); for (Class<?> t : getAllSuperTypes(type)) result.addAll(getFields(t, predicates)); return result; }
/** get all fields of given {@code type}, up the super class hierarchy, optionally filtered by {@code predicates} */ public static Set<Field> getAllFields(final Class<?> type, Predicate<? super Field>... predicates) { Set<Field> result = Sets.newHashSet(); for (Class<?> t : getAllSuperTypes(type)) result.addAll(getFields(t, predicates)); return result; }
/** * Fetches all TelemetryFields and create a map associating field's name (key) to field's value (value). * @return a map with key (field's name) and value (field's value). */ public Map<String, ?> createTelemetryFieldToValue() { return AccessController.doPrivileged((PrivilegedAction<Map<String, ?>>) () -> { telemetryFieldToValue = new HashMap<>(); Set<Field> fields = ReflectionUtils.getFields(this.getClass(), ReflectionUtils.withAnnotation(TelemetryField.class)); for (Field field : fields) { try { field.setAccessible(true); telemetryFieldToValue.put(field.getName(), field.get(this)); } catch (IllegalAccessException e) { logger.error("The field is not inaccessible: ", e); } } return telemetryFieldToValue; }); }
/** * Get a list of all the telemetry field names marked with {@link org.terasology.telemetry.TelemetryField} annotation in this class. * The field name is in the form telemetryCategory.id() + ":" fieldName. * @return the list of all the telemetry field names in this class. */ public List<String> createTelemetryFieldList() { TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class); List<String> fieldsList = new ArrayList<>(); if (!telemetryCategory.isOneMapMetric()) { Set<Field> fields = ReflectionUtils.getFields(this.getClass(), ReflectionUtils.withAnnotation(TelemetryField.class)); for (Field field : fields) { String fieldName = telemetryCategory.id() + ":" + field.getName(); fieldsList.add(fieldName); } } return fieldsList; }
/** * Add a listener to the checkbox in the telemetry category row. * If this checkbox is checked, all the sub telemetry fields will be enabled/disabled. */ private void addGroupEnablingListener() { fetchTelemetryCategoriesFromEnvironment(); for (Map.Entry<TelemetryCategory, Class> telemetryCategory: telemetryCategories.entrySet()) { if (!telemetryCategory.getKey().isOneMapMetric()) { UICheckbox uiCheckbox = this.find(telemetryCategory.getKey().id(), UICheckbox.class); if (uiCheckbox == null) { continue; } uiCheckbox.subscribe((checkbox) -> { Map<String, Boolean> bindingMap = config.getTelemetryConfig().getMetricsUserPermissionConfig().getBindingMap(); if (bindingMap.containsKey(telemetryCategory.getKey().id())) { boolean isGroupEnable = bindingMap.get(telemetryCategory.getKey().id()); Set<Field> fields = ReflectionUtils.getFields(telemetryCategory.getValue(), ReflectionUtils.withAnnotation(TelemetryField.class)); for (Field field : fields) { String fieldName = telemetryCategory.getKey().id() + ":" + field.getName(); bindingMap.put(fieldName, isGroupEnable); } } }); } } }
/** * Add a listener to the telemetryEnable checkbox. If the checkbox os enabled/disabled, it will enable/disable all the telemetry field. */ private void addEnablingAllTelemetryListener() { UICheckbox uiCheckbox = this.find("telemetryEnabled", UICheckbox.class); if (uiCheckbox != null) { uiCheckbox.subscribe((checkbox) -> { boolean telemetryEnabled = config.getTelemetryConfig().isTelemetryEnabled(); Map<String, Boolean> bindingMap = config.getTelemetryConfig().getMetricsUserPermissionConfig().getBindingMap(); for (Map.Entry<String, Boolean> entry : bindingMap.entrySet()) { entry.setValue(telemetryEnabled); } fetchTelemetryCategoriesFromEnvironment(); for (Map.Entry<TelemetryCategory, Class> telemetryCategory : telemetryCategories.entrySet()) { UICheckbox categoryBox = this.find(telemetryCategory.getKey().id(), UICheckbox.class); if (categoryBox != null) { categoryBox.setEnabled(telemetryEnabled); } Set<Field> fields = ReflectionUtils.getFields(telemetryCategory.getValue(), ReflectionUtils.withAnnotation(TelemetryField.class)); for (Field field : fields) { String fieldName = telemetryCategory.getKey().id() + ":" + field.getName(); UICheckbox fieldBox = this.find(fieldName, UICheckbox.class); if (fieldBox != null) { fieldBox.setEnabled(telemetryEnabled); } } } }); } }
bindingMap.put(telemetryCategory.id(), true); } else { Set<Field> fields = ReflectionUtils.getFields(telemetryCategories.get(telemetryCategory), ReflectionUtils.withAnnotation(TelemetryField.class)); boolean isOneEnabled = false; for (Field field : fields) {
private void injectMockMuleContext(Object injectionTarget) throws IllegalAccessException { final Field contextField = getFields(DefaultProcessorInterceptorManager.class, withType(MuleContext.class)).iterator().next(); contextField.setAccessible(true); contextField.set(injectionTarget, mock(MuleContext.class, RETURNS_DEEP_STUBS)); }
public static Set<Field> getAllFields(final Class<?> type , Predicate<Field>... predicates) { Set<Field> result = new HashSet(); for (Class<?> t : getAllSuperTypes(type)) result.addAll(getFields(t , predicates)); return result; }
/** get all fields of given {@code type}, up the super class hierarchy, optionally filtered by {@code predicates} */ public static Set<Field> getAllFields(final Class<?> type, Predicate<? super Field>... predicates) { Set<Field> result = Sets.newHashSet(); for (Class<?> t : getAllSuperTypes(type)) result.addAll(getFields(t, predicates)); return result; }
/** get all fields of given {@code type}, up the super class hierarchy, optionally filtered by {@code predicates} */ public static Set<Field> getAllFields(final Class<?> type, Predicate<? super Field>... predicates) { Set<Field> result = Sets.newHashSet(); for (Class<?> t : getAllSuperTypes(type)) result.addAll(getFields(t, predicates)); return result; }
@SuppressWarnings("unchecked") private List<Object> getFingerprintableValues() { final List<Object> fieldValues = new ArrayList<>(); try { final Set<Field> fields = ReflectionUtils.getFields(getClass()); for (final Field field : fields) { field.setAccessible(true); final Object value = field.get(this); if ((value != null) && !isAnnotationPresent(field, IgnoreFingerprint.class, Version.class, Transient.class)) { fieldValues.add(value); } } return fieldValues; } catch (final Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") private List<Object> getFingerprintableValues() { final List<Object> fieldValues = new ArrayList<>(); try { final Set<Field> fields = ReflectionUtils.getFields(getClass()); for (final Field field : fields) { field.setAccessible(true); final Object value = field.get(this); if ((value != null) && !isAnnotationPresent(field, IgnoreFingerprint.class, Version.class, Transient.class)) { fieldValues.add(value); } } return fieldValues; } catch (final Exception e) { throw new RuntimeException(e); } }
@SuppressWarnings("unchecked") private Set<Field> getMockitoInjectedApplinkFields() { // ReadOnlyApplicationLink (and all assignable types) fields annotated with @Mock, which means Mockito has // already injected mocks into them return getFields(test.getClass(), withTypeAssignableTo(ReadOnlyApplicationLink.class), withAnnotation(Mock.class)); }
@SuppressWarnings("unchecked") private Set<Field> getMockApplinkOnlyFields() { // ReadOnlyApplicationLink (and all assignable types) fields annotated with @MockApplink but not @Mock - hence // not processed by Mockito return getFields(test.getClass(), withTypeAssignableTo(ReadOnlyApplicationLink.class), withAnnotation(MockApplink.class), not(withAnnotation(Mock.class)) ); }
/** * Used to check if class has specified field. * * @param objectClass class to check. * @param fieldName field name to search in hierarchy. * * @return true if class has specified field. */ private static boolean classHasField(Class objectClass, String fieldName) { String getterName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); String boolGetterName = "is" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); String setterName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); Set<Method> getters = ReflectionUtils.getMethods(objectClass, ReflectionUtils.withName(getterName)); Set<Method> bGetters = ReflectionUtils.getMethods(objectClass, ReflectionUtils.withName(boolGetterName)); Set<Method> setters = ReflectionUtils.getMethods(objectClass, ReflectionUtils.withName(setterName)); if ((!getters.isEmpty() || !bGetters.isEmpty()) && !setters.isEmpty()) { return true; } Set<Field> fields = ReflectionUtils.getFields(objectClass, ReflectionUtils.withName(fieldName)); return !fields.isEmpty(); }
private void injectMockMuleContext(Object injectionTarget) throws IllegalAccessException { final Field contextField = getFields(DefaultProcessorInterceptorManager.class, withType(MuleContext.class)).iterator().next(); contextField.setAccessible(true); contextField.set(injectionTarget, mock(MuleContext.class, RETURNS_DEEP_STUBS)); }
Set<Field> fields = ReflectionUtils.getFields(objectClass, ReflectionUtils.withName(fieldName)); if (!fields.isEmpty()) { Field field = fields.iterator().next();
Set<Field> fields = ReflectionUtils.getFields(objectClass, ReflectionUtils.withName(fieldName)); if (!fields.isEmpty()) { Field next = fields.iterator().next();
Set<Field> fields = ReflectionUtils.getFields(objectClass, ReflectionUtils.withName(fieldName)); if (!fields.isEmpty()) { Field next = fields.iterator().next();