Skip to content

Commit

Permalink
Removed instrumented type naming from latent matcher to indicate broa…
Browse files Browse the repository at this point in the history
…der usage.
  • Loading branch information
raphw committed Mar 10, 2016
1 parent c46d64d commit dbb8762
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 39 deletions.
Expand Up @@ -209,8 +209,8 @@ protected FieldTransformer getTransformer() {
}

@Override
public ElementMatcher<? super FieldDescription> resolve(TypeDescription instrumentedType) {
return matcher.resolve(instrumentedType);
public ElementMatcher<? super FieldDescription> resolve(TypeDescription typeDescription) {
return matcher.resolve(typeDescription);
}

@Override
Expand Down
Expand Up @@ -642,8 +642,8 @@ protected Handler getHandler() {
}

@Override
public ElementMatcher<? super MethodDescription> resolve(TypeDescription instrumentedType) {
return matcher.resolve(instrumentedType);
public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) {
return matcher.resolve(typeDescription);
}

@Override
Expand Down
Expand Up @@ -58,10 +58,10 @@ protected static LatentMatcher<MethodDescription> of(LatentMatcher<? super Metho
}

@Override
public ElementMatcher<? super MethodDescription> resolve(TypeDescription instrumentedType) {
return (ElementMatcher<? super MethodDescription>) not(ignoredMethods.resolve(instrumentedType))
.and(isVirtual().and(not(isFinal())).or(isDeclaredBy(instrumentedType)))
.or(isDeclaredBy(instrumentedType).and(not(predefinedMethodSignatures)));
public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) {
return (ElementMatcher<? super MethodDescription>) not(ignoredMethods.resolve(typeDescription))
.and(isVirtual().and(not(isFinal())).or(isDeclaredBy(typeDescription)))
.or(isDeclaredBy(typeDescription).and(not(predefinedMethodSignatures)));
}

@Override
Expand Down
Expand Up @@ -235,12 +235,12 @@ protected InstrumentableMatcher(LatentMatcher<? super MethodDescription> ignored
}

@Override
public ElementMatcher<? super MethodDescription> resolve(TypeDescription instrumentedType) {
public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) {
// Casting is required by JDK 6.
return (ElementMatcher<? super MethodDescription>) isVirtual().and(not(isFinal()))
.and(isVisibleTo(instrumentedType))
.and(not(ignoredMethods.resolve(instrumentedType)))
.or(isDeclaredBy(instrumentedType));
.and(isVisibleTo(typeDescription))
.and(not(ignoredMethods.resolve(typeDescription)))
.or(isDeclaredBy(typeDescription));
}

@Override
Expand Down
Expand Up @@ -10,19 +10,19 @@
import static net.bytebuddy.matcher.ElementMatchers.none;

/**
* A latent matcher that resolves an {@link ElementMatcher} after supplying the instrumented type.
* A latent matcher that resolves an {@link ElementMatcher} after supplying a type description.
*
* @param <T> The type of the matched element.
*/
public interface LatentMatcher<T> {

/**
* Resolves the element matcher this instance represents for the instrumented type.
* Resolves the element matcher this instance represents for the supplied type description.
*
* @param instrumentedType The instrumented type.
* @param typeDescription The type description for which the represented matcher should be resolved.
* @return An {@link ElementMatcher} that represents this matcher's resolved form.
*/
ElementMatcher<? super T> resolve(TypeDescription instrumentedType);
ElementMatcher<? super T> resolve(TypeDescription typeDescription);

/**
* A latent matcher representing an already resolved {@link ElementMatcher}.
Expand All @@ -46,7 +46,7 @@ public Resolved(ElementMatcher<? super S> matcher) {
}

@Override
public ElementMatcher<? super S> resolve(TypeDescription instrumentedType) {
public ElementMatcher<? super S> resolve(TypeDescription typeDescription) {
return matcher;
}

Expand All @@ -70,7 +70,7 @@ public String toString() {
}

/**
* A latent matcher where the field token is being attached to the instrumented type before matching.
* A latent matcher where the field token is being attached to the supplied type description before matching.
*/
class ForFieldToken implements LatentMatcher<FieldDescription> {

Expand All @@ -89,8 +89,8 @@ public ForFieldToken(FieldDescription.Token token) {
}

@Override
public ElementMatcher<? super FieldDescription> resolve(TypeDescription instrumentedType) {
return new ResolvedMatcher(token.asSignatureToken(instrumentedType));
public ElementMatcher<? super FieldDescription> resolve(TypeDescription typeDescription) {
return new ResolvedMatcher(token.asSignatureToken(typeDescription));
}

@Override
Expand Down Expand Up @@ -156,7 +156,7 @@ public String toString() {
}

/**
* A latent matcher where the method token is being attached to the instrumented type before matching.
* A latent matcher where the method token is being attached to the supplied type description before matching.
*/
class ForMethodToken implements LatentMatcher<MethodDescription> {

Expand All @@ -175,8 +175,8 @@ public ForMethodToken(MethodDescription.Token token) {
}

@Override
public ElementMatcher<? super MethodDescription> resolve(TypeDescription instrumentedType) {
return new ResolvedMatcher(token.asSignatureToken(instrumentedType));
public ElementMatcher<? super MethodDescription> resolve(TypeDescription typeDescription) {
return new ResolvedMatcher(token.asSignatureToken(typeDescription));
}

@Override
Expand Down Expand Up @@ -274,10 +274,10 @@ public Compound(List<? extends LatentMatcher<? super S>> matchers) {
}

@Override
public ElementMatcher<? super S> resolve(TypeDescription instrumentedType) {
public ElementMatcher<? super S> resolve(TypeDescription typeDescription) {
ElementMatcher.Junction<S> matcher = none();
for (LatentMatcher<? super S> latentMatcher : matchers) {
matcher = matcher.or(latentMatcher.resolve(instrumentedType));
matcher = matcher.or(latentMatcher.resolve(typeDescription));
}
return matcher;
}
Expand Down
Expand Up @@ -26,19 +26,19 @@ public class LatentMatcherCompoundTest {
private ElementMatcher<?> leftMatcher, rightMatcher;

@Mock
private TypeDescription instrumentedType;
private TypeDescription typeDescription;

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
when(left.resolve(instrumentedType)).thenReturn((ElementMatcher) leftMatcher);
when(right.resolve(instrumentedType)).thenReturn((ElementMatcher) rightMatcher);
when(left.resolve(typeDescription)).thenReturn((ElementMatcher) leftMatcher);
when(right.resolve(typeDescription)).thenReturn((ElementMatcher) rightMatcher);
}

@Test
@SuppressWarnings("unchecked")
public void testManifestation() throws Exception {
assertThat(new LatentMatcher.Compound(left, right).resolve(instrumentedType),
assertThat(new LatentMatcher.Compound(left, right).resolve(typeDescription),
is((ElementMatcher) none().or((ElementMatcher) leftMatcher).or((ElementMatcher) rightMatcher)));
}

Expand Down
Expand Up @@ -28,7 +28,7 @@ public class LatentMatcherForFieldTokenTest {
private FieldDescription.SignatureToken signatureToken, otherSignatureToken;

@Mock
private TypeDescription instrumentedType;
private TypeDescription typeDescription;

@Mock
private FieldDescription fieldDescription;
Expand All @@ -42,15 +42,15 @@ public void setUp() throws Exception {
@Test
public void testMatch() throws Exception {
when(fieldDescription.asSignatureToken()).thenReturn(signatureToken);
when(token.asSignatureToken(instrumentedType)).thenReturn(signatureToken);
assertThat(new LatentMatcher.ForFieldToken(token).resolve(instrumentedType).matches(fieldDescription), is(true));
when(token.asSignatureToken(typeDescription)).thenReturn(signatureToken);
assertThat(new LatentMatcher.ForFieldToken(token).resolve(typeDescription).matches(fieldDescription), is(true));
}

@Test
public void testNoMatch() throws Exception {
when(fieldDescription.asSignatureToken()).thenReturn(otherSignatureToken);
when(token.asSignatureToken(instrumentedType)).thenReturn(signatureToken);
assertThat(new LatentMatcher.ForFieldToken(token).resolve(instrumentedType).matches(fieldDescription), is(false));
when(token.asSignatureToken(typeDescription)).thenReturn(signatureToken);
assertThat(new LatentMatcher.ForFieldToken(token).resolve(typeDescription).matches(fieldDescription), is(false));
}

@Test
Expand Down
Expand Up @@ -26,23 +26,23 @@ public class LatentMatcherForMethodTokenTest {
private MethodDescription.SignatureToken signatureToken, otherToken;

@Mock
private TypeDescription instrumentedType;
private TypeDescription typeDescription;

@Mock
private MethodDescription methodDescription;

@Test
public void testMatch() throws Exception {
when(methodDescription.asSignatureToken()).thenReturn(signatureToken);
when(token.asSignatureToken(instrumentedType)).thenReturn(signatureToken);
assertThat(new LatentMatcher.ForMethodToken(token).resolve(instrumentedType).matches(methodDescription), is(true));
when(token.asSignatureToken(typeDescription)).thenReturn(signatureToken);
assertThat(new LatentMatcher.ForMethodToken(token).resolve(typeDescription).matches(methodDescription), is(true));
}

@Test
public void testNoMatch() throws Exception {
when(methodDescription.asSignatureToken()).thenReturn(signatureToken);
when(token.asSignatureToken(instrumentedType)).thenReturn(otherToken);
assertThat(new LatentMatcher.ForMethodToken(token).resolve(instrumentedType).matches(methodDescription), is(false));
when(token.asSignatureToken(typeDescription)).thenReturn(otherToken);
assertThat(new LatentMatcher.ForMethodToken(token).resolve(typeDescription).matches(methodDescription), is(false));
}

@Test
Expand Down

0 comments on commit dbb8762

Please sign in to comment.