Skip to content

Commit

Permalink
Streamlined API method names.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jan 24, 2016
1 parent 93bf67a commit f823d90
Show file tree
Hide file tree
Showing 3 changed files with 183 additions and 183 deletions.
Expand Up @@ -105,7 +105,7 @@ public interface AgentBuilder {
* @param byteBuddy The Byte Buddy instance to be used. * @param byteBuddy The Byte Buddy instance to be used.
* @return A new instance of this agent builder which makes use of the given {@code byteBuddy} instance. * @return A new instance of this agent builder which makes use of the given {@code byteBuddy} instance.
*/ */
AgentBuilder withByteBuddy(ByteBuddy byteBuddy); AgentBuilder with(ByteBuddy byteBuddy);


/** /**
* Defines the given {@link net.bytebuddy.agent.builder.AgentBuilder.Listener} to be notified by the created agent. * Defines the given {@link net.bytebuddy.agent.builder.AgentBuilder.Listener} to be notified by the created agent.
Expand All @@ -116,48 +116,31 @@ public interface AgentBuilder {
* @return A new instance of this agent builder which creates an agent that informs the given listener about * @return A new instance of this agent builder which creates an agent that informs the given listener about
* events. * events.
*/ */
AgentBuilder withListener(Listener listener); AgentBuilder with(Listener listener);


/** /**
* Defines the use of the given binary locator for locating binary data to given class names. * Defines the use of the given binary locator for locating binary data to given class names.
* *
* @param binaryLocator The binary locator to use. * @param binaryLocator The binary locator to use.
* @return A new instance of this agent builder which uses the given binary locator for looking up class files. * @return A new instance of this agent builder which uses the given binary locator for looking up class files.
*/ */
AgentBuilder withBinaryLocator(BinaryLocator binaryLocator); AgentBuilder with(BinaryLocator binaryLocator);


/** /**
* Defines the use of the given definition handler that determines if a type should be rebased or redefined. * Defines the use of the given definition handler that determines if a type should be rebased or redefined.
* *
* @param typeStrategy The definition handler to use. * @param typeStrategy The definition handler to use.
* @return A new instance of this agent builder which uses the given definition handler. * @return A new instance of this agent builder which uses the given definition handler.
*/ */
AgentBuilder withTypeStrategy(TypeStrategy typeStrategy); AgentBuilder with(TypeStrategy typeStrategy);

/**
* Enables the use of the given native method prefix for instrumented methods. Note that this prefix is also
* applied when preserving non-native methods. The use of this prefix is also registered when installing the
* final agent with an {@link java.lang.instrument.Instrumentation}.
*
* @param prefix The prefix to be used.
* @return A new instance of this agent builder which uses the given native method prefix.
*/
AgentBuilder withNativeMethodPrefix(String prefix);

/**
* Disables the use of a native method prefix for instrumented methods.
*
* @return A new instance of this agent builder which does not use a native method prefix.
*/
AgentBuilder withoutNativeMethodPrefix();


/** /**
* Defines classes to be loaded using the given access control context. * Defines classes to be loaded using the given access control context.
* *
* @param accessControlContext The access control context to be used for loading classes. * @param accessControlContext The access control context to be used for loading classes.
* @return A new instance of this agent builder which uses the given access control context for class loading. * @return A new instance of this agent builder which uses the given access control context for class loading.
*/ */
AgentBuilder withAccessControlContext(AccessControlContext accessControlContext); AgentBuilder with(AccessControlContext accessControlContext);


/** /**
* Defines a given initialization strategy to be applied to generated types. An initialization strategy is responsible * Defines a given initialization strategy to be applied to generated types. An initialization strategy is responsible
Expand All @@ -168,15 +151,15 @@ public interface AgentBuilder {
* @param initializationStrategy The initialization strategy to use. * @param initializationStrategy The initialization strategy to use.
* @return A new instance of this agent builder that applies the given initialization strategy. * @return A new instance of this agent builder that applies the given initialization strategy.
*/ */
AgentBuilder withInitializationStrategy(InitializationStrategy initializationStrategy); AgentBuilder with(InitializationStrategy initializationStrategy);


/** /**
* Specifies a strategy for modifying existing types. * Specifies a strategy for modifying existing types.
* *
* @param redefinitionStrategy The redefinition strategy to apply. * @param redefinitionStrategy The redefinition strategy to apply.
* @return A new instance of this agent builder that applies the given redefinition strategy. * @return A new instance of this agent builder that applies the given redefinition strategy.
*/ */
AgentBuilder withRedefinitionStrategy(RedefinitionStrategy redefinitionStrategy); AgentBuilder with(RedefinitionStrategy redefinitionStrategy);


/** /**
* Enables class injection of auxiliary classes into the bootstrap class loader. * Enables class injection of auxiliary classes into the bootstrap class loader.
Expand All @@ -195,6 +178,23 @@ public interface AgentBuilder {
*/ */
AgentBuilder disableBootstrapInjection(); AgentBuilder disableBootstrapInjection();


/**
* Enables the use of the given native method prefix for instrumented methods. Note that this prefix is also
* applied when preserving non-native methods. The use of this prefix is also registered when installing the
* final agent with an {@link java.lang.instrument.Instrumentation}.
*
* @param prefix The prefix to be used.
* @return A new instance of this agent builder which uses the given native method prefix.
*/
AgentBuilder withNativeMethodPrefix(String prefix);

/**
* Disables the use of a native method prefix for instrumented methods.
*
* @return A new instance of this agent builder which does not use a native method prefix.
*/
AgentBuilder withoutNativeMethodPrefix();

AgentBuilder enableLambdaInstrumentation(boolean enable); AgentBuilder enableLambdaInstrumentation(boolean enable);


/** /**
Expand Down Expand Up @@ -2036,7 +2036,7 @@ public Identified type(ElementMatcher<? super TypeDescription> typeMatcher, Elem
} }


@Override @Override
public AgentBuilder withByteBuddy(ByteBuddy byteBuddy) { public AgentBuilder with(ByteBuddy byteBuddy) {
return new Default(byteBuddy, return new Default(byteBuddy,
binaryLocator, binaryLocator,
typeStrategy, typeStrategy,
Expand All @@ -2051,7 +2051,7 @@ public AgentBuilder withByteBuddy(ByteBuddy byteBuddy) {
} }


@Override @Override
public AgentBuilder withListener(Listener listener) { public AgentBuilder with(Listener listener) {
return new Default(byteBuddy, return new Default(byteBuddy,
binaryLocator, binaryLocator,
typeStrategy, typeStrategy,
Expand All @@ -2066,7 +2066,7 @@ public AgentBuilder withListener(Listener listener) {
} }


@Override @Override
public AgentBuilder withTypeStrategy(TypeStrategy typeStrategy) { public AgentBuilder with(TypeStrategy typeStrategy) {
return new Default(byteBuddy, return new Default(byteBuddy,
binaryLocator, binaryLocator,
typeStrategy, typeStrategy,
Expand All @@ -2081,7 +2081,7 @@ public AgentBuilder withTypeStrategy(TypeStrategy typeStrategy) {
} }


@Override @Override
public AgentBuilder withBinaryLocator(BinaryLocator binaryLocator) { public AgentBuilder with(BinaryLocator binaryLocator) {
return new Default(byteBuddy, return new Default(byteBuddy,
binaryLocator, binaryLocator,
typeStrategy, typeStrategy,
Expand Down Expand Up @@ -2126,7 +2126,7 @@ public AgentBuilder withoutNativeMethodPrefix() {
} }


@Override @Override
public AgentBuilder withAccessControlContext(AccessControlContext accessControlContext) { public AgentBuilder with(AccessControlContext accessControlContext) {
return new Default(byteBuddy, return new Default(byteBuddy,
binaryLocator, binaryLocator,
typeStrategy, typeStrategy,
Expand All @@ -2141,7 +2141,7 @@ public AgentBuilder withAccessControlContext(AccessControlContext accessControlC
} }


@Override @Override
public AgentBuilder withRedefinitionStrategy(RedefinitionStrategy redefinitionStrategy) { public AgentBuilder with(RedefinitionStrategy redefinitionStrategy) {
return new Default(byteBuddy, return new Default(byteBuddy,
binaryLocator, binaryLocator,
typeStrategy, typeStrategy,
Expand All @@ -2156,7 +2156,7 @@ public AgentBuilder withRedefinitionStrategy(RedefinitionStrategy redefinitionSt
} }


@Override @Override
public AgentBuilder withInitializationStrategy(InitializationStrategy initializationStrategy) { public AgentBuilder with(InitializationStrategy initializationStrategy) {
return new Default(byteBuddy, return new Default(byteBuddy,
binaryLocator, binaryLocator,
typeStrategy, typeStrategy,
Expand Down Expand Up @@ -3239,23 +3239,23 @@ public Identified type(ElementMatcher<? super TypeDescription> typeMatcher, Elem
} }


@Override @Override
public AgentBuilder withByteBuddy(ByteBuddy byteBuddy) { public AgentBuilder with(ByteBuddy byteBuddy) {
return materialize().withByteBuddy(byteBuddy); return materialize().with(byteBuddy);
} }


@Override @Override
public AgentBuilder withListener(Listener listener) { public AgentBuilder with(Listener listener) {
return materialize().withListener(listener); return materialize().with(listener);
} }


@Override @Override
public AgentBuilder withTypeStrategy(TypeStrategy typeStrategy) { public AgentBuilder with(TypeStrategy typeStrategy) {
return materialize().withTypeStrategy(typeStrategy); return materialize().with(typeStrategy);
} }


@Override @Override
public AgentBuilder withBinaryLocator(BinaryLocator binaryLocator) { public AgentBuilder with(BinaryLocator binaryLocator) {
return materialize().withBinaryLocator(binaryLocator); return materialize().with(binaryLocator);
} }


@Override @Override
Expand All @@ -3269,18 +3269,18 @@ public AgentBuilder withoutNativeMethodPrefix() {
} }


@Override @Override
public AgentBuilder withAccessControlContext(AccessControlContext accessControlContext) { public AgentBuilder with(AccessControlContext accessControlContext) {
return materialize().withAccessControlContext(accessControlContext); return materialize().with(accessControlContext);
} }


@Override @Override
public AgentBuilder withInitializationStrategy(InitializationStrategy initializationStrategy) { public AgentBuilder with(InitializationStrategy initializationStrategy) {
return materialize().withInitializationStrategy(initializationStrategy); return materialize().with(initializationStrategy);
} }


@Override @Override
public AgentBuilder withRedefinitionStrategy(RedefinitionStrategy redefinitionStrategy) { public AgentBuilder with(RedefinitionStrategy redefinitionStrategy) {
return materialize().withRedefinitionStrategy(redefinitionStrategy); return materialize().with(redefinitionStrategy);
} }


@Override @Override
Expand Down
Expand Up @@ -85,8 +85,8 @@ public void setUp() throws Exception {
public void testAgentWithoutSelfInitialization() throws Exception { public void testAgentWithoutSelfInitialization() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE) .with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
try { try {
Expand All @@ -102,7 +102,7 @@ public void testAgentWithoutSelfInitialization() throws Exception {
public void testAgentSelfInitialization() throws Exception { public void testAgentSelfInitialization() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new BarTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new BarTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
try { try {
Expand All @@ -118,7 +118,7 @@ public void testAgentSelfInitialization() throws Exception {
public void testAgentSelfInitializationAuxiliaryTypeEager() throws Exception { public void testAgentSelfInitializationAuxiliaryTypeEager() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new QuxTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new QuxTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
try { try {
Expand All @@ -134,7 +134,7 @@ public void testAgentSelfInitializationAuxiliaryTypeEager() throws Exception {
public void testAgentSelfInitializationAuxiliaryTypeLazy() throws Exception { public void testAgentSelfInitializationAuxiliaryTypeLazy() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new QuxBazTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new QuxBazTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
try { try {
Expand All @@ -150,8 +150,8 @@ public void testAgentSelfInitializationAuxiliaryTypeLazy() throws Exception {
public void testAgentWithoutSelfInitializationWithNativeMethodPrefix() throws Exception { public void testAgentWithoutSelfInitializationWithNativeMethodPrefix() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE) .with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.withNativeMethodPrefix(QUX) .withNativeMethodPrefix(QUX)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
Expand All @@ -176,10 +176,10 @@ public void testRedefinition() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
assertThat(classLoader.loadClass(SimpleType.class.getName()).getName(), is(SimpleType.class.getName())); // ensure that class is loaded assertThat(classLoader.loadClass(SimpleType.class.getName()).getName(), is(SimpleType.class.getName())); // ensure that class is loaded
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE) .with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.withTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE) .with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.withRedefinitionStrategy(AgentBuilder.RedefinitionStrategy.REDEFINITION) .with(AgentBuilder.RedefinitionStrategy.REDEFINITION)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
try { try {
Expand All @@ -198,10 +198,10 @@ public void testRetransformation() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
assertThat(classLoader.loadClass(SimpleType.class.getName()).getName(), is(SimpleType.class.getName())); // ensure that class is loaded assertThat(classLoader.loadClass(SimpleType.class.getName()).getName(), is(SimpleType.class.getName())); // ensure that class is loaded
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.withInitializationStrategy(AgentBuilder.InitializationStrategy.NoOp.INSTANCE) .with(AgentBuilder.InitializationStrategy.NoOp.INSTANCE)
.withTypeStrategy(AgentBuilder.TypeStrategy.Default.REDEFINE) .with(AgentBuilder.TypeStrategy.Default.REDEFINE)
.withRedefinitionStrategy(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION) .with(AgentBuilder.RedefinitionStrategy.RETRANSFORMATION)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new FooTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
try { try {
Expand All @@ -217,7 +217,7 @@ public void testRetransformation() throws Exception {
public void testChainedAgent() throws Exception { public void testChainedAgent() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
AgentBuilder agentBuilder = new AgentBuilder.Default() AgentBuilder agentBuilder = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new QuxTransformer()); .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new QuxTransformer());
ClassFileTransformer firstTransformer = agentBuilder.installOnByteBuddyAgent(); ClassFileTransformer firstTransformer = agentBuilder.installOnByteBuddyAgent();
ClassFileTransformer secondTransformer = agentBuilder.installOnByteBuddyAgent(); ClassFileTransformer secondTransformer = agentBuilder.installOnByteBuddyAgent();
Expand All @@ -235,7 +235,7 @@ public void testChainedAgent() throws Exception {
public void testSignatureTypesAreAvailableAfterLoad() throws Exception { public void testSignatureTypesAreAvailableAfterLoad() throws Exception {
assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class)); assertThat(ByteBuddyAgent.install(), instanceOf(Instrumentation.class));
ClassFileTransformer classFileTransformer = new AgentBuilder.Default() ClassFileTransformer classFileTransformer = new AgentBuilder.Default()
.withBinaryLocator(binaryLocator) .with(binaryLocator)
.type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new ConstructorTransformer()) .type(isAnnotatedWith(ShouldRebase.class), ElementMatchers.is(classLoader)).transform(new ConstructorTransformer())
.installOnByteBuddyAgent(); .installOnByteBuddyAgent();
try { try {
Expand Down

0 comments on commit f823d90

Please sign in to comment.