Java Code Examples for org.springframework.core.ResolvableType#hasGenerics()

The following examples show how to use org.springframework.core.ResolvableType#hasGenerics() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReturnTypeParser.java    From springdoc-openapi with Apache License 2.0 6 votes vote down vote up
/**
 * Resolve variable resolvable type.
 *
 * @param typeVariable the type variable
 * @param contextType the context type
 * @return the resolvable type
 */
static ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) {
	ResolvableType resolvedType;
	if (contextType.hasGenerics()) {
		resolvedType = ResolvableType.forType(typeVariable, contextType);
		if (resolvedType.resolve() != null) {
			return resolvedType;
		}
	}

	ResolvableType superType = contextType.getSuperType();
	if (superType != ResolvableType.NONE) {
		resolvedType = resolveVariable(typeVariable, superType);
		if (resolvedType.resolve() != null) {
			return resolvedType;
		}
	}
	for (ResolvableType ifc : contextType.getInterfaces()) {
		resolvedType = resolveVariable(typeVariable, ifc);
		if (resolvedType.resolve() != null) {
			return resolvedType;
		}
	}
	return ResolvableType.NONE;
}
 
Example 2
Source File: AbstractJackson2HttpMessageConverter.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) {
	ResolvableType resolvedType;
	if (contextType.hasGenerics()) {
		resolvedType = ResolvableType.forType(typeVariable, contextType);
		if (resolvedType.resolve() != null) {
			return resolvedType;
		}
	}

	ResolvableType superType = contextType.getSuperType();
	if (superType != ResolvableType.NONE) {
		resolvedType = resolveVariable(typeVariable, superType);
		if (resolvedType.resolve() != null) {
			return resolvedType;
		}
	}
	for (ResolvableType ifc : contextType.getInterfaces()) {
		resolvedType = resolveVariable(typeVariable, ifc);
		if (resolvedType.resolve() != null) {
			return resolvedType;
		}
	}
	return ResolvableType.NONE;
}
 
Example 3
Source File: FastJsonHttpMessageConverter.java    From uavstack with Apache License 2.0 6 votes vote down vote up
private static ResolvableType resolveVariable(TypeVariable<?> typeVariable, ResolvableType contextType) {
    ResolvableType resolvedType;
    if (contextType.hasGenerics()) {
        resolvedType = ResolvableType.forType(typeVariable, contextType);
        if (resolvedType.resolve() != null) {
            return resolvedType;
        }
    }

    ResolvableType superType = contextType.getSuperType();
    if (superType != ResolvableType.NONE) {
        resolvedType = resolveVariable(typeVariable, superType);
        if (resolvedType.resolve() != null) {
            return resolvedType;
        }
    }
    for (ResolvableType ifc : contextType.getInterfaces()) {
        resolvedType = resolveVariable(typeVariable, ifc);
        if (resolvedType.resolve() != null) {
            return resolvedType;
        }
    }
    return ResolvableType.NONE;
}
 
Example 4
Source File: RpcComponent.java    From Brutusin-RPC with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param rt
 * @return
 */
protected static Type getType(final ResolvableType rt) {
    if (!rt.hasGenerics()) {
        return rt.resolve();
    } else {
        return new ParameterizedType() {
            public Type[] getActualTypeArguments() {
                Type[] ret = new Type[rt.getGenerics().length];
                for (int i = 0; i < ret.length; i++) {
                    ret[i] = getType(rt.getGenerics()[i]);
                }
                return ret;
            }

            public Type getRawType() {
                return rt.resolve();
            }

            public Type getOwnerType() {
                return null;
            }
        };
    }
}
 
Example 5
Source File: ControlInitializerSupport.java    From jdal with Apache License 2.0 6 votes vote down vote up
protected List<Object> getEntityList(ResolvableType propertyType, String sortProperty) {
	Class<?> entityClass = null;

	if (propertyType.asCollection() != ResolvableType.NONE) {
		// look for generic type
		if (propertyType.hasGenerics()) {
			entityClass = propertyType.getGeneric().resolve();
		}
		else {
			if (log.isWarnEnabled())
				log.warn("Can't resolve generic type of [" + propertyType.toString() + "]");
		
			return new ArrayList<Object>();
		}
	}
	else  {
		entityClass = propertyType.resolve();
	}
	
	return getEntityList(entityClass, sortProperty);
}
 
Example 6
Source File: DefaultListableBeanFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public String[] getBeanNamesForType(ResolvableType type) {
	Class<?> resolved = type.resolve();
	if (resolved != null && !type.hasGenerics()) {
		return getBeanNamesForType(resolved, true, true);
	}
	else {
		return doGetBeanNamesForType(type, true, true);
	}
}
 
Example 7
Source File: DefaultListableBeanFactory.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public String[] getBeanNamesForType(ResolvableType type) {
	Class<?> resolved = type.resolve();
	if (resolved != null && !type.hasGenerics()) {
		return getBeanNamesForType(resolved, true, true);
	}
	else {
		return doGetBeanNamesForType(type, true, true);
	}
}
 
Example 8
Source File: AbstractConverter.java    From spring-cloud-sockets with Apache License 2.0 5 votes vote down vote up
public ResolvableType getActualType(ResolvableType original){
	if(!original.hasGenerics()){
		return  original;
	}else{
		return original.getGeneric(0);
	}
}
 
Example 9
Source File: GenericApplicationListenerAdapter.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
static ResolvableType resolveDeclaredEventType(Class<?> listenerType) {
	ResolvableType resolvableType = ResolvableType.forClass(listenerType).as(ApplicationListener.class);
	if (resolvableType == null || !resolvableType.hasGenerics()) {
		return null;
	}
	return resolvableType.getGeneric();
}
 
Example 10
Source File: GenericApplicationListenerAdapter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
static ResolvableType resolveDeclaredEventType(Class<?> listenerType) {
	ResolvableType resolvableType = ResolvableType.forClass(listenerType).as(ApplicationListener.class);
	return (resolvableType.hasGenerics() ? resolvableType.getGeneric() : null);
}