Java Code Examples for net.bytebuddy.description.method.MethodDescription#TypeToken

The following examples show how to use net.bytebuddy.description.method.MethodDescription#TypeToken . 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: RebaseImplementationTarget.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Implementation.SpecialMethodInvocation withCheckedCompatibilityTo(MethodDescription.TypeToken token) {
    if (methodDescription.asTypeToken().equals(new MethodDescription.TypeToken(token.getReturnType(),
            CompoundList.of(token.getParameterTypes(), prependedParameters)))) {
        return this;
    } else {
        return Illegal.INSTANCE;
    }
}
 
Example 2
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Extends this key by the given method description.
 *
 * @param methodDescription The method to extend this key with.
 * @param harmonizer        The harmonizer to use for determining method equality.
 * @return The harmonized key representing the extension of this key with the provided method.
 */
protected Harmonized<V> extend(MethodDescription.InDefinedShape methodDescription, Harmonizer<V> harmonizer) {
    Map<V, Set<MethodDescription.TypeToken>> identifiers = new HashMap<V, Set<MethodDescription.TypeToken>>(this.identifiers);
    MethodDescription.TypeToken typeToken = methodDescription.asTypeToken();
    V identifier = harmonizer.harmonize(typeToken);
    Set<MethodDescription.TypeToken> typeTokens = identifiers.get(identifier);
    if (typeTokens == null) {
        identifiers.put(identifier, Collections.singleton(typeToken));
    } else {
        typeTokens = new HashSet<MethodDescription.TypeToken>(typeTokens);
        typeTokens.add(typeToken);
        identifiers.put(identifier, typeTokens);
    }
    return new Harmonized<V>(internalName, parameterCount, identifiers);
}
 
Example 3
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms this store into a method graph by applying the given merger.
 *
 * @param merger The merger to apply for resolving the representative for ambiguous resolutions.
 * @return The method graph that represents this key store.
 */
protected MethodGraph asGraph(Merger merger) {
    LinkedHashMap<Key<MethodDescription.TypeToken>, Node> entries = new LinkedHashMap<Key<MethodDescription.TypeToken>, Node>();
    for (Entry<V> entry : this.entries.values()) {
        Node node = entry.asNode(merger);
        entries.put(entry.getKey().detach(node.getRepresentative().asTypeToken()), node);
    }
    return new Graph(entries);
}
 
Example 4
Source File: MethodRegistry.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new entry for a compiled method registry.
 *
 * @param handler           The handler to be used for implementing a method.
 * @param attributeAppender The attribute appender of a compiled method.
 * @param methodDescription The method to be implemented including potential transformations.
 * @param bridgeTypes       The type tokens representing all bridge methods for the method.
 * @param visibility        The represented method's minimum visibility.
 * @param bridgeMethod      {@code true} if this entry represents a bridge method.
 */
protected Entry(Handler.Compiled handler,
                MethodAttributeAppender attributeAppender,
                MethodDescription methodDescription,
                Set<MethodDescription.TypeToken> bridgeTypes,
                Visibility visibility,
                boolean bridgeMethod) {
    this.handler = handler;
    this.attributeAppender = attributeAppender;
    this.methodDescription = methodDescription;
    this.bridgeTypes = bridgeTypes;
    this.visibility = visibility;
    this.bridgeMethod = bridgeMethod;
}
 
Example 5
Source File: MethodRegistry.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new prepared entry.
 *
 * @param handler                  The handler for implementing methods.
 * @param attributeAppenderFactory A attribute appender factory for appending attributes for any implemented method.
 * @param methodDescription        The method this entry represents.
 * @param typeTokens               A set of bridges representing the bridge methods of this method.
 * @param visibility               The minimum required visibility of this method.
 * @param bridgeMethod             {@code true} if this entry represents a bridge method.
 */
protected Entry(Handler handler,
                MethodAttributeAppender.Factory attributeAppenderFactory,
                MethodDescription methodDescription,
                Set<MethodDescription.TypeToken> typeTokens,
                Visibility visibility,
                boolean bridgeMethod) {
    this.handler = handler;
    this.attributeAppenderFactory = attributeAppenderFactory;
    this.methodDescription = methodDescription;
    this.typeTokens = typeTokens;
    this.visibility = visibility;
    this.bridgeMethod = bridgeMethod;
}
 
