Obtains a value for the given method argument.

@param resolutionContext The resolution context
@param context           The bean context
@param methodIndex       The method index
@param argIndex          The argument index
@return The value
558859
@SuppressWarnings({"unused", "unchecked"})
    @Internal
    protected final Object getValueForMethodArgument(BeanResolutionContext resolutionContext, BeanContext context, int methodIndex, int argIndex) {
        MethodInjectionPoint injectionPoint = methodInjectionPoints.get(methodIndex);
        Argument argument = injectionPoint.getArguments()[argIndex];
        BeanResolutionContext.Path path = resolutionContext.getPath();
        path.pushMethodArgumentResolve(this, injectionPoint, argument);
        if (context instanceof ApplicationContext) {
            // can't use orElseThrow here due to compiler bug
            try {
                String valueAnnStr = argument.getAnnotationMetadata().getValue(Value.class, String.class).orElse(null);
                Class argumentType = argument.getType();

                if (isInnerConfiguration(argumentType)) {
                    Qualifier qualifier = resolveQualifier(resolutionContext, argument, true);
                    return ((DefaultBeanContext) context).getBean(resolutionContext, argumentType, qualifier);
                } else {
                    String argumentName = argument.getName();
                    String valString = resolvePropertyValueName(resolutionContext, injectionPoint.getAnnotationMetadata(), argument, valueAnnStr);


                    ApplicationContext applicationContext = (ApplicationContext) context;
                    ArgumentConversionContext conversionContext = ConversionContext.of(argument);
                    Optional value = resolveValue(applicationContext, conversionContext, valueAnnStr != null, valString);
                    if (argumentType == Optional.class) {
                        return resolveOptionalObject(value);
                    } else {
                        if (value.isPresent()) {
                            return value.get();
                        } else {
                            if (argument.isDeclaredAnnotationPresent(Nullable.class)) {
                                return null;
                            }
                            throw new DependencyInjectionException(resolutionContext, injectionPoint, conversionContext, valString);
                        }
                    }
                }
            } finally {
                path.pop();
            }
        } else {
            path.pop();
            throw new DependencyInjectionException(resolutionContext, argument, "BeanContext must support property resolution");
        }
    }
248262
public Resolution intercept(ExecutionContext executionContext) throws Exception {
        // Remove expired contexts.
        removeExpired(contexts);
        
        // Get wait context, if any.
        Context context = getContext(executionContext);
        LifecycleStage stage = executionContext.getLifecycleStage();
        
        if (executionContext.getActionBeanContext().getRequest().getRequestURI().contains(THREAD_URL)) {
            // The request we are processing is the one used to invoke event handler in background and to get resolution to send to user when event completes.
            // Since we are going to invoke the real event, the action bean and event must stay the same.
            // Binding and validation must be skipped since they were done in the first request.
            switch (executionContext.getLifecycleStage()) {
                // Use action bean that will process event.
                case ActionBeanResolution:
                    log.trace("injecting ActionBean");
                    // Since session can be lost from original request (Tomcat is a good example), request must be updated with the background request.
                    context.actionBean.setContext(executionContext.getActionBeanContext());
                    executionContext.setActionBean(context.actionBean);
                    // Skip normal action bean resolution.
                    return null;
                // Select event to call.
                case HandlerResolution:
                    log.trace("injecting event handler");
                    executionContext.setHandler(context.eventHandler);
                    // Skip normal handler resolution.
                    return null;
                // No biding or validation, it was done before a background request was created to handle event.
                case BindingAndValidation:
                case CustomValidation:
                    log.trace("skipping binding and validation");
                    // Skip binding and validation.
                    return null;
                // Execute event since we are in the background request.
                case EventHandling:
                    log.trace("executing event handler");
                    // Execute event and save exception if any.
                    try {
                        return executionContext.proceed();
                    }
                    catch (Exception e) {
                        synchronized(context.actionBean)
                        {
                            log.trace("setting exception in context");
                            context.throwable = e;
                            context.status = Context.Status.COMPLETE;
                            context.completeMoment = System.currentTimeMillis();
                            context.actionBean.notifyAll();
                            context.eventFlashScope = FlashScope.getCurrent(context.actionBean.getContext().getRequest(), false);
                        }
                        throw e;
                    }
                // Save resolution to send to user when he will refresh wait page.
                case ResolutionExecution:
                    synchronized(context.actionBean)
                    {
                        log.trace("setting resolution in context");
                        context.resolution = executionContext.getResolution();
                        context.status = Context.Status.COMPLETE;
                        context.completeMoment = System.currentTimeMillis();
                        context.actionBean.notifyAll();
                        context.eventFlashScope = FlashScope.getCurrent(context.actionBean.getContext().getRequest(), false);
                    }
                    
                    // Use a default resolution to prevent processing the one event returned.
                    executionContext.setResolution(new StreamingResolution("text/plain", "thread complete"));
                    return executionContext.proceed();
                case RequestInit:
                case RequestComplete:
                    return executionContext.proceed();
            }
        }
        else {
            if (LifecycleStage.ActionBeanResolution.equals(stage)) {
                if (context != null) {
                    // We are using a wait context for this request. Go to wait page or event's resolution depending on status and skip everything else.
                    return checkStatus(executionContext, context);
                }
            }
            else if (LifecycleStage.EventHandling.equals(stage)) {
                WaitPage annotation = executionContext.getHandler().getAnnotation(WaitPage.class);
                if (annotation != null) {
                    // Event has @WaitPage annotation. Create wait context to invoke event in background and redirect user to wait page.
                    return createContextAndRedirect(executionContext, annotation);
                }
            }
        }
        
        return executionContext.proceed();
    }
