/** * {@inheritDoc} */ public String getInternalName() { return bridgeTarget.getName(); } }
/** * {@inheritDoc} */ public Resolution resolve(MethodDescription source, MethodDelegationBinder.MethodBinding left, MethodDelegationBinder.MethodBinding right) { boolean leftEquals = left.getTarget().getName().equals(source.getName()); boolean rightEquals = right.getTarget().getName().equals(source.getName()); if (leftEquals ^ rightEquals) { return leftEquals ? Resolution.LEFT : Resolution.RIGHT; } else { return Resolution.AMBIGUOUS; } } }
/** * Creates an annotation description for the values that were defined for this builder. * * @return An appropriate annotation description. */ public AnnotationDescription build() { for (MethodDescription methodDescription : annotationType.getDeclaredMethods()) { if (annotationValues.get(methodDescription.getName()) == null && methodDescription.getDefaultValue() == null) { throw new IllegalStateException("No value or default value defined for " + methodDescription.getName()); } } return new Latent(annotationType, annotationValues); } }
/** * Returns a builder with the additional, given property. * * @param property The name of the property to define. * @param value An explicit description of the annotation value. * @return A builder with the additional, given property. */ public Builder define(String property, AnnotationValue<?, ?> value) { MethodList<?> methodDescriptions = annotationType.getDeclaredMethods().filter(named(property)); if (methodDescriptions.isEmpty()) { throw new IllegalArgumentException(annotationType + " does not define a property named " + property); } else if (!methodDescriptions.getOnly().getReturnType().asErasure().isAnnotationValue(value.resolve())) { throw new IllegalArgumentException(value + " cannot be assigned to " + property); } Map<String, AnnotationValue<?, ?>> annotationValues = new HashMap<String, AnnotationValue<?, ?>>(); annotationValues.putAll(this.annotationValues); if (annotationValues.put(methodDescriptions.getOnly().getName(), value) != null) { throw new IllegalArgumentException("Property already defined: " + property); } return new Builder(annotationType, annotationValues); }
@Override public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Advice.ArgumentHandler argumentHandler, Sort sort) { final String returnType = instrumentedMethod.getReturnType().asErasure().getSimpleName(); final String className = instrumentedMethod.getDeclaringType().getTypeName(); final String signature = String.format("%s %s.%s(%s)", returnType, className, instrumentedMethod.getName(), getSignature(instrumentedMethod)); return Target.ForStackManipulation.of(signature); } };
public String getRequestName(MethodDescription instrumentedMethod) { final NamingParameters namingParameters = getNamingParameters(instrumentedMethod); return SignatureUtils.getSignature(instrumentedMethod.getDeclaringType().getTypeName(), instrumentedMethod.getName(), namingParameters.getNameFromAnnotation(), namingParameters.isAbsolute()); }
public static String getRequestName(MethodDescription instrumentedMethod) { final AnnotationDescription.Loadable<Traced> monitorRequestsLoadable = instrumentedMethod .getDeclaredAnnotations() .ofType(Traced.class); if (monitorRequestsLoadable != null) { final Traced traced = monitorRequestsLoadable.loadSilent(); if (!traced.requestName().isEmpty()) { return traced.requestName(); } if (traced.resolveNameAtRuntime()) { return null; } } return getBusinessTransationName(instrumentedMethod.getDeclaringType().getTypeName(), instrumentedMethod.getName()); }
/** * 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); }
@Override public boolean matches(TypeDescription targetInterface) { if (ElementMatchers.declaresMethod(named(targetMethod.getName()) .and(returns(targetMethod.getReturnType().asErasure())) .and(takesArguments(targetMethod.getParameters().asTypeList().asErasures()))) .matches(targetInterface)) { return true; } else { for (TypeDescription typeDescription : targetInterface.getInterfaces().asErasures()) { if (matches(typeDescription)) { return true; } } } return false; } }
@Override public boolean matches(MethodDescription targetMethod) { TypeDescription superClass = targetMethod.getDeclaringType().asErasure(); do { superClass = superClass.getSuperClass().asErasure(); if (declaresMethod(named(targetMethod.getName()) .and(returns(targetMethod.getReturnType().asErasure())) .and(takesArguments(targetMethod.getParameters().asTypeList().asErasures())) .and(extraMethodMatcher)) .matches(superClass)) { return true; } } while (superClassMatcher.matches(superClass)); return false; } }
@Override public Target resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, Advice.ArgumentHandler argumentHandler, Sort sort) { final String className = instrumentedMethod.getDeclaringType().getTypeName(); String simpleClassName = className.substring(className.lastIndexOf('$') + 1); simpleClassName = simpleClassName.substring(simpleClassName.lastIndexOf('.') + 1); final String signature = String.format("%s#%s", simpleClassName, instrumentedMethod.getName()); return Target.ForStackManipulation.of(signature); } };
buf.append(method.getName()).append("\n"); buf.append(' ').append(plainSignature).append("\n"); buf.append(' ').append(annotatedSignature).append("\n");
buf.append(method.getName()).append("\n"); buf.append(' ').append(plainSignature).append("\n"); buf.append(' ').append(annotatedSignature).append("\n");
@Override protected Object doResolve(TypeDescription instrumentedType, MethodDescription method, ParameterDescription.InDefinedShape target, AnnotationDescription.Loadable<ProfilerSignature> annotation, Assigner assigner, boolean initialized) { final String returnType = method.getReturnType().asErasure().getSimpleName(); final String className = method.getDeclaringType().getTypeName(); return String.format("%s %s.%s(%s)", returnType, className, method.getName(), getSignature(method)); }
private static boolean isAccessor(MethodDescription method) { if (method.getDeclaringType().represents(Object.class)) { return false; } String methodName = method.getName(); Generic returnType = method.getReturnType(); ParameterList<?> args = method.getParameters(); boolean isSetter = Generic.VOID.equals(returnType) && args.size() == 1 && ReflectTools.isSetterName(methodName); boolean isGetter = !Generic.VOID.equals(returnType) && args.isEmpty() && ReflectTools.isGetterName(methodName, returnType.represents(boolean.class)); return isSetter || isGetter; }
private static boolean isAccessor(MethodDescription method) { if (method.getDeclaringType().represents(Object.class)) { return false; } String methodName = method.getName(); Generic returnType = method.getReturnType(); ParameterList<?> args = method.getParameters(); boolean isSetter = Generic.VOID.equals(returnType) && args.size() == 1 && ReflectTools.isSetterName(methodName); boolean isGetter = !Generic.VOID.equals(returnType) && args.isEmpty() && ReflectTools.isGetterName(methodName, returnType.represents(boolean.class)); return isSetter || isGetter; }
public static String getRequestName(MethodDescription instrumentedMethod) { final AnnotationDescription.Loadable<MonitorRequests> monitorRequestsLoadable = instrumentedMethod .getDeclaredAnnotations() .ofType(MonitorRequests.class); if (monitorRequestsLoadable != null) { final MonitorRequests monitorRequests = monitorRequestsLoadable.loadSilent(); if (!monitorRequests.requestName().isEmpty()) { return monitorRequests.requestName(); } if (monitorRequests.resolveNameAtRuntime()) { return null; } } return getBusinessTransationName(instrumentedMethod.getDeclaringType().getTypeName(), instrumentedMethod.getName()); }
private static BiFunction<StateNode, BeanModelType<?>, Object> createProxyConstructor( ClassLoader classLoader, Builder<?> proxyBuilder) { Class<?> proxyType = proxyBuilder // Handle bean methods (and abstract methods for error handling) .method(method -> isAccessor(method) || method.isAbstract()) .intercept(MethodDelegation.to(proxyHandler)) // Handle internal $stateNode methods .defineField("$stateNode", StateNode.class) .method(method -> "$stateNode".equals(method.getName())) .intercept(FieldAccessor.ofField("$stateNode")) // Handle internal $modelType methods .defineField("$modelType", BeanModelType.class) .method(method -> "$modelType".equals(method.getName())) .intercept(FieldAccessor.ofField("$modelType")) // Create the class .make().load(classLoader, ClassLoadingStrategy.Default.WRAPPER) .getLoaded(); return (node, modelType) -> { Object instance = ReflectTools.createInstance(proxyType); ModelProxy modelProxy = (ModelProxy) instance; modelProxy.$stateNode(node); modelProxy.$modelType(modelType); return instance; }; }
private static BiFunction<StateNode, BeanModelType<?>, Object> createProxyConstructor( ClassLoader classLoader, Builder<?> proxyBuilder, String classFqn) { String proxyClassName = generateProxyClassName(classFqn, classLoader); Class<?> proxyType = proxyBuilder // Handle bean methods (and abstract methods for error handling) .method(method -> isAccessor(method) || method.isAbstract()) .intercept(MethodDelegation.to(proxyHandler)) // Handle internal $stateNode methods .defineField("$stateNode", StateNode.class) .method(method -> "$stateNode".equals(method.getName())) .intercept(FieldAccessor.ofField("$stateNode")) // Handle internal $modelType methods .defineField("$modelType", BeanModelType.class) .method(method -> "$modelType".equals(method.getName())) .intercept(FieldAccessor.ofField("$modelType")) // Create the class .name(proxyClassName).make() .load(classLoader, ClassLoadingStrategy.Default.WRAPPER) .getLoaded(); return (node, modelType) -> { Object instance = ReflectTools.createProxyInstance(proxyType, modelType.getProxyType()); ModelProxy modelProxy = (ModelProxy) instance; modelProxy.$stateNode(node); modelProxy.$modelType(modelType); modelType.createInitialValues(node); return instance; }; }
private boolean declaresInHierarchy(MethodDescription targetMethod, TypeDescription type) { if (declaresMethod(named(targetMethod.getName()) .and(returns(targetMethod.getReturnType().asErasure())) .and(takesArguments(targetMethod.getParameters().asTypeList().asErasures())) .and(extraMethodMatcher)) .matches(type)) { return true; } for (TypeDescription interfaze : type.getInterfaces().asErasures()) { if (superClassMatcher.matches(interfaze)) { if (declaresInHierarchy(targetMethod, interfaze)) { return true; } } } final TypeDescription.Generic superClass = type.getSuperClass(); if (superClass != null && superClassMatcher.matches(superClass.asErasure())) { return declaresInHierarchy(targetMethod, superClass.asErasure()); } return false; }