Skip to content

Commit

Permalink
Further renaming.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Winterhalter committed Apr 14, 2015
1 parent ac6f8a6 commit 708c0a2
Show file tree
Hide file tree
Showing 52 changed files with 256 additions and 256 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -68,7 +68,7 @@ class and which can be easily composed. The creation of custom matchers is howev


For implementing the `toString` method, the `FixedValue` class defines a constant return value for the overridden For implementing the `toString` method, the `FixedValue` class defines a constant return value for the overridden
method. Defining a constant value is only one example of many method interceptors that ship with Byte Buddy. By method. Defining a constant value is only one example of many method interceptors that ship with Byte Buddy. By
implementing the `Instrumentation` interface, a method could however even be defined by custom byte code. implementing the `Implementation` interface, a method could however even be defined by custom byte code.


Finally, the described Java class is created and then loaded into the Java virtual machine. For this purpose, a target Finally, the described Java class is created and then loaded into the Java virtual machine. For this purpose, a target
class loader is required as well as a class loading strategy where we choose a wrapper strategy. The latter creates a class loader is required as well as a class loading strategy where we choose a wrapper strategy. The latter creates a
Expand All @@ -84,10 +84,10 @@ In reality, a user of such a library wants to perform more complex manipulations
logic to a compiled Java program. Using Byte Buddy, doing so is however not much harder and the following example logic to a compiled Java program. Using Byte Buddy, doing so is however not much harder and the following example
gives a taste of how method calls can be intercepted. gives a taste of how method calls can be intercepted.


Byte Buddy describes method implementations by instances of the `Instrumentation` interface such as `FixedValue` which Byte Buddy describes method implementations by instances of the `Implementation` interface such as `FixedValue` which
we used in the above example. By implementing this interface, a user of Byte Buddy can go to the length of defining we used in the above example. By implementing this interface, a user of Byte Buddy can go to the length of defining
custom byte code for a method. Normally, it is however easier to use Byte Buddy's `MethodDelegation` which allows custom byte code for a method. Normally, it is however easier to use Byte Buddy's `MethodDelegation` which allows
to implement an intercepted method in plain Java. Using this instrumentation is straight forward as it operates on any to implement an intercepted method in plain Java. Using this implementation is straight forward as it operates on any
POJO. For example, we can implement the `Comparator` interface by defining the following class which mimics the POJO. For example, we can implement the `Comparator` interface by defining the following class which mimics the
signature of the `Comparator:compare` method we want to implement later: signature of the `Comparator:compare` method we want to implement later:


Expand Down Expand Up @@ -166,7 +166,7 @@ Byte Buddy is written on top of [ASM](http://asm.ow2.org/), a mature and well-te
compiled Java classes. In order to allow for advanced type manipulations, Byte Buddy is intentionally exposing the compiled Java classes. In order to allow for advanced type manipulations, Byte Buddy is intentionally exposing the
ASM API to its users. Of course, the direct use of ASM remains fully optional and most users will most likely never ASM API to its users. Of course, the direct use of ASM remains fully optional and most users will most likely never
require it. This choice was made such that a user of Byte Buddy is not restrained to its higher-level functionality require it. This choice was made such that a user of Byte Buddy is not restrained to its higher-level functionality
but can implement custom instrumentations without a fuzz when it is necessary. but can implement custom implementations without a fuzz when it is necessary.


However, this imposes one possible problem when relying onto Byte Buddy as a project dependency and making use of the However, this imposes one possible problem when relying onto Byte Buddy as a project dependency and making use of the
exposed ASM API. The authors of ASM require their users to exposed ASM API. The authors of ASM require their users to
Expand Down
Expand Up @@ -1112,7 +1112,7 @@ public ByteCodeAppender appender(Target implementationTarget) {
} }


@Override @Override
public Size apply(MethodVisitor methodVisitor, Context instrumentationContext, MethodDescription instrumentedMethod) { public Size apply(MethodVisitor methodVisitor, Context implementationContext, MethodDescription instrumentedMethod) {
throw new IllegalStateException("Initialization strategy illegally applied to " + instrumentedMethod); throw new IllegalStateException("Initialization strategy illegally applied to " + instrumentedMethod);
} }


Expand Down
Expand Up @@ -156,7 +156,7 @@ public boolean isValid() {
} }


@Override @Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context instrumentationContext) { public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
throw new IllegalStateException("Cannot apply non-defined type initializer"); throw new IllegalStateException("Cannot apply non-defined type initializer");
} }


Expand Down Expand Up @@ -207,8 +207,8 @@ public boolean isValid() {
} }


@Override @Override
public Size apply(MethodVisitor methodVisitor, Implementation.Context instrumentationContext) { public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) {
return stackManipulation.apply(methodVisitor, instrumentationContext); return stackManipulation.apply(methodVisitor, implementationContext);
} }