120484
public Plugin.Factory.UsingReflection.ArgumentResolver toArgumentResolver() {
        return new Plugin.Factory.UsingReflection.ArgumentResolver.ForIndex.WithDynamicType(index, value);
    }
175577
private static <A extends Annotation> A getParameterAnnotation(Method method,
            int index, Class<A> annotationClass) {
        for (Annotation a : method.getParameterAnnotations()[index]) {
            if (annotationClass.isInstance(a)) {
                return annotationClass.cast(a);
            }
        }
        return null;
    }
902598
public static Integer getRequiredIntegerParameter(UimaContext context,
      String parameter)
      throws ResourceInitializationException {

    Integer value = getOptionalIntegerParameter(context, parameter);

    checkForNull(value, parameter);

    return value;
  }
1214807
private int extractValidIndex(ElementReference ref) {
        Reference<E> iRef = asIndexedRef(ref);
        int idx = iRef.index;
        if (idx < 0 || idx >= size) {
            throw new InvalidReferenceException(
                    "Index " + idx + " is not valid for collection with size " + size + ".");
        }
        return idx;
    }
716625
static Object[] toArguments(List<AnnotatedValueResolver> resolvers,
                                ResolverContext resolverContext) {
        requireNonNull(resolvers, "resolvers");
        requireNonNull(resolverContext, "resolverContext");
        if (resolvers.isEmpty()) {
            return emptyArguments;
        }
        return resolvers.stream().map(resolver -> resolver.resolve(resolverContext)).toArray();
    }
118139
public Object getValue(ELContext context)
    {
        Object base = this.orig.getValue(context);
        if (base != null)
        {
            context.setPropertyResolved(false);
            return context.getELResolver().getValue(context, base, i);
        }
        return null;
    }
325082
public static List<Class> getMethodGenericParameterTypes(Method method, int index) {
    	List<Class> results = new ArrayList<Class>();
    	Type[] genericParameterTypes = method.getGenericParameterTypes();
    	if (index >= genericParameterTypes.length ||index < 0) {
			throw new IllegalArgumentException("index "+ (index<0 ? " must > 0 " : " over total arguments"));
		}
    	Type genericParameterType = genericParameterTypes[index];
    	if(genericParameterType instanceof ParameterizedType){
    	     ParameterizedType aType = (ParameterizedType) genericParameterType;
    	     Type[] parameterArgTypes = aType.getActualTypeArguments();
    	     for(Type parameterArgType : parameterArgTypes){
    	         Class parameterArgClass = (Class) parameterArgType;
    	         results.add(parameterArgClass);
    	     }
    	     return results;
    	}
    	return results;
    }
