summaryrefslogtreecommitdiff
path: root/src/main/java/org/mockito/internal/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/mockito/internal/util')
-rw-r--r--src/main/java/org/mockito/internal/util/ConsoleMockitoLogger.java2
-rw-r--r--src/main/java/org/mockito/internal/util/reflection/GenericMetadataSupport.java102
2 files changed, 31 insertions, 73 deletions
diff --git a/src/main/java/org/mockito/internal/util/ConsoleMockitoLogger.java b/src/main/java/org/mockito/internal/util/ConsoleMockitoLogger.java
index 3eb8939..d8df8eb 100644
--- a/src/main/java/org/mockito/internal/util/ConsoleMockitoLogger.java
+++ b/src/main/java/org/mockito/internal/util/ConsoleMockitoLogger.java
@@ -4,8 +4,6 @@
*/
package org.mockito.internal.util;
-import org.mockito.plugins.MockitoLogger;
-
public class ConsoleMockitoLogger implements MockitoLogger {
/* (non-Javadoc)
diff --git a/src/main/java/org/mockito/internal/util/reflection/GenericMetadataSupport.java b/src/main/java/org/mockito/internal/util/reflection/GenericMetadataSupport.java
index 80cbf65..8efd384 100644
--- a/src/main/java/org/mockito/internal/util/reflection/GenericMetadataSupport.java
+++ b/src/main/java/org/mockito/internal/util/reflection/GenericMetadataSupport.java
@@ -8,23 +8,8 @@ package org.mockito.internal.util.reflection;
import org.mockito.exceptions.base.MockitoException;
import org.mockito.internal.util.Checks;
-import java.lang.reflect.GenericArrayType;
-import java.lang.reflect.Method;
-import java.lang.reflect.ParameterizedType;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-import java.lang.reflect.WildcardType;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Queue;
-import java.util.Set;
+import java.lang.reflect.*;
+import java.util.*;
/**
@@ -32,20 +17,20 @@ import java.util.Set;
* and accessible members.
*
* <p>
- * The main idea of this code is to create a Map that will help to resolve return types.
- * In order to actually work with nested generics, this map will have to be passed along new instances
- * as a type context.
+ * The main idea of this code is to create a Map that will help to resolve return types.
+ * In order to actually work with nested generics, this map will have to be passed along new instances
+ * as a type context.
* </p>
*
* <p>
- * Hence :
- * <ul>
- * <li>A new instance representing the metadata is created using the {@link #inferFrom(Type)} method from a real
- * <code>Class</code> or from a <code>ParameterizedType</code>, other types are not yet supported.</li>
+ * Hence :
+ * <ul>
+ * <li>A new instance representing the metadata is created using the {@link #inferFrom(Type)} method from a real
+ * <code>Class</code> or from a <code>ParameterizedType</code>, other types are not yet supported.</li>
*
- * <li>Then from this metadata, we can extract meta-data for a generic return type of a method, using
- * {@link #resolveGenericReturnType(Method)}.</li>
- * </ul>
+ * <li>Then from this metadata, we can extract meta-data for a generic return type of a method, using
+ * {@link #resolveGenericReturnType(Method)}.</li>
+ * </ul>
* </p>
*
* <p>
@@ -112,9 +97,8 @@ public abstract class GenericMetadataSupport {
}
if (type instanceof TypeVariable) {
/*
- * If type is a TypeVariable, then it is needed to gather data elsewhere.
- * Usually TypeVariables are declared on the class definition, such as such
- * as List<E>.
+ * If type is a TypeVariable, then it is needed to gather data elsewhere. Usually TypeVariables are declared
+ * on the class definition, such as such as List<E>.
*/
return extractRawTypeOf(contextualActualTypeParameters.get(type));
}
@@ -132,23 +116,6 @@ public abstract class GenericMetadataSupport {
TypeVariable<?> typeParameter = typeParameters[i];
Type actualTypeArgument = actualTypeArguments[i];
- if (actualTypeArgument instanceof TypeVariable) {
- /*
- * If actualTypeArgument is a TypeVariable, and it is not present in
- * the context map then it is needed to try harder to gather more data
- * from the type argument itself. In some case the type argument do
- * define upper bounds, this allow to look for them if not in the
- * context map.
- */
- registerTypeVariableIfNotPresent((TypeVariable<?>) actualTypeArgument);
-
- // Prevent registration of a cycle of TypeVariables. This can happen when we are processing
- // type parameters in a Method, while we already processed the type parameters of a class.
- if (contextualActualTypeParameters.containsKey(typeParameter)) {
- continue;
- }
- }
-
if (actualTypeArgument instanceof WildcardType) {
contextualActualTypeParameters.put(typeParameter, boundsOf((WildcardType) actualTypeArgument));
} else if (typeParameter != actualTypeArgument) {
@@ -174,7 +141,7 @@ public abstract class GenericMetadataSupport {
/**
* @param typeParameter The TypeVariable parameter
* @return A {@link BoundedType} for easy bound information, if first bound is a TypeVariable
- * then retrieve BoundedType of this TypeVariable
+ * then retrieve BoundedType of this TypeVariable
*/
private BoundedType boundsOf(TypeVariable<?> typeParameter) {
if (typeParameter.getBounds()[0] instanceof TypeVariable) {
@@ -186,17 +153,13 @@ public abstract class GenericMetadataSupport {
/**
* @param wildCard The WildCard type
* @return A {@link BoundedType} for easy bound information, if first bound is a TypeVariable
- * then retrieve BoundedType of this TypeVariable
+ * then retrieve BoundedType of this TypeVariable
*/
private BoundedType boundsOf(WildcardType wildCard) {
/*
* According to JLS(http://docs.oracle.com/javase/specs/jls/se5.0/html/typesValues.html#4.5.1):
- * - Lower and upper can't coexist: (for instance, this is not allowed:
- * <? extends List<String> & super MyInterface>)
- * - Multiple concrete type bounds are not supported (for instance, this is not allowed:
- * <? extends ArrayList<String> & MyInterface>)
- * But the following form is possible where there is a single concrete tyep bound followed by interface type bounds
- * <T extends List<String> & Comparable>
+ * - Lower and upper can't coexist: (for instance, this is not allowed: <? extends List<String> & super MyInterface>)
+ * - Multiple bounds are not supported (for instance, this is not allowed: <? extends List<String> & MyInterface>)
*/
WildCardBoundedType wildCardBoundedType = new WildCardBoundedType(wildCard);
@@ -272,7 +235,7 @@ public abstract class GenericMetadataSupport {
// logger.log("Method '" + method.toGenericString() + "' has return type : " + genericReturnType.getClass().getInterfaces()[0].getSimpleName() + " : " + genericReturnType);
int arity = 0;
- while (genericReturnType instanceof GenericArrayType) {
+ while(genericReturnType instanceof GenericArrayType) {
arity++;
genericReturnType = ((GenericArrayType) genericReturnType).getGenericComponentType();
}
@@ -304,8 +267,8 @@ public abstract class GenericMetadataSupport {
* Create an new instance of {@link GenericMetadataSupport} inferred from a {@link Type}.
*
* <p>
- * At the moment <code>type</code> can only be a {@link Class} or a {@link ParameterizedType}, otherwise
- * it'll throw a {@link MockitoException}.
+ * At the moment <code>type</code> can only be a {@link Class} or a {@link ParameterizedType}, otherwise
+ * it'll throw a {@link MockitoException}.
* </p>
*
* @param type The class from which the {@link GenericMetadataSupport} should be built.
@@ -331,7 +294,7 @@ public abstract class GenericMetadataSupport {
/**
* Generic metadata implementation for {@link Class}.
- * <p>
+ *
* Offer support to retrieve generic metadata on a {@link Class} by reading type parameters and type variables on
* the class and its ancestors and interfaces.
*/
@@ -353,10 +316,10 @@ public abstract class GenericMetadataSupport {
/**
* Generic metadata implementation for "standalone" {@link ParameterizedType}.
- * <p>
+ *
* Offer support to retrieve generic metadata on a {@link ParameterizedType} by reading type variables of
* the related raw type and declared type variable of this parameterized type.
- * <p>
+ *
* This class is not designed to work on ParameterizedType returned by {@link Method#getGenericReturnType()}, as
* the ParameterizedType instance return in these cases could have Type Variables that refer to type declaration(s).
* That's what meant the "standalone" word at the beginning of the Javadoc.
@@ -418,7 +381,6 @@ public abstract class GenericMetadataSupport {
private final TypeVariable<?> typeVariable;
private final TypeVariable<?>[] typeParameters;
private Class<?> rawType;
- private List<Type> extraInterfaces;
public TypeVariableReturnType(GenericMetadataSupport source, TypeVariable<?>[] typeParameters, TypeVariable<?> typeVariable) {
this.typeParameters = typeParameters;
@@ -437,7 +399,7 @@ public abstract class GenericMetadataSupport {
for (Type type : typeVariable.getBounds()) {
registerTypeVariablesOn(type);
}
- registerTypeParametersOn(new TypeVariable[]{typeVariable});
+ registerTypeParametersOn(new TypeVariable[] { typeVariable });
registerTypeVariablesOn(getActualTypeArgumentFor(typeVariable));
}
@@ -451,18 +413,15 @@ public abstract class GenericMetadataSupport {
@Override
public List<Type> extraInterfaces() {
- if (extraInterfaces != null) {
- return extraInterfaces;
- }
Type type = extractActualBoundedTypeOf(typeVariable);
if (type instanceof BoundedType) {
- return extraInterfaces = Arrays.asList(((BoundedType) type).interfaceBounds());
+ return Arrays.asList(((BoundedType) type).interfaceBounds());
}
if (type instanceof ParameterizedType) {
- return extraInterfaces = Collections.singletonList(type);
+ return Collections.singletonList(type);
}
if (type instanceof Class) {
- return extraInterfaces = Collections.emptyList();
+ return Collections.emptyList();
}
throw new MockitoException("Cannot extract extra-interfaces from '" + typeVariable + "' : '" + type + "'");
}
@@ -477,7 +436,7 @@ public abstract class GenericMetadataSupport {
for (Type extraInterface : extraInterfaces) {
Class<?> rawInterface = extractRawTypeOf(extraInterface);
// avoid interface collision with actual raw type (with typevariables, resolution ca be quite aggressive)
- if (!rawType().equals(rawInterface)) {
+ if(!rawType().equals(rawInterface)) {
rawExtraInterfaces.add(rawInterface);
}
}
@@ -549,6 +508,7 @@ public abstract class GenericMetadataSupport {
}
+
/**
* Type representing bounds of a type
*
@@ -571,7 +531,7 @@ public abstract class GenericMetadataSupport {
*
* <p>If upper bounds are declared with SomeClass and additional interfaces, then firstBound will be SomeClass and
* interfacesBound will be an array of the additional interfaces.
- * <p>
+ *
* i.e. <code>SomeClass</code>.
* <pre class="code"><code class="java">
* interface UpperBoundedTypeWithClass<E extends Comparable<E> & Cloneable> {