Example 6
Source File: MethodRegistry.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Transforms this entry into a prepared state.
 *
 * @param instrumentedType  The instrumented type.
 * @param methodDescription The non-transformed method to be implemented.
 * @param methodTypes       The method types this method represents.
 * @param visibility        The represented method's minimum visibility.
 * @return A prepared version of this entry.
 */
protected Prepared.Entry asPreparedEntry(TypeDescription instrumentedType,
                                         MethodDescription methodDescription,
                                         Set<MethodDescription.TypeToken> methodTypes,
                                         Visibility visibility) {
    return new Prepared.Entry(handler,
            attributeAppenderFactory,
            transformer.transform(instrumentedType, methodDescription),
            methodTypes,
            visibility,
            false);
}
 
Example 7
Source File: Implementation.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public SpecialMethodInvocation withCheckedCompatibilityTo(MethodDescription.TypeToken token) {
    if (methodDescription.asTypeToken().equals(token)) {
        return this;
    } else {
        return SpecialMethodInvocation.Illegal.INSTANCE;
    }
}
 
Example 8
Source File: MethodRegistry.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * Resolves the type tokens of all bridge methods that are required to be implemented for this entry.
 *
 * @return A set of type tokens representing the bridge methods required for implementing this type.
 */
protected Set<MethodDescription.TypeToken> resolveBridgeTypes() {
    HashSet<MethodDescription.TypeToken> typeTokens = new HashSet<MethodDescription.TypeToken>(this.typeTokens);
    typeTokens.remove(methodDescription.asTypeToken());
    return typeTokens;
}
 
Example 9
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Set<MethodDescription.TypeToken> getMethodTypes() {
    throw new IllegalStateException("Cannot resolve bridge method of an illegal node");
}
 
Example 10
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Set<MethodDescription.TypeToken> getMethodTypes() {
    return Collections.emptySet();
}
 
Example 11
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Token harmonize(MethodDescription.TypeToken typeToken) {
    return new Token(typeToken);
}
 
Example 12
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Token harmonize(MethodDescription.TypeToken typeToken) {
    return new Token(typeToken);
}
 
Example 13
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
@Override
protected Set<MethodDescription.TypeToken> getIdentifiers() {
    return identifiers;
}
 
Example 14
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Set<MethodDescription.TypeToken> getMethodTypes() {
    return key.getIdentifiers();
}
 
Example 15
Source File: Implementation.java    From byte-buddy with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public SpecialMethodInvocation withCheckedCompatibilityTo(MethodDescription.TypeToken token) {
    return this;
}
 
Example 16
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Returns a set of type tokens that this method represents. This set contains the actual method's type including the
 * types of all bridge methods.
 *
 * @return A set of type tokens that this method represents.
 */
Set<MethodDescription.TypeToken> getMethodTypes();
 
Example 17
Source File: Implementation.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Checks that this special method invocation is compatible with the supplied type representation.
 *
 * @param token The type token to check against.
 * @return This special method invocation or an illegal invocation if the method invocation is not applicable.
 */
SpecialMethodInvocation withCheckedCompatibilityTo(MethodDescription.TypeToken token);
 
Example 18
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new type token for a Java method.
 *
 * @param typeToken The represented type token.
 */
protected Token(MethodDescription.TypeToken typeToken) {
    this.typeToken = typeToken;
    hashCode = typeToken.getParameterTypes().hashCode();
}
 
Example 19
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new type token for a JVM method.
 *
 * @param typeToken The represented type token.
 */
public Token(MethodDescription.TypeToken typeToken) {
    this.typeToken = typeToken;
    hashCode = typeToken.getReturnType().hashCode() + 31 * typeToken.getParameterTypes().hashCode();
}
 
Example 20
Source File: MethodGraph.java    From byte-buddy with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new harmonized key.
 *
 * @param internalName   The internal name of the method this key identifies.
 * @param parameterCount The number of method parameters of the method this key identifies.
 * @param identifiers    A mapping of identifiers to the type tokens they represent.
 */
protected Harmonized(String internalName, int parameterCount, Map<V, Set<MethodDescription.TypeToken>> identifiers) {
    super(internalName, parameterCount);
    this.identifiers = identifiers;
}