checkstyle
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1535757 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
70b3504b9f
commit
b39f106258
|
@ -24,7 +24,6 @@
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.commons.lang3.ClassUtils;
|
|
||||||
import org.apache.commons.lang3.tuple.Pair;
|
import org.apache.commons.lang3.tuple.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -51,22 +51,38 @@ public class TypeUtils {
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
public static class WildcardTypeBuilder implements Builder<WildcardType> {
|
public static class WildcardTypeBuilder implements Builder<WildcardType> {
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
private WildcardTypeBuilder() {
|
private WildcardTypeBuilder() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Type[] upperBounds;
|
private Type[] upperBounds;
|
||||||
private Type[] lowerBounds;
|
private Type[] lowerBounds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify upper bounds of the wildcard type to build.
|
||||||
|
* @param bounds to set
|
||||||
|
* @return {@code this}
|
||||||
|
*/
|
||||||
public WildcardTypeBuilder withUpperBounds(Type... bounds) {
|
public WildcardTypeBuilder withUpperBounds(Type... bounds) {
|
||||||
this.upperBounds = bounds;
|
this.upperBounds = bounds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify lower bounds of the wildcard type to build.
|
||||||
|
* @param bounds to set
|
||||||
|
* @return {@code this}
|
||||||
|
*/
|
||||||
public WildcardTypeBuilder withLowerBounds(Type... bounds) {
|
public WildcardTypeBuilder withLowerBounds(Type... bounds) {
|
||||||
this.lowerBounds = bounds;
|
this.lowerBounds = bounds;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public WildcardType build() {
|
public WildcardType build() {
|
||||||
return new WildcardTypeImpl(upperBounds, lowerBounds);
|
return new WildcardTypeImpl(upperBounds, lowerBounds);
|
||||||
|
@ -80,25 +96,41 @@ public WildcardType build() {
|
||||||
private static final class GenericArrayTypeImpl implements GenericArrayType {
|
private static final class GenericArrayTypeImpl implements GenericArrayType {
|
||||||
private final Type componentType;
|
private final Type componentType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param componentType of this array type
|
||||||
|
*/
|
||||||
private GenericArrayTypeImpl(Type componentType) {
|
private GenericArrayTypeImpl(Type componentType) {
|
||||||
this.componentType = componentType;
|
this.componentType = componentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Type getGenericComponentType() {
|
public Type getGenericComponentType() {
|
||||||
return componentType;
|
return componentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return TypeUtils.toString(this);
|
return TypeUtils.toString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj == this || obj instanceof GenericArrayType && TypeUtils.equals(this, (GenericArrayType) obj);
|
return obj == this || obj instanceof GenericArrayType && TypeUtils.equals(this, (GenericArrayType) obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = 67 << 4;
|
int result = 67 << 4;
|
||||||
|
@ -116,37 +148,61 @@ private static final class ParameterizedTypeImpl implements ParameterizedType {
|
||||||
private final Type useOwner;
|
private final Type useOwner;
|
||||||
private final Type[] typeArguments;
|
private final Type[] typeArguments;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param raw type
|
||||||
|
* @param useOwner owner type to use, if any
|
||||||
|
* @param typeArguments formal type arguments
|
||||||
|
*/
|
||||||
private ParameterizedTypeImpl(Class<?> raw, Type useOwner, Type[] typeArguments) {
|
private ParameterizedTypeImpl(Class<?> raw, Type useOwner, Type[] typeArguments) {
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
this.useOwner = useOwner;
|
this.useOwner = useOwner;
|
||||||
this.typeArguments = typeArguments;
|
this.typeArguments = typeArguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Type getRawType() {
|
public Type getRawType() {
|
||||||
return raw;
|
return raw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Type getOwnerType() {
|
public Type getOwnerType() {
|
||||||
return useOwner;
|
return useOwner;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Type[] getActualTypeArguments() {
|
public Type[] getActualTypeArguments() {
|
||||||
return typeArguments.clone();
|
return typeArguments.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return TypeUtils.toString(this);
|
return TypeUtils.toString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj == this || obj instanceof ParameterizedType && TypeUtils.equals(this, ((ParameterizedType) obj));
|
return obj == this || obj instanceof ParameterizedType && TypeUtils.equals(this, ((ParameterizedType) obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = 71 << 4;
|
int result = 71 << 4;
|
||||||
|
@ -169,31 +225,51 @@ private static final class WildcardTypeImpl implements WildcardType {
|
||||||
private final Type[] upperBounds;
|
private final Type[] upperBounds;
|
||||||
private final Type[] lowerBounds;
|
private final Type[] lowerBounds;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param upperBounds of this type
|
||||||
|
* @param lowerBounds of this type
|
||||||
|
*/
|
||||||
private WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
|
private WildcardTypeImpl(Type[] upperBounds, Type[] lowerBounds) {
|
||||||
this.upperBounds = ObjectUtils.defaultIfNull(upperBounds, EMPTY_BOUNDS);
|
this.upperBounds = ObjectUtils.defaultIfNull(upperBounds, EMPTY_BOUNDS);
|
||||||
this.lowerBounds = ObjectUtils.defaultIfNull(lowerBounds, EMPTY_BOUNDS);
|
this.lowerBounds = ObjectUtils.defaultIfNull(lowerBounds, EMPTY_BOUNDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Type[] getUpperBounds() {
|
public Type[] getUpperBounds() {
|
||||||
return upperBounds.clone();
|
return upperBounds.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Type[] getLowerBounds() {
|
public Type[] getLowerBounds() {
|
||||||
return lowerBounds.clone();
|
return lowerBounds.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return TypeUtils.toString(this);
|
return TypeUtils.toString(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
return obj == this || obj instanceof WildcardType && TypeUtils.equals(this, (WildcardType) obj);
|
return obj == this || obj instanceof WildcardType && TypeUtils.equals(this, (WildcardType) obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = 73 << 8;
|
int result = 73 << 8;
|
||||||
|
@ -406,6 +482,7 @@ private static boolean isAssignable(final Type type, final ParameterizedType toP
|
||||||
* i.e. keep looking until the value found is <em>not</em> a type variable.
|
* i.e. keep looking until the value found is <em>not</em> a type variable.
|
||||||
* @param var the type variable to look up
|
* @param var the type variable to look up
|
||||||
* @param typeVarAssigns the map used for the look up
|
* @param typeVarAssigns the map used for the look up
|
||||||
|
* @return Type or {@code null} if some variable was not in the map
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
*/
|
*/
|
||||||
private static Type unrollVariableAssignments(TypeVariable<?> var, final Map<TypeVariable<?>, Type> typeVarAssigns) {
|
private static Type unrollVariableAssignments(TypeVariable<?> var, final Map<TypeVariable<?>, Type> typeVarAssigns) {
|
||||||
|
@ -1430,6 +1507,12 @@ public static final ParameterizedType parameterizeWithOwner(final Type owner, fi
|
||||||
return parameterizeWithOwner(owner, raw, extractTypeArgumentsFrom(typeArgMappings, raw.getTypeParameters()));
|
return parameterizeWithOwner(owner, raw, extractTypeArgumentsFrom(typeArgMappings, raw.getTypeParameters()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper method to establish the formal parameters for a parameterized type.
|
||||||
|
* @param mappings map containing the assignements
|
||||||
|
* @param variables expected map keys
|
||||||
|
* @return array of map values corresponding to specified keys
|
||||||
|
*/
|
||||||
private static Type[] extractTypeArgumentsFrom(Map<TypeVariable<?>, Type> mappings, TypeVariable<?>[] variables) {
|
private static Type[] extractTypeArgumentsFrom(Map<TypeVariable<?>, Type> mappings, TypeVariable<?>[] variables) {
|
||||||
final Type[] result = new Type[variables.length];
|
final Type[] result = new Type[variables.length];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
Loading…
Reference in New Issue