Java Code Examples for net.bytebuddy.description.type.TypeDescription#getDeclaredMethods()

The following examples show how to use net.bytebuddy.description.type.TypeDescription#getDeclaredMethods() . 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: TransformerInvokerGenerator.java    From Diorite with MIT License 6 votes vote down vote up
@Override
        public ClassVisitor wrap(TypeDescription typeDescription, ClassVisitor cv, Context context, TypePool typePool,
                                 FieldList<FieldDescription.InDefinedShape> fieldList, MethodList<?> methodList, int i, int i1)
        {
//            public void visit(int version, int modifiers, String name, String signature, String superName, String[] interfaces) {
            cv.visit(ClassFileVersion.JAVA_V9.getMinorMajorVersion(), typeDescription.getModifiers(), typeDescription.getInternalName(), null,
                     typeDescription.getSuperClass().asErasure().getInternalName(), typeDescription.getInterfaces().asErasures().toInternalNames());
            TypeDescription clazz = this.clazz;
            String internalName = clazz.getInternalName();
            String descriptor = clazz.getDescriptor();
            MethodList<InDefinedShape> declaredMethods = clazz.getDeclaredMethods();
            int methodsSize = declaredMethods.size();
            String implName = GENERATED_PREFIX + "." + clazz.getName();
            String internalImplName = GENERATED_PREFIX.replace('.', '/') + "/" + internalName;
            String descriptorImplName = "L" + GENERATED_PREFIX.replace('.', '/') + "/" + internalName + ";";

            FieldVisitor fv;
            MethodVisitor mv;
            AnnotationVisitor av0;

            cv.visitEnd();
            return cv;
        }
 
Example 2
Source File: MethodAnnotationMatch.java    From skywalking with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isMatch(TypeDescription typeDescription) {
    for (MethodDescription.InDefinedShape methodDescription : typeDescription.getDeclaredMethods()) {
        List<String> annotationList = new ArrayList<String>(Arrays.asList(annotations));

        AnnotationList declaredAnnotations = methodDescription.getDeclaredAnnotations();
        for (AnnotationDescription annotation : declaredAnnotations) {
            annotationList.remove(annotation.getAnnotationType().getActualName());
        }
        if (annotationList.isEmpty()) {
            return true;
        }
    }

    return false;
}
 
Example 3
Source File: AnnotationDescription.java    From byte-buddy with Apache License 2.0 6 votes vote down vote up
@Override
public boolean equals(Object other) {
    if (this == other) {
        return true;
    } else if (!(other instanceof AnnotationDescription)) {
        return false;
    }
    AnnotationDescription annotationDescription = ((AnnotationDescription) other);
    TypeDescription annotationType = getAnnotationType();
    if (!annotationDescription.getAnnotationType().equals(annotationType)) {
        return false;
    }
    for (MethodDescription.InDefinedShape methodDescription : annotationType.getDeclaredMethods()) {
        if (!getValue(methodDescription).equals(annotationDescription.getValue(methodDescription))) {
            return false;
        }
    }
    return true;
}
 
Example 4
Source File: AnnotationValueOffsetMappingFactory.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Nullable
private Object getAnnotationValue(MethodDescription instrumentedMethod, AnnotationValueExtractor annotationValueExtractor) {
    for (TypeDescription typeDescription : instrumentedMethod.getDeclaredAnnotations().asTypeList()) {
        if (named(annotationValueExtractor.annotationClassName()).matches(typeDescription)) {
            for (MethodDescription.InDefinedShape annotationMethod : typeDescription.getDeclaredMethods()) {
                if (annotationMethod.getName().equals(annotationValueExtractor.method())) {
                    return instrumentedMethod.getDeclaredAnnotations().ofType(typeDescription).getValue(annotationMethod).resolve();
                }
            }
        }
    }
    return null;
}
 
Example 5
Source File: InliningImplementationMatcher.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a matcher where only overridable or declared methods are matched unless those are ignored. Methods that
 * are declared by the target type are only matched if they are not ignored. Declared methods that are not found on the
 * target type are always matched.
 *
 * @param ignoredMethods A method matcher that matches any ignored method.
 * @param originalType   The original type of the instrumentation before adding any user methods.
 * @return A latent method matcher that identifies any method to instrument for a rebasement or redefinition.
 */
protected static LatentMatcher<MethodDescription> of(LatentMatcher<? super MethodDescription> ignoredMethods, TypeDescription originalType) {
    ElementMatcher.Junction<MethodDescription> predefinedMethodSignatures = none();
    for (MethodDescription methodDescription : originalType.getDeclaredMethods()) {
        ElementMatcher.Junction<MethodDescription> signature = methodDescription.isConstructor()
                ? isConstructor()
                : ElementMatchers.<MethodDescription>named(methodDescription.getName());
        signature = signature.and(returns(methodDescription.getReturnType().asErasure()));
        signature = signature.and(takesArguments(methodDescription.getParameters().asTypeList().asErasures()));
        predefinedMethodSignatures = predefinedMethodSignatures.or(signature);
    }
    return new InliningImplementationMatcher(ignoredMethods, predefinedMethodSignatures);
}
 
Example 6
Source File: MethodRebaseResolver.java    From byte-buddy with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new method rebase resolver.
 *
 * @param instrumentedType            The instrumented type.
 * @param rebaseableMethodTokens      Tokens describing all methods that can possibly be rebased.
 * @param classFileVersion            The class file version for the instrumentation.
 * @param auxiliaryTypeNamingStrategy The naming strategy for naming a potential auxiliary type.
 * @param methodNameTransformer       A transformer for method names.
 * @return A method rebase resolver that is capable of rebasing any of the provided methods.
 */
public static MethodRebaseResolver make(TypeDescription instrumentedType,
                                        Set<? extends MethodDescription.Token> rebaseableMethodTokens,
                                        ClassFileVersion classFileVersion,
                                        AuxiliaryType.NamingStrategy auxiliaryTypeNamingStrategy,
                                        MethodNameTransformer methodNameTransformer) {
    DynamicType placeholderType = null;
    Map<MethodDescription.InDefinedShape, Resolution> resolutions = new HashMap<MethodDescription.InDefinedShape, Resolution>();
    for (MethodDescription.InDefinedShape instrumentedMethod : instrumentedType.getDeclaredMethods()) {
        if (rebaseableMethodTokens.contains(instrumentedMethod.asToken(is(instrumentedType)))) {
            Resolution resolution;
            if (instrumentedMethod.isConstructor()) {
                if (placeholderType == null) {
                    placeholderType = TrivialType.SIGNATURE_RELEVANT.make(auxiliaryTypeNamingStrategy.name(instrumentedType),
                            classFileVersion,
                            MethodAccessorFactory.Illegal.INSTANCE);
                }
                resolution = Resolution.ForRebasedConstructor.of(instrumentedMethod, placeholderType.getTypeDescription());
            } else {
                resolution = Resolution.ForRebasedMethod.of(instrumentedType, instrumentedMethod, methodNameTransformer);
            }
            resolutions.put(instrumentedMethod, resolution);
        }
    }
    return placeholderType == null
            ? new Default(resolutions, Collections.<DynamicType>emptyList())
            : new Default(resolutions, Collections.singletonList(placeholderType));
}