Search in sources :

Example 31 with AccessibleObject

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;
}
Also used : ArrayList(java.util.ArrayList) AccessibleObject(java.lang.reflect.AccessibleObject) Method(java.lang.reflect.Method)

Example 32 with AccessibleObject

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;
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) PropertyModel(org.qi4j.runtime.property.PropertyModel) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) AccessibleObject(java.lang.reflect.AccessibleObject) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Annotation(java.lang.annotation.Annotation)

Example 33 with AccessibleObject

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;
}
Also used : UsesInstance(org.qi4j.runtime.composite.UsesInstance) MixinModel(org.qi4j.runtime.composite.MixinModel) HashMap(java.util.HashMap) PropertyModel(org.qi4j.runtime.property.PropertyModel) PropertyInstance(org.qi4j.runtime.property.PropertyInstance) InjectionContext(org.qi4j.runtime.injection.InjectionContext) TransientStateInstance(org.qi4j.runtime.composite.TransientStateInstance) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) Property(org.qi4j.api.property.Property)

Example 34 with AccessibleObject

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;
}
Also used : PropertyModel(org.qi4j.runtime.property.PropertyModel) AccessibleObject(java.lang.reflect.AccessibleObject) AccessibleObject(java.lang.reflect.AccessibleObject) BuilderEntityState(org.qi4j.runtime.unitofwork.BuilderEntityState) Property(org.qi4j.api.property.Property)

Example 35 with AccessibleObject

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);
}
Also used : Optional(org.qi4j.api.common.Optional) MetaInfo(org.qi4j.api.common.MetaInfo) PropertyModel(org.qi4j.runtime.property.PropertyModel) ValueConstraintsModel(org.qi4j.runtime.composite.ValueConstraintsModel) AccessibleObject(java.lang.reflect.AccessibleObject) ValueConstraintsInstance(org.qi4j.runtime.composite.ValueConstraintsInstance) Annotation(java.lang.annotation.Annotation)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)51 ArrayList (java.util.ArrayList)17 Method (java.lang.reflect.Method)13 Field (java.lang.reflect.Field)9 Annotation (java.lang.annotation.Annotation)7 PropertyModel (org.qi4j.runtime.property.PropertyModel)6 HashSet (java.util.HashSet)5 Property (org.qi4j.api.property.Property)4 BuilderEntityState (org.qi4j.runtime.unitofwork.BuilderEntityState)4 MethodInvocation (org.aopalliance.intercept.MethodInvocation)3 MetaInfo (org.qi4j.api.common.MetaInfo)3 Optional (org.qi4j.api.common.Optional)3 DynamicFinder (com.google.inject.persist.finder.DynamicFinder)2 Finder (com.google.inject.persist.finder.Finder)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)2 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)2 Module (org.jboss.modules.Module)2