net.bytebuddy.description.ByteCodeElement Java Examples

The following examples show how to use net.bytebuddy.description.ByteCodeElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public FieldDescription resolve(TypeDescription targetType, ByteCodeElement target, TypeList.Generic parameters, TypeDescription.Generic result) {
    if (parameters.isEmpty()) {
        throw new IllegalStateException("Cannot substitute parameterless instruction with " + target);
    } else if (parameters.get(0).isPrimitive() || parameters.get(0).isArray()) {
        throw new IllegalStateException("Cannot access field on primitive or array type for " + target);
    }
    TypeDefinition current = parameters.get(0);
    do {
        FieldList<?> fields = current.getDeclaredFields().filter(not(isStatic()).<FieldDescription>and(isVisibleTo(instrumentedType)).and(matcher));
        if (fields.size() == 1) {
            return fields.getOnly();
        } else if (fields.size() > 1) {
            throw new IllegalStateException("Ambiguous field location of " + fields);
        }
        current = current.getSuperClass();
    } while (current != null);
    throw new IllegalStateException("Cannot locate field matching " + matcher + " on " + targetType);
}
 
Example #2
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public MethodDescription resolve(TypeDescription targetType, ByteCodeElement target, TypeList.Generic parameters, TypeDescription.Generic result) {
    if (parameters.isEmpty()) {
        throw new IllegalStateException("Cannot substitute parameterless instruction with " + target);
    } else if (parameters.get(0).isPrimitive() || parameters.get(0).isArray()) {
        throw new IllegalStateException("Cannot invoke method on primitive or array type for " + target);
    }
    TypeDefinition typeDefinition = parameters.get(0);
    List<MethodDescription> candidates = CompoundList.<MethodDescription>of(methodGraphCompiler.compile(typeDefinition, instrumentedType)
            .listNodes()
            .asMethodList()
            .filter(matcher), typeDefinition.getDeclaredMethods().filter(isPrivate().<MethodDescription>and(isVisibleTo(instrumentedType)).and(matcher)));
    if (candidates.size() == 1) {
        return candidates.get(0);
    } else {
        throw new IllegalStateException("Not exactly one method that matches " + matcher + ": " + candidates);
    }
}
 
Example #3
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation resolve(TypeDescription targetType,
                                 ByteCodeElement target,
                                 TypeList.Generic parameters,
                                 TypeDescription.Generic result,
                                 int freeOffset) {
    List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(1
            + parameters.size()
            + steps.size() * 2
            + (result.represents(void.class) ? 0 : 2));
    Map<Integer, Integer> offsets = new HashMap<Integer, Integer>();
    for (int index = parameters.size() - 1; index >= 0; index--) {
        stackManipulations.add(MethodVariableAccess.of(parameters.get(index)).storeAt(freeOffset));
        offsets.put(index, freeOffset);
        freeOffset += parameters.get(index).getStackSize().getSize();
    }
    stackManipulations.add(DefaultValue.of(result));
    TypeDescription.Generic current = result;
    for (Step step : steps) {
        Step.Resolution resulution = step.resolve(targetType,
                target,
                parameters,
                current,
                offsets,
                freeOffset);
        stackManipulations.add(resulution.getStackManipulation());
        current = resulution.getResultType();
    }
    stackManipulations.add(assigner.assign(current, result, typing));
    return new StackManipulation.Compound(stackManipulations);
}
 
Example #4
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameContainsIgnoreCase() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(ElementMatchers.nameContainsIgnoreCase(FOO.substring(1, 2)).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameContainsIgnoreCase(FOO.substring(1, 2).toUpperCase()).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameContainsIgnoreCase(BAR).matches(byteCodeElement), is(false));
}
 
Example #5
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation resolve(TypeDescription targetType,
                                 ByteCodeElement target,
                                 TypeList.Generic parameters,
                                 TypeDescription.Generic result,
                                 int freeOffset) {
    List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(parameters.size());
    for (int index = parameters.size() - 1; index >= 0; index--) {
        stackManipulations.add(Removal.of(parameters.get(index)));
    }
    return new StackManipulation.Compound(CompoundList.of(stackManipulations, DefaultValue.of(result.asErasure())));
}
 
