Skip to content

Commit

Permalink
Futher advancement on type annotation support.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jan 11, 2016
1 parent d0ea0f7 commit fec8fb2
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 20 deletions.
48 changes: 35 additions & 13 deletions byte-buddy-dep/src/main/java/net/bytebuddy/pool/TypePool.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4198,6 +4198,11 @@ public TypeDescription asErasure() {
return typeDescription; return typeDescription;
} }


@Override
public Generic getComponentType() {
return UNDEFINED;
}

@Override @Override
public AnnotationList getDeclaredAnnotations() { public AnnotationList getDeclaredAnnotations() {
return LazyAnnotationDescription.asListOfNullable(typePool, annotationTokens.get(typePath)); return LazyAnnotationDescription.asListOfNullable(typePool, annotationTokens.get(typePath));
Expand Down Expand Up @@ -4357,27 +4362,39 @@ protected static class RawAnnotatedType extends Generic.OfNonGenericType {


private final TypePool typePool; private final TypePool typePool;


private final String typePath;

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


private final String descriptor; private final TypeDescription typeDescription;


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


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


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

@Override
public Generic getComponentType() {
TypeDescription componentType = typeDescription.getComponentType();
return componentType == null
? UNDEFINED
: new RawAnnotatedType(typePool, typePath + '[', annotationTokens, componentType); // TODO
} }


@Override @Override
Expand Down Expand Up @@ -4895,7 +4912,7 @@ public Generic toGenericType(TypePool typePool, TypeVariableSource typeVariableS
annotationTokens == null annotationTokens == null
? Collections.emptyMap() ? Collections.emptyMap()
: annotationTokens, : annotationTokens,
name); typePool.describe(name).resolve());
} }


@Override @Override
Expand Down Expand Up @@ -4923,21 +4940,26 @@ protected static class LazyNonGenericType extends Generic.OfNonGenericType {


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


/** private final TypeDescription typeDescription;
* The name of the represented type.
*/
private final String name;


public LazyNonGenericType(TypePool typePool, String typePath, Map<String, List<AnnotationToken>> annotationTokens, String name) { public LazyNonGenericType(TypePool typePool, String typePath, Map<String, List<AnnotationToken>> annotationTokens, TypeDescription typeDescription) {
this.typePool = typePool; this.typePool = typePool;
this.typePath = typePath; this.typePath = typePath;
this.annotationTokens = annotationTokens; this.annotationTokens = annotationTokens;
this.name = name; this.typeDescription = typeDescription;
} }


@Override @Override
public TypeDescription asErasure() { public TypeDescription asErasure() {
return typePool.describe(name).resolve(); return typeDescription;
}

@Override
public Generic getComponentType() {
TypeDescription componentType = typeDescription.getComponentType();
return componentType == null
? UNDEFINED
: new LazyNonGenericType(typePool, typePath + '[', annotationTokens, componentType); // TODO
} }


@Override @Override
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,32 +16,34 @@ protected TypeDescription describe(Class<?> type) {


@Override @Override
protected TypeDescription.Generic describeType(Field field) { protected TypeDescription.Generic describeType(Field field) {
return TypeDefinition.Sort.describe(field.getGenericType()); return TypeDefinition.Sort.describe(field.getGenericType(), TypeDescription.Generic.AnnotationReader.DISPATCHER.resolve(field));
} }


@Override @Override
protected TypeDescription.Generic describeReturnType(Method method) { protected TypeDescription.Generic describeReturnType(Method method) {
return TypeDefinition.Sort.describe(method.getGenericReturnType()); return TypeDefinition.Sort.describe(method.getGenericReturnType(), TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveReturnType(method));
} }


@Override @Override
protected TypeDescription.Generic describeParameterType(Method method, int index) { protected TypeDescription.Generic describeParameterType(Method method, int index) {
return TypeDefinition.Sort.describe(method.getGenericParameterTypes()[index]); return TypeDefinition.Sort.describe(method.getGenericParameterTypes()[index],
TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveParameterType(method, index));
} }


@Override @Override
protected TypeDescription.Generic describeExceptionType(Method method, int index) { protected TypeDescription.Generic describeExceptionType(Method method, int index) {
return TypeDefinition.Sort.describe(method.getGenericExceptionTypes()[index]); return TypeDefinition.Sort.describe(method.getGenericExceptionTypes()[index],
TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveExceptionType(method, index));
} }


@Override @Override
protected TypeDescription.Generic describeSuperType(Class<?> type) { protected TypeDescription.Generic describeSuperType(Class<?> type) {
return TypeDefinition.Sort.describe(type.getGenericSuperclass()); return TypeDefinition.Sort.describe(type.getGenericSuperclass(), TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveSuperType(type));
} }


@Override @Override
protected TypeDescription.Generic describeInterfaceType(Class<?> type, int index) { protected TypeDescription.Generic describeInterfaceType(Class<?> type, int index) {
return TypeDefinition.Sort.describe(type.getGenericInterfaces()[index]); return TypeDefinition.Sort.describe(type.getGenericInterfaces()[index], TypeDescription.Generic.AnnotationReader.DISPATCHER.resolveInterface(type, index));
} }


@Test(expected = IllegalArgumentException.class) @Test(expected = IllegalArgumentException.class)
Expand Down
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.bytebuddy.description.type; package net.bytebuddy.description.type;


import net.bytebuddy.description.field.FieldDescription;
import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.method.MethodDescription;


import java.lang.reflect.Field; import java.lang.reflect.Field;
Expand All @@ -14,7 +15,7 @@ protected TypeDescription describe(Class<?> type) {


@Override @Override
protected TypeDescription.Generic describeType(Field field) { protected TypeDescription.Generic describeType(Field field) {
return TypeDefinition.Sort.describe(field.getGenericType()); return new FieldDescription.ForLoadedField(field).getType();
} }


@Override @Override
Expand Down

0 comments on commit fec8fb2

Please sign in to comment.