Skip to content

Commit

Permalink
Added missing documentation and added missing test.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Apr 19, 2016
1 parent 25ed90a commit c2ed926
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,11 @@ interface Identified {
* Applies the given transformer for the already supplied matcher.
*
* @param transformer The transformer to apply.
* @return This agent builder with the transformer being applied when the previously supplied matcher
* @return A new instance of this agent builder with the transformer being applied when the previously supplied matcher
* identified a type for instrumentation which also allows for the registration of subsequent transformers.
*/
Extendable transform(Transformer transformer);

AgentBuilder asDecorator();

/**
* Allows to specify a type matcher for a type to instrument.
*/
Expand All @@ -511,7 +509,17 @@ interface Narrowable extends Matchable<Narrowable>, Identified {
* to be instrumented. Any subsequent transformers are applied in the order they are registered.
*/
interface Extendable extends AgentBuilder, Identified {
/* this is merely a unionizing interface that does not declare methods */

/**
* 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.
*
* @return A new instance of this agent builder with the specified transformation being applied as a decorator.
*/
AgentBuilder asDecorator();
}
}

Expand Down Expand Up @@ -4541,10 +4549,27 @@ Resolution resolve(TypeDescription typeDescription,
*/
interface Resolution {

/**
* Returns the sort of this resolution.
*
* @return The sort of this resolution.
*/
Sort getSort();

/**
* Resolves this resolution as a decorator of the supplied resolution.
*
* @param resolution The resolution for which this resolution should serve as a decorator.
* @return A resolution where this resolution is applied as a decorator if this resolution is alive.
*/
Resolution asDecoratorOf(Resolution resolution);

/**
* Resolves this resolution as a decorator of the supplied resolution.
*
* @param resolution The resolution for which this resolution should serve as a decorator.
* @return A resolution where this resolution is applied as a decorator if this resolution is alive.
*/
Resolution prepend(Decoratable resolution);

/**
Expand All @@ -4569,25 +4594,68 @@ byte[] apply(InitializationStrategy initializationStrategy,
AccessControlContext accessControlContext,
Listener listener);

/**
* Describes a specific sort of a {@link Resolution}.
*/
enum Sort {

/**
* A terminal resolution. After discovering such a resolution, no further transformers are considered.
*/
TERMINAL(true),

/**
* A resolution that can serve as a decorator for another resolution. After discovering such a resolution
* further transformations are considered where the represented resolution is prepended if applicable.
*/
DECORATOR(true),

/**
* A non-resolved resolution.
*/
UNDEFINED(false);

/**
* Indicates if this sort represents an active resolution.
*/
private final boolean alive;

/**
* Creates a new resolution sort.
*
* @param alive Indicates if this sort represents an active resolution.
*/
Sort(boolean alive) {
this.alive = alive;
}

/**
* Returns {@code true} if this resolution is alive.
*
* @return {@code true} if this resolution is alive.
*/
protected boolean isAlive() {
return alive;
}

@Override
public String toString() {
return "AgentBuilder.Default.Transformation.Resolution.Sort." + name();
}
}

/**
* A resolution that can be decorated by a transformer.
*/
interface Decoratable extends Resolution {

Transformation.Resolution prepend(Transformer transformer);
/**
* Prepends the supplied transformer to this resolution.
*
* @param transformer The transformer to prepend.
* @return A new resolution with the supplied transformer prepended.
*/
Resolution prepend(Transformer transformer);
}

/**
Expand Down Expand Up @@ -4710,14 +4778,17 @@ class Simple implements Transformation {
*/
private final Transformer transformer;

/**
* {@code true} if this transformer serves as a decorator.
*/
private final boolean decorator;

/**
* Creates a new transformation.
*
* @param rawMatcher The raw matcher that is represented by this transformation.
* @param transformer The transformer that is represented by this transformation.
* @param decorator
* @param decorator {@code true} if this transformer serves as a decorator.
*/
protected Simple(RawMatcher rawMatcher, Transformer transformer, boolean decorator) {
this.rawMatcher = rawMatcher;
Expand All @@ -4740,13 +4811,15 @@ public Transformation.Resolution resolve(TypeDescription typeDescription,
@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& decorator == ((Simple) other).decorator
&& rawMatcher.equals(((Simple) other).rawMatcher)
&& transformer.equals(((Simple) other).transformer);
}

@Override
public int hashCode() {
int result = rawMatcher.hashCode();
result = 31 * result + (decorator ? 1 : 0);
result = 31 * result + transformer.hashCode();
return result;
}
Expand All @@ -4756,6 +4829,7 @@ public String toString() {
return "AgentBuilder.Default.Transformation.Simple{" +
"rawMatcher=" + rawMatcher +
", transformer=" + transformer +
", decorator=" + decorator +
'}';
}

Expand Down Expand Up @@ -4784,6 +4858,9 @@ protected static class Resolution implements Transformation.Resolution.Decoratab
*/
private final Transformer transformer;

/**
* {@code true} if this transformer serves as a decorator.
*/
private final boolean decorator;

/**
Expand All @@ -4793,7 +4870,7 @@ protected static class Resolution implements Transformation.Resolution.Decoratab
* @param classLoader The class loader of the transformed type.
* @param protectionDomain The protection domain of the transformed type.
* @param transformer The transformer to be applied.
* @param decorator
* @param decorator {@code true} if this transformer serves as a decorator.
*/
protected Resolution(TypeDescription typeDescription,
ClassLoader classLoader,
Expand Down Expand Up @@ -4861,6 +4938,7 @@ public boolean equals(Object other) {
if (other == null || getClass() != other.getClass()) return false;
Resolution that = (Resolution) other;
return typeDescription.equals(that.typeDescription)
&& decorator == that.decorator
&& !(classLoader != null ? !classLoader.equals(that.classLoader) : that.classLoader != null)
&& !(protectionDomain != null ? !protectionDomain.equals(that.protectionDomain) : that.protectionDomain != null)
&& transformer.equals(that.transformer);
Expand All @@ -4869,6 +4947,7 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
int result = typeDescription.hashCode();
result = 31 * result + (decorator ? 1 : 0);
result = 31 * result + (classLoader != null ? classLoader.hashCode() : 0);
result = 31 * result + (protectionDomain != null ? protectionDomain.hashCode() : 0);
result = 31 * result + transformer.hashCode();
Expand All @@ -4882,6 +4961,7 @@ public String toString() {
", classLoader=" + classLoader +
", protectionDomain=" + protectionDomain +
", transformer=" + transformer +
", decorator=" + decorator +
'}';
}

Expand Down Expand Up @@ -5013,7 +5093,7 @@ public Resolution resolve(TypeDescription typeDescription,
case TERMINAL:
return current.asDecoratorOf(resolution);
case DECORATOR:
current = current.asDecoratorOf(resolution); // TODO: WAT?
current = current.asDecoratorOf(resolution);
case UNDEFINED:
break;
default:
Expand Down Expand Up @@ -5439,14 +5519,17 @@ protected class Transforming extends Delegator<Identified.Narrowable> implements
*/
private final Transformer transformer;

/**
* {@code true} if this transformer serves as a decorator.
*/
private final boolean decorator;

/**
* Creates a new matched default agent builder.
*
* @param rawMatcher The supplied raw matcher.
* @param transformer The supplied transformer.
* @param decorator
* @param decorator {@code true} if this transformer serves as a decorator.
*/
protected Transforming(RawMatcher rawMatcher, Transformer transformer, boolean decorator) {
this.rawMatcher = rawMatcher;
Expand Down Expand Up @@ -5502,6 +5585,7 @@ private Default getOuter() {
@Override
public boolean equals(Object other) {
return this == other || !(other == null || getClass() != other.getClass())
&& decorator == ((Transforming) other).decorator
&& rawMatcher.equals(((Transforming) other).rawMatcher)
&& transformer.equals(((Transforming) other).transformer)
&& Default.this.equals(((Transforming) other).getOuter());
Expand All @@ -5510,6 +5594,7 @@ public boolean equals(Object other) {
@Override
public int hashCode() {
int result = rawMatcher.hashCode();
result = 31 * result + (decorator ? 1 : 0);
result = 31 * result + transformer.hashCode();
result = 31 * result + Default.this.hashCode();
return result;
Expand All @@ -5520,6 +5605,7 @@ public String toString() {
return "AgentBuilder.Default.Transforming{" +
"rawMatcher=" + rawMatcher +
", transformer=" + transformer +
", decorator=" + decorator +
", agentBuilder=" + Default.this +
'}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ public AccessControlContext create() {
ObjectPropertyAssertion.of(AgentBuilder.Default.Transformation.Ignored.class).apply();
ObjectPropertyAssertion.of(AgentBuilder.Default.Transformation.Compound.class).apply();
ObjectPropertyAssertion.of(AgentBuilder.Default.Transformation.Resolution.Unresolved.class).apply();
ObjectPropertyAssertion.of(AgentBuilder.Default.Transformation.Resolution.Sort.class).apply();
ObjectPropertyAssertion.of(AgentBuilder.Default.BootstrapInjectionStrategy.Enabled.class).apply();
ObjectPropertyAssertion.of(AgentBuilder.Default.BootstrapInjectionStrategy.Disabled.class).apply();
ObjectPropertyAssertion.of(AgentBuilder.Default.ExecutingTransformer.class).create(new ObjectPropertyAssertion.Creator<AccessControlContext>() {
Expand Down

0 comments on commit c2ed926

Please sign in to comment.