Skip to content

Commit

Permalink
Reversed order of transformer application. Updated javadoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Apr 19, 2016
1 parent 0d393b6 commit 513206f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,16 @@ interface Narrowable extends Matchable<Narrowable>, Identified {
interface Extendable extends AgentBuilder, Identified {

/**
* <p>
* Applies the specified transformation as a decorative transformation. For a decorative transformation, the supplied
* transformer is prepended to any previous transformation that also matches the instrumented type, i.e. both transformations
* are supplied. This procedure is repeated until a transformer is reached that matches the instrumented type but is not
* defined as decorating after which no further transformations are considered. If all matching transformations are declared
* as decorating, all matching transformers are applied.
* </p>
* <p>
* <b>Note</b>: A decorating transformer is applied <b>after</b> previously registered transformers.
* </p>
*
* @return A new instance of this agent builder with the specified transformation being applied as a decorator.
*/
Expand Down Expand Up @@ -4650,12 +4655,12 @@ public String toString() {
interface Decoratable extends Resolution {

/**
* Prepends the supplied transformer to this resolution.
* Appends the supplied transformer to this resolution.
*
* @param transformer The transformer to prepend.
* @return A new resolution with the supplied transformer prepended.
* @param transformer The transformer to append to the transformer that is represented bz this instance.
* @return A new resolution with the supplied transformer appended to this transformer.
*/
Resolution prepend(Transformer transformer);
Resolution append(Transformer transformer);
}

/**
Expand Down Expand Up @@ -4898,15 +4903,15 @@ public Transformation.Resolution asDecoratorOf(Transformation.Resolution resolut

@Override
public Transformation.Resolution prepend(Decoratable resolution) {
return resolution.prepend(transformer);
return resolution.append(transformer);
}

@Override
public Transformation.Resolution prepend(Transformer transformer) {
public Transformation.Resolution append(Transformer transformer) {
return new Resolution(typeDescription,
classLoader,
protectionDomain,
new Transformer.Compound(transformer, this.transformer),
new Transformer.Compound(this.transformer, transformer),
decorator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ public void testDecoration() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.with(binaryLocator)
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer())
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()).asDecorator()
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer())
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator()
.installOnByteBuddyAgent();
try {
Class<?> type = classLoader.loadClass(Foo.class.getName());
Expand All @@ -291,8 +291,8 @@ public void testDecorationFallThrough() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.with(binaryLocator)
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator()
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()).asDecorator()
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator()
.installOnByteBuddyAgent();
try {
Class<?> type = classLoader.loadClass(Foo.class.getName());
Expand All @@ -308,12 +308,12 @@ public void testDecorationBlocked() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.with(binaryLocator)
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer()).asDecorator()
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer())
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new BarAdviceTransformer()).asDecorator()
.type(ElementMatchers.is(Foo.class), ElementMatchers.is(classLoader)).transform(new QuxAdviceTransformer())
.installOnByteBuddyAgent();
try {
Class<?> type = classLoader.loadClass(Foo.class.getName());
assertThat(type.getDeclaredMethod(FOO).invoke(type.newInstance()), is((Object) (FOO + BAR)));
assertThat(type.getDeclaredMethod(FOO).invoke(type.newInstance()), is((Object) (FOO + QUX)));
} finally {
ByteBuddyAgent.getInstrumentation().removeTransformer(classFileTransformer);
}
Expand Down

0 comments on commit 513206f

Please sign in to comment.