Skip to content

Commit

Permalink
Refactored types for elements that are defined within a Java class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Jul 24, 2015
1 parent 1a3acba commit 7018097
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 87 deletions.
Expand Up @@ -3,6 +3,7 @@
import net.bytebuddy.description.annotation.AnnotatedCodeElement; import net.bytebuddy.description.annotation.AnnotatedCodeElement;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.description.type.generic.GenericTypeDescription; import net.bytebuddy.description.type.generic.GenericTypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import net.bytebuddy.matcher.FilterableList; import net.bytebuddy.matcher.FilterableList;


import java.util.ArrayList; import java.util.ArrayList;
Expand Down Expand Up @@ -43,6 +44,15 @@ public interface ByteCodeElement extends NamedElement.WithRuntimeName, ModifierR
*/ */
boolean isVisibleTo(TypeDescription typeDescription); boolean isVisibleTo(TypeDescription typeDescription);


interface TypeDependant<T extends TypeDependant<T, S>, S extends ByteCodeElement.Token<S>> {

T asDefined();

S asToken();

S asToken(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher);
}

/** /**
* Representation of a tokenized, detached byte code element. * Representation of a tokenized, detached byte code element.
* *
Expand Down Expand Up @@ -109,9 +119,4 @@ public int size() {
} }
} }
} }

interface Member<T extends Member<T>> extends ByteCodeElement {

T asDefined();
}
} }

This file was deleted.

Expand Up @@ -3,7 +3,6 @@
import net.bytebuddy.description.ByteCodeElement; import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable; import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.TypeDefinable;
import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList; import net.bytebuddy.description.annotation.AnnotationList;
import net.bytebuddy.description.type.TypeDescription; import net.bytebuddy.description.type.TypeDescription;
Expand All @@ -25,7 +24,7 @@
*/ */
public interface FieldDescription extends ByteCodeElement, public interface FieldDescription extends ByteCodeElement,
NamedElement.WithGenericName, NamedElement.WithGenericName,
TypeDefinable<FieldDescription, FieldDescription.InDefinedShape> { ByteCodeElement.TypeDependant<FieldDescription.InDefinedShape, FieldDescription.Token> {


/** /**
* Returns the type of the described field. * Returns the type of the described field.
Expand All @@ -34,24 +33,6 @@ public interface FieldDescription extends ByteCodeElement,
*/ */
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();

/**
* 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);

interface InDefinedShape extends FieldDescription { interface InDefinedShape extends FieldDescription {


@Override @Override
Expand Down Expand Up @@ -114,7 +95,7 @@ public FieldDescription.Token asToken() {
} }


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


FieldList<FieldDescription.InDefinedShape> asDefined(); FieldList<FieldDescription.InDefinedShape> asDefined();


Expand All @@ -48,7 +48,7 @@ public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList() {
} }


@Override @Override
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) { public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
List<FieldDescription.Token> tokens = new ArrayList<FieldDescription.Token>(size()); List<FieldDescription.Token> tokens = new ArrayList<FieldDescription.Token>(size());
for (FieldDescription fieldDescription : this) { for (FieldDescription fieldDescription : this) {
tokens.add(fieldDescription.asToken(targetTypeMatcher)); tokens.add(fieldDescription.asToken(targetTypeMatcher));
Expand Down Expand Up @@ -235,7 +235,7 @@ public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList() {
} }


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


Expand Down
Expand Up @@ -3,7 +3,6 @@
import net.bytebuddy.description.ByteCodeElement; import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable; import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.TypeDefinable;
import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList; import net.bytebuddy.description.annotation.AnnotationList;
import net.bytebuddy.description.enumeration.EnumerationDescription; import net.bytebuddy.description.enumeration.EnumerationDescription;
Expand Down Expand Up @@ -38,7 +37,7 @@
*/ */
public interface MethodDescription extends TypeVariableSource, public interface MethodDescription extends TypeVariableSource,
NamedElement.WithGenericName, NamedElement.WithGenericName,
TypeDefinable<MethodDescription, MethodDescription.InDefinedShape> { ByteCodeElement.TypeDependant<MethodDescription.InDefinedShape, MethodDescription.Token> {


/** /**
* The internal name of a Java constructor. * The internal name of a Java constructor.
Expand Down Expand Up @@ -227,24 +226,6 @@ public interface MethodDescription extends TypeVariableSource,
*/ */
boolean isDefaultValue(Object value); boolean isDefaultValue(Object value);


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

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

interface InDefinedShape extends MethodDescription { interface InDefinedShape extends MethodDescription {


@Override @Override
Expand Down Expand Up @@ -561,7 +542,7 @@ public Token asToken() {
} }


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


MethodList<MethodDescription.InDefinedShape> asDefined(); MethodList<MethodDescription.InDefinedShape> asDefined();


Expand All @@ -54,7 +54,7 @@ public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList() {
} }


@Override @Override
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) { public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
List<MethodDescription.Token> tokens = new ArrayList<MethodDescription.Token>(size()); List<MethodDescription.Token> tokens = new ArrayList<MethodDescription.Token>(size());
for (MethodDescription fieldDescription : this) { for (MethodDescription fieldDescription : this) {
tokens.add(fieldDescription.asToken(targetTypeMatcher)); tokens.add(fieldDescription.asToken(targetTypeMatcher));
Expand Down Expand Up @@ -259,7 +259,7 @@ public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList() {
} }


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


Expand Down
Expand Up @@ -3,7 +3,6 @@
import net.bytebuddy.description.ByteCodeElement; import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable; import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.TypeDefinable;
import net.bytebuddy.description.annotation.AnnotatedCodeElement; import net.bytebuddy.description.annotation.AnnotatedCodeElement;
import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList; import net.bytebuddy.description.annotation.AnnotationList;
Expand All @@ -30,7 +29,7 @@
public interface ParameterDescription extends AnnotatedCodeElement, public interface ParameterDescription extends AnnotatedCodeElement,
NamedElement.WithRuntimeName, NamedElement.WithRuntimeName,
ModifierReviewable, ModifierReviewable,
TypeDefinable<ParameterDescription, ParameterDescription.InDefinedShape> { ByteCodeElement.TypeDependant<ParameterDescription.InDefinedShape, ParameterDescription.Token> {


/** /**
* The prefix for names of an unnamed parameter. * The prefix for names of an unnamed parameter.
Expand Down Expand Up @@ -81,26 +80,6 @@ public interface ParameterDescription extends AnnotatedCodeElement,
*/ */
int getOffset(); int getOffset();


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

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

InDefinedShape asDefined();

interface InDefinedShape extends ParameterDescription { interface InDefinedShape extends ParameterDescription {


@Override @Override
Expand Down Expand Up @@ -160,7 +139,7 @@ public Token asToken() {
} }


@Override @Override
public Token asToken(ElementMatcher<? super TypeDescription> targetTypeMatcher) { public Token asToken(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
return new Token(getType().accept(new GenericTypeDescription.Visitor.Substitutor.ForDetachment(targetTypeMatcher)), return new Token(getType().accept(new GenericTypeDescription.Visitor.Substitutor.ForDetachment(targetTypeMatcher)),
getDeclaredAnnotations(), getDeclaredAnnotations(),
isNamed() isNamed()
Expand Down
@@ -1,7 +1,6 @@
package net.bytebuddy.description.method; package net.bytebuddy.description.method;


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


ParameterList<ParameterDescription.InDefinedShape> asDefined(); ParameterList<ParameterDescription.InDefinedShape> asDefined();


Expand Down Expand Up @@ -75,7 +74,7 @@ public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList()
} }


@Override @Override
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> targetTypeMatcher) { public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super GenericTypeDescription> targetTypeMatcher) {
List<ParameterDescription.Token> tokens = new ArrayList<ParameterDescription.Token>(size()); List<ParameterDescription.Token> tokens = new ArrayList<ParameterDescription.Token>(size());
for (ParameterDescription parameterDescription : this) { for (ParameterDescription parameterDescription : this) {
tokens.add(parameterDescription.asToken(targetTypeMatcher)); tokens.add(parameterDescription.asToken(targetTypeMatcher));
Expand Down Expand Up @@ -475,7 +474,7 @@ public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList()
} }


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


Expand Down
Expand Up @@ -3,7 +3,6 @@
import net.bytebuddy.description.ByteCodeElement; import net.bytebuddy.description.ByteCodeElement;
import net.bytebuddy.description.ModifierReviewable; import net.bytebuddy.description.ModifierReviewable;
import net.bytebuddy.description.NamedElement; import net.bytebuddy.description.NamedElement;
import net.bytebuddy.description.TypeDefinable;
import net.bytebuddy.description.annotation.AnnotatedCodeElement; import net.bytebuddy.description.annotation.AnnotatedCodeElement;
import net.bytebuddy.description.annotation.AnnotationDescription; import net.bytebuddy.description.annotation.AnnotationDescription;
import net.bytebuddy.description.annotation.AnnotationList; import net.bytebuddy.description.annotation.AnnotationList;
Expand Down

0 comments on commit 7018097

Please sign in to comment.