From f250701c73ba64e1976737a5107ab15adea070a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=ADn=20Sotuyo=20Dodero?= Date: Thu, 18 Aug 2022 00:18:43 -0300 Subject: [PATCH] Add completion candidates for PMD report properties - The help is still the only source of truth for which ones are valid --- .../pmd/cli/commands/internal/PmdCommand.java | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java index 1cec851066..ce6eff9b31 100644 --- a/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java +++ b/pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/PmdCommand.java @@ -8,6 +8,7 @@ import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.nio.file.Path; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Optional; @@ -165,9 +166,9 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { this.minimumPriority = priority; } - // TODO : Autocomplete candidates? @Option(names = { "--property", "-P" }, description = "Key-value pair defining a property for the report format.%n" - + "Supported values for each report format:%n${sys:pmd-cli.pmd.report.properties.help}") + + "Supported values for each report format:%n${sys:pmd-cli.pmd.report.properties.help}", + completionCandidates = PmdReportPropertiesCandidates.class) public void setProperties(final Properties properties) { this.properties = properties; } @@ -384,6 +385,29 @@ public class PmdCommand extends AbstractAnalysisPmdSubcommand { } } + /** + * Provider of candidates for valid report properties. + * + * Check the help for which ones are supported by each report format and possible values. + */ + private static class PmdReportPropertiesCandidates implements Iterable { + + @Override + public Iterator iterator() { + final List propertyNames = new ArrayList<>(); + final Properties emptyProps = new Properties(); + for (final String rendererName : RendererFactory.supportedRenderers()) { + final Renderer renderer = RendererFactory.createRenderer(rendererName, emptyProps); + + for (final PropertyDescriptor property : renderer.getPropertyDescriptors()) { + propertyNames.add(property.name()); + } + } + return propertyNames.iterator(); + } + + } + /** * Provider of candidates for valid languages. *