Example #6
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public StackManipulation resolve(TypeDescription targetType,
                                 ByteCodeElement target,
                                 TypeList.Generic parameters,
                                 TypeDescription.Generic result,
                                 int freeOffset) {
    FieldDescription fieldDescription = fieldResolver.resolve(targetType, target, parameters, result);
    if (!fieldDescription.isAccessibleTo(instrumentedType)) {
        throw new IllegalStateException(instrumentedType + " cannot access " + fieldDescription);
    } else if (result.represents(void.class)) {
        if (parameters.size() != (fieldDescription.isStatic() ? 1 : 2)) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " with " + parameters);
        } else if (!fieldDescription.isStatic() && !parameters.get(0).asErasure().isAssignableTo(fieldDescription.getDeclaringType().asErasure())) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " on " + parameters.get(0));
        } else if (!parameters.get(fieldDescription.isStatic() ? 0 : 1).asErasure().isAssignableTo(fieldDescription.getType().asErasure())) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " to " + parameters.get(fieldDescription.isStatic() ? 0 : 1));
        }
        return FieldAccess.forField(fieldDescription).write();
    } else {
        if (parameters.size() != (fieldDescription.isStatic() ? 0 : 1)) {
            throw new IllegalStateException("Cannot set " + fieldDescription + " with " + parameters);
        } else if (!fieldDescription.isStatic() && !parameters.get(0).asErasure().isAssignableTo(fieldDescription.getDeclaringType().asErasure())) {
            throw new IllegalStateException("Cannot get " + fieldDescription + " on " + parameters.get(0));
        } else if (!fieldDescription.getType().asErasure().isAssignableTo(result.asErasure())) {
            throw new IllegalStateException("Cannot get " + fieldDescription + " as " + result);
        }
        return FieldAccess.forField(fieldDescription).read();
    }
}
 
Example #7
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testHasDescriptor() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getDescriptor()).thenReturn(FOO);
    assertThat(ElementMatchers.hasDescriptor(FOO).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.hasDescriptor(FOO.toUpperCase()).matches(byteCodeElement), is(false));
    assertThat(ElementMatchers.hasDescriptor(BAR).matches(byteCodeElement), is(false));
}
 
Example #8
Source File: AccessibilityMatcherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoMatch() throws Exception {
    when(byteCodeElement.isAccessibleTo(typeDescription)).thenReturn(false);
    assertThat(new AccessibilityMatcher<ByteCodeElement>(typeDescription).matches(byteCodeElement), is(false));
    verify(byteCodeElement).isAccessibleTo(typeDescription);
    verifyNoMoreInteractions(byteCodeElement);
    verifyZeroInteractions(typeDescription);
}
 
Example #9
Source File: VisibilityMatcherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testMatch() throws Exception {
    when(byteCodeElement.isVisibleTo(typeDescription)).thenReturn(true);
    assertThat(new VisibilityMatcher<ByteCodeElement>(typeDescription).matches(byteCodeElement), is(true));
    verify(byteCodeElement).isVisibleTo(typeDescription);
    verifyNoMoreInteractions(byteCodeElement);
    verifyZeroInteractions(typeDescription);
}
 
Example #10
Source File: VisibilityMatcherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoMatch() throws Exception {
    when(byteCodeElement.isVisibleTo(typeDescription)).thenReturn(false);
    assertThat(new VisibilityMatcher<ByteCodeElement>(typeDescription).matches(byteCodeElement), is(false));
    verify(byteCodeElement).isVisibleTo(typeDescription);
    verifyNoMoreInteractions(byteCodeElement);
    verifyZeroInteractions(typeDescription);
}
 
