/** * {@inheritDoc} */ public MethodDescription.InDefinedShape get(int index) { return index < constructors.size() ? new MethodDescription.ForLoadedConstructor(constructors.get(index)) : new MethodDescription.ForLoadedMethod(methods.get(index - constructors.size())); }
/** * Creates a privileged method constant action with one argument. * * @param name The name of the method. * @param field The name of a field to define. * @param type The type of the field to define. */ PrivilegedMemberLookupAction(String name, String field, Class<?> type) { try { methodDescription = new MethodDescription.ForLoadedMethod(Class.class.getMethod(name, type)); } catch (NoSuchMethodException exception) { throw new IllegalStateException("Could not locate method: " + name, exception); } fields = Collections.<String, Class<?>>singletonMap(field, type); }
/** {@inheritDoc} */ public StackManipulation resolve(MethodDescription instrumentedMethod, TypeDescription instrumentedType) { try { return MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Throwable.class.getMethod("printStackTrace"))); } catch (NoSuchMethodException exception) { throw new IllegalStateException("Cannot locate Throwable::printStackTrace"); } } }
/** * {@inheritDoc} */ public TypeVariableSource getTypeVariableSource() { GenericDeclaration genericDeclaration = typeVariable.getGenericDeclaration(); if (genericDeclaration instanceof Class) { return TypeDescription.ForLoadedType.of((Class<?>) genericDeclaration); } else if (genericDeclaration instanceof Method) { return new MethodDescription.ForLoadedMethod((Method) genericDeclaration); } else if (genericDeclaration instanceof Constructor) { return new MethodDescription.ForLoadedConstructor((Constructor<?>) genericDeclaration); } else { throw new IllegalStateException("Unknown declaration: " + genericDeclaration); } }
/** * {@inheritDoc} */ public MethodDescription.InDefinedShape getEnclosingMethod() { Method enclosingMethod = type.getEnclosingMethod(); Constructor<?> enclosingConstructor = type.getEnclosingConstructor(); if (enclosingMethod != null) { return new MethodDescription.ForLoadedMethod(enclosingMethod); } else if (enclosingConstructor != null) { return new MethodDescription.ForLoadedConstructor(enclosingConstructor); } else { return MethodDescription.UNDEFINED; } }
/** * {@inheritDoc} */ public Size apply(MethodVisitor methodVisitor, Implementation.Context implementationContext) { try { return new Compound( ClassConstant.of(fieldDescription.getDeclaringType()), new TextConstant(fieldDescription.getInternalName()), MethodInvocation.invoke(new MethodDescription.ForLoadedMethod(Class.class.getMethod("getDeclaredField", String.class))) ).apply(methodVisitor, implementationContext); } catch (NoSuchMethodException exception) { throw new IllegalStateException("Cannot locate Class::getDeclaredField", exception); } }
/** * {@inheritDoc} */ @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST", justification = "The implicit field type casting is not understood by Findbugs") public MethodDescription.InDefinedShape getDeclaringMethod() { return new MethodDescription.ForLoadedMethod(executable); }
/** * Returns a method type description of the given method. * * @param method The method to extract the method type from. * @return The method type of the given method. */ public static MethodType of(Method method) { return of(new MethodDescription.ForLoadedMethod(method)); }
/** * {@inheritDoc} */ public boolean represents(Method method) { return this.method.equals(method) || equals(new MethodDescription.ForLoadedMethod(method)); }
/** * {@inheritDoc} */ public MethodDefinition.ImplementationDefinition<S> define(Method method) { return define(new MethodDescription.ForLoadedMethod(method)); }
/** * {@inheritDoc} */ public MethodDescription.InDefinedShape getDeclaringMethod() { return new MethodDescription.ForLoadedMethod(method); }
/** * Binds the supplied bootstrap method for the resolution of a dynamic constant. * * @param name The name of the bootstrap constant that is provided to the bootstrap method or constructor. * @param method The bootstrap method to invoke. * @param rawArguments The arguments for the bootstrap method represented as primitive wrapper types, * {@link String}, {@link TypeDescription} or {@link JavaConstant} values or their loaded forms. * @return A dynamic constant that represents the bootstrapped method's result. */ public static Dynamic bootstrap(String name, Method method, List<?> rawArguments) { return bootstrap(name, new MethodDescription.ForLoadedMethod(method), rawArguments); }
/** * Represents a constant that is resolved by invoking a {@code static} factory method. * * @param method The method to invoke to create the represented constant value. * @param rawArguments The method's constant arguments. * @return A dynamic constant that is resolved by the supplied factory method. */ public static Dynamic ofInvocation(Method method, List<?> rawArguments) { return ofInvocation(new MethodDescription.ForLoadedMethod(method), rawArguments); }
/** * {@inheritDoc} */ public InnerTypeDefinition<S> innerTypeOf(Method method) { return innerTypeOf(new MethodDescription.ForLoadedMethod(method)); }
/** * Exactly matches a given method as a {@link MethodDescription} in its defined shape. * * @param method The method to match by its description * @param <T> The type of the matched object. * @return An element matcher that exactly matches the given method in its defined shape. */ public static <T extends MethodDescription> ElementMatcher.Junction<T> is(Method method) { return is(new MethodDescription.ForLoadedMethod(method)); }
/** * Creates a method handle representation of the given method for an explicit special method invocation of an otherwise virtual method. * * @param method The method ro represent. * @param type The type on which the method is to be invoked on as a special method invocation. * @return A method handle representing the given method as special method invocation. */ public static MethodHandle ofSpecial(Method method, Class<?> type) { return ofSpecial(new MethodDescription.ForLoadedMethod(method), TypeDescription.ForLoadedType.of(type)); }
/** * Creates a method handle representation of the given method. * * @param method The method ro represent. * @return A method handle representing the given method. */ public static MethodHandle of(Method method) { return of(new MethodDescription.ForLoadedMethod(method)); }
/** * Invokes the given method. Without further specification, the method is invoked without any arguments on * the instance of the instrumented class or statically, if the given method is {@code static}. * * @param method The method to invoke. * @return A method call implementation that invokes the given method without providing any arguments. */ public static WithoutSpecifiedTarget invoke(Method method) { return invoke(new MethodDescription.ForLoadedMethod(method)); }
/** * {@inheritDoc} */ public boolean represents(Method method) { return equals(new ForLoadedMethod(method)); }
@Override public boolean isOverridden(Object instance, Method origin) { SoftReference<MethodGraph> reference = graphs.get(instance.getClass()); MethodGraph methodGraph = reference == null ? null : reference.get(); if (methodGraph == null) { methodGraph = compiler.compile(new TypeDescription.ForLoadedType(instance.getClass())); graphs.put(instance.getClass(), new SoftReference<MethodGraph>(methodGraph)); } MethodGraph.Node node = methodGraph.locate(new MethodDescription.ForLoadedMethod(origin).asSignatureToken()); return !node.getSort().isResolved() || !node.getRepresentative().asDefined().getDeclaringType().represents(origin.getDeclaringClass()); }