Search in sources :

Example 1 with BridgeMethodBinding

use of org.gradle.model.internal.manage.binding.BridgeMethodBinding in project gradle by gradle.

the class ManagedProxyClassGenerator method writeViewMethods.

private void writeViewMethods(ClassVisitor visitor, Type generatedType, Collection<ModelType<?>> viewTypes, StructBindings<?> bindings) {
    Type delegateType;
    StructSchema<?> delegateSchema = bindings.getDelegateSchema();
    if (delegateSchema != null) {
        Class<?> delegateClass = delegateSchema.getType().getRawClass();
        declareDelegateField(visitor, delegateClass);
        delegateType = Type.getType(delegateClass);
    } else {
        delegateType = null;
    }
    Multimap<String, ModelProperty<?>> viewPropertiesByNameBuilder = ArrayListMultimap.create();
    Set<Wrapper<Method>> viewMethods = Sets.newLinkedHashSet();
    for (StructSchema<?> viewSchema : bindings.getImplementedViewSchemas()) {
        for (ModelType<?> viewType : viewTypes) {
            if (viewType.equals(viewSchema.getType())) {
                for (ModelProperty<?> property : viewSchema.getProperties()) {
                    String propertyName = property.getName();
                    viewPropertiesByNameBuilder.put(propertyName, property);
                }
                for (WeaklyTypeReferencingMethod<?, ?> viewMethod : viewSchema.getAllMethods()) {
                    viewMethods.add(SIGNATURE_EQUIVALENCE.wrap(viewMethod.getMethod()));
                }
                break;
            }
        }
    }
    Class<?> viewClass = bindings.getPublicSchema().getType().getConcreteClass();
    for (Collection<ModelProperty<?>> viewProperties : viewPropertiesByNameBuilder.asMap().values()) {
        writeViewPropertyDslMethods(visitor, generatedType, viewProperties, viewClass);
    }
    for (StructMethodBinding methodBinding : bindings.getMethodBindings()) {
        WeaklyTypeReferencingMethod<?, ?> weakViewMethod = methodBinding.getViewMethod();
        Method viewMethod = weakViewMethod.getMethod();
        // Don't generate method if it's not part of the view schema
        Wrapper<Method> methodKey = SIGNATURE_EQUIVALENCE.wrap(viewMethod);
        if (!viewMethods.contains(methodKey)) {
            continue;
        }
        if (methodBinding instanceof DirectMethodBinding) {
            // TODO:LPTR What is with the "metaClass" property here?
            boolean isGetterMethod = methodBinding.getAccessorType() == GET_GETTER || methodBinding.getAccessorType() == IS_GETTER;
            if (isGetterMethod && !Modifier.isFinal(viewMethod.getModifiers()) && !viewMethod.getName().equals("getMetaClass")) {
                writeNonAbstractMethodWrapper(visitor, generatedType, viewClass, viewMethod);
            }
        } else if (methodBinding instanceof BridgeMethodBinding) {
            writeBridgeMethod(visitor, generatedType, viewMethod);
        } else if (methodBinding instanceof DelegateMethodBinding) {
            writeDelegatingMethod(visitor, generatedType, delegateType, viewMethod);
        } else if (methodBinding instanceof ManagedPropertyMethodBinding) {
            ManagedPropertyMethodBinding propertyBinding = (ManagedPropertyMethodBinding) methodBinding;
            ManagedProperty<?> managedProperty = bindings.getManagedProperty(propertyBinding.getPropertyName());
            String propertyName = managedProperty.getName();
            Class<?> propertyClass = managedProperty.getType().getRawClass();
            WeaklyTypeReferencingMethod<?, ?> propertyAccessor = propertyBinding.getViewMethod();
            switch(propertyBinding.getAccessorType()) {
                case GET_GETTER:
                case IS_GETTER:
                    writeGetter(visitor, generatedType, propertyName, propertyClass, propertyAccessor);
                    break;
                case SETTER:
                    writeSetter(visitor, generatedType, propertyName, propertyClass, propertyAccessor);
                    break;
                default:
                    throw new AssertionError();
            }
        } else {
            throw new AssertionError();
        }
    }
}
Also used : Wrapper(com.google.common.base.Equivalence.Wrapper) DirectMethodBinding(org.gradle.model.internal.manage.binding.DirectMethodBinding) Method(java.lang.reflect.Method) WeaklyTypeReferencingMethod(org.gradle.model.internal.method.WeaklyTypeReferencingMethod) BridgeMethodBinding(org.gradle.model.internal.manage.binding.BridgeMethodBinding) ManagedPropertyMethodBinding(org.gradle.model.internal.manage.binding.ManagedPropertyMethodBinding) DelegateMethodBinding(org.gradle.model.internal.manage.binding.DelegateMethodBinding) WeaklyTypeReferencingMethod(org.gradle.model.internal.method.WeaklyTypeReferencingMethod) ManagedProperty(org.gradle.model.internal.manage.binding.ManagedProperty) Type(org.objectweb.asm.Type) ModelType(org.gradle.model.internal.type.ModelType) StructMethodBinding(org.gradle.model.internal.manage.binding.StructMethodBinding) ModelProperty(org.gradle.model.internal.manage.schema.ModelProperty)

Aggregations

Wrapper (com.google.common.base.Equivalence.Wrapper)1 Method (java.lang.reflect.Method)1 BridgeMethodBinding (org.gradle.model.internal.manage.binding.BridgeMethodBinding)1 DelegateMethodBinding (org.gradle.model.internal.manage.binding.DelegateMethodBinding)1 DirectMethodBinding (org.gradle.model.internal.manage.binding.DirectMethodBinding)1 ManagedProperty (org.gradle.model.internal.manage.binding.ManagedProperty)1 ManagedPropertyMethodBinding (org.gradle.model.internal.manage.binding.ManagedPropertyMethodBinding)1 StructMethodBinding (org.gradle.model.internal.manage.binding.StructMethodBinding)1 ModelProperty (org.gradle.model.internal.manage.schema.ModelProperty)1 WeaklyTypeReferencingMethod (org.gradle.model.internal.method.WeaklyTypeReferencingMethod)1 ModelType (org.gradle.model.internal.type.ModelType)1 Type (org.objectweb.asm.Type)1