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 @Override
public ElementMatcher<? super FieldDescription> resolve(TypeDescription instrumentedType) { public ElementMatcher<? super FieldDescription> resolve(TypeDescription typeDescription) {
return matcher.resolve(instrumentedType); return matcher.resolve(typeDescription);
} }


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


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


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


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


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


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


@Override @Override
Expand Down
Expand Up @@ -10,19 +10,19 @@
import static net.bytebuddy.matcher.ElementMatchers.none; 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. * @param <T> The type of the matched element.
*/ */
public interface LatentMatcher<T> { 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. * @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}. * A latent matcher representing an already resolved {@link ElementMatcher}.
Expand All @@ -46,7 +46,7 @@ public Resolved(ElementMatcher<? super S> matcher) {
} }


@Override @Override
public ElementMatcher<? super S> resolve(TypeDescription instrumentedType) { public ElementMatcher<? super S> resolve(TypeDescription typeDescription) {
return matcher; 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> { class ForFieldToken implements LatentMatcher<FieldDescription> {


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


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


@Override @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> { class ForMethodToken implements LatentMatcher<MethodDescription> {


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


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


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


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


@Mock @Mock
private TypeDescription instrumentedType; private TypeDescription typeDescription;


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


@Test @Test
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testManifestation() throws Exception { 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))); 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; private FieldDescription.SignatureToken signatureToken, otherSignatureToken;


@Mock @Mock
private TypeDescription instrumentedType; private TypeDescription typeDescription;


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


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


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


@Mock @Mock
private TypeDescription instrumentedType; private TypeDescription typeDescription;


@Mock @Mock
private MethodDescription methodDescription; private MethodDescription methodDescription;


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


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


@Test @Test
Expand Down

0 comments on commit dbb8762

Please sign in to comment.