StandardParameterResolver implements ParameterResolver { @Override public List<CompletionProposal> complete(MethodParameter methodParameter, CompletionContext context) { boolean set; Exception unfinished = null; ParameterRawValue parameterRawValue = null; int arity = 1; try { resolve(methodParameter, context.getWords()); CacheKey cacheKey = new CacheKey(methodParameter.getMethod(), context.getWords()); Parameter parameter = methodParameter.getMethod().getParameters()[methodParameter.getParameterIndex()]; arity = getArity(parameter); parameterRawValue = parameterCache.get(cacheKey).get(parameter); set = parameterRawValue.explicit; } catch (ParameterMissingResolutionException e) { set = false; } catch (UnfinishedParameterResolutionException e) { if (e.getParameterDescription().parameter().equals(methodParameter)) { unfinished = e; set = false; } else { return Collections.emptyList(); } } catch (Exception e) { return argumentKeysThatStartWithContextPrefix(methodParameter, context); } if (!set) { if (unfinished == null) { return argumentKeysThatStartWithContextPrefix(methodParameter, context); } else { return valueCompletions(methodParameter, context); } } else { List<CompletionProposal> result = new ArrayList<>(); Object value = convertRawValue(parameterRawValue, methodParameter); if (value instanceof Collection && ((Collection) value).size() == arity || (ObjectUtils.isArray(value) && Array.getLength(value) == arity)) { return result; } if (!context.currentWord().equals("")) { result.addAll(valueCompletions(methodParameter, context)); } if (parameterRawValue.positional()) { result.addAll(argumentKeysThatStartWithContextPrefix(methodParameter, context)); } return result; } } @Autowired  StandardParameterResolver(ConversionService conversionService); @Autowired(required = false) void setValueProviders(Collection<ValueProvider> valueProviders); @Autowired(required = false) void setValidatorFactory(ValidatorFactory validatorFactory); @Override boolean supports(MethodParameter parameter); @Override ValueResult resolve(MethodParameter methodParameter, List<String> wordsBuffer); @Override Stream<ParameterDescription> describe(MethodParameter parameter); @Override List<CompletionProposal> complete(MethodParameter methodParameter, CompletionContext context);  }
@Test public void testNoMoreAvailableParameters() { Method method = findMethod(Remote.class, "zap", boolean.class, String.class, String.class, String.class); List<String> completions = resolver.complete( Utils.createMethodParameter(method, 2), contextFor("--name ") ).stream().map(CompletionProposal::value).collect(Collectors.toList()); assertThat(completions).isEmpty(); }
@Test public void testNotTheRightTimeToCompleteThatParameter() { Method method = findMethod(Remote.class, "shutdown", Remote.Delay.class); List<String> completions = resolver.complete( Utils.createMethodParameter(method, 0), contextFor("--delay 323") ).stream().map(CompletionProposal::value).collect(Collectors.toList()); assertThat(completions).isEmpty(); }
@Test public void testParameterKeyNotYetSetAppearsInProposals() { Method method = findMethod(Remote.class, "zap", boolean.class, String.class, String.class, String.class); List<String> completions = resolver.complete( Utils.createMethodParameter(method, 1), contextFor("") ).stream().map(CompletionProposal::value).collect(Collectors.toList()); assertThat(completions).contains("--name"); completions = resolver.complete( Utils.createMethodParameter(method, 1), contextFor("--force ") ).stream().map(CompletionProposal::value).collect(Collectors.toList()); assertThat(completions).contains("--name"); }
@Test public void testParameterKeyNotFullySpecified() { Method method = findMethod(Remote.class, "zap", boolean.class, String.class, String.class, String.class); List<String> completions = resolver.complete( Utils.createMethodParameter(method, 1), contextFor("--na") ).stream().map(CompletionProposal::value).collect(Collectors.toList()); assertThat(completions).contains("--name"); completions = resolver.complete( Utils.createMethodParameter(method, 1), contextFor("--force --na") ).stream().map(CompletionProposal::value).collect(Collectors.toList()); assertThat(completions).contains("--name"); }