• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 9750018739

01 Jul 2024 07:32PM UTC coverage: 60.3% (-0.03%) from 60.328%
9750018739

push

github

web-flow
#418: Fix autocomplete of version (#432)

1894 of 3450 branches covered (54.9%)

Branch coverage included in aggregate %.

4982 of 7953 relevant lines covered (62.64%)

2.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
cli/src/main/java/com/devonfw/tools/ide/completion/CompletionCandidateCollector.java
1
package com.devonfw.tools.ide.completion;
2

3
import com.devonfw.tools.ide.commandlet.Commandlet;
4
import com.devonfw.tools.ide.property.Property;
5

6
import java.util.Arrays;
7
import java.util.List;
8
import java.util.stream.Collectors;
9

10
/**
11
 * Collects the {@link CompletionCandidate}s for auto-completion.
12
 */
13
public interface CompletionCandidateCollector {
14

15
  /**
16
   * @param text the suggested word to add to auto-completion.
17
   * @param description the description of the suggestion candidate or {@code null} to determine automatically form the given parameters.
18
   * @param property the {@link Property} that triggered this suggestion.
19
   * @param commandlet the {@link Commandlet} owning the {@link Property}.
20
   */
21
  void add(String text, String description, Property<?> property, Commandlet commandlet);
22

23
  /**
24
   * @param text the suggested word to add to auto-completion.
25
   * @param description the description of the suggestion candidate or {@code null} to determine automatically form the given parameters.
26
   * @param property the {@link Property} that triggered this suggestion.
27
   * @param commandlet the {@link Commandlet} owning the {@link Property}.
28
   * @return the {@link CompletionCandidate} for the given parameters.
29
   */
30
  default CompletionCandidate createCandidate(String text, String description, Property<?> property, Commandlet commandlet) {
31

32
    if (description == null) {
2✔
33
      // compute description from property + commandlet like in HelpCommandlet?
34
    }
35
    CompletionCandidate candidate = new CompletionCandidate(text, description);
6✔
36
    return candidate;
2✔
37
  }
38

39
  /**
40
   * @param text the suggested word to add to auto-completion.
41
   * @param sortedCandidates the array of candidates sorted in ascending order.
42
   * @param property the {@link Property} that triggered this suggestion.
43
   * @param commandlet the {@link Commandlet} owning the {@link Property}.
44
   * @return the number of {@link CompletionCandidate}s that have been added.
45
   */
46
  default int addAllMatches(String text, String[] sortedCandidates, Property<?> property, Commandlet commandlet) {
47

48
    if (text.isEmpty()) {
3✔
49
      for (String candidate : sortedCandidates) {
16✔
50
        add(candidate, "", property, commandlet);
6✔
51
      }
52
      return sortedCandidates.length;
3✔
53
    }
54

55
    List<String> prefixWords = Arrays.asList(sortedCandidates).stream().filter(word -> word.startsWith(text))
10✔
56
        .collect(Collectors.toList());
4✔
57

58
    for (String match : prefixWords) {
10✔
59
      add(match, "", property, commandlet);
6✔
60
    }
1✔
61

62
    return prefixWords.size();
3✔
63
  }
64

65
  /**
66
   * Resets this {@link CompletionCandidateCollector} to reuse trying the next {@link Commandlet}.
67
   */
68
  default void clear() {
69

70
    getCandidates().clear();
×
71
  }
×
72

73
  /**
74
   * @return the list of {@link CompletionCandidate}s.
75
   */
76
  List<CompletionCandidate> getCandidates();
77

78
  /**
79
   * Disables the {@link #getSortedCandidates() sorting}.
80
   */
81
  void disableSorting();
82

83
  /**
84
   * @return the sorted {@link #getCandidates() candidates}.
85
   */
86
  List<CompletionCandidate> getSortedCandidates();
87

88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc