use of java.lang.reflect.AccessibleObject in project android_frameworks_base by ParanoidAndroid.
the class ViewDebug method getExportedPropertyMethods.
private static Method[] getExportedPropertyMethods(Class<?> klass) {
if (sMethodsForClasses == null) {
sMethodsForClasses = new HashMap<Class<?>, Method[]>(100);
}
if (sAnnotations == null) {
sAnnotations = new HashMap<AccessibleObject, ExportedProperty>(512);
}
final HashMap<Class<?>, Method[]> map = sMethodsForClasses;
Method[] methods = map.get(klass);
if (methods != null) {
return methods;
}
final ArrayList<Method> foundMethods = new ArrayList<Method>();
methods = klass.getDeclaredMethods();
int count = methods.length;
for (int i = 0; i < count; i++) {
final Method method = methods[i];
if (method.getParameterTypes().length == 0 && method.isAnnotationPresent(ExportedProperty.class) && method.getReturnType() != Void.class) {
method.setAccessible(true);
foundMethods.add(method);
sAnnotations.put(method, method.getAnnotation(ExportedProperty.class));
}
}
methods = foundMethods.toArray(new Method[foundMethods.size()]);
map.put(klass, methods);
return methods;
}
use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.
the class EntityAssemblyImpl method newPropertyModel.
@Override
protected PropertyModel newPropertyModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
boolean optional = first(filter(isType(Optional.class), annotations)) != null;
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericPropertyInfo.propertyTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance valueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
valueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
Object defaultValue = stateDeclarations.initialValueOf(accessor);
boolean useDefaults = metaInfo.get(UseDefaults.class) != null || stateDeclarations.useDefaults(accessor);
boolean immutable = this.immutable || metaInfo.get(Immutable.class) != null;
PropertyModel propertyModel = new PropertyModel(accessor, immutable, useDefaults, valueConstraintsInstance, metaInfo, defaultValue);
return propertyModel;
}
use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.
the class ServiceModel method newInstance.
public ServiceInstance newInstance(final ModuleInstance module) {
Object[] mixins = mixinsModel.newMixinHolder();
Map<AccessibleObject, Property<?>> properties = new HashMap<>();
for (PropertyModel propertyModel : stateModel.properties()) {
Object initialValue = propertyModel.initialValue(module);
if (propertyModel.accessor().equals(identityMethod)) {
initialValue = identity;
}
Property<?> property = new PropertyInstance<>(propertyModel, initialValue);
properties.put(propertyModel.accessor(), property);
}
TransientStateInstance state = new TransientStateInstance(properties);
ServiceInstance compositeInstance = new ServiceInstance(this, module, mixins, state);
// Instantiate all mixins
int i = 0;
UsesInstance uses = UsesInstance.EMPTY_USES.use(this);
InjectionContext injectionContext = new InjectionContext(compositeInstance, uses, state);
for (MixinModel mixinModel : mixinsModel.mixinModels()) {
mixins[i++] = mixinModel.newInstance(injectionContext);
}
return compositeInstance;
}
use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.
the class EntityStateInstance method propertyFor.
@Override
@SuppressWarnings("unchecked")
public <T> Property<T> propertyFor(AccessibleObject accessor) throws IllegalArgumentException {
Map<AccessibleObject, Object> state = state();
Property<T> property = (Property<T>) state.get(accessor);
if (property == null) {
PropertyModel entityPropertyModel = stateModel.propertyModelFor(accessor);
property = new EntityPropertyInstance<>(entityState instanceof BuilderEntityState ? entityPropertyModel.getBuilderInfo() : entityPropertyModel, entityState);
state.put(accessor, property);
}
return property;
}
use of java.lang.reflect.AccessibleObject in project qi4j-sdk by Qi4j.
the class ValueAssemblyImpl method newPropertyModel.
@Override
protected PropertyModel newPropertyModel(AccessibleObject accessor, Iterable<Class<? extends Constraint<?, ?>>> constraintClasses) {
Iterable<Annotation> annotations = Annotations.findAccessorAndTypeAnnotationsIn(accessor);
boolean optional = first(filter(isType(Optional.class), annotations)) != null;
ValueConstraintsModel valueConstraintsModel = constraintsFor(annotations, GenericPropertyInfo.propertyTypeOf(accessor), ((Member) accessor).getName(), optional, constraintClasses, accessor);
ValueConstraintsInstance valueConstraintsInstance = null;
if (valueConstraintsModel.isConstrained()) {
valueConstraintsInstance = valueConstraintsModel.newInstance();
}
MetaInfo metaInfo = stateDeclarations.metaInfoFor(accessor);
boolean useDefaults = metaInfo.get(UseDefaults.class) != null || stateDeclarations.useDefaults(accessor);
Object initialValue = stateDeclarations.initialValueOf(accessor);
return new PropertyModel(accessor, true, useDefaults, valueConstraintsInstance, metaInfo, initialValue);
}
Aggregations