Skip to content

Commit

Permalink
Added shortcut method for raw type conversion for generic type lists.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Dec 20, 2015
1 parent 70afa52 commit ec885ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
Expand Up @@ -27,6 +27,8 @@ public interface GenericTypeList extends FilterableList<GenericTypeDescription,
*/
TypeList asErasures();

GenericTypeList asRawTypes();

/**
* Transforms the generic types by applying the supplied visitor to each of them.
*
Expand Down Expand Up @@ -78,6 +80,15 @@ public TypeList asErasures() {
}
return new TypeList.Explicit(typeDescriptions);
}

@Override
public GenericTypeList asRawTypes() {
List<GenericTypeDescription> typeDescriptions = new ArrayList<GenericTypeDescription>(size());
for (GenericTypeDescription genericTypeDescription : this) {
typeDescriptions.add(genericTypeDescription.asRawType());
}
return new Explicit(typeDescriptions);
}
}

/**
Expand Down Expand Up @@ -642,6 +653,11 @@ public TypeList asErasures() {
return new TypeList.Empty();
}

@Override
public GenericTypeList asRawTypes() {
return this;
}

@Override
public GenericTypeList accept(GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor) {
return new GenericTypeList.Empty();
Expand Down
Expand Up @@ -795,7 +795,7 @@ public FieldDescription cache(StackManipulation fieldValue, TypeDescription fiel
if (!fieldCacheCanAppendEntries) {
throw new IllegalStateException("Cached values cannot be registered after defining the type initializer for " + instrumentedType);
}
fieldCache = new CacheValueField(instrumentedType, fieldType, suffix, fieldValue.hashCode());
fieldCache = new CacheValueField(instrumentedType, fieldType.asGenericType(), suffix, fieldValue.hashCode());
registeredFieldCacheEntries.put(fieldCacheEntry, fieldCache);
return fieldCache;
}
Expand Down Expand Up @@ -868,7 +868,7 @@ protected static class CacheValueField extends FieldDescription.InDefinedShape.A
/**
* The type of the cache's field.
*/
private final TypeDescription fieldType;
private final GenericTypeDescription fieldType;

/**
* The suffix to use for the cache field's name.
Expand All @@ -888,7 +888,7 @@ protected static class CacheValueField extends FieldDescription.InDefinedShape.A
* @param suffix The suffix to use for the cache field's name.
* @param valueHashCode The hash value of the field's value for creating a unique field name.
*/
protected CacheValueField(TypeDescription instrumentedType, TypeDescription fieldType, String suffix, int valueHashCode) {
protected CacheValueField(TypeDescription instrumentedType, GenericTypeDescription fieldType, String suffix, int valueHashCode) {
this.instrumentedType = instrumentedType;
this.fieldType = fieldType;
this.suffix = suffix;
Expand Down Expand Up @@ -1055,17 +1055,17 @@ protected AccessorMethod(TypeDescription instrumentedType, MethodDescription met

@Override
public GenericTypeDescription getReturnType() {
return methodDescription.getReturnType().asErasure();
return methodDescription.getReturnType().asRawType();
}

@Override
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
return new ParameterList.Explicit.ForTypes(this, methodDescription.getParameters().asTypeList().asErasures());
return new ParameterList.Explicit.ForTypes(this, methodDescription.getParameters().asTypeList().asRawTypes());
}

@Override
public GenericTypeList getExceptionTypes() {
return methodDescription.getExceptionTypes().asErasures().asGenericTypes();
return methodDescription.getExceptionTypes().asRawTypes();
}

@Override
Expand Down Expand Up @@ -1136,12 +1136,12 @@ protected FieldGetter(TypeDescription instrumentedType, FieldDescription fieldDe

@Override
public GenericTypeDescription getReturnType() {
return fieldDescription.getType().asErasure();
return fieldDescription.getType().asRawType();
}

@Override
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
return new ParameterList.Empty();
return new ParameterList.Empty<ParameterDescription.InDefinedShape>();
}

@Override
Expand Down Expand Up @@ -1222,7 +1222,7 @@ public GenericTypeDescription getReturnType() {

@Override
public ParameterList<ParameterDescription.InDefinedShape> getParameters() {
return new ParameterList.Explicit.ForTypes(this, Collections.singletonList(fieldDescription.getType().asErasure()));
return new ParameterList.Explicit.ForTypes(this, Collections.singletonList(fieldDescription.getType().asRawType()));
}

@Override
Expand Down

0 comments on commit ec885ae

Please sign in to comment.