Example #11
Source File: TransformerForMethodTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    when(returnType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(returnType);
    when(typeVariableBound.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(typeVariableBound);
    when(parameterType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(parameterType);
    when(exceptionType.accept(any(TypeDescription.Generic.Visitor.class))).thenReturn(exceptionType);
    when(typeVariableBound.getSymbol()).thenReturn(QUX);
    when(typeVariableBound.getSort()).thenReturn(TypeDefinition.Sort.VARIABLE);
    when(typeVariableBound.asGenericType()).thenReturn(typeVariableBound);
    when(methodDescription.asToken(matchesPrototype(none()))).thenReturn(methodToken);
    when(methodDescription.getDeclaringType()).thenReturn(declaringType);
    when(methodDescription.asDefined()).thenReturn(definedMethod);
    when(methodToken.getName()).thenReturn(FOO);
    when(methodToken.getModifiers()).thenReturn(MODIFIERS);
    when(methodToken.getReturnType()).thenReturn(returnType);
    when(methodToken.getTypeVariableTokens())
            .thenReturn(new ByteCodeElement.Token.TokenList<TypeVariableToken>(new TypeVariableToken(QUX, new TypeList.Generic.Explicit(typeVariableBound))));
    when(methodToken.getExceptionTypes()).thenReturn(new TypeList.Generic.Explicit(exceptionType));
    when(methodToken.getParameterTokens())
            .thenReturn(new ByteCodeElement.Token.TokenList<ParameterDescription.Token>(parameterToken));
    when(methodToken.getAnnotations()).thenReturn(new AnnotationList.Explicit(methodAnnotation));
    when(modifierContributor.getMask()).thenReturn(MASK);
    when(modifierContributor.getRange()).thenReturn(RANGE);
    when(parameterToken.getType()).thenReturn(parameterType);
    when(parameterToken.getAnnotations()).thenReturn(new AnnotationList.Explicit(parameterAnnotation));
    when(parameterToken.getName()).thenReturn(BAR);
    when(parameterToken.getModifiers()).thenReturn(MODIFIERS * 2);
    when(definedMethod.getParameters())
            .thenReturn(new ParameterList.Explicit<ParameterDescription.InDefinedShape>(definedParameter));
    when(declaringType.asErasure()).thenReturn(rawDeclaringType);
    when(returnType.asErasure()).thenReturn(rawReturnType);
    when(parameterType.asErasure()).thenReturn(rawParameterType);
    when(exceptionType.asGenericType()).thenReturn(exceptionType);
}
 
Example #12
Source File: ConstructorStrategyForDefaultConstructorTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    when(methodRegistry.append(any(LatentMatcher.class),
            any(MethodRegistry.Handler.class),
            any(MethodAttributeAppender.Factory.class),
            any(Transformer.class))).thenReturn(methodRegistry);
    when(instrumentedType.getSuperClass()).thenReturn(superClass);
    when(superClass.getDeclaredMethods()).thenReturn(new MethodList.Explicit<MethodDescription.InGenericShape>(methodDescription));
    when(methodDescription.isConstructor()).thenReturn(true);
    when(methodDescription.isVisibleTo(instrumentedType)).thenReturn(true);
    when(methodDescription.asToken(ElementMatchers.is(instrumentedType))).thenReturn(token);
    when(token.getName()).thenReturn(FOO);
    when(token.getModifiers()).thenReturn(MODIFIERS);
    when(token.getTypeVariableTokens()).thenReturn(new ByteCodeElement.Token.TokenList<TypeVariableToken>());
    when(token.getReturnType()).thenReturn(typeDescription);
    when(token.getParameterTokens()).thenReturn(new ByteCodeElement.Token.TokenList<ParameterDescription.Token>());
    when(token.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(token.getAnnotations()).thenReturn(new AnnotationList.Empty());
    when(token.getDefaultValue()).thenReturn((AnnotationValue) defaultValue);
    when(token.getReceiverType()).thenReturn(typeDescription);
    stripped = new MethodDescription.Token(FOO,
            MODIFIERS,
            Collections.<TypeVariableToken>emptyList(),
            typeDescription,
            Collections.<ParameterDescription.Token>emptyList(),
            Collections.<TypeDescription.Generic>emptyList(),
            Collections.<AnnotationDescription>emptyList(),
            defaultValue,
            TypeDescription.Generic.UNDEFINED);
}
 
Example #13
Source File: ConstructorStrategyDefaultTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    when(methodRegistry.append(any(LatentMatcher.class),
            any(MethodRegistry.Handler.class),
            any(MethodAttributeAppender.Factory.class),
            any(Transformer.class))).thenReturn(methodRegistry);
    when(instrumentedType.getSuperClass()).thenReturn(superClass);
    when(superClass.getDeclaredMethods()).thenReturn(new MethodList.Explicit<MethodDescription.InGenericShape>(methodDescription));
    when(methodDescription.isConstructor()).thenReturn(true);
    when(methodDescription.isVisibleTo(instrumentedType)).thenReturn(true);
    when(methodDescription.asToken(matchesPrototype(ElementMatchers.is(instrumentedType)))).thenReturn(token);
    when(token.getName()).thenReturn(FOO);
    when(token.getModifiers()).thenReturn(MODIFIERS);
    when(token.getTypeVariableTokens()).thenReturn(new ByteCodeElement.Token.TokenList<TypeVariableToken>());
    when(token.getReturnType()).thenReturn(typeDescription);
    when(token.getParameterTokens()).thenReturn(new ByteCodeElement.Token.TokenList<ParameterDescription.Token>());
    when(token.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(token.getAnnotations()).thenReturn(new AnnotationList.Empty());
    when(token.getDefaultValue()).thenReturn((AnnotationValue) defaultValue);
    when(token.getReceiverType()).thenReturn(typeDescription);
    stripped = new MethodDescription.Token(FOO,
            MODIFIERS,
            Collections.<TypeVariableToken>emptyList(),
            typeDescription,
            Collections.<ParameterDescription.Token>emptyList(),
            Collections.<TypeDescription.Generic>emptyList(),
            Collections.<AnnotationDescription>emptyList(),
            defaultValue,
            TypeDescription.Generic.UNDEFINED);
}
 
Example #14
Source File: AccessibilityMatcherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testMatch() throws Exception {
    when(byteCodeElement.isAccessibleTo(typeDescription)).thenReturn(true);
    assertThat(new AccessibilityMatcher<ByteCodeElement>(typeDescription).matches(byteCodeElement), is(true));
    verify(byteCodeElement).isAccessibleTo(typeDescription);
    verifyNoMoreInteractions(byteCodeElement);
    verifyZeroInteractions(typeDescription);
}
 
Example #15
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameEndsWith() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(ElementMatchers.nameEndsWith(FOO.substring(1)).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameEndsWith(FOO.substring(1).toUpperCase()).matches(byteCodeElement), is(false));
    assertThat(ElementMatchers.nameEndsWith(BAR).matches(byteCodeElement), is(false));
}
 
Example #16
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameEndsWithIgnoreCase() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(ElementMatchers.nameEndsWithIgnoreCase(FOO.substring(1)).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameEndsWithIgnoreCase(FOO.substring(1).toUpperCase()).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameEndsWithIgnoreCase(BAR).matches(byteCodeElement), is(false));
}
 
