@Restricted(NoExternalUse.class)
    @VisibleForTesting
    public static Set<String> getAutoCompletionCandidates(List<String> loggerNamesList) {
        Set<String> loggerNames = new HashSet<>(loggerNamesList);

        // now look for package prefixes that make sense to offer for autocompletion:
        // Only prefixes that match multiple loggers will be shown.
        // Example: 'org' will show 'org', because there's org.apache, org.jenkinsci, etc.
        // 'io' might only show 'io.jenkins.plugins' rather than 'io' if all loggers starting with 'io' start with 'io.jenkins.plugins'.
        HashMap<String, Integer> seenPrefixes = new HashMap<>();
        SortedSet<String> relevantPrefixes = new TreeSet<>();
        for (String loggerName : loggerNames) {
            String[] loggerNameParts = loggerName.split("[.]");

            String longerPrefix = null;
            for (int i = loggerNameParts.length; i > 0; i--) {
                String loggerNamePrefix = String.join(".", Arrays.copyOf(loggerNameParts, i));
                seenPrefixes.put(loggerNamePrefix, seenPrefixes.getOrDefault(loggerNamePrefix, 0) + 1);
                if (longerPrefix == null) {
                    relevantPrefixes.add(loggerNamePrefix); // actual logger name
                    longerPrefix = loggerNamePrefix;
                    continue;
                }

                if (seenPrefixes.get(loggerNamePrefix) > seenPrefixes.get(longerPrefix)) {
                    relevantPrefixes.add(loggerNamePrefix);
                }
                longerPrefix = loggerNamePrefix;
            }
        }
        return relevantPrefixes;
    }
@Test
    public void autocompletionTest() {
        List<String> loggers = Arrays.asList(
                "com.company.whatever.Foo", "com.foo.Bar", "com.foo.Baz",
                "org.example.app.Main", "org.example.app.impl.xml.Parser", "org.example.app.impl.xml.Validator");

        Set<String> candidates = LogRecorder.getAutoCompletionCandidates(loggers);

        isCandidate(candidates, "com");
        isCandidate(candidates, "com.company.whatever.Foo");
        isCandidate(candidates, "com.foo");
        isCandidate(candidates, "com.foo.Bar");
        isCandidate(candidates, "com.foo.Baz");
        isCandidate(candidates, "org.example.app");
        isCandidate(candidates, "org.example.app.Main");
        isCandidate(candidates, "org.example.app.impl.xml");
        isCandidate(candidates, "org.example.app.impl.xml.Parser");
        isCandidate(candidates, "org.example.app.impl.xml.Validator");

        isNotCandidate(candidates, "org");
        isNotCandidate(candidates, "org.example");

        assertEquals("expected number of items", 10, candidates.size());
    }