/* (non-Javadoc)
@see org.spockframework.runtime.extension.AbstractMethodInterceptor#interceptSetupMethod(org.spockframework.runtime.extension.IMethodInvocation)
14252
@Override
    public void interceptSetupMethod(IMethodInvocation invocation) throws Throwable {
        log.fine("before " + invocation.getFeature().getFeatureMethod().getReflection().getName());
        getTestRunner().before(invocation.getTarget(), invocation.getFeature().getFeatureMethod().getReflection(),
            new InvocationExecutor(invocation));
    }
189384
private void updateEJBMethodInfoInterceptorProxies() // d386227
    throws EJBConfigurationException
    {
        final boolean isTraceOn = TraceComponent.isAnyTracingEnabled();
        if (isTraceOn && tc.isEntryEnabled())
        {
            Tr.entry(tc, "updateEJBMethodInfoInterceptorProxies: " + ivEjbName);
        }

        // For each method, update EJBMethodInfo with the correct array of
        // InterceptorProxy array needed for that method.
        for (Map.Entry<Method, ArrayList<EJBMethodInfoImpl>> entry : ivEJBMethodInfoMap.entrySet()) // d630717
        {
            InterceptorProxy[] proxies = getAroundInterceptorProxies(InterceptorMethodKind.AROUND_INVOKE, entry.getKey()); // F743-17763

            // Update the EJBMethodInfos with the InterceptorProxy array for this method.
            if (proxies != null)
            {
                for (EJBMethodInfoImpl info : entry.getValue()) // d630717
                {
                    info.setAroundInterceptorProxies(proxies); // F743-17763.1
                }
            }
        }

        // F743-17763 - For each timer method, update EJBMethodInfo with the
        // correct array of InterceptorProxy for that method.  The preceding loop
        // does not include EJBMethodInfoImpls for MethodInterface.TIMED_OBJECT,
        // so this loop's call to setAroundInterceptorProxies does not conflict.
        if (ivBmd.timedMethodInfos != null)
        {
            for (EJBMethodInfoImpl info : ivBmd.timedMethodInfos)
            {
                InterceptorProxy[] proxies = getAroundInterceptorProxies(InterceptorMethodKind.AROUND_TIMEOUT
                                                                         , info.getMethod());

                if (proxies != null)
                {
                    info.setAroundInterceptorProxies(proxies); // F743-17763.1
                }
            }
        }

        if (isTraceOn && tc.isEntryEnabled())
        {
            Tr.exit(tc, "updateEJBMethodInfoInterceptorProxies: " + ivJ2EEName);
        }
    }
70805
@Internal
    public static Interceptor[] resolveAroundInterceptors(BeanContext beanContext, ExecutableMethod<?, ?> method, Interceptor... interceptors) {
        instrumentAnnotationMetadata(beanContext, method);
        return resolveInterceptorsInternal(method, Around.class, interceptors);
    }
907023
public void afterMethodHook(String hookedClassQualifiedName, String hookedMethodSimpleName) {
        if (currentRunResult == null) {
            return; // maybe called outside of the root method
        }
        TestMethod rootMethod = currentRunResult.getRootMethod();
        if (!rootMethod.getTestClassKey().equals(hookedClassQualifiedName)
                || !rootMethod.getSimpleName().equals(hookedMethodSimpleName)) {
            return; // hooked method is not current root method
        }

        long currentTime = System.currentTimeMillis();
        currentRunResult.setExecutionTime((int) (currentTime - startMethodTime));
        logger.info("afterMethodHook: " + hookedMethodSimpleName);

        // use encoded name to avoid various possible file name encoding problem
        // and to escape invalid file name character (Method name may contain such characters
        // if method is Groovy method, for example).
        File runResultFile = new File(String.format("%s/%s/%s", runResultsRootDir,
                CommonUtils.encodeToSafeAsciiFileNameString(hookedClassQualifiedName, StandardCharsets.UTF_8),
                CommonUtils.encodeToSafeAsciiFileNameString(hookedMethodSimpleName, StandardCharsets.UTF_8)));
        if (runResultFile.getParentFile() != null) {
            runResultFile.getParentFile().mkdirs();
        }
        // write runResult to YAML file
        YamlUtils.dump(currentRunResult.toYamlObject(), runResultFile);

        // clear current captureNo and runResult
        currentCaptureNo = -1;
        currentRunResult = null;
        currentActualRootMethodSimpleName = null;
    }
952364
public static void callMethod(final Object obj, final String methodName, final Object... args) {
		try {
			callMethod(obj, methodName, false, args);
		} catch (InvocationTargetException e) {
			JK.throww(e);
		}
	}
158016
@SuppressWarnings("unchecked")
    private void processManuallyTracedMethods(ClassTraceInfo info) {
        for (MethodNode mn : (List<MethodNode>) info.classNode.methods) {
            // Don't re-process methods that have already had trace injected
            if (isMethodAlreadyInjectedAnnotationPresent(mn)) {
                continue;
            }

            // Look through the method's instruction stream for well known entry/exit methods
            Iterator<? extends AbstractInsnNode> instructionIterator = mn.instructions.iterator();
            while (instructionIterator.hasNext()) {
                AbstractInsnNode insnNode = instructionIterator.next();

                // Look for calls to Tr.entry, Tr.exit, Logger.entering, Logger.exiting
                boolean manuallyTraced = false;
                if (insnNode.getType() == AbstractInsnNode.METHOD_INSN) {
                    MethodInsnNode methodInsn = (MethodInsnNode) insnNode;
                    String methodName = methodInsn.name;
                    if (methodInsn.owner.equals(LOGGER_TYPE.getInternalName())) {
                        manuallyTraced = (methodName.equals("entering") || methodName.equals("exiting"));
                    } else if (methodInsn.owner.equals(LIBERTY_TR_TYPE.getInternalName())) {
                        manuallyTraced = (methodName.equals("entry") || methodName.equals("exit"));
                    } else if (methodInsn.owner.equals(WEBSPHERE_TR_TYPE.getInternalName())) {
                        manuallyTraced = (methodName.equals("entry") || methodName.equals("exit"));
                    }
                }

                // Mark the manually traced method, and create a warning
                if (manuallyTraced) {
                    mn.visitAnnotation(MANUAL_TRACE_TYPE.getDescriptor(), true).visitEnd();

                    StringBuilder sb = new StringBuilder();
                    sb.append("WARNING: Hard coded entry/exit trace point found in ");
                    sb.append(info.classNode.name.replaceAll("/", "\\.")).append(".").append(mn.name).append(mn.desc);
                    sb.append(".  Skipping method.");
                    info.warnings.add(sb.toString());
                    break;
                }
            }
        }
    }
609122
@Override
  public final Method retrieveMethod(final Class<?> pClazz,
    final String pMethodName) throws Exception {
    for (Method mfd : pClazz.getDeclaredMethods()) {
      if (mfd.getName().equals(pMethodName)) {
        return mfd;
      }
    }
    final Class<?> superClazz = pClazz.getSuperclass();
    Method method = null;
    if (superClazz != null && superClazz != java.lang.Object.class) {
      method = retrieveMethod(superClazz, pMethodName);
    }
    if (method == null) {
      throw new Exception("There is no method " + pMethodName + " in class "
        + pClazz); //TO-DO class must be original
    }
    return method;
  }
1086413
public final void setHttpMethod(HttpMethod httpMethod) {
        if (overriddenURL != null && httpMethod != HttpMethod.GET) {
            throw new FacebookException("Can't change HTTP method on request with overridden URL.");
            }
        this.httpMethod = (httpMethod != null) ? httpMethod : HttpMethod.GET;
    }
511175
@Override
    public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
        if (method.getName().equals("annotationType")) {
            return annotationType;
        } else if (method.getName().equals("toString")) { 
            return toString();
        } else if (method.getName().equals("equals")) {
           return annotationEquals(args[0]);
        } else if (method.getName().equals("hashCode")) { 
            return proxy.hashCode();
        } else {
            return attributeData.get(method.getName());
        }
       
    }
1097280
public synchronized void setInitializationMethod(String newMethodName)
    {
        Method newMethod = null;
        if (newMethodName != null)
        {
            initializationMethodName = newMethodName;
            try
            {
                // see if we have a publicly accessible method by the name
                newMethod = getClassOfObject().getMethod(newMethodName, NO_PARAMS);
            }
            catch (NoSuchMethodException e)
            {
                try
                {
                    // no publicly accessible method, see if there is a private/protected one
                    newMethod = getClassOfObject().getDeclaredMethod(newMethodName, NO_PARAMS);
                }
                catch (NoSuchMethodException e2)
                {
                    // there is no such method available
                    throw new MetadataException(
                        "Invalid initialization method, there is not"
                            + " a zero argument method named "
                            + newMethodName
                            + " on class "
                            + getClassOfObject().getName()
                            + ".");
                }
            }
        }
        setInitializationMethod(newMethod);
    }
89168
public void setInvocationHandler(Object proxy, InvocationHandler handler) {
        Field field = getInvocationHandlerField();
        try {
            field.set(proxy, handler);
        } catch (IllegalArgumentException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
457322
private <Y> void checkObserverMethod(EnhancedAnnotatedMethod<T, Y> annotated) {
        // Make sure exactly one and only one parameter is annotated with Observes or ObservesAsync
        List<EnhancedAnnotatedParameter<?, Y>> eventObjects = annotated.getEnhancedParameters(Observes.class);
        eventObjects.addAll(annotated.getEnhancedParameters(ObservesAsync.class));
        if (this.reception.equals(Reception.IF_EXISTS) && declaringBean.getScope().equals(Dependent.class)) {
            throw EventLogger.LOG.invalidScopedConditionalObserver(this, Formats.formatAsStackTraceElement(annotated.getJavaMember()));
        }
        if (eventObjects.size() > 1) {
            throw EventLogger.LOG.multipleEventParameters(this, Formats.formatAsStackTraceElement(annotated.getJavaMember()));
        }
        EnhancedAnnotatedParameter<?, Y> eventParameter = eventObjects.iterator().next();
        checkRequiredTypeAnnotations(eventParameter);
        // Check for parameters annotated with @Disposes
        List<?> disposeParams = annotated.getEnhancedParameters(Disposes.class);
        if (disposeParams.size() > 0) {
            throw EventLogger.LOG.invalidDisposesParameter(this, Formats.formatAsStackTraceElement(annotated.getJavaMember()));
        }
        // Check annotations on the method to make sure this is not a producer
        // method, initializer method, or destructor method.
        if (this.observerMethod.getAnnotated().isAnnotationPresent(Produces.class)) {
            throw EventLogger.LOG.invalidProducer(this, Formats.formatAsStackTraceElement(annotated.getJavaMember()));
        }
        if (this.observerMethod.getAnnotated().isAnnotationPresent(Inject.class)) {
            throw EventLogger.LOG.invalidInitializer(this, Formats.formatAsStackTraceElement(annotated.getJavaMember()));
        }
        boolean containerLifecycleObserverMethod = Observers.isContainerLifecycleObserverMethod(this);
        for (EnhancedAnnotatedParameter<?, ?> parameter : annotated.getEnhancedParameters()) {
            // if this is an observer method for container lifecycle event, it must not inject anything besides BeanManager
            if (containerLifecycleObserverMethod && !parameter.isAnnotationPresent(Observes.class) && !parameter.isAnnotationPresent(ObservesAsync.class) && !BeanManager.class.equals(parameter.getBaseType())) {
                throw EventLogger.LOG.invalidInjectionPoint(this, Formats.formatAsStackTraceElement(annotated.getJavaMember()));
            }
        }

    }
648309
@RuntimeType
    public Object interceptInterface(@AllArguments Object[] params,
                                     @Origin Method method) throws Throwable {
        if (ProxyParent.canInvoke(method)) {
            return Interception.invokeWrap(interception, null, method, null, params,
                () -> ProxyParent.invoke(method, proxyParent));
        } else {
            return Interception.invokeWrap(interception, null, method, null, params, null);
        }
    }
1009179
@Override
	public void interceptRequest(IHttpRequest theRequest) {
		for (Map.Entry<String, List<String>> header : additionalHttpHeaders.entrySet()) {
			for (String headerValue : header.getValue()) {
				if (headerValue != null) {
					theRequest.addHeader(header.getKey(), headerValue);
				}
			}
		}
	}
1306486
public static void proxy(Method method, InvocationHandler invocationHandler) {
		assertInvocationHandlerNotNull(invocationHandler);
		MockRepository.putMethodProxy(method, invocationHandler);
	}
972098
public static void validateObserverMethod(ObserverMethod<?> observerMethod, BeanManager beanManager, ObserverMethod<?> originalObserverMethod) {
        Set<Annotation> qualifiers = observerMethod.getObservedQualifiers();
        if (observerMethod.getBeanClass() == null) {
            throw EventLogger.LOG.observerMethodsMethodReturnsNull("getBeanClass", observerMethod);
        }
        if (observerMethod.getObservedType() == null) {
            throw EventLogger.LOG.observerMethodsMethodReturnsNull("getObservedType", observerMethod);
        }
        Bindings.validateQualifiers(qualifiers, beanManager, observerMethod, "ObserverMethod.getObservedQualifiers");
        if (observerMethod.getReception() == null) {
            throw EventLogger.LOG.observerMethodsMethodReturnsNull("getReception", observerMethod);
        }
        if (observerMethod.getTransactionPhase() == null) {
            throw EventLogger.LOG.observerMethodsMethodReturnsNull("getTransactionPhase", observerMethod);
        }
        if (originalObserverMethod != null && (!observerMethod.getBeanClass().equals(originalObserverMethod.getBeanClass()))) {
            throw EventLogger.LOG.beanClassMismatch(originalObserverMethod, observerMethod);
        }
        if (!(observerMethod instanceof SyntheticObserverMethod) && !hasNotifyOverriden(observerMethod.getClass(), observerMethod)) {
            throw EventLogger.LOG.notifyMethodNotImplemented(observerMethod);
        }
    }
504008
function (interfaceMethods, interceptor, allInterceptors) {
        var interceptedMethods = allInterceptors || {};
        // for a class object, intercept specific methods
        for (var m in interfaceMethods) {
            if (interfaceMethods.hasOwnProperty(m) && __hasBeenIntercepted(m, interceptor)) {
                (interceptedMethods[m] || (interceptedMethods[m] = [])).push({
                    fn : __callInterceptorMethod,
                    scope : interceptor
                });
            }
        }
        return interceptedMethods;
    }