Gets list inner class from generic type.

@param genericType the generic type
@return the list inner class from generic type
764417
public static Class<?> getListInnerClassFromGenericType(Type genericType) {
        ParameterizedType innerClass = (ParameterizedType) genericType;
        return (Class<?>) innerClass.getActualTypeArguments()[0];
    }
1216128
protected Class<?> getCollectionElementType(Type genericType) throws ConversionException {
        if (genericType instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) genericType;
            Type[] typeArguments = parameterizedType.getActualTypeArguments();
            if (typeArguments.length != 1) {
                throw new ConversionException("Types with more then one generic are not supported");
            }

            Type type = typeArguments[0];
            if (type instanceof Class) {
                return (Class<?>) type;
            }

            throw new ConversionException(String.format("Could not resolve generic type <%s>", type));
        }
        return String.class;
    }
236538
public static <T extends Item> List<T> fromNameList(ItemGroup context, @Nonnull String list, @Nonnull Class<T> type) {
        final Jenkins jenkins = Jenkins.getInstance();
        
        List<T> r = new ArrayList<>();
        if (jenkins == null) {
            return r;
        }
        
        StringTokenizer tokens = new StringTokenizer(list,",");
        while(tokens.hasMoreTokens()) {
            String fullName = tokens.nextToken().trim();
            if (StringUtils.isNotEmpty(fullName)) {
                T item = jenkins.getItem(fullName, context, type);
                if(item!=null)
                    r.add(item);
            }
        }
        return r;
    }
1209593
public static Class[] getImplementorClasses( Class interfaceType )
    {
        String interfaceName = interfaceType.getName();
        ArrayList/*< Class >*/ classes = new ArrayList/*< Class >*/();
        ClassLoader classLoader = getClassLoader();
        
        try
        {
            Enumeration e = classLoader.getResources( "META-INF/services/" + interfaceName );
            
            while ( e.hasMoreElements() )
            {
                URL url = ( URL ) e.nextElement();
                
                if ( _log.isTraceEnabled() )
                {
                    _log.trace( "Found implementor entry for interface " + interfaceName + " at " + url );
                }
                
                InputStream is = null;
                String className = null;
                
                try
                {
                    is = url.openStream();
                    BufferedReader reader = new BufferedReader( new InputStreamReader( is ) );
                    className = reader.readLine().trim();
                    Class implementorClass = loadImplementorClass( className, interfaceType, classLoader );
                    if ( implementorClass != null ) classes.add( implementorClass );
                }
                catch ( IOException ioe )
                {
                    _log.error( "Could not read implementor class entry at + " + url );
                }
                finally
                {
                    if ( is != null ) is.close();
                }
            }
        }
        catch ( IOException e )
        {
            _log.error( "Could not discover implementors for " + interfaceName, e );
        }
        
        return ( Class[] ) classes.toArray( new Class[0] );
    }
1079397
private static Class <?> type2class(Type type){
		if(type instanceof Class <?>){
			return (Class <?>) type;	//base case
		}else if(type instanceof ParameterizedType){
			return type2class( ((ParameterizedType) type).getRawType() );
		}else if(type instanceof TypeVariable<?>){
			return type2class( ((TypeVariable<?>) type).getBounds()[0] );
		}else if(type instanceof WildcardType){
			return type2class( ((WildcardType) type).getUpperBounds()[0] );
		}else{
			throw new IllegalArgumentException("Cannot convert type to class: " + type);
		}
	}
903735
public <T> List<T> getItems(Class<T> type) {
        List<T> r = new ArrayList<>();
        for (TopLevelItem i : getItems())
            if (type.isInstance(i))
                 r.add(type.cast(i));
        return r;
    }
985487
public <T extends Descriptor> T getDescriptorByType(Class<T> type) {
        for( Descriptor d : getExtensionList(Descriptor.class) )
            if(d.getClass()==type)
                return type.cast(d);
        return null;
    }
1334381
public <T> List<T> getInstances(Class<T> type) {
		return getInstances(Key.get(type));
	}
728444
public static Type getArrayComponentType(Type type) {
		if (type instanceof Class) {
			Class<?> clazz = (Class<?>)type;
			return clazz.getComponentType();
		} else if (type instanceof GenericArrayType) {
			GenericArrayType aType = (GenericArrayType) type;
			return aType.getGenericComponentType();
		} else {
			return null;
		}
	}
702365
private static Class<?> typeToClass(Type t)
  {
    if(t instanceof Class<?>) {
      return (Class<?>)t;
    }
    if(t instanceof ParameterizedType) {
      return (Class<?>)((ParameterizedType)t).getRawType();
    }
    throw new BugError("Unknown type %s to convert to class.", t);
  }
344947
public static <T> T convertToObject(Object genericObject) {

        try {
            return (T) innerToConvertObject(genericObject, new IdentityHashMap<Object, Object>());
        } catch (Throwable t) {
            throw new ConvertException(t);
        }
    }
821673
public <T> Set<Class<? extends T>> getSubTypesOf(final Class<T> type) {
        return Sets.newHashSet(ReflectionUtils.<T>forNames(
                store.getAll(index(SubTypesScanner.class), Arrays.asList(type.getName())), loaders()));
    }
410310
@SuppressWarnings("unchecked")
    public static List<Class<?>> getSupertypes(Class<?> type) {
        List<Class<?>> supertypes = new LinkedList<>();
        supertypes.add(type.getSuperclass());
        Collections.addAll(supertypes, type.getInterfaces());
        return supertypes;
    }
1043589
protected static <T> List<T> toList(JSONArray jsonArray, Class<T> elementType) {
		return Convert.toList(elementType, jsonArray);
	}
1187873
public static Class<?> typeToClass(Type t) {
		if (t instanceof Class) {
			return (Class<?>)t;
		}
		else if (t instanceof ParameterizedType) {
			return ((Class<?>) ((ParameterizedType) t).getRawType());
		}
		throw new IllegalArgumentException("Cannot convert type to class");
	}
1192827
public <T> List<T> getList(String name, Class<T> type) {

		Object value = super.get(name);

		// make sure correct objects are returned
		if (value instanceof List) {

			ArrayList<T> output = new ArrayList<>();

			List list = (List) value;
			for (Object item : list) {
				output.add(type.cast(item));
			}

			return output;
		}

		throw new IllegalArgumentException("Setting: '" + name + "', can't be converted to List<" + type.getName() + ">: '" + value + "'!");
	}
933675
@SuppressWarnings("unckecked")
    public static Class<?> getRawType(Type type) {
        if (type instanceof Class<?>) {
            // type is a normal class.
            return (Class<?>) type;

        } else if (type instanceof ParameterizedType) {
            ParameterizedType parameterizedType = (ParameterizedType) type;

            // I'm not exactly sure why getRawType() returns Type instead of Class.
            // Neal isn't either but suspects some pathological case related
            // to nested classes exists.
            Type rawType = parameterizedType.getRawType();
            checkArgument(rawType instanceof Class,
                    "Expected a Class, but <%s> is of type %s", type, type.getClass().getName());
            //noinspection ConstantConditions
            return (Class<?>) rawType;

        } else if (type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            return Array.newInstance(getRawType(componentType), 0).getClass();

        } else if (type instanceof TypeVariable) {
            // we could use the variable's bounds, but that'll won't work if there are multiple.
            // having a raw type that's more general than necessary is okay
            return Object.class;

        } else {
            throw new IllegalArgumentException("Expected a Class, ParameterizedType, or "
                    + "GenericArrayType, but <" + type + "> is of type " + type.getClass().getName());
        }
    }