public CacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass, KeyGenerator keyGenerator, CacheResolver cacheResolver) { this.operation = operation; this.method = BridgeMethodResolver.findBridgedMethod(method); this.targetClass = targetClass; this.targetMethod = (!Proxy.isProxyClass(targetClass) ? AopUtils.getMostSpecificMethod(method, targetClass) : this.method); this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass); this.keyGenerator = keyGenerator; this.cacheResolver = cacheResolver; } }
@Override public boolean matches(Method method, Class<?> targetClass) { if (matchesMethod(method)) { return true; } // Proxy classes never have annotations on their redeclared methods. if (Proxy.isProxyClass(targetClass)) { return false; } // The method may be on an interface, so let's check on the target class as well. Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass); return (specificMethod != method && matchesMethod(specificMethod)); }
@Nullable private JCacheOperation<?> computeCacheOperation(Method method, @Nullable Class<?> targetClass) { // Don't allow no-public methods as required. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { return null; } // The method may be on an interface, but we need attributes from the target class. // If the target class is null, the method will be unchanged. Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass); // First try is the method in the target class. JCacheOperation<?> operation = findCacheOperation(specificMethod, targetClass); if (operation != null) { return operation; } if (specificMethod != method) { // Fallback is to look at the original method. operation = findCacheOperation(method, targetClass); if (operation != null) { return operation; } } return null; }
public CacheOperationMetadata(CacheOperation operation, Method method, Class<?> targetClass, KeyGenerator keyGenerator, CacheResolver cacheResolver) { this.operation = operation; this.method = BridgeMethodResolver.findBridgedMethod(method); this.targetClass = targetClass; this.targetMethod = (!Proxy.isProxyClass(targetClass) ? AopUtils.getMostSpecificMethod(method, targetClass) : this.method); this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass); this.keyGenerator = keyGenerator; this.cacheResolver = cacheResolver; } }
private ShadowMatch getTargetShadowMatch(Method method, Class<?> targetClass) { Method targetMethod = AopUtils.getMostSpecificMethod(method, targetClass); if (targetMethod.getDeclaringClass().isInterface()) { // Try to build the most specific interface possible for inherited methods to be // considered for sub-interface matches as well, in particular for proxy classes. // Note: AspectJ is only going to take Method.getDeclaringClass() into account. Set<Class<?>> ifcs = ClassUtils.getAllInterfacesForClassAsSet(targetClass); if (ifcs.size() > 1) { try { Class<?> compositeInterface = ClassUtils.createCompositeInterface( ClassUtils.toClassArray(ifcs), targetClass.getClassLoader()); targetMethod = ClassUtils.getMostSpecificMethod(targetMethod, compositeInterface); } catch (IllegalArgumentException ex) { // Implemented interfaces probably expose conflicting method signatures... // Proceed with original target method. } } } return getShadowMatch(targetMethod, method); }
@Nullable public Method getMostSpecificMethod() { if (this.mostSpecificMethod != null) { return this.mostSpecificMethod; } Method method = getMethod(); if (method != null) { Object bean = getBean(); if (AopUtils.isAopProxy(bean)) { Class<?> targetClass = AopProxyUtils.ultimateTargetClass(bean); method = AopUtils.getMostSpecificMethod(method, targetClass); } } return method; }
private void addArgumentsAsVariables() { Object[] args = mi.getArguments(); if (args.length == 0) { return; } Object targetObject = mi.getThis(); // SEC-1454 Class<?> targetClass = AopProxyUtils.ultimateTargetClass(targetObject); if (targetClass == null) { // TODO: Spring should do this, but there's a bug in ultimateTargetClass() // which returns null targetClass = targetObject.getClass(); } Method method = AopUtils.getMostSpecificMethod(mi.getMethod(), targetClass); String[] paramNames = parameterNameDiscoverer.getParameterNames(method); if (paramNames == null) { logger.warn("Unable to resolve method parameter names for method: " + method + ". Debug symbol information is required if you are using parameter names in expressions."); return; } for (int i = 0; i < args.length; i++) { if (paramNames[i] != null) { setVariable(paramNames[i], args[i]); } } }
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) { this.beanName = beanName; this.method = BridgeMethodResolver.findBridgedMethod(method); this.targetMethod = (!Proxy.isProxyClass(targetClass) ? AopUtils.getMostSpecificMethod(method, targetClass) : this.method); this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass); EventListener ann = AnnotatedElementUtils.findMergedAnnotation(this.targetMethod, EventListener.class); this.declaredEventTypes = resolveDeclaredEventTypes(method, ann); this.condition = (ann != null ? ann.condition() : null); this.order = resolveOrder(this.targetMethod); }
void addAnnotatedParameters(MethodInvocation pjp) { try { Method method = pjp.getMethod(); Method mostSpecificMethod = AopUtils.getMostSpecificMethod(method, pjp.getThis().getClass()); List<SleuthAnnotatedParameter> annotatedParameters = SleuthAnnotationUtils .findAnnotatedParameters(mostSpecificMethod, pjp.getArguments()); getAnnotationsFromInterfaces(pjp, mostSpecificMethod, annotatedParameters); mergeAnnotatedMethodsIfNecessary(pjp, method, mostSpecificMethod, annotatedParameters); addAnnotatedArguments(annotatedParameters); } catch (SecurityException ex) { log.error("Exception occurred while trying to add annotated parameters", ex); } }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); if (method == null) { return invocation.proceed(); } Method mostSpecificMethod = AopUtils.getMostSpecificMethod(method, invocation.getThis().getClass()); NewSpan newSpan = SleuthAnnotationUtils.findAnnotation(mostSpecificMethod, NewSpan.class); ContinueSpan continueSpan = SleuthAnnotationUtils .findAnnotation(mostSpecificMethod, ContinueSpan.class); if (newSpan == null && continueSpan == null) { return invocation.proceed(); } return methodInvocationProcessor().process(invocation, newSpan, continueSpan); }
@Nullable private JCacheOperation<?> computeCacheOperation(Method method, @Nullable Class<?> targetClass) { // Don't allow no-public methods as required. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { return null; } // The method may be on an interface, but we need attributes from the target class. // If the target class is null, the method will be unchanged. Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass); // First try is the method in the target class. JCacheOperation<?> operation = findCacheOperation(specificMethod, targetClass); if (operation != null) { return operation; } if (specificMethod != method) { // Fallback is to look at the original method. operation = findCacheOperation(method, targetClass); if (operation != null) { return operation; } } return null; }
private void addArgumentsAsVariables() { Object[] args = mi.getArguments(); if (args.length == 0) { return; } Object targetObject = mi.getThis(); // SEC-1454 Class<?> targetClass = AopProxyUtils.ultimateTargetClass(targetObject); if (targetClass == null) { // TODO: Spring should do this, but there's a bug in ultimateTargetClass() // which returns null targetClass = targetObject.getClass(); } Method method = AopUtils.getMostSpecificMethod(mi.getMethod(), targetClass); String[] paramNames = parameterNameDiscoverer.getParameterNames(method); if (paramNames == null) { logger.warn("Unable to resolve method parameter names for method: " + method + ". Debug symbol information is required if you are using parameter names in expressions."); return; } for (int i = 0; i < args.length; i++) { if (paramNames[i] != null) { setVariable(paramNames[i], args[i]); } } }
public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) { // The method may be on an interface, but we need attributes from the target // class. // If the target class is null, the method will be unchanged. Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass); // First try is the method in the target class. Collection<ConfigAttribute> attr = findAttributes(specificMethod, targetClass); if (attr != null) { return attr; } // Second try is the config attribute on the target class. attr = findAttributes(specificMethod.getDeclaringClass()); if (attr != null) { return attr; } if (specificMethod != method || targetClass == null) { // Fallback is to look at the original method. attr = findAttributes(method, method.getDeclaringClass()); if (attr != null) { return attr; } // Last fallback is the class of the original method. return findAttributes(method.getDeclaringClass()); } return Collections.emptyList(); }
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
public Collection<ConfigAttribute> getAttributes(Method method, Class<?> targetClass) { // The method may be on an interface, but we need attributes from the target // class. // If the target class is null, the method will be unchanged. Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass); // First try is the method in the target class. Collection<ConfigAttribute> attr = findAttributes(specificMethod, targetClass); if (attr != null) { return attr; } // Second try is the config attribute on the target class. attr = findAttributes(specificMethod.getDeclaringClass()); if (attr != null) { return attr; } if (specificMethod != method || targetClass == null) { // Fallback is to look at the original method. attr = findAttributes(method, method.getDeclaringClass()); if (attr != null) { return attr; } // Last fallback is the class of the original method. return findAttributes(method.getDeclaringClass()); } return Collections.emptyList(); }
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) { this.beanName = beanName; this.method = BridgeMethodResolver.findBridgedMethod(method); this.targetMethod = (!Proxy.isProxyClass(targetClass) ? AopUtils.getMostSpecificMethod(method, targetClass) : this.method); this.methodKey = new AnnotatedElementKey(this.targetMethod, targetClass); EventListener ann = AnnotatedElementUtils.findMergedAnnotation(this.targetMethod, EventListener.class); this.declaredEventTypes = resolveDeclaredEventTypes(method, ann); this.condition = (ann != null ? ann.condition() : null); this.order = resolveOrder(method); }
Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass);
@Override @SuppressWarnings("rawtypes") public boolean matches(Method method, Class targetClass) { if (AnnotationUtils.getAnnotation(method, this.annotationType) != null) { return true; } // The method may be on an interface, so let's check on the target class as well. Method specificMethod = AopUtils.getMostSpecificMethod(method, targetClass); return (specificMethod != method && (AnnotationUtils.getAnnotation(specificMethod, this.annotationType) != null)); } }