950591
function resolveValue(context, fn, source, property, factoryContext){
  var oldAdapter = context[property] || null;
  var newAdapter = null;

  // as functions could be a value, invoke only functions with factory property
  // i.e. source -> function(){ /* factory code */ }).factory === FACTORY
  // apply only for top-level resolveValue() invocation
  if (source && fn !== resolveAdapterProxy && basis.fn.isFactory(source))
    source = source.call(factoryContext || context, factoryContext || context);

  if (source && source.bindingBridge)
  {
    if (!oldAdapter || oldAdapter.source !== source)
      newAdapter = new BBResolveAdapter(context, fn, source, DEFAULT_CHANGE_ADAPTER_HANDLER);
    else
      newAdapter = oldAdapter;

    source = resolveValue(newAdapter, resolveAdapterProxy, source.bindingBridge.get(source), 'next');
  }

  if (property && oldAdapter !== newAdapter)
  {
    var cursor = oldAdapter;

    // drop old adapter chain
    while (cursor)
    {
      var adapter = cursor;
      adapter.detach();
      cursor = adapter.next;
      adapter.next = null;
    }

    if (newAdapter)
      newAdapter.attach(RESOLVEVALUE_DESTROY_ADAPTER_HANDLER);

    context[property] = newAdapter;
  }

  return source;
}
777713
public ResultFunction<M, G, R> resultFunction() throws
                                                  MethodAmbiguouslyDefinedException {
    final MasterClass masterClass = new MasterClass(this.master.getClass());
    final GuestClass guestClass = new GuestClass(this.guest.getClass());
    final GenericsContext context = GenericsResolver.resolve(this.getClass())
                                                    .type(Dispatch.class);
    // final Class<?> masterClassRestriction = context.generics().get(0); // Class M for right method searching
    // final Class<?> guestClassRestriction = context.generics().get(1); // Class G for right method searching
    final ReturnClass returnClass = new ReturnClass(context.generics()
                                                           .get(2)); // Class R for right method searching
    ResultFunction<M, G, R> method;
    final Set<Method> methods = new ByParameterClass(masterClass,
                                                     guestClass,
                                                     this.methodName,
                                                     returnClass,
                                                     new ByParameterInterfaces(masterClass,
                                                                               guestClass,
                                                                               this.methodName,
                                                                               returnClass,
                                                                               new ByParameterSuperClass(masterClass,
                                                                                                         guestClass,
                                                                                                         this.methodName,
                                                                                                         returnClass,
                                                                                                         new EmptyMethods()))).findMethods();
    if (methods.isEmpty()) {
      method = new ResultFunction<M, G, R>() {
        @Override
        public String toString() {
          return "default method";
        }

        @Override
        public R apply(final M m,
                       final G g) {
          return Dispatch.this.defaultMethod.apply(m,
                                                   g);
        }
      };
    } else {
      final Iterator<Method> iterator = methods.iterator();
      MethodRepresentation currentMethod = new OneMethod(iterator.next());
      while (iterator.hasNext()) {
        final MethodRepresentation nextMethod = new OneMethod(iterator.next());
        currentMethod = new OneOfTwoMethods(currentMethod,
                                            nextMethod);
      }
      final Method finalMethod = currentMethod.toMethod();
      method = new MethodFunction<>(finalMethod);
    }
    return method;
  }
520846
public MessageArg get(int index) {
    return index < args.size() ? args.get(index) : null;
  }