Example #17
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameStartsWithIgnoreCase() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(ElementMatchers.nameStartsWithIgnoreCase(FOO.substring(0, 2)).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameStartsWithIgnoreCase(FOO.substring(0, 2).toUpperCase()).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameStartsWithIgnoreCase(BAR).matches(byteCodeElement), is(false));
}
 
Example #18
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Resolution resolve(TypeDescription targetType,
                          ByteCodeElement target,
                          TypeList.Generic parameters,
                          TypeDescription.Generic current,
                          Map<Integer, Integer> offsets,
                          int freeOffset) {
    return targetType.represents(void.class)
            ? this
            : new Simple(new StackManipulation.Compound(Removal.of(targetType), stackManipulation), resultType);
}
 
Example #19
Source File: MemberSubstitution.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new resolved binding.
 *
 * @param instrumentedType   The instrumented type.
 * @param instrumentedMethod The instrumented method.
 * @param targetType         The type on which a field or method was accessed.
 * @param target             The field or method that was accessed.
 * @param substitution       The substitution to apply.
 */
protected Resolved(TypeDescription instrumentedType,
                   MethodDescription instrumentedMethod,
                   TypeDescription targetType,
                   ByteCodeElement target,
                   Substitution substitution) {
    this.instrumentedType = instrumentedType;
    this.instrumentedMethod = instrumentedMethod;
    this.targetType = targetType;
    this.target = target;
    this.substitution = substitution;
}
 
Example #20
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNameStartsWith() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(ElementMatchers.nameStartsWith(FOO.substring(0, 2)).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.nameStartsWith(FOO.substring(0, 2).toUpperCase()).matches(byteCodeElement), is(false));
    assertThat(ElementMatchers.nameStartsWith(BAR).matches(byteCodeElement), is(false));
}
 
Example #21
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNamedIgnoreCase() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(ElementMatchers.namedIgnoreCase(FOO).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.namedIgnoreCase(FOO.toUpperCase()).matches(byteCodeElement), is(true));
    assertThat(ElementMatchers.namedIgnoreCase(BAR).matches(byteCodeElement), is(false));
}
 
