/** * Create new configuration value mapping exception with additional contextual details describing the failure. * * @param key key associated with the mapped configuration value. * @param type requested mapping type. * @param detail detailed information about the configuration value mapping failure. * @param cause root exception cause. */ public ConfigMappingException(Config.Key key, Type type, String detail, Throwable cause) { super("Mapping of value stored under key '" + key + "' to type '" + type.getTypeName() + "' has failed: " + detail, cause); }
@Override public String getTypeName() { StringBuilder result = new StringBuilder(this.rawType.getTypeName()); if (this.typeArguments.length > 0) { result.append('<'); for (int i = 0; i < this.typeArguments.length; i++) { if (i > 0) { result.append(", "); } result.append(this.typeArguments[i].getTypeName()); } result.append('>'); } return result.toString(); }
@Override public String getTypeName() { return forwarding.getTypeName(); } }
private Class<?> getClass(Type type) { if (type instanceof Class) { return (Class<?>) type; } else { throw new RuntimeException( "Oops. That's a strange internal Ninja error.\n" + "Seems someone tried to convert a type into a class that is not a real class. ( " + type.getTypeName() + ")"); } }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj == null) { return false; } else if (!(obj instanceof Type)) { return false; } final Type other = (Type) obj; return Objects.equals(typeName, other.getTypeName()); }
/** * Checks if the specified type is a java {@link Optional}. * * @param type the type to check * @return <code>true</code> if Optional, else <code>false</code> */ private boolean isOptional(Type type) { return type.getTypeName().startsWith("java.lang.Optional"); }
/** * Returns the corresponding wrapper type for the specified primitive type. * If the type is not primitive, an exception is thrown. * * @param primitiveType the primitive type * @return the corresponding wrapper type */ public static Class<?> wrapperFor(Type primitiveType) { return requireNonNull(WRAPPERS.get(primitiveType.getTypeName()), "No wrapper found for type '" + primitiveType.getTypeName() + "'." ); }
@Override public void serialize(final Type value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException { gen.writeObject(value.getTypeName()); } }
protected boolean isImpliedType(Type type) { String typeName = type.getTypeName(); switch (typeName) { case "boolean": case "java.lang.Boolean": case "int": case "java.lang.Integer": case "byte": case "java.lang.Byte": case "double": case "java.lang.Double": case "float": case "java.lang.Float": case "short": case "java.lang.Short": case "long": case "java.lang.Long": case "java.lang.String": case "io.bootique.resource.ResourceFactory": case "io.bootique.resource.FolderResourceFactory": return true; default: return false; } }
/** * Returns {@code true} if the specified type is a primitive type. Wrapper * types does <em>not</em> count as primitives. * * @param type the type to check * @return {@code true} if it is primitive, else {@code false} */ public static boolean isPrimitive(Type type) { return WRAPPERS.keySet().contains(type.getTypeName()); }
@Override public String getTypeName() { StringBuilder result = new StringBuilder(this.rawType.getTypeName()); if (this.typeArguments.length > 0) { result.append('<'); for (int i = 0; i < this.typeArguments.length; i++) { if (i > 0) { result.append(", "); } result.append(this.typeArguments[i].getTypeName()); } result.append('>'); } return result.toString(); }
public java.lang.reflect.Type type() { if (status != null && status == 204 && forwarding.getTypeName() .equals(Result.class.getName())) { return void.class; } return forwarding; }
private boolean isVoid(Type type) { return "void".equals(type.getTypeName()) || Void.class.getName().equals(type.getTypeName()); }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Type)) { return false; } if (o instanceof GeneratedEnumType) { final GeneratedEnumType that = (GeneratedEnumType) o; return typeName.equals(that.typeName) && constants.equals(that.constants); } else { return typeName.equals(((Type) o).getTypeName()); } }
/** * Returns <code>true</code> if the specified type is a primitive type. * * @param type the type * @return <code>true</code> if primitive, else <code>false</code> */ protected boolean isPrimitive(Type type) { requireNonNull(type); switch (type.getTypeName()) { case "byte": case "short": case "int": case "long": case "float": case "double": case "boolean": case "char": return true; default: return false; } }
/** * Returns {@code true} if the specified type is a wrapper type, else * {@code false}. * * @param type the type to check * @return {@code true} if it is a wrapper, else {@code false} * * @since 2.5 */ public static boolean isWrapper(Type type) { return WRAPPERS.values().stream() .map(Class::getTypeName) .anyMatch(type.getTypeName()::equals); }
private ProcedureException javaToNeoMappingError( Type cls ) { List<String> types = Iterables.asList( javaToNeo.keySet() ) .stream() .map( Type::getTypeName ) .sorted( String::compareTo ) .collect( Collectors.toList() ); return new ProcedureException( Status.Statement.TypeError, "Don't know how to map `%s` to the Neo4j Type System.%n" + "Please refer to to the documentation for full details.%n" + "For your reference, known types are: %s", cls.getTypeName(), types ); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); qualifiers.forEach(qualifier -> builder.append(qualifier).append(" ")); builder.append(type.getTypeName()); return builder.toString(); } }
@SuppressWarnings("unchecked") static <T extends Type> Class<T> getParameterizedTypeFromArray( TypeReference typeReference) throws ClassNotFoundException { java.lang.reflect.Type type = typeReference.getType(); java.lang.reflect.Type[] typeArguments = ((ParameterizedType) type).getActualTypeArguments(); String parameterizedTypeName = typeArguments[0].getTypeName(); return (Class<T>) Class.forName(parameterizedTypeName); }
/** * Creates a new {@code SimpleParameterizedType} based on the class name of * the specified class and the specified parameters. * * @param mainType the class to get the name from * @param parameters list of generic parameters to this type * @return the created type */ public static SimpleParameterizedType create(Type mainType, Type... parameters) { return create(mainType.getTypeName(), parameters); }