Skip to content

Commit

Permalink
Refactored type declaration to allow for generic types.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Jul 10, 2015
1 parent f99f0ed commit c7c8cd9
Show file tree
Hide file tree
Showing 25 changed files with 558 additions and 42 deletions.
Expand Up @@ -111,7 +111,7 @@ public void testObjectProperties() throws Exception {
public File create() { public File create() {
return folder; return folder;
} }
}).applyMutable(); }).applyCustom();
ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.class).apply(); ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.class).apply();
ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.Conversion.class).create(new ObjectPropertyAssertion.Creator<DexFile>() { ObjectPropertyAssertion.of(AndroidClassLoadingStrategy.DexProcessor.ForSdkCompiler.Conversion.class).create(new ObjectPropertyAssertion.Creator<DexFile>() {
@Override @Override
Expand Down
@@ -1,6 +1,6 @@
package net.bytebuddy.description; package net.bytebuddy.description;


import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.generic.GenericTypeDescription;


/** /**
* This interface represents all elements that can be declared within a type, i.e. other types and type members. * This interface represents all elements that can be declared within a type, i.e. other types and type members.
Expand All @@ -12,5 +12,5 @@ public interface DeclaredByType {
* *
* @return The declaring type or {@code null} if no such type exists. * @return The declaring type or {@code null} if no such type exists.
*/ */
TypeDescription getDeclaringType(); GenericTypeDescription getDeclaringType();
} }
Expand Up @@ -21,10 +21,29 @@
*/ */
public interface FieldDescription extends ByteCodeElement, NamedElement.WithGenericName { public interface FieldDescription extends ByteCodeElement, NamedElement.WithGenericName {


/**
* Returns the type of the described field.
*
* @return The type of the described field.
*/
GenericTypeDescription getType(); GenericTypeDescription getType();


/**
* Transforms this field description into a token. For the resulting token, all type variables within the scope
* of this field's type are detached from their declaration context.
*
* @return A token representing this field.
*/
Token asToken(); Token asToken();


/**
* Transforms this field description into a token. For the resulting token, all type variables within the scope
* of this field's type are detached from their declaration context.
*
* @param targetTypeMatcher A matcher that is applied to the field type for replacing any matched
* type by {@link net.bytebuddy.dynamic.TargetType}.
* @return A token representing this field.
*/
Token asToken(ElementMatcher<? super TypeDescription> targetTypeMatcher); Token asToken(ElementMatcher<? super TypeDescription> targetTypeMatcher);


/** /**
Expand Down Expand Up @@ -236,12 +255,27 @@ public int getModifiers() {
} }
} }


/**
* A field description that represents a given field but with a substituted field type.
*/
class TypeSubstituting extends AbstractFieldDescription { class TypeSubstituting extends AbstractFieldDescription {


/**
* The represented field.
*/
private final FieldDescription fieldDescription; private final FieldDescription fieldDescription;


/**
* A visitor that is applied to the field type.
*/
private final GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor; private final GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor;


/**
* Creates a field description with a substituted field type.
*
* @param fieldDescription The represented field.
* @param visitor A visitor that is applied to the field type.
*/
public TypeSubstituting(FieldDescription fieldDescription, GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor) { public TypeSubstituting(FieldDescription fieldDescription, GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor) {
this.fieldDescription = fieldDescription; this.fieldDescription = fieldDescription;
this.visitor = visitor; this.visitor = visitor;
Expand Down Expand Up @@ -273,16 +307,40 @@ public String getName() {
} }
} }


/**
* A token that represents a field's shape. A field token is equal to another token when the other field
* tokens's name is equal to this token.
*/
class Token implements ByteCodeElement.Token<Token> { class Token implements ByteCodeElement.Token<Token> {


/**
* The name of the represented field.
*/
private final String name; private final String name;


/**
* The modifiers of the represented field.
*/
private final int modifiers; private final int modifiers;


/**
* The type of the represented field.
*/
private final GenericTypeDescription type; private final GenericTypeDescription type;


/**
* The annotations of the represented field.
*/
private final List<? extends AnnotationDescription> annotations; private final List<? extends AnnotationDescription> annotations;


/**
* Creates a new field token.
*
* @param name The name of the represented field.
* @param modifiers The modifiers of the represented field.
* @param type The type of the represented field.
* @param annotations The annotations of the represented field.
*/
public Token(String name, public Token(String name,
int modifiers, int modifiers,
GenericTypeDescription type, GenericTypeDescription type,
Expand All @@ -293,18 +351,38 @@ public Token(String name,
this.annotations = annotations; this.annotations = annotations;
} }


/**
* Returns the name of the represented field.
*
* @return The name of the represented field.
*/
public String getName() { public String getName() {
return name; return name;
} }


/**
* Returns the type of the represented field.
*
* @return The type of the represented field.
*/
public GenericTypeDescription getType() { public GenericTypeDescription getType() {
return type; return type;
} }


/**
* Returns the modifiers of the represented field.
*
* @return The modifiers of the represented field.
*/
public int getModifiers() { public int getModifiers() {
return modifiers; return modifiers;
} }


/**
* Returns the annotations of the represented field.
*
* @return The annotations of the represented field.
*/
public AnnotationList getAnnotations() { public AnnotationList getAnnotations() {
return new AnnotationList.Explicit(annotations); return new AnnotationList.Explicit(annotations);
} }
Expand Down

0 comments on commit c7c8cd9

Please sign in to comment.