/** * True if parameter is optional. A parameter is optional when there is a default value or * {@link #type()} is {@link Optional}. * * @return True if parameter is optional. A parameter is optional when there is a default value or * {@link #type()} is {@link Optional}. */ public boolean optional() { return value != null || MoreTypes.getRawType(type) == Optional.class; }
private String simpleClassName(Type type) { return MoreTypes.getRawType(type).getSimpleName(); }
private Type componentType(final Type type) { Class<?> rawType = MoreTypes.getRawType(type); if (rawType.isArray()) { return rawType.getComponentType(); } if (Collection.class.isAssignableFrom(rawType) && type instanceof ParameterizedType) { return ((ParameterizedType) type).getActualTypeArguments()[0]; } return type; }
/** * Constructs a new type literal. Derives represented class from type parameter. * * <p>Clients create an empty anonymous subclass. Doing so embeds the type parameter in the * anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure. */ @SuppressWarnings("unchecked") protected TypeLiteral() { this.type = getSuperclassTypeParameter(getClass()); this.rawType = (Class<? super T>) MoreTypes.getRawType(type); this.hashCode = type.hashCode(); }
/** Unsafe. Constructs a type literal manually. */ @SuppressWarnings("unchecked") TypeLiteral(Type type) { this.type = canonicalize(checkNotNull(type, "type")); this.rawType = (Class<? super T>) MoreTypes.getRawType(this.type); this.hashCode = this.type.hashCode(); }
/** * List of enum values when the {@link #type()} represents an enum. * * @return Enum values. */ public List<String> enums() { return Optional.ofNullable(MoreTypes.getRawType(type)) .map(Class::getEnumConstants) .filter(Objects::nonNull) .map(values -> Arrays.asList(values).stream() .map(value -> ((Enum) value).name()) .collect(Collectors.toList()) ).orElse(Collections.emptyList()); }
return Array.newInstance(getRawType(componentType), 0).getClass();
static java.lang.reflect.Type simplifyType(final java.lang.reflect.Type type) { Class<?> rawType = MoreTypes.getRawType(type); if (Primitives.isWrapperType(rawType)) { return Primitives.unwrap(rawType); } return type; }
/** * Define/map a custom Java type to RAML type. * * <pre> * RamlType uuid = raml.define(UUID.class, RamlType.STRING); * uuid.setPattern("..."); * </pre> * * @param javaType Java type. * @param baseType RAML base type. * @return New RAML type. */ public RamlType define(Type javaType, RamlType baseType) { Objects.requireNonNull(javaType, "Java type required."); Objects.requireNonNull(baseType, "Raml type required."); if (types == null) { types = new LinkedHashMap<>(); } String typeName = MoreTypes.getRawType(javaType).getSimpleName(); RamlType ramlType = new RamlType(baseType.getType(), typeName); types.put(typeName, ramlType); return ramlType; }
types.add(Array.newInstance(MoreTypes.getRawType(element), 0).getClass()); break; } else if (!Character.isWhitespace(ch)){
String typeName = MoreTypes.getRawType(componentType).getSimpleName(); RamlType ramlType = RamlType.valueOf(typeName); if (ramlType.isObject()) {
if (finsn.getOpcode() == GETSTATIC) { java.lang.reflect.Type possibleEnum = loadType(loader, finsn.owner); if (MoreTypes.getRawType(possibleEnum).isEnum()) { return finsn.name;
Class<?> rawType = getRawType(type.getType()); Errors errors = new Errors(rawType);
private Type componentType(final Type type) { Class<?> rawType = MoreTypes.getRawType(type); if (rawType.isArray()) { return rawType.getComponentType(); } if (Collection.class.isAssignableFrom(rawType) && type instanceof ParameterizedType) { return ((ParameterizedType) type).getActualTypeArguments()[0]; } return type; }
/** * Constructs a new type literal. Derives represented class from type parameter. * * <p>Clients create an empty anonymous subclass. Doing so embeds the type parameter in the * anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure. */ @SuppressWarnings("unchecked") protected TypeLiteral() { this.type = getSuperclassTypeParameter(getClass()); this.rawType = (Class<? super T>) MoreTypes.getRawType(type); this.hashCode = type.hashCode(); }
/** Unsafe. Constructs a type literal manually. */ @SuppressWarnings("unchecked") TypeLiteral(Type type) { this.type = canonicalize(checkNotNull(type, "type")); this.rawType = (Class<? super T>) MoreTypes.getRawType(this.type); this.hashCode = this.type.hashCode(); }
/** * Constructs a new type literal. Derives represented class from type parameter. * * <p>Clients create an empty anonymous subclass. Doing so embeds the type parameter in the * anonymous class's type hierarchy so we can reconstitute it at runtime despite erasure. */ @SuppressWarnings("unchecked") protected TypeLiteral() { this.type = getSuperclassTypeParameter(getClass()); this.rawType = (Class<? super T>) MoreTypes.getRawType(type); this.hashCode = type.hashCode(); }
/** Unsafe. Constructs a type literal manually. */ @SuppressWarnings("unchecked") TypeLiteral(Type type) { this.type = canonicalize(checkNotNull(type, "type")); this.rawType = (Class<? super T>) MoreTypes.getRawType(this.type); this.hashCode = this.type.hashCode(); }
/** * Unsafe. Constructs a type literal manually. */ @SuppressWarnings("unchecked") TypeLiteral(Type type) { this.type = canonicalize(checkNotNull(type, "type")); this.rawType = (Class<? super T>) MoreTypes.getRawType(this.type); this.hashCode = this.type.hashCode(); }
static java.lang.reflect.Type simplifyType(final java.lang.reflect.Type type) { Class<?> rawType = MoreTypes.getRawType(type); if (Primitives.isWrapperType(rawType)) { return Primitives.unwrap(rawType); } return type; }