Skip to content

Commit

Permalink
Removed possibility of non-detached tokens to streamline API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Jan 6, 2016
1 parent b2153a6 commit f417ec9
Show file tree
Hide file tree
Showing 40 changed files with 377 additions and 262 deletions.
Expand Up @@ -69,21 +69,14 @@ interface TypeDependant<T extends TypeDependant<?, S>, S extends ByteCodeElement
*/
T asDefined();

/**
* Returns a token representative of this type dependant.
*
* @return A token representative of this type dependant.
*/
S asToken();

/**
* Returns a token representative of this type dependant. All types that are matched by the supplied matcher are replaced by
* {@link net.bytebuddy.dynamic.TargetType} descriptions.
*
* @param targetTypeMatcher A matcher to identify types to be replaced by {@link net.bytebuddy.dynamic.TargetType} descriptions.
* @param matcher 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 TypeDescription.Generic> targetTypeMatcher);
S asToken(ElementMatcher<? super TypeDescription> matcher);
}

/**
Expand Down
Expand Up @@ -15,8 +15,6 @@
import java.util.Collections;
import java.util.List;

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

/**
* Implementations of this interface describe a Java field. Implementations of this interface must provide meaningful
* {@code equal(Object)} and {@code hashCode()} implementations.
Expand Down Expand Up @@ -108,12 +106,7 @@ public boolean isVisibleTo(TypeDescription typeDescription) {
}

@Override
public FieldDescription.Token asToken() {
return asToken(none());
}

@Override
public FieldDescription.Token asToken(ElementMatcher<? super TypeDescription.Generic> matcher) {
public FieldDescription.Token asToken(ElementMatcher<? super TypeDescription> matcher) {
return new FieldDescription.Token(getName(),
getModifiers(),
getType().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)),
Expand Down
Expand Up @@ -10,30 +10,21 @@
import java.util.Arrays;
import java.util.List;

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

/**
* Implementations represent a list of field descriptions.
*
* @param <T> The type of field descriptions represented by this list.
*/
public interface FieldList<T extends FieldDescription> extends FilterableList<T, FieldList<T>> {

/**
* Transforms the list of field descriptions into a list of detached tokens.
*
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList();

/**
* Transforms the list of field descriptions into a list of detached tokens. All types that are matched by the provided
* target type matcher are substituted by {@link net.bytebuddy.dynamic.TargetType}.
*
* @param matcher A matcher that indicates type substitution.
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher);
ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher);

/**
* Returns this list of these field descriptions resolved to their defined shape.
Expand All @@ -50,12 +41,7 @@ public interface FieldList<T extends FieldDescription> extends FilterableList<T,
abstract class AbstractBase<S extends FieldDescription> extends FilterableList.AbstractBase<S, FieldList<S>> implements FieldList<S> {

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

@Override
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher) {
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
List<FieldDescription.Token> tokens = new ArrayList<FieldDescription.Token>(size());
for (FieldDescription fieldDescription : this) {
tokens.add(fieldDescription.asToken(matcher));
Expand Down Expand Up @@ -260,12 +246,7 @@ public int size() {
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>();
}

@Override
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher) {
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
return new ByteCodeElement.Token.TokenList<FieldDescription.Token>();
}

Expand Down
Expand Up @@ -572,15 +572,10 @@ public <T> T accept(TypeVariableSource.Visitor<T> visitor) {
}

@Override
public Token asToken() {
return asToken(none());
}

@Override
public Token asToken(ElementMatcher<? super TypeDescription.Generic> matcher) {
public Token asToken(ElementMatcher<? super TypeDescription> matcher) {
return new Token(getInternalName(),
getModifiers(),
getTypeVariables().asTokenList(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)),
getTypeVariables().asTokenList(matcher),
getReturnType().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)),
getParameters().asTokenList(matcher),
getExceptionTypes().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)),
Expand Down Expand Up @@ -970,7 +965,7 @@ public Latent(TypeDescription declaringType, Token token) {
this(declaringType,
token.getName(),
token.getModifiers(),
token.getTypeVariables(),
token.getTypeVariableTokens(),
token.getReturnType(),
token.getParameterTokens(),
token.getExceptionTypes(),
Expand Down Expand Up @@ -1454,7 +1449,7 @@ public int getModifiers() {
*
* @return A a list of tokens representing the method's type variables.
*/
public TokenList<TypeVariableToken> getTypeVariables() {
public TokenList<TypeVariableToken> getTypeVariableTokens() {
return new TokenList<TypeVariableToken>(typeVariables);
}

Expand Down Expand Up @@ -1507,7 +1502,7 @@ public Object getDefaultValue() {
public Token accept(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor) {
return new Token(getName(),
getModifiers(),
getTypeVariables().accept(visitor),
getTypeVariableTokens().accept(visitor),
getReturnType().accept(visitor),
getParameterTokens().accept(visitor),
getExceptionTypes().accept(visitor),
Expand Down
Expand Up @@ -11,30 +11,21 @@
import java.util.Arrays;
import java.util.List;

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

/**
* Implementations represent a list of method descriptions.
*
* @param <T> The type of method descriptions represented by this list.
*/
public interface MethodList<T extends MethodDescription> extends FilterableList<T, MethodList<T>> {

/**
* Transforms the list of method descriptions into a list of detached tokens.
*
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList();

/**
* Transforms the list of method descriptions into a list of detached tokens. All types that are matched by the provided
* target type matcher are substituted by {@link net.bytebuddy.dynamic.TargetType}.
*
* @param matcher A matcher that indicates type substitution.
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher);
ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher);

/**
* Returns this list of these method descriptions resolved to their defined shape.
Expand All @@ -56,12 +47,7 @@ protected MethodList<S> wrap(List<S> values) {
}

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

@Override
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher) {
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
List<MethodDescription.Token> tokens = new ArrayList<MethodDescription.Token>(size());
for (MethodDescription fieldDescription : this) {
tokens.add(fieldDescription.asToken(matcher));
Expand Down Expand Up @@ -284,12 +270,7 @@ public int size() {
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>();
}

@Override
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher) {
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
return new ByteCodeElement.Token.TokenList<MethodDescription.Token>();
}

Expand Down
Expand Up @@ -18,8 +18,6 @@
import java.util.Collections;
import java.util.List;

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

/**
* Description of the parameter of a Java method or constructor.
*/
Expand Down Expand Up @@ -146,12 +144,7 @@ public int getOffset() {
}

@Override
public Token asToken() {
return asToken(none());
}

@Override
public Token asToken(ElementMatcher<? super TypeDescription.Generic> matcher) {
public Token asToken(ElementMatcher<? super TypeDescription> matcher) {
return new Token(getType().accept(new TypeDescription.Generic.Visitor.Substitutor.ForDetachment(matcher)),
getDeclaredAnnotations(),
isNamed()
Expand Down
Expand Up @@ -15,8 +15,6 @@
import java.util.Arrays;
import java.util.List;

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

/**
* Represents a list of parameters of a method or a constructor.
*
Expand All @@ -31,21 +29,14 @@ public interface ParameterList<T extends ParameterDescription> extends Filterabl
*/
TypeList.Generic asTypeList();

/**
* Transforms the list of parameter descriptions into a list of detached tokens.
*
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList();

/**
* Transforms the list of parameter descriptions into a list of detached tokens. All types that are matched by the provided
* target type matcher are substituted by {@link net.bytebuddy.dynamic.TargetType}.
*
* @param targetTypeMatcher A matcher that indicates type substitution.
* @return The transformed token list.
*/
ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> targetTypeMatcher);
ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher);

/**
* Returns this list of these parameter descriptions resolved to their defined shape.
Expand Down Expand Up @@ -79,12 +70,7 @@ public boolean hasExplicitMetaData() {
}

@Override
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList() {
return asTokenList(none());
}

@Override
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher) {
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
List<ParameterDescription.Token> tokens = new ArrayList<ParameterDescription.Token>(size());
for (ParameterDescription parameterDescription : this) {
tokens.add(parameterDescription.asToken(matcher));
Expand Down Expand Up @@ -617,12 +603,7 @@ public TypeList.Generic asTypeList() {
}

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

@Override
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription.Generic> matcher) {
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
return new ByteCodeElement.Token.TokenList<ParameterDescription.Token>();
}

Expand Down
Expand Up @@ -968,14 +968,14 @@ public static class ForDetachment extends Substitutor {
/**
* A type matcher for identifying the declaring type.
*/
private final ElementMatcher<? super TypeDescription.Generic> typeMatcher;
private final ElementMatcher<? super TypeDescription> typeMatcher;

/**
* Creates a visitor for detaching a type.
*
* @param typeMatcher A type matcher for identifying the declaring type.
*/
public ForDetachment(ElementMatcher<? super TypeDescription.Generic> typeMatcher) {
public ForDetachment(ElementMatcher<? super TypeDescription> typeMatcher) {
this.typeMatcher = typeMatcher;
}

Expand All @@ -996,7 +996,7 @@ public Generic onTypeVariable(Generic typeVariable) {

@Override
protected Generic onSimpleType(Generic typeDescription) {
return typeMatcher.matches(typeDescription)
return typeMatcher.matches(typeDescription.asErasure())
? TargetType.GENERIC_DESCRIPTION
: typeDescription;
}
Expand Down
Expand Up @@ -7,6 +7,7 @@
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.method.ParameterDescription;
import net.bytebuddy.implementation.bytecode.StackSize;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.FilterableList;
import org.objectweb.asm.Type;

Expand Down Expand Up @@ -211,15 +212,15 @@ interface Generic extends FilterableList<TypeDescription.Generic, Generic> {
* @param visitor The visitor to use for detaching the type variable's bounds.
* @return A list of tokens representing the type variables contained in this list.
*/
ByteCodeElement.Token.TokenList<TypeVariableToken> asTokenList(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor);
ByteCodeElement.Token.TokenList<TypeVariableToken> asTokenList(ElementMatcher<? super TypeDescription> visitor);

/**
* Transforms the generic types by applying the supplied visitor to each of them.
*
* @param visitor The visitor to apply to each type.
* @return A list of the types returned by the supplied visitor.
*/
Generic accept(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor);
Generic accept(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> matcher);

/**
* Returns the sum of the size of all types contained in this list.
Expand Down Expand Up @@ -248,10 +249,10 @@ public Generic accept(TypeDescription.Generic.Visitor<? extends TypeDescription.
}

@Override
public ByteCodeElement.Token.TokenList<TypeVariableToken> asTokenList(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor) {
public ByteCodeElement.Token.TokenList<TypeVariableToken> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
List<TypeVariableToken> tokens = new ArrayList<TypeVariableToken>(size());
for (TypeDescription.Generic typeVariable : this) {
tokens.add(TypeVariableToken.of(typeVariable, visitor));
tokens.add(TypeVariableToken.of(typeVariable, matcher));
}
return new ByteCodeElement.Token.TokenList<TypeVariableToken>(tokens);
}
Expand Down Expand Up @@ -547,7 +548,7 @@ protected AttachedTypeVariable(TypeVariableSource typeVariableSource,

@Override
public Generic getUpperBounds() {
return typeVariableToken.getUpperBounds().accept(visitor);
return typeVariableToken.getBounds().accept(visitor);
}

@Override
Expand Down Expand Up @@ -830,7 +831,7 @@ public Generic accept(TypeDescription.Generic.Visitor<? extends TypeDescription.
}

@Override
public ByteCodeElement.Token.TokenList<TypeVariableToken> asTokenList(TypeDescription.Generic.Visitor<? extends TypeDescription.Generic> visitor) {
public ByteCodeElement.Token.TokenList<TypeVariableToken> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
return new ByteCodeElement.Token.TokenList<TypeVariableToken>();
}

Expand Down

0 comments on commit f417ec9

Please sign in to comment.