Skip to content

Commit

Permalink
Fixed type variable resolution to be retained for transformed methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 28, 2016
1 parent bb3a37f commit 52a3752
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 92 deletions.
6 changes: 3 additions & 3 deletions byte-buddy-dep/src/main/java/net/bytebuddy/ByteBuddy.java
Expand Up @@ -305,17 +305,17 @@ public <T> DynamicType.Builder<T> subclass(TypeDefinition superType) {
public <T> DynamicType.Builder<T> subclass(TypeDefinition superType, ConstructorStrategy constructorStrategy) { public <T> DynamicType.Builder<T> subclass(TypeDefinition superType, ConstructorStrategy constructorStrategy) {
TypeDescription.Generic actualSuperType; TypeDescription.Generic actualSuperType;
TypeList.Generic interfaceTypes; TypeList.Generic interfaceTypes;
if (superType.isPrimitive() || superType.isArray() || superType.asErasure().isFinal()) { if (superType.isPrimitive() || superType.isArray() || superType.isFinal()) {
throw new IllegalArgumentException("Cannot subclass primitive, array or final types: " + superType); throw new IllegalArgumentException("Cannot subclass primitive, array or final types: " + superType);
} else if (superType.asErasure().isInterface()) { } else if (superType.isInterface()) {
interfaceTypes = new TypeList.Generic.Explicit(superType.asGenericType()); interfaceTypes = new TypeList.Generic.Explicit(superType.asGenericType());
actualSuperType = TypeDescription.Generic.OBJECT; actualSuperType = TypeDescription.Generic.OBJECT;
} else { } else {
interfaceTypes = new TypeList.Generic.Empty(); interfaceTypes = new TypeList.Generic.Empty();
actualSuperType = superType.asGenericType(); actualSuperType = superType.asGenericType();
} }
return new SubclassDynamicTypeBuilder<T>(InstrumentedType.Default.subclass(namingStrategy.subclass(superType.asGenericType()), return new SubclassDynamicTypeBuilder<T>(InstrumentedType.Default.subclass(namingStrategy.subclass(superType.asGenericType()),
ModifierContributor.Resolver.of(Visibility.PUBLIC, TypeManifestation.PLAIN).resolve(superType.asErasure().getModifiers()), ModifierContributor.Resolver.of(Visibility.PUBLIC, TypeManifestation.PLAIN).resolve(superType.getModifiers()),
actualSuperType).withInterfaces(interfaceTypes), actualSuperType).withInterfaces(interfaceTypes),
classFileVersion, classFileVersion,
auxiliaryTypeNamingStrategy, auxiliaryTypeNamingStrategy,
Expand Down
Expand Up @@ -112,7 +112,7 @@ interface OfEnumeration extends OfByteCodeElement {
/** /**
* A modifier reviewable for a {@link net.bytebuddy.description.type.TypeDescription}. * A modifier reviewable for a {@link net.bytebuddy.description.type.TypeDescription}.
*/ */
interface ForTypeDescription extends OfAbstraction, OfEnumeration { interface ForTypeDefinition extends OfAbstraction, OfEnumeration {


/** /**
* Specifies if the modifier described by this object represents the interface flag. * Specifies if the modifier described by this object represents the interface flag.
Expand Down Expand Up @@ -206,7 +206,7 @@ interface ForParameterDescription extends ModifierReviewable {
/** /**
* An abstract base implementation of a {@link ModifierReviewable} class. * An abstract base implementation of a {@link ModifierReviewable} class.
*/ */
abstract class AbstractBase implements ForTypeDescription, ForFieldDescription, ForMethodDescription, ForParameterDescription { abstract class AbstractBase implements ForTypeDefinition, ForFieldDescription, ForMethodDescription, ForParameterDescription {


@Override @Override
public boolean isAbstract() { public boolean isAbstract() {
Expand Down
@@ -1,15 +1,16 @@
package net.bytebuddy.description; package net.bytebuddy.description;


import net.bytebuddy.description.method.MethodDescription; import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDefinition;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.TypeList; import net.bytebuddy.description.type.TypeList;


import static net.bytebuddy.matcher.ElementMatchers.named; import static net.bytebuddy.matcher.ElementMatchers.named;


/** /**
* A type variable source represents a byte code element that can declare type variables. * A type variable source represents a code element that can declare type variables.
*/ */
public interface TypeVariableSource extends ByteCodeElement { public interface TypeVariableSource extends ModifierReviewable.OfAbstraction {


/** /**
* Indicates that a type variable source is undefined. * Indicates that a type variable source is undefined.
Expand Down Expand Up @@ -68,10 +69,10 @@ interface Visitor<T> {
/** /**
* Applies the visitor on a type. * Applies the visitor on a type.
* *
* @param typeDescription The type onto which this visitor is applied. * @param typeDefinition The type onto which this visitor is applied.
* @return The visitor's return value. * @return The visitor's return value.
*/ */
T onType(TypeDescription typeDescription); T onType(TypeDefinition typeDefinition);


/** /**
* Applies the visitor on a method. * Applies the visitor on a method.
Expand All @@ -92,8 +93,8 @@ enum NoOp implements Visitor<TypeVariableSource> {
INSTANCE; INSTANCE;


@Override @Override
public TypeVariableSource onType(TypeDescription typeDescription) { public TypeVariableSource onType(TypeDefinition typeDefinition) {
return typeDescription; return typeDefinition;
} }


@Override @Override
Expand Down
Expand Up @@ -38,6 +38,7 @@
public interface MethodDescription extends TypeVariableSource, public interface MethodDescription extends TypeVariableSource,
ModifierReviewable.ForMethodDescription, ModifierReviewable.ForMethodDescription,
NamedElement.WithGenericName, NamedElement.WithGenericName,
ByteCodeElement,
ByteCodeElement.TypeDependant<MethodDescription.InDefinedShape, MethodDescription.Token> { ByteCodeElement.TypeDependant<MethodDescription.InDefinedShape, MethodDescription.Token> {


/** /**
Expand Down Expand Up @@ -458,7 +459,7 @@ public boolean isVirtual() {


@Override @Override
public boolean isDefaultMethod() { public boolean isDefaultMethod() {
return !isAbstract() && !isBridge() && getDeclaringType().asErasure().isInterface(); return !isAbstract() && !isBridge() && getDeclaringType().isInterface();
} }


@Override @Override
Expand Down Expand Up @@ -648,7 +649,7 @@ private static boolean isAnnotationType(TypeDescription annotationType, Annotati
public TypeVariableSource getEnclosingSource() { public TypeVariableSource getEnclosingSource() {
return isStatic() return isStatic()
? TypeVariableSource.UNDEFINED ? TypeVariableSource.UNDEFINED
: getDeclaringType().asErasure(); : getDeclaringType();
} }


@Override @Override
Expand Down
@@ -1,6 +1,8 @@
package net.bytebuddy.description.type; package net.bytebuddy.description.type;


import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.TypeVariableSource;
import net.bytebuddy.description.field.FieldList; import net.bytebuddy.description.field.FieldList;
import net.bytebuddy.description.method.MethodList; import net.bytebuddy.description.method.MethodList;
import net.bytebuddy.implementation.bytecode.StackSize; import net.bytebuddy.implementation.bytecode.StackSize;
Expand All @@ -12,7 +14,7 @@
/** /**
* Implementations define a type, either as a {@link TypeDescription} or as a {@link TypeDescription.Generic}. * Implementations define a type, either as a {@link TypeDescription} or as a {@link TypeDescription.Generic}.
*/ */
public interface TypeDefinition extends NamedElement, Iterable<TypeDefinition> { public interface TypeDefinition extends NamedElement, TypeVariableSource, ModifierReviewable.ForTypeDefinition, Iterable<TypeDefinition> {


/** /**
* Returns this type definition as a generic type. * Returns this type definition as a generic type.
Expand Down

0 comments on commit 52a3752

Please sign in to comment.