Skip to content

Commit

Permalink
Refactored description classes to adapt new type representation hiera…
Browse files Browse the repository at this point in the history
…rchy.
  • Loading branch information
raphw committed Dec 20, 2015
1 parent 7aa0010 commit 70afa52
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 101 deletions.
Expand Up @@ -83,7 +83,7 @@ interface TypeDependant<T extends TypeDependant<?, S>, S extends ByteCodeElement
* @param targetTypeMatcher A matcher to identify types to be replaced by {@link net.bytebuddy.dynamic.TargetType} descriptions.
* @return A token representative of this type dependant.
*/
S asToken(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher);
S asToken(ElementMatcher<? super TypeDescription> targetTypeMatcher);
}

/**
Expand Down
Expand Up @@ -44,11 +44,10 @@ interface InGenericShape extends FieldDescription {
GenericTypeDescription getDeclaringType();
}

// TODO: Remove extends InGenericShape
/**
* Represents a field in its defined shape, i.e. in the form it is defined by a class without its type variables being resolved.
*/
interface InDefinedShape extends FieldDescription, ByteCodeElement.Accessible, InGenericShape {
interface InDefinedShape extends FieldDescription, ByteCodeElement.Accessible {

@Override
TypeDescription getDeclaringType();
Expand Down Expand Up @@ -117,7 +116,7 @@ public FieldDescription.Token asToken() {
}

@Override
public FieldDescription.Token asToken(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public FieldDescription.Token asToken(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
return new FieldDescription.Token(getName(),
getModifiers(),
getType().accept(new GenericTypeDescription.Visitor.Substitutor.ForDetachment(targetTypeMatcher)),
Expand Down
Expand Up @@ -35,7 +35,7 @@ public interface FieldList<T extends FieldDescription> extends FilterableList<T,
* @param targetTypeMatcher A matcher that indicates type substitution.
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher);
ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher);

/**
* Returns this list of these field descriptions resolved to their defined shape.
Expand All @@ -57,7 +57,7 @@ public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList() {
}

@Override
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
List<FieldDescription.Token> tokens = new ArrayList<FieldDescription.Token>(size());
for (FieldDescription fieldDescription : this) {
tokens.add(fieldDescription.asToken(targetTypeMatcher));
Expand Down Expand Up @@ -237,22 +237,22 @@ public int size() {
/**
* An implementation of an empty field list.
*/
class Empty extends FilterableList.Empty<FieldDescription.InDefinedShape, FieldList<FieldDescription.InDefinedShape>>
implements FieldList<FieldDescription.InDefinedShape> {
class Empty<S extends FieldDescription> extends FilterableList.Empty<S, FieldList<S>> implements FieldList<S> {

@Override
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList() {
return new ByteCodeElement.Token.TokenList<FieldDescription.Token>(Collections.<FieldDescription.Token>emptyList());
}

@Override
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
return new ByteCodeElement.Token.TokenList<FieldDescription.Token>(Collections.<FieldDescription.Token>emptyList());
}

@Override
@SuppressWarnings("unchecked")
public FieldList<FieldDescription.InDefinedShape> asDefined() {
return this;
return (FieldList<FieldDescription.InDefinedShape>) this;
}
}
}
Expand Up @@ -247,11 +247,10 @@ interface InGenericShape extends MethodDescription {
ParameterList<? extends ParameterDescription.InGenericShape> getParameters();
}

// TODO: Remove extends InGenericShape
/**
* Represents a method in its defined shape, i.e. in the form it is defined by a class without its type variables being resolved.
*/
interface InDefinedShape extends MethodDescription, ByteCodeElement.Accessible, InGenericShape {
interface InDefinedShape extends MethodDescription, ByteCodeElement.Accessible {

@Override
TypeDescription getDeclaringType();
Expand Down Expand Up @@ -573,7 +572,7 @@ public Token asToken() {
}

@Override
public Token asToken(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public Token asToken(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
GenericTypeDescription.Visitor<GenericTypeDescription> visitor = new GenericTypeDescription.Visitor.Substitutor.ForDetachment(targetTypeMatcher);
return new Token(getInternalName(),
getModifiers(),
Expand Down Expand Up @@ -1074,7 +1073,7 @@ public GenericTypeDescription getReturnType() {

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

@Override
Expand Down Expand Up @@ -1226,7 +1225,7 @@ public GenericTypeDescription onParameterizedType(GenericTypeDescription paramet
return new GenericTypeDescription.ForParameterizedType.Latent(parameterizedType.asErasure(),
parameters,
ownerType == null
? TypeDescription.UNDEFINED
? GenericTypeDescription.UNDEFINED
: ownerType.accept(this));
}

Expand Down
Expand Up @@ -36,7 +36,7 @@ public interface MethodList<T extends MethodDescription> extends FilterableList<
* @param targetTypeMatcher A matcher that indicates type substitution.
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher);
ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher);

/**
* Returns this list of these method descriptions resolved to their defined shape.
Expand All @@ -63,7 +63,7 @@ public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList() {
}

@Override
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
List<MethodDescription.Token> tokens = new ArrayList<MethodDescription.Token>(size());
for (MethodDescription fieldDescription : this) {
tokens.add(fieldDescription.asToken(targetTypeMatcher));
Expand Down Expand Up @@ -261,22 +261,22 @@ public int size() {
/**
* An implementation of an empty method list.
*/
class Empty extends FilterableList.Empty<MethodDescription.InDefinedShape, MethodList<MethodDescription.InDefinedShape>>
implements MethodList<MethodDescription.InDefinedShape> {
class Empty<S extends MethodDescription> extends FilterableList.Empty<S, MethodList<S>> implements MethodList<S> {

@Override
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList() {
return new ByteCodeElement.Token.TokenList<MethodDescription.Token>(Collections.<MethodDescription.Token>emptyList());
}

@Override
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
return new ByteCodeElement.Token.TokenList<MethodDescription.Token>(Collections.<MethodDescription.Token>emptyList());
}

@Override
@SuppressWarnings("unchecked")
public MethodList<MethodDescription.InDefinedShape> asDefined() {
return this;
return (MethodList<MethodDescription.InDefinedShape>) this;
}
}
}
Expand Up @@ -87,11 +87,10 @@ interface InGenericShape extends ParameterDescription {
MethodDescription.InGenericShape getDeclaringMethod();
}

// TODO: Remove extends InGenericShape
/**
* Represents a parameter in its defined shape, i.e. in the form it is defined by a class without its type variables being resolved.
*/
interface InDefinedShape extends ParameterDescription, InGenericShape {
interface InDefinedShape extends ParameterDescription {

@Override
MethodDescription.InDefinedShape getDeclaringMethod();
Expand Down Expand Up @@ -153,7 +152,7 @@ public Token asToken() {
}

@Override
public Token asToken(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public Token asToken(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
return new Token(getType().accept(new GenericTypeDescription.Visitor.Substitutor.ForDetachment(targetTypeMatcher)),
getDeclaredAnnotations(),
isNamed()
Expand Down Expand Up @@ -332,7 +331,7 @@ protected interface Dispatcher {
List<Annotation> getDeclaredAnnotations(Object parameter);

/**
* Returns the given parameter's declaring exectuable, i.e, method or constructor.
* Returns the given parameter's declaring executable, i.e, method or constructor.
*
* @param parameter The parameter to introspect.
* @return The parameter's declaring executable.
Expand Down Expand Up @@ -565,7 +564,7 @@ protected OfLegacyVmMethod(Method method, int index, Class<?> parameterType, Ann

@Override
public GenericTypeDescription getType() {
return new TypeDescription.LazyProjection.OfLoadedParameter.OfLegacyVmMethod(method, index, parameterType);
return new GenericTypeDescription.LazyProjection.OfLoadedParameter.OfLegacyVmMethod(method, index, parameterType);
}

@Override
Expand Down Expand Up @@ -637,7 +636,7 @@ protected OfLegacyVmConstructor(Constructor<?> constructor, int index, Class<?>

@Override
public GenericTypeDescription getType() {
return new TypeDescription.LazyProjection.OfLoadedParameter.OfLegacyVmConstructor(constructor, index, parameterType);
return new GenericTypeDescription.LazyProjection.OfLoadedParameter.OfLegacyVmConstructor(constructor, index, parameterType);
}

@Override
Expand Down
@@ -1,6 +1,7 @@
package net.bytebuddy.description.method;

import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.generic.GenericTypeDescription;
import net.bytebuddy.description.type.generic.GenericTypeList;
import net.bytebuddy.matcher.ElementMatcher;
Expand Down Expand Up @@ -44,7 +45,7 @@ public interface ParameterList<T extends ParameterDescription> extends Filterabl
* @param targetTypeMatcher A matcher that indicates type substitution.
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher);
ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher);

/**
* Returns this list of these parameter descriptions resolved to their defined shape.
Expand Down Expand Up @@ -83,7 +84,7 @@ public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList()
}

@Override
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
List<ParameterDescription.Token> tokens = new ArrayList<ParameterDescription.Token>(size());
for (ParameterDescription parameterDescription : this) {
tokens.add(parameterDescription.asToken(targetTypeMatcher));
Expand Down Expand Up @@ -572,8 +573,7 @@ public int size() {
/**
* An empty list of parameters.
*/
class Empty extends FilterableList.Empty<ParameterDescription.InDefinedShape, ParameterList<ParameterDescription.InDefinedShape>>
implements ParameterList<ParameterDescription.InDefinedShape> {
class Empty<S extends ParameterDescription> extends FilterableList.Empty<S, ParameterList<S>> implements ParameterList<S> {

@Override
public boolean hasExplicitMetaData() {
Expand All @@ -591,13 +591,14 @@ public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList()
}

@Override
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) {
return new ByteCodeElement.Token.TokenList<ParameterDescription.Token>(Collections.<ParameterDescription.Token>emptyList());
}

@Override
@SuppressWarnings("unchecked")
public ParameterList<ParameterDescription.InDefinedShape> asDefined() {
return this;
return (ParameterList<ParameterDescription.InDefinedShape>) this;
}
}
}
Expand Up @@ -1017,12 +1017,12 @@ public boolean isMemberClass() {

@Override
public FieldList<FieldDescription.InDefinedShape> getDeclaredFields() {
return new FieldList.Empty();
return new FieldList.Empty<FieldDescription.InDefinedShape>();
}

@Override
public MethodList<MethodDescription.InDefinedShape> getDeclaredMethods() {
return new MethodList.Empty();
return new MethodList.Empty<MethodDescription.InDefinedShape>();
}

@Override
Expand Down Expand Up @@ -1265,12 +1265,12 @@ public TypeList getDeclaredTypes() {

@Override
public FieldList<FieldDescription.InDefinedShape> getDeclaredFields() {
return new FieldList.Empty();
return new FieldList.Empty<FieldDescription.InDefinedShape>();
}

@Override
public MethodList<MethodDescription.InDefinedShape> getDeclaredMethods() {
return new MethodList.Empty();
return new MethodList.Empty<MethodDescription.InDefinedShape>();
}

@Override
Expand Down
Expand Up @@ -36,22 +36,6 @@ public interface TypeList extends FilterableList<TypeDescription, TypeList> {
*/
int getStackSize();

/**
* Represents this list of types into a list of generic types. Invoking this method does not transform types, i.e.
* no generic information is attached.
*
* @return This list of types represented as generic types.
*/
GenericTypeList asGenericTypes();

/**
* Transforms the types of this list by applying the supplied visitor.
*
* @param visitor The visitor to apply to each type.
* @return This type list with all types transformed by the supplied visitor.
*/
GenericTypeList accept(GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor);

/**
* An abstract base implementation of a type list.
*/
Expand All @@ -61,15 +45,6 @@ abstract class AbstractBase extends FilterableList.AbstractBase<TypeDescription,
protected TypeList wrap(List<TypeDescription> values) {
return new Explicit(values);
}

@Override
public GenericTypeList accept(GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor) {
List<GenericTypeDescription> visited = new ArrayList<GenericTypeDescription>(size());
for (TypeDescription typeDescription : this) {
visited.add(typeDescription.accept(visitor));
}
return new GenericTypeList.Explicit(visited);
}
}

/**
Expand Down Expand Up @@ -126,11 +101,6 @@ public String[] toInternalNames() {
public int getStackSize() {
return StackSize.sizeOf(types);
}

@Override
public GenericTypeList asGenericTypes() {
return new GenericTypeList.ForLoadedTypes(types);
}
}

/**
Expand Down Expand Up @@ -182,11 +152,6 @@ public int getStackSize() {
}
return stackSize;
}

@Override
public GenericTypeList asGenericTypes() {
return new GenericTypeList.Explicit(typeDescriptions);
}
}

/**
Expand All @@ -204,15 +169,5 @@ public String[] toInternalNames() {
public int getStackSize() {
return 0;
}

@Override
public GenericTypeList asGenericTypes() {
return new GenericTypeList.Empty();
}

@Override
public GenericTypeList accept(GenericTypeDescription.Visitor<? extends GenericTypeDescription> visitor) {
return new GenericTypeList.Empty();
}
}
}

0 comments on commit 70afa52

Please sign in to comment.