Example #22
Source File: FieldList.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ByteCodeElement.Token.TokenList<FieldDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
    List<FieldDescription.Token> tokens = new ArrayList<FieldDescription.Token>(size());
    for (FieldDescription fieldDescription : this) {
        tokens.add(fieldDescription.asToken(matcher));
    }
    return new ByteCodeElement.Token.TokenList<FieldDescription.Token>(tokens);
}
 
Example #23
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNamedOneOf() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(namedOneOf(FOO, BAR).matches(byteCodeElement), is(true));
    assertThat(namedOneOf(FOO.toUpperCase(), BAR).matches(byteCodeElement), is(false));
    assertThat(namedOneOf(FOO.toUpperCase()).matches(byteCodeElement), is(false));
    assertThat(namedOneOf(BAR).matches(byteCodeElement), is(false));
}
 
Example #24
Source File: ElementMatchersTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
public void testNamed() throws Exception {
    ByteCodeElement byteCodeElement = mock(ByteCodeElement.class);
    when(byteCodeElement.getActualName()).thenReturn(FOO);
    assertThat(named(FOO).matches(byteCodeElement), is(true));
    assertThat(named(FOO.toUpperCase()).matches(byteCodeElement), is(false));
    assertThat(named(BAR).matches(byteCodeElement), is(false));
}
 
Example #25
Source File: ParameterList.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ByteCodeElement.Token.TokenList<ParameterDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
    List<ParameterDescription.Token> tokens = new ArrayList<ParameterDescription.Token>(size());
    for (ParameterDescription parameterDescription : this) {
        tokens.add(parameterDescription.asToken(matcher));
    }
    return new ByteCodeElement.Token.TokenList<ParameterDescription.Token>(tokens);
}
 
Example #26
Source File: DefinedShapeMatcherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testNoMatch() throws Exception {
    when(matcher.matches(resolvedDependant)).thenReturn(true);
    when(dependent.asDefined()).thenReturn((ByteCodeElement.TypeDependant) otherResolvedDependant);
    assertThat(new DefinedShapeMatcher(matcher).matches(dependent), is(false));
    verify(dependent).asDefined();
    verifyNoMoreInteractions(dependent);
    verify(matcher).matches(otherResolvedDependant);
    verifyNoMoreInteractions(matcher);
}
 
Example #27
Source File: DefinedShapeMatcherTest.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testMatch() throws Exception {
    when(matcher.matches(resolvedDependant)).thenReturn(true);
    when(dependent.asDefined()).thenReturn((ByteCodeElement.TypeDependant) resolvedDependant);
    assertThat(new DefinedShapeMatcher(matcher).matches(dependent), is(true));
    verify(dependent).asDefined();
    verifyNoMoreInteractions(dependent);
    verify(matcher).matches(resolvedDependant);
    verifyNoMoreInteractions(matcher);
}
 
Example #28
Source File: MethodList.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ByteCodeElement.Token.TokenList<MethodDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
    List<MethodDescription.Token> tokens = new ArrayList<MethodDescription.Token>(size());
    for (MethodDescription methodDescription : this) {
        tokens.add(methodDescription.asToken(matcher));
    }
    return new ByteCodeElement.Token.TokenList<MethodDescription.Token>(tokens);
}
 
Example #29
Source File: RecordComponentList.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ByteCodeElement.Token.TokenList<RecordComponentDescription.Token> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
    List<RecordComponentDescription.Token> tokens = new ArrayList<RecordComponentDescription.Token>(size());
    for (RecordComponentDescription recordComponentDescription : this) {
        tokens.add(recordComponentDescription.asToken(matcher));
    }
    return new ByteCodeElement.Token.TokenList<RecordComponentDescription.Token>(tokens);
}
 
Example #30
Source File: TypeList.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ByteCodeElement.Token.TokenList<TypeVariableToken> asTokenList(ElementMatcher<? super TypeDescription> matcher) {
    List<TypeVariableToken> tokens = new ArrayList<TypeVariableToken>(size());
    for (TypeDescription.Generic typeVariable : this) {
        tokens.add(TypeVariableToken.of(typeVariable, matcher));
    }
    return new ByteCodeElement.Token.TokenList<TypeVariableToken>(tokens);
}