mockit.internal.classGeneration.MockedTypeInfo Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmockit Show documentation
Show all versions of jmockit Show documentation
JMockit is a Java toolkit for automated developer testing.
It contains APIs for the creation of the objects to be tested, for mocking dependencies, and for faking external
APIs; JUnit (4 & 5) and TestNG test runners are supported.
It also contains an advanced code coverage tool.
/*
* Copyright (c) 2006 Rogério Liesenfeld
* This file is subject to the terms of the MIT license (see LICENSE.txt).
*/
package mockit.internal.classGeneration;
import java.lang.reflect.*;
import javax.annotation.*;
import mockit.internal.reflection.*;
import mockit.internal.util.*;
public final class MockedTypeInfo
{
@Nonnull public final GenericTypeReflection genericTypeMap;
@Nonnull public final String implementationSignature;
public MockedTypeInfo(@Nonnull Type mockedType)
{
Class mockedClass = Utilities.getClassType(mockedType);
genericTypeMap = new GenericTypeReflection(mockedClass, mockedType);
String signature = getGenericClassSignature(mockedType);
String classDesc = mockedClass.getName().replace('.', '/');
implementationSignature = 'L' + classDesc + signature;
}
@Nonnull
private static String getGenericClassSignature(@Nonnull Type mockedType)
{
StringBuilder signature = new StringBuilder(100);
if (mockedType instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) mockedType;
Type[] typeArguments = parameterizedType.getActualTypeArguments();
if (typeArguments.length > 0) {
signature.append('<');
for (Type typeArg : typeArguments) {
if (typeArg instanceof Class) {
Class classArg = (Class) typeArg;
signature.append('L').append(classArg.getName().replace('.', '/')).append(';');
}
else {
signature.append('*');
}
}
signature.append('>');
}
}
signature.append(';');
return signature.toString();
}
}