Example usage for java.lang.reflect ParameterizedType getOwnerType

List of usage examples for java.lang.reflect ParameterizedType getOwnerType

Introduction

In this page you can find the example usage for java.lang.reflect ParameterizedType getOwnerType.

Prototype

Type getOwnerType();

Source Link

Document

Returns a Type object representing the type that this type is a member of.

Usage

From source file:org.xwiki.component.descriptor.DefaultComponentDependency.java

/**
 * @param mappingType the class of the type for the injection (java.lang.String, java.util.List, etc)
 * @deprecated since 4.0M1 use {@link #setRoleType(java.lang.reflect.Type)} instead
 *//*from   w w w .  j  a  va 2s  . c om*/
@Deprecated
public void setMappingType(Class<?> mappingType) {
    Type ownerType;
    Type[] parameters;
    if (getRoleType() instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) getRoleType();
        ownerType = parameterizedType.getOwnerType();
        parameters = parameterizedType.getActualTypeArguments();

        setRoleType(new DefaultParameterizedType(ownerType, mappingType, parameters));
    } else {
        setRoleType(mappingType);
    }
}

From source file:org.xwiki.component.descriptor.DefaultComponentDependency.java

@Override
public void setRole(Class<T> role) {
    Class mapping = getMappingType();

    if (mapping == List.class || mapping == Collection.class || mapping == Map.class
            || mapping == Provider.class) {
        Type ownerType;/* w w w . j av  a2  s  .c o  m*/
        Class<?> rawType;
        if (getRoleType() instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) getRoleType();
            ownerType = parameterizedType.getOwnerType();
            rawType = (Class<?>) parameterizedType.getRawType();
        } else {
            ownerType = null;
            rawType = mapping;
        }

        setRoleType(new DefaultParameterizedType(ownerType, rawType, role));
    } else {
        super.setRole(role);
    }
}