Skip to content

Commit

Permalink
Generified Byte Buddy commons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Jun 4, 2015
1 parent 5836482 commit 8a2d979
Show file tree
Hide file tree
Showing 11 changed files with 483 additions and 231 deletions.
25 changes: 13 additions & 12 deletions byte-buddy-dep/src/main/java/net/bytebuddy/ByteBuddy.java
Expand Up @@ -386,7 +386,7 @@ public <T> DynamicType.Builder<T> subclass(TypeDescription superType, Constructo
List<TypeDescription> interfaceTypes = this.interfaceTypes;
if (nonNull(superType).isInterface()) {
actualSuperType = TypeDescription.OBJECT;
interfaceTypes = joinUnique(superType, interfaceTypes);
interfaceTypes = joinUniqueRaw(interfaceTypes, Collections.singleton(superType));
}
return new SubclassDynamicTypeBuilder<T>(classFileVersion,
nonNull(namingStrategy.subclass(superType)),
Expand Down Expand Up @@ -753,7 +753,7 @@ public <T> DynamicType.Builder<T> rebase(TypeDescription levelType,
ClassFileLocator classFileLocator,
MethodRebaseResolver.MethodNameTransformer methodNameTransformer) {
return new RebaseDynamicTypeBuilder<T>(classFileVersion,
nonNull(namingStrategy.rebase(levelType)),
nonNull(namingStrategy.rebase(isDefineable(levelType))),
auxiliaryTypeNamingStrategy,
levelType,
interfaceTypes,
Expand Down Expand Up @@ -997,7 +997,7 @@ public OptionalMethodInterception withImplementing(Collection<? extends TypeDesc
return new OptionalMethodInterception(classFileVersion,
namingStrategy,
auxiliaryTypeNamingStrategy,
joinUnique(interfaceTypes, toList(isInterface(types))),
joinUniqueRaw(interfaceTypes, toList(isImplementable(types))),
ignoredMethods,
bridgeMethodResolverFactory,
classVisitorWrapperChain,
Expand Down Expand Up @@ -1376,19 +1376,20 @@ public String toString() {
public interface MethodInterceptable {

/**
* Intercepts the given method with the given implementations.
* Intercepts the currently selected methods with the provided implementation. If this intercepted method is
* not yet declared by the current type, it might be added to the currently built type as a result of this
* interception. If the method is already declared by the current type, its byte code code might be copied
* into the body of a synthetic method in order to preserve the original code's invokeability.
*
* @param implementation The implementation to apply to the selected methods.
* @return A method annotation target for this instance with the given implementation applied to the
* current selection.
* @param implementation The implementation to apply to the currently selected method.
* @return A configuration which will intercept the currently selected methods by the given implementation.
*/
MethodAnnotationTarget intercept(Implementation implementation);

/**
* Defines the currently selected methods as {@code abstract}.
* Implements the currently selected methods as {@code abstract} methods.
*
* @return A method annotation target for this instance with implementing the currently selected methods
* as {@code abstract}.
* @return A configuration which will implement the currently selected methods as {@code abstract} methods.
*/
MethodAnnotationTarget withoutCode();

Expand All @@ -1397,7 +1398,7 @@ public interface MethodInterceptable {
*
* @param value The value that the annotation property should set as a default.
* @param type The type of the annotation property.
* @return A builder which defines the given default value for all matched methods.
* @return A configuration which defines the given default value for all matched methods.
*/
MethodAnnotationTarget withDefaultValue(Object value, Class<?> type);

Expand All @@ -1408,7 +1409,7 @@ public interface MethodInterceptable {
* {@link Class} values as {@link TypeDescription} instances. Other values are handed in their raw format or as their wrapper types.
*
* @param value A non-loaded value that the annotation property should set as a default.
* @return A builder which defines the given default value for all matched methods.
* @return A configuration which defines the given default value for all matched methods.
*/
MethodAnnotationTarget withDefaultValue(Object value);
}
Expand Down
Expand Up @@ -1319,7 +1319,7 @@ public OptionalMatchedMethodInterception<S> implement(TypeDescription... interfa

@Override
public OptionalMatchedMethodInterception<S> implement(Collection<? extends TypeDescription> interfaceTypes) {
return new DefaultOptionalMatchedMethodInterception(new ArrayList<TypeDescription>(isInterface(interfaceTypes)));
return new DefaultOptionalMatchedMethodInterception(new ArrayList<TypeDescription>(isImplementable(interfaceTypes)));
}

@Override
Expand Down Expand Up @@ -1620,7 +1620,7 @@ public FieldValueTarget<S> defineField(String name,
public FieldValueTarget<S> defineField(String name,
TypeDescription fieldTypeDescription,
int modifiers) {
return new DefaultFieldValueTarget(new FieldToken(isValidIdentifier(name), nonVoid(fieldTypeDescription), modifiers),
return new DefaultFieldValueTarget(new FieldToken(isValidIdentifier(name), isActualType(fieldTypeDescription), modifiers),
defaultFieldAttributeAppenderFactory);
}

Expand All @@ -1639,11 +1639,7 @@ public ExceptionDeclarableMethodInterception<S> defineMethod(String name,
TypeDescription returnType,
List<? extends TypeDescription> parameterTypes,
ModifierContributor.ForMethod... modifier) {
return new DefaultExceptionDeclarableMethodInterception(new MethodToken(isValidIdentifier(name),
nonNull(returnType),
nonVoid(parameterTypes),
Collections.<TypeDescription>emptyList(),
resolveModifierContributors(METHOD_MODIFIER_MASK, nonNull(modifier))));
return defineMethod(name, returnType, parameterTypes, resolveModifierContributors(METHOD_MODIFIER_MASK, modifier));
}

@Override
Expand Down Expand Up @@ -1679,8 +1675,8 @@ public ExceptionDeclarableMethodInterception<S> defineMethod(String name,
List<? extends TypeDescription> parameterTypes,
int modifiers) {
return new DefaultExceptionDeclarableMethodInterception(new MethodToken(isValidIdentifier(name),
nonNull(returnType),
nonVoid(parameterTypes),
isActualTypeOrVoid(returnType),
isActualType(parameterTypes),
Collections.<TypeDescription>emptyList(),
modifiers));
}
Expand Down Expand Up @@ -1713,7 +1709,7 @@ public ExceptionDeclarableMethodInterception<S> defineConstructor(Iterable<? ext

@Override
public ExceptionDeclarableMethodInterception<S> defineConstructor(List<? extends TypeDescription> parameterTypes, int modifiers) {
return new DefaultExceptionDeclarableMethodInterception(new MethodToken(nonVoid(parameterTypes),
return new DefaultExceptionDeclarableMethodInterception(new MethodToken(isActualType(parameterTypes),
Collections.<TypeDescription>emptyList(),
modifiers));
}
Expand Down Expand Up @@ -2717,7 +2713,7 @@ public MatchedMethodInterception<S> throwing(Collection<? extends TypeDescriptio
return materialize(new MethodToken(methodToken.getInternalName(),
methodToken.getReturnType(),
methodToken.getParameterTypes(),
unique(isThrowable(new ArrayList<TypeDescription>(exceptionTypes))),
uniqueRaw(isThrowable(new ArrayList<TypeDescription>(exceptionTypes))),
methodToken.getModifiers()));
}

Expand Down Expand Up @@ -2988,7 +2984,7 @@ protected DynamicType.Builder<S> materialize() {
namingStrategy,
auxiliaryTypeNamingStrategy,
targetType,
joinUnique(interfaceTypes, additionalInterfaceTypes),
joinUniqueRaw(interfaceTypes, additionalInterfaceTypes),
modifiers,
attributeAppender,
ignoredMethods,
Expand Down
Expand Up @@ -12,7 +12,7 @@

import java.util.*;

import static net.bytebuddy.utility.ByteBuddyCommons.isInterface;
import static net.bytebuddy.utility.ByteBuddyCommons.isImplementable;
import static net.bytebuddy.utility.ByteBuddyCommons.nonNull;
import static net.bytebuddy.utility.ByteBuddyCommons.toList;

Expand Down Expand Up @@ -48,10 +48,7 @@ public class DefaultMethodCall implements Implementation {
* be called.
*/
protected DefaultMethodCall(List<TypeDescription> prioritizedInterfaces) {
for (TypeDescription typeDescription : prioritizedInterfaces) {
isInterface(typeDescription);
}
this.prioritizedInterfaces = prioritizedInterfaces;
this.prioritizedInterfaces = isImplementable(prioritizedInterfaces);
}

/**
Expand Down
Expand Up @@ -717,7 +717,7 @@ public AssignerConfigurable defineAs(TypeDescription typeDescription, ModifierCo
return new ForNamedField(assigner,
dynamicallyTyped,
fieldName,
PreparationHandler.FieldDefiner.of(fieldName, nonVoid(typeDescription), nonNull(modifier)),
PreparationHandler.FieldDefiner.of(fieldName, isActualType(typeDescription), nonNull(modifier)),
FieldLocator.ForInstrumentedType.INSTANCE);
}

Expand Down
Expand Up @@ -102,7 +102,7 @@ public static Implementation toStaticField(String fieldName, Class<?> fieldType)
*/
public static Implementation toStaticField(String fieldName, TypeDescription fieldType) {
return new Forwarding(isValidIdentifier(fieldName),
nonVoid(fieldType),
isActualType(fieldType),
PreparationHandler.ForStaticField.INSTANCE);
}

Expand Down
Expand Up @@ -2199,7 +2199,7 @@ public MethodCall onInstanceField(Class<?> type, String fieldName) {
*/
public MethodCall onInstanceField(TypeDescription typeDescription, String fieldName) {
return new MethodCall(methodLocator,
new TargetHandler.ForInstanceField(nonNull(fieldName), nonVoid(typeDescription)),
new TargetHandler.ForInstanceField(nonNull(fieldName), isActualType(typeDescription)),
argumentLoaders,
MethodInvoker.ForStandardInvocation.INSTANCE,
TerminationHandler.ForMethodReturn.INSTANCE,
Expand Down
Expand Up @@ -740,7 +740,7 @@ public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArgu
public static <T extends MethodDescription> ElementMatcher.Junction<T> takesArguments(Iterable<? extends TypeDescription> typeDescriptions) {
List<ElementMatcher<? super TypeDescription>> typeMatchers = new LinkedList<ElementMatcher<? super TypeDescription>>();
for (TypeDescription typeDescription : typeDescriptions) {
typeMatchers.add(is(nonVoid(typeDescription)));
typeMatchers.add(is(isActualType(typeDescription)));
}
return takesArguments(new CollectionOneToOneMatcher<TypeDescription>(typeMatchers));
}
Expand Down Expand Up @@ -1000,7 +1000,7 @@ public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(
* @return A matcher that matches a setter method with the specified argument type.
*/
public static <T extends MethodDescription> ElementMatcher.Junction<T> isSetter(TypeDescription typeDescription) {
return isSetter(is(nonVoid(typeDescription)));
return isSetter(is(isActualType(typeDescription)));
}

/**
Expand Down Expand Up @@ -1045,7 +1045,7 @@ public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(
* @return A matcher that matches a getter method with the given type.
*/
public static <T extends MethodDescription> ElementMatcher.Junction<T> isGetter(TypeDescription typeDescription) {
return isGetter(is(nonVoid(typeDescription)));
return isGetter(is(isActualType(typeDescription)));
}

/**
Expand Down

0 comments on commit 8a2d979

Please sign in to comment.