Skip to content

Commit

Permalink
Added additional tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jan 11, 2016
1 parent 3fc986d commit 25bff26
Show file tree
Hide file tree
Showing 4 changed files with 247 additions and 62 deletions.
174 changes: 112 additions & 62 deletions byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java
Expand Up @@ -4295,47 +4295,47 @@ public Generic resolveFieldType(String fieldTypeDescriptor,
TypePool typePool,
Map<String, List<AnnotationToken>> annotationTokens,
FieldDescription.InDefinedShape definingField) {
return TokenizedGenericType.toErasure(typePool, fieldTypeDescriptor).asGenericType();
return RawAnnotatedType.of(typePool, annotationTokens, fieldTypeDescriptor);
}

@Override
public Generic resolveReturnType(String returnTypeDescriptor,
TypePool typePool,
Map<String, List<AnnotationToken>> annotationTokens,
MethodDescription.InDefinedShape definingMethod) {
return TokenizedGenericType.toErasure(typePool, returnTypeDescriptor).asGenericType();
return RawAnnotatedType.of(typePool, annotationTokens, returnTypeDescriptor);
}

@Override
public TypeList.Generic resolveParameterTypes(List<String> parameterTypeDescriptors,
TypePool typePool,
Map<Integer, Map<String, List<AnnotationToken>>> annotationTokens,
MethodDescription.InDefinedShape definingMethod) {
return new LazyTypeList.Generic(typePool, parameterTypeDescriptors);
return RawAnnotatedType.LazyRawAnnotatedTypeList.of(typePool, annotationTokens, parameterTypeDescriptors);
}

@Override
public TypeList.Generic resolveExceptionTypes(List<String> exceptionTypeDescriptors,
TypePool typePool,
Map<Integer, Map<String, List<AnnotationToken>>> annotationTokens,
MethodDescription.InDefinedShape definingMethod) {
return new LazyTypeList.Generic(typePool, exceptionTypeDescriptors);
return RawAnnotatedType.LazyRawAnnotatedTypeList.of(typePool, annotationTokens, exceptionTypeDescriptors);
}

@Override
public Generic resolveSuperType(String superTypeDescriptor,
TypePool typePool,
Map<String, List<AnnotationToken>> annotationTokens,
TypeDescription definingType) {
return TokenizedGenericType.toErasure(typePool, superTypeDescriptor).asGenericType();
return RawAnnotatedType.of(typePool, annotationTokens, superTypeDescriptor);
}

@Override
public TypeList.Generic resolveInterfaceTypes(List<String> interfaceTypeDescriptors,
TypePool typePool,
Map<Integer, Map<String, List<AnnotationToken>>> annotationTokens,
TypeDescription definingType) {
return new LazyTypeList.Generic(typePool, interfaceTypeDescriptors);
return RawAnnotatedType.LazyRawAnnotatedTypeList.of(typePool, annotationTokens, interfaceTypeDescriptors);
}

@Override
Expand All @@ -4350,6 +4350,112 @@ public TypeList.Generic resolveTypeVariables(TypePool typePool,
public String toString() {
return "TypePool.LazyTypeDescription.GenericTypeToken.Resolution.Raw." + name();
}

protected static class RawAnnotatedType extends Generic.OfNonGenericType {

private static final String EMPTY_TYPE_PATH = "";

private final TypePool typePool;

private final Map<String, List<AnnotationToken>> annotationTokens;

private final String descriptor;

protected RawAnnotatedType(TypePool typePool, Map<String, List<AnnotationToken>> annotationTokens, String descriptor) {
this.typePool = typePool;
this.annotationTokens = annotationTokens;
this.descriptor = descriptor;
}

protected static Generic of(TypePool typePool, Map<String, List<AnnotationToken>> annotationTokens, String descriptor) {
return new RawAnnotatedType(typePool,
annotationTokens == null
? Collections.emptyMap()
: annotationTokens,
descriptor);
}

@Override
public TypeDescription asErasure() {
return TokenizedGenericType.toErasure(typePool, descriptor);
}

@Override
public AnnotationList getDeclaredAnnotations() {
return LazyAnnotationDescription.asListOfNullable(typePool, annotationTokens.get(EMPTY_TYPE_PATH));
}

/**
* A generic type list representing raw types.
*/
protected static class LazyRawAnnotatedTypeList extends TypeList.Generic.AbstractBase {

/**
* The type pool to use for locating types.
*/
private final TypePool typePool;

private final Map<Integer, Map<String, List<AnnotationToken>>> annotationTokens;

/**
* A list of type descriptors that this list represents.
*/
private final List<String> descriptors;

/**
* A generic type list only representing raw types.
*
* @param typePool The type pool to use for locating types.
* @param descriptors A list of type descriptors that this list represents.
*/
protected LazyRawAnnotatedTypeList(TypePool typePool,
Map<Integer, Map<String, List<AnnotationToken>>> annotationTokens,
List<String> descriptors) {
this.typePool = typePool;
this.annotationTokens = annotationTokens;
this.descriptors = descriptors;
}

protected static TypeList.Generic of(TypePool typePool,
Map<Integer, Map<String, List<AnnotationToken>>> annotationTokens,
List<String> descriptors) {
return new LazyRawAnnotatedTypeList(typePool,
annotationTokens == null
? Collections.emptyMap()
: annotationTokens,
descriptors);
}

@Override
public TypeDescription.Generic get(int index) {
return RawAnnotatedType.of(typePool, annotationTokens.get(index), descriptors.get(index));
}

@Override
public int size() {
return descriptors.size();
}

@Override
public TypeList asErasures() {
return new LazyTypeList(typePool, descriptors);
}

@Override
public TypeList.Generic asRawTypes() {
return this;
}

@Override
public int getStackSize() {
int stackSize = 0;
for (String descriptor : descriptors) {
stackSize += Type.getType(descriptor).getSize();
}
return stackSize;
}
}
}
}

/**
Expand Down Expand Up @@ -6630,62 +6736,6 @@ public int getStackSize() {
}
return stackSize;
}

/**
* A generic type list representing raw types.
*/
protected static class Generic extends TypeList.Generic.AbstractBase {

/**
* The type pool to use for locating types.
*/
private final TypePool typePool;

/**
* A list of type descriptors that this list represents.
*/
private final List<String> descriptors;

/**
* A generic type list only representing raw types.
*
* @param typePool The type pool to use for locating types.
* @param descriptors A list of type descriptors that this list represents.
*/
protected Generic(TypePool typePool, List<String> descriptors) {
this.typePool = typePool;
this.descriptors = descriptors;
}

@Override
public TypeDescription.Generic get(int index) {
return TokenizedGenericType.toErasure(typePool, descriptors.get(index)).asGenericType();
}

@Override
public int size() {
return descriptors.size();
}

@Override
public TypeList asErasures() {
return new LazyTypeList(typePool, descriptors);
}

@Override
public TypeList.Generic asRawTypes() {
return this;
}

@Override
public int getStackSize() {
int stackSize = 0;
for (String descriptor : descriptors) {
stackSize += Type.getType(descriptor).getSize();
}
return stackSize;
}
}
}

/**
Expand Down

0 comments on commit 25bff26

Please sign in to comment.