@Override @Override
Expand Down
Expand Up @@ -545,7 +545,7 @@ protected static class Prepared implements MethodRegistry.Prepared {
/** /**
* A map of all method descriptions mapped to their handling entires. * A map of all method descriptions mapped to their handling entires.
*/ */
private final Map<MethodDescription, Entry> instrumentations; private final Map<MethodDescription, Entry> implementations;


/** /**
* The loaded type initializer of the instrumented type. * The loaded type initializer of the instrumented type.
Expand All @@ -565,16 +565,16 @@ protected static class Prepared implements MethodRegistry.Prepared {
/** /**
* Creates a prepared version of a default method registry. * Creates a prepared version of a default method registry.
* *
* @param instrumentations A map of all method descriptions mapped to their handling entires. * @param implementations A map of all method descriptions mapped to their handling entires.
* @param loadedTypeInitializer The loaded type initializer of the instrumented type. * @param loadedTypeInitializer The loaded type initializer of the instrumented type.
* @param typeInitializer The type intiailizer of the instrumented type. * @param typeInitializer The type intiailizer of the instrumented type.
* @param finding The analyzed instrumented type. * @param finding The analyzed instrumented type.
*/ */
public Prepared(Map<MethodDescription, Entry> instrumentations, public Prepared(Map<MethodDescription, Entry> implementations,
LoadedTypeInitializer loadedTypeInitializer, LoadedTypeInitializer loadedTypeInitializer,
InstrumentedType.TypeInitializer typeInitializer, InstrumentedType.TypeInitializer typeInitializer,
MethodLookupEngine.Finding finding) { MethodLookupEngine.Finding finding) {
this.instrumentations = instrumentations; this.implementations = implementations;
this.loadedTypeInitializer = loadedTypeInitializer; this.loadedTypeInitializer = loadedTypeInitializer;
this.typeInitializer = typeInitializer; this.typeInitializer = typeInitializer;
this.finding = finding; this.finding = finding;
Expand All @@ -597,16 +597,16 @@ public InstrumentedType.TypeInitializer getTypeInitializer() {


@Override @Override
public MethodList getInstrumentedMethods() { public MethodList getInstrumentedMethods() {
return new MethodList.Explicit(new ArrayList<MethodDescription>(instrumentations.keySet())).filter(not(isTypeInitializer())); return new MethodList.Explicit(new ArrayList<MethodDescription>(implementations.keySet())).filter(not(isTypeInitializer()));
} }


@Override @Override
public MethodRegistry.Compiled compile(Implementation.Target.Factory implementationTargetFactory) { public MethodRegistry.Compiled compile(Implementation.Target.Factory implementationTargetFactory) {
Map<Handler, Handler.Compiled> compilationCache = new HashMap<Handler, Handler.Compiled>(instrumentations.size()); Map<Handler, Handler.Compiled> compilationCache = new HashMap<Handler, Handler.Compiled>(implementations.size());
Map<MethodAttributeAppender.Factory, MethodAttributeAppender> attributeAppenderCache = new HashMap<MethodAttributeAppender.Factory, MethodAttributeAppender>(instrumentations.size()); Map<MethodAttributeAppender.Factory, MethodAttributeAppender> attributeAppenderCache = new HashMap<MethodAttributeAppender.Factory, MethodAttributeAppender>(implementations.size());
Map<MethodDescription, TypeWriter.MethodPool.Entry> entries = new HashMap<MethodDescription, TypeWriter.MethodPool.Entry>(instrumentations.size()); Map<MethodDescription, TypeWriter.MethodPool.Entry> entries = new HashMap<MethodDescription, TypeWriter.MethodPool.Entry>(implementations.size());
Implementation.Target implementationTarget = implementationTargetFactory.make(finding, getInstrumentedMethods()); Implementation.Target implementationTarget = implementationTargetFactory.make(finding, getInstrumentedMethods());
for (Map.Entry<MethodDescription, Entry> entry : instrumentations.entrySet()) { for (Map.Entry<MethodDescription, Entry> entry : implementations.entrySet()) {
Handler.Compiled cachedEntry = compilationCache.get(entry.getValue().getHandler()); Handler.Compiled cachedEntry = compilationCache.get(entry.getValue().getHandler());
if (cachedEntry == null) { if (cachedEntry == null) {
cachedEntry = entry.getValue().getHandler().compile(implementationTarget); cachedEntry = entry.getValue().getHandler().compile(implementationTarget);
Expand All @@ -627,15 +627,15 @@ public boolean equals(Object other) {
if (this == other) return true; if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false; if (other == null || getClass() != other.getClass()) return false;
Prepared prepared = (Prepared) other; Prepared prepared = (Prepared) other;
return instrumentations.equals(prepared.instrumentations) return implementations.equals(prepared.implementations)
&& loadedTypeInitializer.equals(prepared.loadedTypeInitializer) && loadedTypeInitializer.equals(prepared.loadedTypeInitializer)
&& typeInitializer.equals(prepared.typeInitializer) && typeInitializer.equals(prepared.typeInitializer)
&& finding.equals(prepared.finding); && finding.equals(prepared.finding);
} }


@Override @Override
public int hashCode() { public int hashCode() {
int result = instrumentations.hashCode(); int result = implementations.hashCode();
result = 31 * result + loadedTypeInitializer.hashCode(); result = 31 * result + loadedTypeInitializer.hashCode();
result = 31 * result + typeInitializer.hashCode(); result = 31 * result + typeInitializer.hashCode();
result = 31 * result + finding.hashCode(); result = 31 * result + finding.hashCode();
Expand All @@ -645,7 +645,7 @@ public int hashCode() {
@Override @Override
public String toString() { public String toString() {
return "MethodRegistry.Default.Prepared{" + return "MethodRegistry.Default.Prepared{" +
"instrumentations=" + instrumentations + "implementations=" + implementations +
", loadedTypeInitializer=" + loadedTypeInitializer + ", loadedTypeInitializer=" + loadedTypeInitializer +
", typeInitializer=" + typeInitializer + ", typeInitializer=" + typeInitializer +
", finding=" + finding + ", finding=" + finding +
Expand Down Expand Up @@ -676,24 +676,24 @@ protected static class Compiled implements MethodRegistry.Compiled {
/** /**
* A map of all method descriptions mapped to their handling entries. * A map of all method descriptions mapped to their handling entries.
*/ */
private final Map<MethodDescription, Entry> instrumentations; private final Map<MethodDescription, Entry> implementations;


/** /**
* Creates a new compiled version of a default method registry. * Creates a new compiled version of a default method registry.
* *
* @param instrumentedType The instrumented type. * @param instrumentedType The instrumented type.
* @param loadedTypeInitializer The loaded type initializer of the instrumented type. * @param loadedTypeInitializer The loaded type initializer of the instrumented type.
* @param typeInitializer The type initializer of the instrumented type. * @param typeInitializer The type initializer of the instrumented type.
* @param instrumentations A map of all method descriptions mapped to their handling entries. * @param implementations A map of all method descriptions mapped to their handling entries.
*/ */
public Compiled(TypeDescription instrumentedType, public Compiled(TypeDescription instrumentedType,
LoadedTypeInitializer loadedTypeInitializer, LoadedTypeInitializer loadedTypeInitializer,
InstrumentedType.TypeInitializer typeInitializer, InstrumentedType.TypeInitializer typeInitializer,
Map<MethodDescription, Entry> instrumentations) { Map<MethodDescription, Entry> implementations) {
this.instrumentedType = instrumentedType; this.instrumentedType = instrumentedType;
this.loadedTypeInitializer = loadedTypeInitializer; this.loadedTypeInitializer = loadedTypeInitializer;
this.typeInitializer = typeInitializer; this.typeInitializer = typeInitializer;
this.instrumentations = instrumentations; this.implementations = implementations;
} }


@Override @Override
Expand All @@ -713,12 +713,12 @@ public InstrumentedType.TypeInitializer getTypeInitializer() {


@Override @Override
public MethodList getInstrumentedMethods() { public MethodList getInstrumentedMethods() {
return new MethodList.Explicit(new ArrayList<MethodDescription>(instrumentations.keySet())).filter(not(isTypeInitializer())); return new MethodList.Explicit(new ArrayList<MethodDescription>(implementations.keySet())).filter(not(isTypeInitializer()));
} }


@Override @Override
public Entry target(MethodDescription methodDescription) { public Entry target(MethodDescription methodDescription) {
Entry entry = instrumentations.get(methodDescription); Entry entry = implementations.get(methodDescription);
return entry == null return entry == null
? Entry.ForSkippedMethod.INSTANCE ? Entry.ForSkippedMethod.INSTANCE
: entry; : entry;
Expand All @@ -732,15 +732,15 @@ public boolean equals(Object other) {
return instrumentedType.equals(compiled.instrumentedType) return instrumentedType.equals(compiled.instrumentedType)
&& loadedTypeInitializer.equals(compiled.loadedTypeInitializer) && loadedTypeInitializer.equals(compiled.loadedTypeInitializer)
&& typeInitializer.equals(compiled.typeInitializer) && typeInitializer.equals(compiled.typeInitializer)
&& instrumentations.equals(compiled.instrumentations); && implementations.equals(compiled.implementations);
} }


@Override @Override
public int hashCode() { public int hashCode() {
int result = instrumentedType.hashCode(); int result = instrumentedType.hashCode();
result = 31 * result + loadedTypeInitializer.hashCode(); result = 31 * result + loadedTypeInitializer.hashCode();
result = 31 * result + typeInitializer.hashCode(); result = 31 * result + typeInitializer.hashCode();
result = 31 * result + instrumentations.hashCode(); result = 31 * result + implementations.hashCode();
return result; return result;
} }


Expand All @@ -750,7 +750,7 @@ public String toString() {
"instrumentedType=" + instrumentedType + "instrumentedType=" + instrumentedType +
", loadedTypeInitializer=" + loadedTypeInitializer + ", loadedTypeInitializer=" + loadedTypeInitializer +
", typeInitializer=" + typeInitializer + ", typeInitializer=" + typeInitializer +
", instrumentations=" + instrumentations + ", implementations=" + implementations +
'}'; '}';
} }
} }
Expand Down

0 comments on commit 708c0a2

Please sign in to comment.