Collects all constants of the given {@link Class}.

@param type The class which includes the constants.
@return A {@link Map} with the found constants.
963912
protected Map<String, Object> collectConstants(Class<?> type) {
        Map<String, Object> constants = new ConstantsHashMap<>(type);

        // Go through all the fields, and put static ones in a map.
        Field[] fields = type.getDeclaredFields();

        for (Field field : fields) {
            // Check to see if this is public static final. If not, it's not a constant.
            int modifiers = field.getModifiers();
            if (!Modifier.isFinal(modifiers) || !Modifier.isStatic(modifiers) || !Modifier.isPublic(modifiers)) {
                continue;
            }

            try {
                Object value = field.get(null); // null for static fields.
                constants.put(field.getName(), value);
            }
            catch (Exception e) {
                throw new FacesException("Could not get value of " + field.getName() + " in " + type.getName() + ".", e);
            }
        }

        return constants;
    }
387680
@SuppressWarnings("unchecked")
  public static <T> TypeLiteral<T> get(Class<T> type, Type... parameters) {
    return (TypeLiteral<T>) TypeLiteral.get(new ParameterizedTypeImpl(type, parameters));
  }
548784
public <U extends T> List<U> getAll(Class<U> type) {
        List<U> r = new ArrayList<>();
        for (T t : data)
            if(type.isInstance(t))
                r.add(type.cast(t));
        return r;
    }
613941
private static List<Field> getAllFields(Class type) {
		final List<Field> fields = new ArrayList<>();
		for (Class<?> c = type; c != null; c = c.getSuperclass()) {
			fields.addAll(Arrays.asList(c.getDeclaredFields()));
		}
		return fields;
	}
231184
public static List<Field> getInstanceFields(Class type) {
        List<Field> fields = Lists.newArrayList(type.getDeclaredFields());
        return ImmutableList.copyOf(Iterables.filter(fields, InstanceFieldPredicate.PREDICATE));
    }
115187
@SuppressWarnings("static-method")
	protected List<JvmTypeParameter> getTypeParametersFor(XtendTypeDeclaration type) {
		if (type instanceof XtendClass) {
			return ((XtendClass) type).getTypeParameters();
		}
		if (type instanceof XtendInterface) {
			return ((XtendInterface) type).getTypeParameters();
		}
		return Collections.emptyList();
	}
933772
@SuppressWarnings("unchecked")
	public static Getter getGetter(Class type, String name) {
		return getGettersAsMap(type).get(name);
	}
701720
public static Class<?> getTypeParameter(Class<?> genericType, Class<?> type) {
        Type[] genericInterfaces = type.getGenericInterfaces();
        for (Type genericInterface : genericInterfaces) {
            if (genericInterface instanceof ParameterizedType) {
                ParameterizedType parameterizedType = (ParameterizedType) genericInterface;
                if (genericType.equals(parameterizedType.getRawType())) {
                    Type typeParameter = ((ParameterizedType) genericInterface).getActualTypeArguments()[0];
                    if (typeParameter instanceof Class<?>) {
                        return (Class<?>) typeParameter;
                    }
                }
            }
        }
        return null;
    }
156158
@Override
  public <T> T instance(Class<T> type)
  {
    Key<T> key = Key.of(type);

    return instance(key);
  }
878937
public Set<Constructor> getConstructorsMatchParams(Class<?>... types) {
        return getConstructorsFromDescriptors(store.get(index(MethodParameterScanner.class), names(types).toString()), loaders());
    }
1334381
public <T> List<T> getInstances(Class<T> type) {
		return getInstances(Key.get(type));
	}
1017821
public static Map<String, Object> getConstantFrom(Class clazz, // NL
                                                 boolean findAncestor, boolean findInterfaces) {

        HashMap<String, Object> map = new HashMap<String, Object>();

        if (findInterfaces) {
            for (Class interfaceClass : clazz.getInterfaces()) {
                fillConstantFrom(interfaceClass, map);
            }
        }

        if (findAncestor) {
            Class superClass = clazz;
            while (superClass != null) {
                fillConstantFrom(superClass, map);
                superClass = superClass.getSuperclass();
            }
        }

        fillConstantFrom(clazz, map);

        return map;
    }
789893
public @Nonnull final <T extends Annotation> List<AnnotationValue<T>> getAnnotations(String member, Class<T> type) {
        AnnotationValue[] values = get(member, AnnotationValue[].class).orElse(null);
        if (ArrayUtils.isNotEmpty(values)) {
            List<AnnotationValue<T>> list = new ArrayList<>(values.length);
            String typeName = type.getName();
            for (AnnotationValue value : values) {
                if (value == null) {
                    continue;
                }
                if (value.getAnnotationName().equals(typeName)) {
                    //noinspection unchecked
                    list.add(value);
                }
            }
            return list;
        }
        return Collections.emptyList();
    }
184571
public <T extends DataObject> List<T> collect(Class<T> type) {
        return collect(type, null);
    }
955063
public static <T> T get(Class<T> type) {
        FactoryBuilder factoryBuilder = REPOSITORY.get(type);
        return (T) factoryBuilder.get();
    }
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;
    }
577639
public <T> Map<String, T> findByTypeWithName(Class<T> type) {
        return BeanFactoryUtils.beansOfTypeIncludingAncestors(applicationContext, type);
    }