547743
private static <CT, I> Function<CT, I> resolveAndExtend(
		Class<CT> contextType,
		List<MethodResolver<CT>> resolvers,
		Class<I> typeToExtend)
	{
		// Resolve generics
		ResolvedTypeWithMembers withMembers = Types.resolveMembers(typeToExtend);

		Map<Method, MethodInvocationHandler<CT>> handlers = new HashMap<>();
		try
		{
			// Go through methods and create invokers for each of them
			for(ResolvedMethod method : withMembers.getMemberMethods())
			{
				// Only try to implement abstract methods
				if(! method.isAbstract()) continue;

				// Create an encounter and let the first method resolver that matches handle the method
				boolean foundInvoker = false;
				MethodEncounter encounter = new MethodEncounterImpl(method);
				for(MethodResolver<CT> resolver : resolvers)
				{
					Optional<MethodInvocationHandler<CT>> opt = resolver.create(encounter);
					if(opt.isPresent())
					{
						// This resolver created an invoker to use
						foundInvoker = true;
						handlers.put(method.getRawMember(), opt.get());
						break;
					}
				}

				if(! foundInvoker)
				{
					// No invoker was found, can not handle the method
					throw new ProxyException("The method " + method.getName() + " could not be handled");
				}
			}
		}
		catch(ProxyException e)
		{
			throw new ProxyException(typeToExtend.getName() + ":\n" + e.getMessage());
		}
		catch(Exception e)
		{
			throw new ProxyException(typeToExtend.getName() + ":\n" + e.getMessage(), e);
		}

		return createFunction(contextType, typeToExtend, Collections.unmodifiableMap(handlers));
	}
1114366
@Pure
	public static Object getContextResolver() throws AndroidException {
		Object resolver;
		synchronized (Android.class) {
			resolver = (contextResolver == null) ? null : contextResolver.get();
		}
		if (resolver == null) {
			final Object context = getContext();
			try {
				final Class<?> resolverType = getContextResolverClass();
				final Class<?> contextType = context.getClass();
				final Method getContextResolverMethod = contextType.getMethod("getContentResolver"); //$NON-NLS-1$
				resolver = getContextResolverMethod.invoke(context);
				resolver = resolverType.cast(resolver);
				synchronized (Android.class) {
					contextResolver = new WeakReference<>(resolver);
				}
			} catch (AssertionError e) {
				throw e;
			} catch (Throwable e) {
				throw new AndroidException(e);
			}
		}
		return resolver;
	}
329533
VariablePointerValue resolveVariablePointer(VariablePointerValue varPointer) throws Exception {
		int contextIndex = varPointer.getContextIndex();
		if (contextIndex == -1)
			contextIndex = getContextIndexOfVariableNamed(varPointer.getVariableName());

		RTObject valueOfVariablePointedTo = getRawVariableWithName(varPointer.getVariableName(), contextIndex);
		// Extra layer of indirection:
		// When accessing a pointer to a pointer (e.g. when calling nested or
		// recursive functions that take a variable references, ensure we don't
		// create
		// a chain of indirection by just returning the final target.
		VariablePointerValue doubleRedirectionPointer = valueOfVariablePointedTo instanceof VariablePointerValue
				? (VariablePointerValue) valueOfVariablePointedTo
				: (VariablePointerValue) null;
		if (doubleRedirectionPointer != null) {
			return doubleRedirectionPointer;
		} else {
			return new VariablePointerValue(varPointer.getVariableName(), contextIndex);
		}
	}
202235
public static _ValueReferenceWrapper resolve(ValueExpression valueExpression, final ELContext elCtx)
    {
        _ValueReferenceResolver resolver = new _ValueReferenceResolver(elCtx.getELResolver());
        ELContext elCtxDecorator = new _ELContextDecorator(elCtx, resolver);
        
        valueExpression.getValue(elCtxDecorator);
        
        while (resolver.lastObject.getBase() instanceof CompositeComponentExpressionHolder)
        {
            valueExpression = ((CompositeComponentExpressionHolder) resolver.lastObject.getBase())
                                  .getExpression((String) resolver.lastObject.getProperty());
            valueExpression.getValue(elCtxDecorator);
        }

        return resolver.lastObject;
    }
850023
@SuppressWarnings("unchecked")
    protected @Nullable Object doResolve(
            ArgumentConversionContext<T> context,
            ConvertibleValues<?> values,
            String annotationValue) {

        Object value = resolveValue(context, values, annotationValue);
        if (value == null) {
            String fallbackName = getFallbackFormat(context.getArgument());
            if (!annotationValue.equals(fallbackName)) {
                annotationValue = fallbackName;
                value = resolveValue(context, values, annotationValue);
            }
        }

        return value;
    }