Skip to content

Commit

Permalink
Added missing documentation and reinstated tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jul 18, 2016
1 parent 4733ee0 commit 0b186eb
Show file tree
Hide file tree
Showing 35 changed files with 1,010 additions and 691 deletions.
@@ -1,5 +1,6 @@
package net.bytebuddy.dynamic.scaffold;

import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.method.MethodList;
import net.bytebuddy.description.type.TypeDescription;
Expand Down Expand Up @@ -27,7 +28,7 @@ public interface MethodRegistry {
* @param methodMatcher A matcher to identify any method that this definition concerns.
* @param handler The handler to instrument any matched method.
* @param attributeAppenderFactory A method attribute appender to apply to any matched method.
* @param transformer The method transformer to be applied to implemented methods.
* @param transformer The method transformer to be applied to implemented methods.
* @return An adapted version of this method registry.
*/
MethodRegistry prepend(LatentMatcher<? super MethodDescription> methodMatcher,
Expand All @@ -41,7 +42,7 @@ MethodRegistry prepend(LatentMatcher<? super MethodDescription> methodMatcher,
* @param methodMatcher A matcher to identify all entries that are to be matched.
* @param handler The handler to instrument any matched method.
* @param attributeAppenderFactory A method attribute appender to apply to any matched method.
* @param transformer The method transformer to be applied to implemented methods.
* @param transformer The method transformer to be applied to implemented methods.
* @return An adapted version of this method registry.
*/
MethodRegistry append(LatentMatcher<? super MethodDescription> methodMatcher,
Expand Down Expand Up @@ -387,9 +388,10 @@ interface Prepared {
* Compiles this prepared method registry.
*
* @param implementationTargetFactory A factory for creating an implementation target.
* @param classFileVersion The type's class file version.
* @return A factory for creating an implementation target.
*/
Compiled compile(Implementation.Target.Factory implementationTargetFactory);
Compiled compile(Implementation.Target.Factory implementationTargetFactory, ClassFileVersion classFileVersion);
}

/**
Expand Down Expand Up @@ -582,7 +584,7 @@ protected static class Entry implements LatentMatcher<MethodDescription> {
* @param matcher The latent method matcher that this entry represents.
* @param handler The handler to apply to all matched entries.
* @param attributeAppenderFactory A method attribute appender factory to apply to all entries.
* @param transformer The method transformer to be applied to implemented methods.
* @param transformer The method transformer to be applied to implemented methods.
*/
protected Entry(LatentMatcher<? super MethodDescription> matcher,
Handler handler,
Expand Down Expand Up @@ -754,11 +756,11 @@ public MethodList<?> getInstrumentedMethods() {
}

@Override
public MethodRegistry.Compiled compile(Implementation.Target.Factory implementationTargetFactory) {
public MethodRegistry.Compiled compile(Implementation.Target.Factory implementationTargetFactory, ClassFileVersion classFileVersion) {
Map<Handler, Handler.Compiled> compilationCache = new HashMap<Handler, Handler.Compiled>();
Map<MethodAttributeAppender.Factory, MethodAttributeAppender> attributeAppenderCache = new HashMap<MethodAttributeAppender.Factory, MethodAttributeAppender>();
LinkedHashMap<MethodDescription, Compiled.Entry> entries = new LinkedHashMap<MethodDescription, Compiled.Entry>();
Implementation.Target implementationTarget = implementationTargetFactory.make(instrumentedType, methodGraph);
Implementation.Target implementationTarget = implementationTargetFactory.make(instrumentedType, methodGraph, classFileVersion);
for (Map.Entry<MethodDescription, Entry> entry : implementations.entrySet()) {
Handler.Compiled cachedHandler = compilationCache.get(entry.getValue().getHandler());
if (cachedHandler == null) {
Expand Down

Large diffs are not rendered by default.

@@ -1,5 +1,6 @@
package net.bytebuddy.dynamic.scaffold.inline;

import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.dynamic.scaffold.MethodGraph;
Expand Down Expand Up @@ -30,14 +31,16 @@ public class RebaseImplementationTarget extends Implementation.Target.AbstractBa
/**
* Creates a rebase implementation target.
*
* @param instrumentedType The instrumented type.
* @param methodGraph A method graph of the instrumented type.
* @param rebaseableMethods A mapping of the instrumented type's declared methods by each method's token.
* @param instrumentedType The instrumented type.
* @param methodGraph A method graph of the instrumented type.
* @param defaultMethodInvocation The default method invocation mode to apply.
* @param rebaseableMethods A mapping of the instrumented type's declared methods by each method's token.
*/
protected RebaseImplementationTarget(TypeDescription instrumentedType,
MethodGraph.Linked methodGraph,
DefaultMethodInvocation defaultMethodInvocation,
Map<MethodDescription.SignatureToken, MethodRebaseResolver.Resolution> rebaseableMethods) {
super(instrumentedType, methodGraph);
super(instrumentedType, methodGraph, defaultMethodInvocation);
this.rebaseableMethods = rebaseableMethods;
}

Expand All @@ -46,11 +49,15 @@ protected RebaseImplementationTarget(TypeDescription instrumentedType,
*
* @param instrumentedType The instrumented type.
* @param methodGraph A method graph of the instrumented type.
* @param classFileVersion The type's class file version.
* @param methodRebaseResolver A method rebase resolver to be used when calling a rebased method.
* @return An implementation target for the given input.
*/
protected static Implementation.Target of(TypeDescription instrumentedType, MethodGraph.Linked methodGraph, MethodRebaseResolver methodRebaseResolver) {
return new RebaseImplementationTarget(instrumentedType, methodGraph, methodRebaseResolver.asTokenMap());
protected static Implementation.Target of(TypeDescription instrumentedType,
MethodGraph.Linked methodGraph,
ClassFileVersion classFileVersion,
MethodRebaseResolver methodRebaseResolver) {
return new RebaseImplementationTarget(instrumentedType, methodGraph, DefaultMethodInvocation.of(classFileVersion), methodRebaseResolver.asTokenMap());
}

@Override
Expand Down Expand Up @@ -211,8 +218,8 @@ public Factory(MethodRebaseResolver methodRebaseResolver) {
}

@Override
public Implementation.Target make(TypeDescription instrumentedType, MethodGraph.Linked methodGraph) {
return RebaseImplementationTarget.of(instrumentedType, methodGraph, methodRebaseResolver);
public Implementation.Target make(TypeDescription instrumentedType, MethodGraph.Linked methodGraph, ClassFileVersion classFileVersion) {
return RebaseImplementationTarget.of(instrumentedType, methodGraph, classFileVersion, methodRebaseResolver);
}

@Override
Expand Down
Expand Up @@ -158,7 +158,7 @@ public DynamicType.Unloaded<T> make(TypeResolutionStrategy typeResolutionStrateg
MethodRegistry.Compiled methodRegistry = constructorStrategy
.inject(this.methodRegistry)
.prepare(applyConstructorStrategy(instrumentedType), methodGraphCompiler, typeValidation, new InstrumentableMatcher(ignoredMethods))
.compile(SubclassImplementationTarget.Factory.SUPER_CLASS);
.compile(SubclassImplementationTarget.Factory.SUPER_CLASS, classFileVersion);
return TypeWriter.Default.<T>forCreation(methodRegistry,
fieldRegistry.compile(methodRegistry.getInstrumentedType()),
typeAttributeAppender,
Expand Down
@@ -1,5 +1,6 @@
package net.bytebuddy.dynamic.scaffold.subclass;

import net.bytebuddy.ClassFileVersion;
import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.description.method.MethodList;
import net.bytebuddy.description.type.TypeDefinition;
Expand Down Expand Up @@ -31,12 +32,16 @@ public class SubclassImplementationTarget extends Implementation.Target.Abstract
/**
* Creates a new subclass implementation target.
*
* @param instrumentedType The instrumented type.
* @param methodGraph A method graph of the instrumented type.
* @param originTypeResolver A resolver for the origin type.
* @param instrumentedType The instrumented type.
* @param methodGraph A method graph of the instrumented type.
* @param defaultMethodInvocation The default method invocation mode to apply.
* @param originTypeResolver A resolver for the origin type.
*/
protected SubclassImplementationTarget(TypeDescription instrumentedType, MethodGraph.Linked methodGraph, OriginTypeResolver originTypeResolver) {
super(instrumentedType, methodGraph);
protected SubclassImplementationTarget(TypeDescription instrumentedType,
MethodGraph.Linked methodGraph,
DefaultMethodInvocation defaultMethodInvocation,
OriginTypeResolver originTypeResolver) {
super(instrumentedType, methodGraph, defaultMethodInvocation);
TypeDescription.Generic superClass = instrumentedType.getSuperClass();
MethodList<?> superConstructors = superClass == null
? new MethodList.Empty<MethodDescription.InGenericShape>()
Expand Down Expand Up @@ -109,6 +114,7 @@ public String toString() {
", originTypeResolver=" + originTypeResolver +
", instrumentedType=" + instrumentedType +
", methodGraph=" + methodGraph +
", defaultMethodInvocation=" + defaultMethodInvocation +
'}';
}

Expand Down Expand Up @@ -182,8 +188,8 @@ public enum Factory implements Implementation.Target.Factory {
}

@Override
public Implementation.Target make(TypeDescription instrumentedType, MethodGraph.Linked methodGraph) {
return new SubclassImplementationTarget(instrumentedType, methodGraph, originTypeResolver);
public Implementation.Target make(TypeDescription instrumentedType, MethodGraph.Linked methodGraph, ClassFileVersion classFileVersion) {
return new SubclassImplementationTarget(instrumentedType, methodGraph, DefaultMethodInvocation.of(classFileVersion), originTypeResolver);
}

@Override
Expand Down

0 comments on commit 0b186eb

Please sign in to comment.