diff --git a/config/checkstyle-checks.xml b/config/checkstyle-checks.xml index 8cce03779..213e61bb3 100644 --- a/config/checkstyle-checks.xml +++ b/config/checkstyle-checks.xml @@ -747,6 +747,9 @@ + + + diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/CheckstylePlugin.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/CheckstylePlugin.java index 131e7d9ed..431953855 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/CheckstylePlugin.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/CheckstylePlugin.java @@ -113,6 +113,12 @@ public static Locale getPlatformLocale() { return platformLocale; } + /** + * Sets the platform locale. + * + * @param locale + * the locale to set + */ public static void setPlatformLocale(final Locale locale) { platformLocale = locale; } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/Messages.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/Messages.java index 17b131039..1a7b75742 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/Messages.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/Messages.java @@ -109,6 +109,9 @@ public final class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + /** + * Utility class, not intended to be instantiated. + */ private Messages() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/Auditor.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/Auditor.java index b3355117f..78935a36e 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/Auditor.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/Auditor.java @@ -163,6 +163,16 @@ public void runAudit(IProject project, IProgressMonitor monitor) } } + /** + * Handles a failure that occurred during the checkstyle run. + * + * @param project + * the project being audited + * @param error + * the thrown checkstyle exception + * @throws CheckstylePluginException + * an unexpected exception occurred + */ private void handleCheckstyleFailure(IProject project, CheckstyleException error) throws CheckstylePluginException { try { @@ -196,6 +206,11 @@ public void addFile(IFile file) { mFiles.put(file.getLocation().toString(), file); } + /** + * Determines whether files have been added to the audit. + * + * @return true if at least one file has been added, false otherwise + */ public boolean hasFiles() { return !mFiles.isEmpty(); } @@ -260,6 +275,12 @@ private class CheckstyleAuditListener implements AuditListener { */ private Set mConnectedFileBufferPaths = new HashSet<>(); + /** + * Creates a listener for the checkstyle audit. + * + * @param project + * the project to audit + */ CheckstyleAuditListener(IProject project) { mProject = project; @@ -395,6 +416,9 @@ public void auditFinished(AuditEvent event) { public void auditStarted(AuditEvent event) { } + /** + * Cleans up the state of the listener. + */ public void cleanup() { mDocument = null; @@ -446,6 +470,13 @@ private void calculateMarkerOffset(AuditEvent error, Map markerA } } + /** + * Connects the file buffer for the given resource. + * + * @param resource + * the resource to connect + * @return the connected document or null + */ private IDocument connectFileBuffer(IResource resource) { IDocument document = null; if (resource instanceof IFile) { @@ -463,6 +494,12 @@ private IDocument connectFileBuffer(IResource resource) { return document; } + /** + * Disconnects the file buffer for the given resource. + * + * @param resource + * the resource to disconnect + */ private void disconnectFileBuffer(IResource resource) { if (resource instanceof IFile) { final IPath path = resource.getFullPath(); @@ -470,6 +507,12 @@ private void disconnectFileBuffer(IResource resource) { } } + /** + * Disconnects the file buffer for the given path. + * + * @param path + * the path to disconnect + */ private void disconnectFileBuffer(IPath path) { try { @@ -484,6 +527,13 @@ private void disconnectFileBuffer(IPath path) { } } + /** + * Converts a severity level into the corresponding marker severity value. + * + * @param severity + * the severity level + * @return the marker severity value + */ private int getSeverityValue(SeverityLevel severity) { int result = IMarker.SEVERITY_WARNING; @@ -500,6 +550,13 @@ else if (severity.equals(SeverityLevel.ERROR)) { return result; } + /** + * Builds the message shown for the given audit event. + * + * @param error + * the audit event + * @return the assembled message + */ private String getMessage(AuditEvent error) { String moduleId = error.getModuleId(); @@ -534,6 +591,13 @@ private String getMessage(AuditEvent error) { return buf.toString(); } + /** + * Determines the rule name for the given audit event. + * + * @param error + * the audit event + * @return the rule name + */ private String getRuleName(AuditEvent error) { final String ruleName; final RuleMetadata metaData = MetadataFactory.getRuleMetadata(error.getSourceName()); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckerFactory.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckerFactory.java index a241b0e2b..7d563aef5 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckerFactory.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckerFactory.java @@ -250,6 +250,12 @@ private static Checker createCheckerInternal(InputSource input, PropertyResolver return checker; } + /** + * Sets the locale on the given checker if it changed. + * + * @param checker + * the checker to update + */ private static void setLocaleIfChanged(final Checker checker) { final String lc = getLocale(); if (lc != null && !lc.equals(CheckstylePlugin.getPlatformLocale().getLanguage())) { @@ -257,6 +263,14 @@ private static void setLocaleIfChanged(final Checker checker) { } } + /** + * Sets the locale on the given checker. + * + * @param checker + * the checker to update + * @param lang + * the language to apply + */ private static void setLocale(final Checker checker, final String lang) { final String lastLocale; if (lang != null) { @@ -277,6 +291,11 @@ private static void setLocale(final Checker checker, final String lang) { } } + /** + * Returns the configured locale language. + * + * @return the configured language or null if the default should be used + */ private static String getLocale() { String lang = CheckstylePluginPrefs.getString(CheckstylePluginPrefs.PREF_LOCALE_LANGUAGE); if (lang != null && (lang.isEmpty() || "default".equals(lang))) { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckstyleMarker.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckstyleMarker.java index 1234768aa..0fad6545c 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckstyleMarker.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/builder/CheckstyleMarker.java @@ -56,10 +56,20 @@ public final class CheckstyleMarker { */ public static final int CATEGORY_ID = 999; + /** + * Utility class, not intended to be instantiated. + */ private CheckstyleMarker() { // utility class } + /** + * Determines whether the given marker is a checkstyle marker. + * + * @param marker + * the marker to check + * @return true if the marker is a checkstyle marker + */ public static boolean isCheckstyleMarker(IMarker marker) { boolean isCheckstyleMarker; try { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationFactory.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationFactory.java index 6ab8e0061..b83427862 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationFactory.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationFactory.java @@ -88,6 +88,9 @@ public final class CheckConfigurationFactory { refresh(); } + /** + * Utility class, not intended to be instantiated. + */ private CheckConfigurationFactory() { } @@ -213,6 +216,13 @@ public FileVisitResult visitFile(final Path file, final BasicFileAttributes attr } } + /** + * Calculates the state location within the given workspace root. + * + * @param newWorkspaceRoot + * the new workspace root + * @return the target state location + */ private static IPath getTargetStateLocation(IPath newWorkspaceRoot) { final IPath currentWorkspaceRoot = Platform.getLocation(); IPath currentStateLocation = CheckstylePlugin.getDefault().getStateLocation(); @@ -277,6 +287,11 @@ private static void loadFromPersistence() throws CheckstylePluginException { } } + /** + * Returns the file used to store the check configurations in the state location. + * + * @return the internal configuration file + */ private static File getInternalConfigurationFile() { IPath configPath = CheckstylePlugin.getDefault().getStateLocation(); configPath = configPath.append(CHECKSTYLE_CONFIG_FILE); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationTester.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationTester.java index c1653af26..1a9edeeed 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationTester.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationTester.java @@ -45,6 +45,9 @@ */ public final class CheckConfigurationTester { + /** + * Utility class, not intended to be instantiated. + */ private CheckConfigurationTester() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationXmlWriter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationXmlWriter.java index 998d4a2ec..f2c4ae9e4 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationXmlWriter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/CheckConfigurationXmlWriter.java @@ -29,6 +29,9 @@ */ public final class CheckConfigurationXmlWriter { + /** + * Utility class, not intended to be instantiated. + */ private CheckConfigurationXmlWriter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigProperty.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigProperty.java index 015116ca3..24be48316 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigProperty.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigProperty.java @@ -76,6 +76,13 @@ public ConfigProperty(String name, String value) { this.value = value; } + /** + * Determines the initial value for a property from its metadata. + * + * @param metaData + * the property metadata + * @return the initial value + */ private static String determineInitialValue(ConfigPropertyMetadata metaData) { final String value; if (metaData.getOverrideDefault() != null) { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationReader.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationReader.java index 71bfb23ef..7c5a93fe9 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationReader.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationReader.java @@ -155,6 +155,13 @@ public static List read(InputSource input) throws CheckstylePluginExcept return rules; } + /** + * Extracts the modules declared in the given document. + * + * @param document + * the document to read + * @return the list of modules + */ private static List getModules(final Document document) { final List modules = new ArrayList<>(); @@ -170,6 +177,13 @@ public void visit(final Element node) { return modules; } + /** + * Creates a module from the given XML element. + * + * @param node + * the module element + * @return the created module + */ private static Module createModule(final Element node) { final String name = node.attributeValue(XMLTags.NAME_TAG); final RuleMetadata metadata = MetadataFactory.getRuleMetadata(name); @@ -190,6 +204,14 @@ private static Module createModule(final Element node) { return module; } + /** + * Adds the property elements of the module element to the module. + * + * @param moduleEl + * the module element + * @param module + * the module to fill + */ private static void addProperties(final Element moduleEl, final Module module) { final List propertyEls = moduleEl.elements(XMLTags.PROPERTY_TAG); @@ -233,6 +255,14 @@ else if (module.getMetaData() != null) { } } + /** + * Adds the message elements of the module element to the module. + * + * @param moduleEl + * the module element + * @param module + * the module to fill + */ private static void addMessages(final Element moduleEl, final Module module) { final List messageEls = moduleEl.elements(XMLTags.MESSAGE_TAG); @@ -246,6 +276,14 @@ private static void addMessages(final Element moduleEl, final Module module) { } } + /** + * Adds the metadata elements of the module element to the module. + * + * @param moduleEl + * the module element + * @param module + * the module to fill + */ private static void addMetadata(final Element moduleEl, final Module module) { final List metaEls = moduleEl.elements(XMLTags.METADATA_TAG); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationWriter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationWriter.java index 9e1da5ed4..f93bf199e 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationWriter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/ConfigurationWriter.java @@ -129,6 +129,18 @@ public static void write(OutputStream out, List modules, } } + /** + * Writes the given module and its remaining children into the result tree. + * + * @param module + * the module to write + * @param parent + * the parent branch in the result tree + * @param parentSeverity + * the severity inherited from the parent module + * @param remainingModules + * the list of modules that still need to be written + */ private static void writeModules(Module module, Branch parent, Severity parentSeverity, List remainingModules) { final Element moduleEl = writeModule(module, parent); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/Severity.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/Severity.java index 1f0b47646..d0bc6b92c 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/Severity.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/Severity.java @@ -47,6 +47,12 @@ public enum Severity { /** String used to serialize the Severity in XML files. */ private final String xmlValue; + /** + * Creates a severity with the given XML value. + * + * @param xmlValue + * the XML value + */ Severity(String xmlValue) { this.xmlValue = xmlValue; } @@ -60,6 +66,13 @@ public String getXmlValue() { return xmlValue; } + /** + * Converts an XML value to the corresponding severity. + * + * @param xmlValue + * the XML value + * @return the matching severity + */ public static Severity fromXmlValue(String xmlValue) { return Arrays.stream(Severity.values()) .filter(severity -> severity.getXmlValue().equals(xmlValue)).findFirst() diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/XMLTags.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/XMLTags.java index 466165785..a30bba161 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/XMLTags.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/XMLTags.java @@ -219,6 +219,9 @@ public final class XMLTags { /** Default weight of a builtin configuration. */ public static final String DEFAULT_WEIGHT = "default-weight"; + /** + * Utility class, not intended to be instantiated. + */ private XMLTags() { // NOOP } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/PropertyResolverFactory.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/PropertyResolverFactory.java index 8faa3bb19..bb1147406 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/PropertyResolverFactory.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/PropertyResolverFactory.java @@ -39,10 +39,26 @@ */ public final class PropertyResolverFactory { + /** + * Utility class, not intended to be instantiated. + */ private PropertyResolverFactory() { } + /** + * Creates the property resolver for the given configuration. + * + * @param config + * the check configuration + * @param configFile + * the configuration file + * @return the assembled property resolver + * @throws IOException + * the configuration file could not be read + * @throws URISyntaxException + * the configuration file URL is malformed + */ public static PropertyResolver getPropertyResolver(ICheckConfiguration config, CheckstyleConfigurationFile configFile) throws IOException, URISyntaxException { final MultiPropertyResolver multiResolver = new MultiPropertyResolver(); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/RemoteConfigurationType.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/RemoteConfigurationType.java index 4e31f8b9c..340cc5c8c 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/RemoteConfigurationType.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/configtypes/RemoteConfigurationType.java @@ -169,6 +169,19 @@ public CheckstyleConfigurationFile getCheckstyleConfiguration( return data; } + /** + * Loads the addition properties bundle for the given configuration. + * + * @param originalFileSuccess + * whether the original file was resolved successfully + * @param useCacheFile + * whether a cached file should be used + * @param data + * the configuration file data + * @param checkConfiguration + * the check configuration + * @return the bundle bytes if available + */ private Optional getPropertiesBundle(boolean originalFileSuccess, boolean useCacheFile, CheckstyleConfigurationFile data, ICheckConfiguration checkConfiguration) { Optional bundle = Optional.empty(); @@ -268,6 +281,16 @@ private Optional getBytesFromCacheBundleFile(ICheckConfiguration checkCo return bytes; } + /** + * Writes the configuration bytes into the cache file of the given configuration. + * + * @param checkConfig + * the check configuration + * @param configFileBytes + * the configuration file bytes + * @param bundleBytes + * the addition properties bundle bytes + */ private void writeToCacheFile(ICheckConfiguration checkConfig, byte[] configFileBytes, byte[] bundleBytes) { @@ -458,6 +481,15 @@ public static void removeCachedAuthInfo(URL resolvedCheckConfigurationURL) } } + /** + * Converts the given configuration URL into a secure storage path. + * + * @param resolvedCheckConfigurationURL + * the resolved configuration URL + * @return the secure storage path + * @throws CheckstylePluginException + * an unexpected exception occurred + */ private static String getSecureStoragePath(URL resolvedCheckConfigurationURL) throws CheckstylePluginException { @@ -482,10 +514,20 @@ private static String getSecureStoragePath(URL resolvedCheckConfigurationURL) return "eclipse-cs/" + urlHash; } + /** + * Returns the stored username. + * + * @return the username + */ public String getUsername() { return username; } + /** + * Returns the stored password. + * + * @return the password + */ public String getPassword() { return password; } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckUtil.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckUtil.java index 36320bcc7..509fb8406 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckUtil.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckUtil.java @@ -41,9 +41,21 @@ * */ public final class CheckUtil { + /** + * Utility class, not intended to be instantiated. + */ private CheckUtil() { } + /** + * Determines the modifiable tokens of the given check. + * + * @param checkName + * the name of the check + * @return the comma separated list of modifiable token names + * @throws IllegalStateException + * if the check has an unexpected class hierarchy + */ public static String getModifiableTokens(String checkName) { final Object checkResult = getCheck(checkName); String result = null; @@ -66,6 +78,15 @@ else if (AbstractCheck.class.isAssignableFrom(checkResult.getClass())) { return result; } + /** + * Creates an instance of the given check. + * + * @param checkName + * the name of the check + * @return the created check instance + * @throws IllegalStateException + * if the check could not be loaded + */ private static AbstractCheck getCheck(String checkName) { final ClassLoader classLoader = CheckstylePlugin.getDefault().getAddonExtensionClassLoader(); @@ -79,6 +100,15 @@ private static AbstractCheck getCheck(String checkName) { } } + /** + * Removes the required tokens from the given tokens. + * + * @param tokens + * the tokens + * @param requiredTokens + * the tokens to remove + * @return the list of remaining tokens + */ private static List subtractTokens(int[] tokens, int... requiredTokens) { final Set requiredTokensSet = new HashSet<>(Arrays.stream(requiredTokens).boxed().collect(Collectors.toList())); @@ -86,6 +116,15 @@ private static List subtractTokens(int[] tokens, int... requiredTokens) .collect(Collectors.toList()); } + /** + * Converts the given token ids into their names. + * + * @param function + * the function mapping a token id to its name + * @param modifiableTokens + * the token ids to convert + * @return the comma separated list of token names + */ private static String getTokens(Function function, List modifiableTokens) { return modifiableTokens.stream().map(function::apply).collect(Collectors.joining(",")); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckstyleMetadataAdapter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckstyleMetadataAdapter.java index 46a751f6f..d9fb2d660 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckstyleMetadataAdapter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/CheckstyleMetadataAdapter.java @@ -57,6 +57,9 @@ public class CheckstyleMetadataAdapter { */ private final Map propertyTypes; + /** + * Creates the metadata adapter and initializes the internal mappings. + */ public CheckstyleMetadataAdapter() { this.packageToGroupName = createPackageToGroupNameMapping(); this.propertyTypes = createPropertyTypeMapping(); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ConfigPropertyType.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ConfigPropertyType.java index 6010f1dcd..ad3a80ba1 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ConfigPropertyType.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ConfigPropertyType.java @@ -52,6 +52,15 @@ public enum ConfigPropertyType { /** A value that contains a regular expression. */ REGEX; + /** + * Converts an XML value to the corresponding property type. + * + * @param xmlValue + * the XML value + * @return the property type + * @throws IllegalArgumentException + * if the XML value is unexpected + */ static ConfigPropertyType fromXmlValue(String xmlValue) { return switch (xmlValue) { case "String" -> STRING; diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataFactory.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataFactory.java index 0c438df72..e398f1f55 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataFactory.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataFactory.java @@ -168,6 +168,12 @@ public static RuleMetadata createGenericMetadata(Module module) { return ruleMeta; } + /** + * Registers the alternative names of the given rule metadata. + * + * @param ruleMetadata + * the rule metadata + */ private static void registerAlternativeNames(RuleMetadata ruleMetadata) { ruleMetadata.identity().alternativeNames() .forEach(alternativeName -> alternativeNamesMap.put(alternativeName, ruleMetadata)); @@ -381,6 +387,13 @@ private static void doInitialization() throws CheckstylePluginException { loadRuleMetadata(); } + /** + * Determines the group id of the given metadata file. + * + * @param metadataFile + * the metadata file name + * @return the group id + */ private static String groupId(String metadataFile) { String res = StringUtils.substringBetween(metadataFile, "/checks/", FILE_NAME_SEPARATOR); res = StringUtils.defaultString(res, metadataFile); @@ -458,6 +471,20 @@ private static ResourceBundle getMetadataI18nBundle(String metadataFile, return resourceBundle; } + /** + * Parses the metadata from the given stream and registers it. + * + * @param metadataStream + * the stream containing the metadata + * @param metadataBundle + * the resource bundle for localization + * @param groupId + * the id of the rule group + * @throws DocumentException + * the metadata document could not be read + * @throws CheckstylePluginException + * an unexpected exception occurred + */ private static void parseMetadata(InputStream metadataStream, ResourceBundle metadataBundle, String groupId) throws DocumentException, CheckstylePluginException { final Collection groups = MetadataXmlReader.parseMetadata(metadataStream, diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataXmlReader.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataXmlReader.java index a526d2a73..fd8749052 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataXmlReader.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/MetadataXmlReader.java @@ -55,10 +55,28 @@ public final class MetadataXmlReader { "-//eclipse-cs//DTD Check Metadata 1.1//EN", "/com/puppycrawl/tools/checkstyle/checkstyle-metadata_1_1.dtd"); + /** + * Utility class, not intended to be instantiated. + */ private MetadataXmlReader() { } + /** + * Parses the metadata from the given stream. + * + * @param metadataStream + * the stream containing the metadata + * @param metadataBundle + * the resource bundle for localization + * @param groupId + * the id of the rule group + * @return the parsed rule groups + * @throws DocumentException + * the metadata document could not be read + * @throws CheckstylePluginException + * an unexpected exception occurred + */ public static Collection parseMetadata(InputStream metadataStream, ResourceBundle metadataBundle, String groupId) throws DocumentException, CheckstylePluginException { @@ -105,6 +123,19 @@ public static Collection parseMetadata(InputStream metadataSt return groups.values(); } + /** + * Processes the modules declared in the given group element. + * + * @param groupElement + * the group element + * @param groupMetadata + * the group metadata + * @param metadataBundle + * the resource bundle for localization + * @return the list of rule metadata + * @throws CheckstylePluginException + * an unexpected exception occurred + */ private static List processModules(Element groupElement, RuleGroupMetadata groupMetadata, ResourceBundle metadataBundle) throws CheckstylePluginException { @@ -181,6 +212,15 @@ private static boolean isNotFalse(Element element, String attributeName) { return !"false".equals(element.attributeValue(attributeName)); } + /** + * Localizes the given candidate using the supplied resource bundle. + * + * @param localizationCandidate + * the candidate to localize + * @param metadataBundle + * the resource bundle for localization + * @return the localized value or the candidate if it could not be localized + */ private static String localize(String localizationCandidate, ResourceBundle metadataBundle) { String localized = localizationCandidate; if (metadataBundle != null && localizationCandidate != null @@ -195,6 +235,17 @@ private static String localize(String localizationCandidate, ResourceBundle meta return localized; } + /** + * Processes the properties declared in the given module element. + * + * @param moduleElement + * the module element + * @param metadataBundle + * the resource bundle for localization + * @return the list of property metadata + * @throws CheckstylePluginException + * an unexpected exception occurred + */ private static List processProperties(Element moduleElement, ResourceBundle metadataBundle) throws CheckstylePluginException { final List properties = new ArrayList<>(); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/RuleGroupMetadata.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/RuleGroupMetadata.java index 08c00dfc0..4c9e58b6b 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/RuleGroupMetadata.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/RuleGroupMetadata.java @@ -48,6 +48,20 @@ public class RuleGroupMetadata { /** The list of modules belonging to the group. */ private List mRuleMetadata = new LinkedList<>(); + /** + * Creates the metadata for a rule group. + * + * @param groupId + * the group id + * @param groupName + * the group name + * @param groupDesc + * the group description + * @param hidden + * whether the group is hidden + * @param priority + * the priority of the group + */ RuleGroupMetadata(String groupId, String groupName, String groupDesc, boolean hidden, int priority) { mGroupId = groupId; diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ThirdPartyRuleGroupParser.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ThirdPartyRuleGroupParser.java index 2e73bde9d..c6c6a9d63 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ThirdPartyRuleGroupParser.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/config/meta/ThirdPartyRuleGroupParser.java @@ -32,6 +32,9 @@ */ final class ThirdPartyRuleGroupParser { + /** + * Utility class, not intended to be instantiated. + */ private ThirdPartyRuleGroupParser() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/AbstractCheckJob.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/AbstractCheckJob.java index 337d8fcc2..00c9f027f 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/AbstractCheckJob.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/AbstractCheckJob.java @@ -33,6 +33,12 @@ public abstract class AbstractCheckJob extends WorkspaceJob implements IScheduli */ public static final Object CHECKSTYLE_JOB_FAMILY = new Object(); + /** + * Creates a check job with the given name. + * + * @param name + * the job name + */ public AbstractCheckJob(String name) { super(name); } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/RunCheckstyleOnFilesJob.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/RunCheckstyleOnFilesJob.java index 830078693..b856fb060 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/RunCheckstyleOnFilesJob.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/RunCheckstyleOnFilesJob.java @@ -112,6 +112,13 @@ public final IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreE return Status.OK_STATUS; } + /** + * Groups the given files by their project. + * + * @param filesToCheck + * the files to check + * @return the files grouped by project + */ private static Map> getFilesSortedToProject(final List filesToCheck) { @@ -132,6 +139,14 @@ public final IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreE return projectFilesMap; } + /** + * Removes files that are filtered by the given project configuration. + * + * @param files + * the files to filter + * @param projectConfig + * the project configuration providing the filters + */ private static void filter(final List files, final IProjectConfiguration projectConfig) { final List filters = projectConfig.getFilters(); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/TransformCheckstyleRulesJob.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/TransformCheckstyleRulesJob.java index c7c7e6af4..5b68f12b8 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/TransformCheckstyleRulesJob.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/jobs/TransformCheckstyleRulesJob.java @@ -130,6 +130,14 @@ public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreExcepti return status; } + /** + * Adds the given module and all its children to the flat list. + * + * @param module + * the module to visit + * @param flatModules + * the list collecting the modules + */ private static void recurseConfiguration(Configuration module, List flatModules) { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/nature/CheckstyleNature.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/nature/CheckstyleNature.java index 1f542d677..13178f8cf 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/nature/CheckstyleNature.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/nature/CheckstyleNature.java @@ -82,6 +82,12 @@ public void configure() throws CoreException { } } + /** + * Ensures the .project file of the project is writable. + * + * @throws CoreException + * the file could not be updated + */ private void ensureProjectFileWritable() throws CoreException { final IFile projectFile = mProject.getFile(".project"); if (projectFile.isReadOnly()) { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/ProjectConfigurationFactory.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/ProjectConfigurationFactory.java index e16c222a1..4a9d075f1 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/ProjectConfigurationFactory.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/ProjectConfigurationFactory.java @@ -66,6 +66,9 @@ public final class ProjectConfigurationFactory { private static final List SUPPORTED_VERSIONS = Arrays.asList("1.0.0", "1.1.0", CURRENT_FILE_FORMAT_VERSION); + /** + * Utility class, not intended to be instantiated. + */ private ProjectConfigurationFactory() { } @@ -189,6 +192,19 @@ private static IProjectConfiguration loadFromPersistence(IProject project) return configuration; } + /** + * Reads the project configuration from the given input stream. + * + * @param input + * the input stream + * @param project + * the project + * @return the project configuration + * @throws DocumentException + * the configuration document could not be read + * @throws CheckstylePluginException + * an unexpected exception occurred + */ private static IProjectConfiguration getProjectConfiguration(InputStream input, IProject project) throws DocumentException, CheckstylePluginException { @@ -215,6 +231,15 @@ private static IProjectConfiguration getProjectConfiguration(InputStream input, syncFormatter); } + /** + * Reads the local check configurations from the given root element. + * + * @param root + * the root element + * @param project + * the project + * @return the list of check configurations + */ private static List getLocalCheckConfigs(Element root, IProject project) { final List configurations = new ArrayList<>(); @@ -268,6 +293,17 @@ private static List getLocalCheckConfigs(Element root, IPro return configurations; } + /** + * Reads the file sets from the given root element. + * + * @param root + * the root element + * @param localCheckConfigs + * the local check configurations + * @return the list of file sets + * @throws CheckstylePluginException + * an unexpected exception occurred + */ private static List getFileSets(Element root, List localCheckConfigs) throws CheckstylePluginException { @@ -318,6 +354,13 @@ private static List getFileSets(Element root, return fileSets; } + /** + * Reads the filters from the given root element. + * + * @param root + * the root element + * @return the list of filters + */ private static List getFilters(Element root) { final List filters = new ArrayList<>(); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/XMLTags.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/XMLTags.java index e8177b527..4ca81d116 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/XMLTags.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/XMLTags.java @@ -88,6 +88,9 @@ public final class XMLTags { /** Sync formatter flag tag. */ static final String SYNC_FORMATTER_TAG = "sync-formatter"; + /** + * Utility class, not intended to be instantiated. + */ private XMLTags() { // NOOP } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/AbstractFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/AbstractFilter.java index 6b979dcab..2f9497eb2 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/AbstractFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/AbstractFilter.java @@ -47,6 +47,9 @@ public abstract class AbstractFilter implements IFilter { /** Flags, if the filter is readonly. */ private boolean mReadonly; + /** + * Creates a new abstract filter. + */ protected AbstractFilter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/DerivedFilesFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/DerivedFilesFilter.java index 47a055907..82a99850d 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/DerivedFilesFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/DerivedFilesFilter.java @@ -28,6 +28,9 @@ */ public class DerivedFilesFilter extends AbstractFilter { + /** + * Creates a filter that filters all derived resources. + */ public DerivedFilesFilter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesInSyncFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesInSyncFilter.java index 1e3c683c7..24e6b89a4 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesInSyncFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesInSyncFilter.java @@ -37,6 +37,9 @@ */ public class FilesInSyncFilter extends AbstractFilter { + /** + * Creates a filter that filters files in sync with the source repository. + */ public FilesInSyncFilter() { } @@ -73,6 +76,15 @@ public boolean accept(Object element) { return accept; } + /** + * Determines whether the given file has changed according to the subscriber. + * + * @param file + * the file to check + * @param subscriber + * the repository subscriber + * @return true if the file has changes + */ private boolean hasChanges(IFile file, Subscriber subscriber) { boolean hasChanges = false; try { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesOlderThanOneDayFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesOlderThanOneDayFilter.java index 45806e0cb..bdea39574 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesOlderThanOneDayFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/FilesOlderThanOneDayFilter.java @@ -31,6 +31,9 @@ public class FilesOlderThanOneDayFilter extends AbstractFilter { /** Milliseconds in 24 hours. */ private static final long MILLIS_IN_24_HOURS = 1000 * 60 * 60 * 24; + /** + * Creates a filter that filters files older than one day. + */ public FilesOlderThanOneDayFilter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/NonSrcDirsFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/NonSrcDirsFilter.java index 89b966f9f..ddecf0482 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/NonSrcDirsFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/NonSrcDirsFilter.java @@ -45,6 +45,9 @@ public class NonSrcDirsFilter extends AbstractFilter { /** The list of source paths of the current project. */ private List mCurrentSourcePaths; + /** + * Creates a filter that filters files outside the source directories. + */ public NonSrcDirsFilter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/PackageFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/PackageFilter.java index b1b6f419c..5809da501 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/PackageFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/PackageFilter.java @@ -48,6 +48,9 @@ public class PackageFilter extends AbstractFilter { /** Whether to exclude sub-packages. */ private boolean mExcludeSubPackages = true; + /** + * Creates a filter that filters files by package. + */ public PackageFilter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/UnOpenedFilesFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/UnOpenedFilesFilter.java index 80744a373..66529167f 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/UnOpenedFilesFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/UnOpenedFilesFilter.java @@ -34,6 +34,9 @@ public class UnOpenedFilesFilter extends AbstractFilter { /** The list of opened files. */ private static final List OPENED_FILES = new ArrayList<>(); + /** + * Creates a filter that filters files that are not opened. + */ public UnOpenedFilesFilter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/WriteProtectedFilter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/WriteProtectedFilter.java index 2a437b137..9c2e4a3f8 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/WriteProtectedFilter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/projectconfig/filters/WriteProtectedFilter.java @@ -29,6 +29,9 @@ */ public class WriteProtectedFilter extends AbstractFilter { + /** + * Creates a filter that filters all write protected resources. + */ public WriteProtectedFilter() { } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java index 572dceac5..728bdfb1f 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java @@ -58,6 +58,9 @@ public CheckstyleFileWriter(final CheckstyleSetting setting, final String file) this.file = file; } + /** + * Writes the configured checkstyle settings to an XML file. + */ public void writeXmlFile() { try (FileOutputStream fw = new FileOutputStream(file)) { writeXMLFile(fw); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterConfigWriter.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterConfigWriter.java index 15986ba17..17958fe2a 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterConfigWriter.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterConfigWriter.java @@ -104,6 +104,16 @@ private void writeFormatterSettings(final Map settings) { } } + /** + * Creates or updates the given settings file with the supplied stream. + * + * @param settingsFile + * the settings file to update + * @param stream + * the stream with the new content + * @throws CoreException + * the file could not be updated + */ private static void createOrUpdateFile(IFile settingsFile, InputStream stream) throws CoreException { if (settingsFile.exists()) { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterTransformer.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterTransformer.java index e3ed32d3e..270d26b31 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterTransformer.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/FormatterTransformer.java @@ -109,6 +109,11 @@ private List loadTransformationClasses( return targetTransformers; } + /** + * Discovers the formatter transformation classes. + * + * @return the discovered transformations by their formatter key + */ @SuppressWarnings("unchecked") private static Map> discoverTransformers() { diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/CheckstyleTokens.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/CheckstyleTokens.java index 337b96720..d761c1c89 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/CheckstyleTokens.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/CheckstyleTokens.java @@ -203,6 +203,9 @@ public final class CheckstyleTokens { /** Type that refers to all types ({@code "?"}). */ public static final String WILDCARD_TYPE = "WILDCARD_TYPE"; + /** + * Utility class, not intended to be instantiated. + */ private CheckstyleTokens() { } } diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/LeftCurlyTransformer.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/LeftCurlyTransformer.java index 262018dd4..dcf2bf054 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/LeftCurlyTransformer.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/transformer/ctransformerclasses/LeftCurlyTransformer.java @@ -63,6 +63,13 @@ public class LeftCurlyTransformer extends AbstractCTransformationClass { private static final List SWITCH_SETTINGS = List .of(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_SWITCH); + /** + * Returns the formatter settings for the given token. + * + * @param token + * the token to look up + * @return the formatter settings for the token + */ private static List getSettingsForToken(String token) { return switch (token) { case null -> Collections.emptyList(); diff --git a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/util/CheckstyleLog.java b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/util/CheckstyleLog.java index 06a184f28..413f78b9e 100644 --- a/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/util/CheckstyleLog.java +++ b/net.sf.eclipsecs.core/src/main/java/net/sf/eclipsecs/core/util/CheckstyleLog.java @@ -36,6 +36,9 @@ public final class CheckstyleLog { /** The platform log. */ private static ILog log; + /** + * Utility class, not intended to be instantiated. + */ private CheckstyleLog() { } diff --git a/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java b/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java index b270de482..4c52de553 100644 --- a/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java +++ b/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java @@ -56,6 +56,13 @@ public int[] getDefaultTokens() { }; } + /** + * Sets the maximum number of methods. + * + * @param limit + * the maximum number of methods + * @since 6.0 + */ public void setMax(int limit) { max = limit; } diff --git a/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/filter/SampleFilter.java b/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/filter/SampleFilter.java index e217393d0..232222a4f 100644 --- a/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/filter/SampleFilter.java +++ b/net.sf.eclipsecs.sample/src/main/java/net/sf/eclipsecs/sample/filter/SampleFilter.java @@ -30,6 +30,9 @@ @ThreadSafe public class SampleFilter extends AbstractFilter { + /** + * Creates a filter that rejects all files. + */ public SampleFilter() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/ApplicationStartedHandler.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/ApplicationStartedHandler.java index f23c6ff65..79f4a2ed3 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/ApplicationStartedHandler.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/ApplicationStartedHandler.java @@ -77,6 +77,9 @@ public void handleEvent(org.osgi.service.event.Event event) { } } + /** + * Registers the listeners needed for the check-on-open support on the workbench windows. + */ private void registerListener() { // add listeners for the Check-On-Open support final IWorkbench workbench = PlatformUI.getWorkbench(); @@ -100,6 +103,9 @@ public void run() { }); } + /** + * Registers the checkstyle icon for the checkstyle job family in the progress service. + */ protected void registerProgressIcon() { final IProgressService service = PlatformUI.getWorkbench().getProgressService(); if (service != null) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/CheckstyleUIPluginImages.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/CheckstyleUIPluginImages.java index 8cfdbbced..b5d7b8180 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/CheckstyleUIPluginImages.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/CheckstyleUIPluginImages.java @@ -116,10 +116,21 @@ public enum CheckstyleUIPluginImages { */ private Image image; + /** + * Creates an image descriptor entry. + * + * @param factory + * the lazy creation factory + */ CheckstyleUIPluginImages(Supplier factory) { this.factory = factory; } + /** + * Returns the image descriptor, lazily creating it on first access. + * + * @return the image descriptor + */ public ImageDescriptor getImageDescriptor() { if (imageDescriptor == null) { imageDescriptor = factory.get(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/Messages.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/Messages.java index 5d165b5d9..ed9ee2c95 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/Messages.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/Messages.java @@ -491,6 +491,9 @@ public final class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + /** + * Utility class, cannot be instantiated. + */ private Messages() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ActivateProjectsAction.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ActivateProjectsAction.java index 61fb0b08e..81bfcb07c 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ActivateProjectsAction.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ActivateProjectsAction.java @@ -76,6 +76,12 @@ private static class BulkCheckstyleActivateJob extends WorkspaceJob { /** The projects to activate Checkstyle on. */ private Collection mProjectsToActivate; + /** + * Creates the job to activate Checkstyle on the given projects. + * + * @param projectsToActivate + * the projects to activate Checkstyle on + */ BulkCheckstyleActivateJob(Collection projectsToActivate) { super(Messages.ActivateProjectsPrintAction_msgActivateSelectedProjects); this.mProjectsToActivate = projectsToActivate; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/CheckSelectedFilesAction.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/CheckSelectedFilesAction.java index 1b13b79c8..d68a26d55 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/CheckSelectedFilesAction.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/CheckSelectedFilesAction.java @@ -74,6 +74,12 @@ public void run(IAction action) { checkSelection(mSelection); } + /** + * Checks the files contained in the given selection. + * + * @param selection + * the selection of resources + */ private void checkSelection(IStructuredSelection selection) { final Set resources = new HashSet<>(); for (Object object : selection.toList()) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ClearSelectedFilesAction.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ClearSelectedFilesAction.java index e63142dcd..805138071 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ClearSelectedFilesAction.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ClearSelectedFilesAction.java @@ -79,6 +79,12 @@ private static class ClearMarkersJob extends WorkspaceJob { /** The resources to clear markers from. */ private Collection mResourcesToClear; + /** + * Creates the job that clears the checkstyle markers from the given resources. + * + * @param resourcesToClear + * the resources whose markers should be cleared + */ ClearMarkersJob(Collection resourcesToClear) { super(Messages.ClearSelectedFilesAction_title); this.mResourcesToClear = resourcesToClear; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ConfigureProjectFromBluePrintAction.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ConfigureProjectFromBluePrintAction.java index 671faa20a..bbef28649 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ConfigureProjectFromBluePrintAction.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/ConfigureProjectFromBluePrintAction.java @@ -117,6 +117,14 @@ private static class BulkConfigureJob extends WorkspaceJob { /** The projects to configure from the blueprint. */ private final Collection mProjectsToConfigure; + /** + * Creates the job configuring the given projects from the blueprint project. + * + * @param blueprint + * the blueprint project to copy configuration from + * @param projectsToConfigure + * the projects to configure + */ BulkConfigureJob(IProject blueprint, Collection projectsToConfigure) { super(Messages.ConfigureProjectFromBluePrintAction_msgConfiguringFromBluePrint); this.mBlueprint = blueprint; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/DeactivateProjectsAction.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/DeactivateProjectsAction.java index 1ab396913..f3c223eea 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/DeactivateProjectsAction.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/actions/DeactivateProjectsAction.java @@ -76,6 +76,12 @@ private static class BulkCheckstyleActivateJob extends WorkspaceJob { /** The projects to deactivate Checkstyle on. */ private Collection mProjectsToDeactivate; + /** + * Creates the job that deactivates Checkstyle on the given projects. + * + * @param projectsToDeactivate + * the projects to deactivate Checkstyle on + */ BulkCheckstyleActivateJob(Collection projectsToDeactivate) { super(Messages.DeactivateProjectsPrintAction_msgDeactivateSelectedProjects); this.mProjectsToDeactivate = projectsToDeactivate; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/AvailableModulesViewer.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/AvailableModulesViewer.java index 802ee0721..01612deed 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/AvailableModulesViewer.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/AvailableModulesViewer.java @@ -67,6 +67,22 @@ public final class AvailableModulesViewer extends Composite { /** The callback for adding new modules. */ private final Consumer> newModule; + /** + * Creates the available modules viewer. + * + * @param parent + * the parent composite + * @param style + * the style of the composite + * @param labelProvider + * the label provider for the tree viewer + * @param configurable + * whether the add button is enabled + * @param newModule + * the callback for adding new modules + * @param selectionChanged + * the callback for selection changes + */ public AvailableModulesViewer(Composite parent, int style, AvailableModulesViewerLabelProvider labelProvider, boolean configurable, Consumer> newModule, Consumer selectionChanged) { @@ -125,6 +141,12 @@ else if (configurable) { treeViewer.getViewer().setInput(MetadataFactory.getRuleGroupMetadata()); } + /** + * Adds all selected modules to the new module callback. + * + * @param selection + * the structured selection of rule groups or rules + */ private void newModule(IStructuredSelection selection) { final List rules = new ArrayList<>(); for (Object element : selection) { @@ -140,18 +162,33 @@ else if (element instanceof RuleMetadata rule) { newModule.accept(rules); } + /** + * Refreshes the tree viewer. + */ public void refresh() { treeViewer.getViewer().refresh(); } + /** + * Forces the focus to the tree viewer. + */ public void focus() { treeViewer.getViewer().getTree().forceFocus(); } + /** + * Sets the selection of the tree viewer. + * + * @param selection + * the selection to set + */ public void setSelection(ISelection selection) { treeViewer.getViewer().setSelection(selection); } + /** + * Selects the first rule group if any groups exist. + */ public void selectFirstGroup() { final List groups = MetadataFactory.getRuleGroupMetadata(); if (!groups.isEmpty()) { @@ -166,6 +203,9 @@ public void selectFirstGroup() { */ private static final class ModulePatternFilter extends PatternFilter { + /** + * Creates the module pattern filter. + */ private ModulePatternFilter() { setIncludeLeadingWildcard(true); } @@ -187,6 +227,9 @@ private static final class MetaDataContentProvider implements ITreeContentProvid /** Singleton instance. */ private static final MetaDataContentProvider INSTANCE = new MetaDataContentProvider(); + /** + * Creates the metadata content provider. + */ private MetaDataContentProvider() { } @@ -255,6 +298,12 @@ public static class AvailableModulesViewerLabelProvider extends LabelProvider { /** The list of configured modules. */ private final List modules; + /** + * Creates the label provider for the available modules. + * + * @param modules + * the list of configured modules + */ public AvailableModulesViewerLabelProvider(List modules) { this.modules = modules; } @@ -295,6 +344,13 @@ else if (element instanceof RuleMetadata) { return image; } + /** + * Determines whether all modules of the group are in use. + * + * @param group + * the rule group metadata + * @return true if all modules of the group are used + */ private boolean isGroupUsed(RuleGroupMetadata group) { boolean used = true; @@ -308,6 +364,13 @@ private boolean isGroupUsed(RuleGroupMetadata group) { return used; } + /** + * Determines whether the given rule metadata is used by a configured module. + * + * @param metadata + * the rule metadata + * @return true if a configured module matches the metadata + */ private boolean isMetadataUsed(RuleMetadata metadata) { boolean used = false; if (modules != null) { @@ -335,6 +398,9 @@ private static final class AvailableModulesViewerFilter extends ViewerFilter { private static final AvailableModulesViewerFilter INSTANCE = new AvailableModulesViewerFilter(); + /** + * Creates the available modules viewer filter. + */ private AvailableModulesViewerFilter() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialog.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialog.java index 2336d7134..e62a2e4eb 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialog.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialog.java @@ -215,6 +215,9 @@ private void initialize() { this.dialogView.selectFirstAvailableGroup(); } + /** + * Loads the modules of the configuration into the dialog. + */ private void loadModules() { try { mModules = mConfiguration.getModules(); @@ -330,6 +333,14 @@ private void removeModule(List modules) { } } + /** + * Updates the severity of the given module when its checked state changes. + * + * @param module + * the module whose checked state changed + * @param checked + * whether the module is now checked + */ private void checkStateChanged(Module module, boolean checked) { if (checked) { // restore last severity before setting to ignore diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialogView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialogView.java index 04aae79f3..51342209a 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialogView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationConfigureDialogView.java @@ -60,6 +60,20 @@ public final class CheckConfigurationConfigureDialogView extends Composite { /** The configured modules panel. */ private final ConfiguredModules configuredModules; + /** + * Creates the module configuration dialog view. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits + * @param callbacks + * the callbacks used by the dialog view + * @param mModules + * the list of configured modules + * @param configurable + * whether the configuration is editable + */ public CheckConfigurationConfigureDialogView(Composite parent, int style, CheckConfigurationConfigureDialogViewCallbacks callbacks, List mModules, boolean configurable) { @@ -99,26 +113,51 @@ public CheckConfigurationConfigureDialogView(Composite parent, int style, }); } + /** + * Sets the text shown in the module description browser. + * + * @param description + * the description to display + */ public void setBrowserDescription(String description) { mBrowserDescription.setText(description); } + /** + * Refreshes the display of the configured modules. + */ public void refreshConfiguredModules() { configuredModules.refresh(); } + /** + * Refreshes the display of the available modules. + */ public void refreshAvailableModules() { availableModulesViewer.refresh(); } + /** + * Selects the first group in the available modules tree. + */ public void selectFirstAvailableGroup() { availableModulesViewer.selectFirstGroup(); } + /** + * Sets focus to the available modules viewer. + */ public void focusAvailableModules() { availableModulesViewer.focus(); } + /** + * Updates the browser description and configured group when the available module selection + * changes. + * + * @param selection + * the newly selected module element + */ private void changeAvailableModuleSelection(Object selection) { String description = null; if (selection instanceof RuleGroupMetadata group) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationLabelProvider.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationLabelProvider.java index b03f7bc9d..617d5646e 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationLabelProvider.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationLabelProvider.java @@ -36,6 +36,9 @@ public class CheckConfigurationLabelProvider extends LabelProvider { public static final CheckConfigurationLabelProvider INSTANCE = new CheckConfigurationLabelProvider(); + /** + * Creates the label provider singleton. + */ protected CheckConfigurationLabelProvider() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialog.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialog.java index 8d40707ee..ada3c8449 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialog.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialog.java @@ -156,6 +156,14 @@ protected Control createDialogArea(Composite parent) { return composite; } + /** + * Recreates the configuration editor when the configuration type selection changed. + * + * @param type + * the new configuration type + * @param isComboEnabled + * whether the type combo is enabled + */ private void changeSelectedConfigurationType(IConfigurationType type, boolean isComboEnabled) { if (isComboEnabled) { final String oldName = mCheckConfig.getName(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialogView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialogView.java index 167bdd902..e87ee5c34 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialogView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationPropertiesDialogView.java @@ -52,6 +52,17 @@ public final class CheckConfigurationPropertiesDialogView extends Composite { /** The placeholder composite for the configuration editor. */ private final Composite mEditorPlaceHolder; + /** + * Constructor building the configuration type selector and the placeholder for the matching + * editor. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits to apply to this composite + * @param changeSelectedConfigurationType + * the callback invoked when the selected configuration type changes + */ public CheckConfigurationPropertiesDialogView(Composite parent, int style, BiConsumer changeSelectedConfigurationType) { super(parent, style); @@ -90,15 +101,31 @@ public CheckConfigurationPropertiesDialogView(Composite parent, int style, GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(mEditorPlaceHolder); } + /** + * Initializes the configuration type combo with the given types and selects the first one. + * + * @param types + * the configuration types to show + */ public void initConfigType(IConfigurationType[] types) { mConfigType.setInput(types); mConfigType.setSelection(new StructuredSelection(types[0]), true); } + /** + * Disables the configuration type combo box. + */ public void disable() { mConfigType.getCombo().setEnabled(false); } + /** + * Binds the given configuration editor into the editor placeholder, removing any previously + * bound editor. + * + * @param mConfigurationEditor + * the configuration editor to bind + */ public void bindEditor(ICheckConfigurationEditor mConfigurationEditor) { // remove old editor final Control[] controls = mEditorPlaceHolder.getChildren(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationViewerSorter.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationViewerSorter.java index 38127e19b..18758c4ca 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationViewerSorter.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationViewerSorter.java @@ -34,6 +34,9 @@ public final class CheckConfigurationViewerSorter extends ViewerComparator { public static final CheckConfigurationViewerSorter INSTANCE = new CheckConfigurationViewerSorter(); + /** + * Private constructor to enforce the singleton pattern. + */ private CheckConfigurationViewerSorter() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java index 770611707..bcfbfa4e8 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java @@ -92,6 +92,14 @@ public CheckConfigurationWorkingSetEditor(Composite parent, int style, GridDataFactory.fillDefaults().grab(true, true).applyTo(editorView); } + /** + * Determines whether the given check configuration is the default configuration of the working + * set. + * + * @param config + * the check configuration to test + * @return true if the configuration is the default, false otherwise + */ private boolean isDefaultConfig(CheckConfigurationWorkingCopy config) { boolean configDefault = false; if (mWorkingSet instanceof GlobalCheckConfigurationWorkingSet globalWorkingSet) { @@ -134,6 +142,10 @@ private void editCheckConfig() { } } + /** + * Opens the configure dialog for the selected check configuration, showing a warning if its + * location cannot be resolved. + */ private void configureCheckConfig() { final CheckConfigurationWorkingCopy config = editorView.getSelectedConfig(); @@ -218,6 +230,9 @@ private void removeCheckConfig() { } } + /** + * Sets the selected check configuration as the default configuration of the working set. + */ private void setDefaultCheckConfig() { final CheckConfigurationWorkingCopy checkConfig = editorView.getSelectedConfig(); if (checkConfig != null) { @@ -253,6 +268,12 @@ private void exportCheckstyleCheckConfig() { } } + /** + * Returns the dialog settings section for this working set, creating it if it does not yet + * exist. + * + * @return the dialog settings section for the working set + */ private IDialogSettings getTableSettings() { final String concreteViewId = mWorkingSet.getClass().getName(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorButtonBar.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorButtonBar.java index be8d219cb..a874269bb 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorButtonBar.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorButtonBar.java @@ -51,6 +51,18 @@ public final class CheckConfigurationWorkingSetEditorButtonBar extends Composite /** The export button. */ private final Button mExportButton; + /** + * Creates the button bar for the working set editor. + * + * @param parent + * the parent composite + * @param style + * the composite style bits + * @param useDefaultButton + * whether to show the default button + * @param actions + * the actions triggered by the buttons + */ public CheckConfigurationWorkingSetEditorButtonBar(Composite parent, int style, boolean useDefaultButton, ButtonBarActions actions) { super(parent, style); @@ -95,6 +107,17 @@ public CheckConfigurationWorkingSetEditorButtonBar(Composite parent, int style, .applyTo(mExportButton); } + /** + * Creates a button with the given text and action. + * + * @param parent + * the parent composite + * @param text + * the button text + * @param action + * the action to run when the button is clicked + * @return the created button + */ private Button createButton(Composite parent, String text, Runnable action) { final Button button = new Button(parent, SWT.PUSH); button.setText(text); @@ -102,6 +125,16 @@ private Button createButton(Composite parent, String text, Runnable action) { return button; } + /** + * Sets the enabled state of the buttons based on the selection state. + * + * @param configSelected + * whether a configuration is selected + * @param configEditable + * whether the selected configuration is editable + * @param configDefault + * whether the selected configuration is the default + */ public void setSelectionState(boolean configSelected, boolean configEditable, boolean configDefault) { mEditButton.setEnabled(configSelected); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorConfigTable.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorConfigTable.java index 860179bc5..b50de1da4 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorConfigTable.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorConfigTable.java @@ -53,6 +53,20 @@ public final class CheckConfigurationWorkingSetEditorConfigTable extends Composi /** The table viewer for check configurations. */ private final TableViewer tableViewer; + /** + * Creates the configuration table. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param model + * the working set editor model + * @param configureCheckConfig + * callback to configure a check configuration + * @param handleSelectionChanged + * callback invoked when the selection changes + */ public CheckConfigurationWorkingSetEditorConfigTable(Composite parent, int style, CheckConfigurationWorkingSetEditorModel model, Runnable configureCheckConfig, @@ -118,20 +132,40 @@ public CheckConfigurationWorkingSetEditorConfigTable(Composite parent, int style TableViewerEnhancer.enhance(tableViewer, model.tableSettings(), tableColumnLayout); } + /** + * Refreshes the table. + */ public void refresh() { tableViewer.refresh(true); } + /** + * Returns the selected configuration. + * + * @return the selected configuration + */ public CheckConfigurationWorkingCopy getSelection() { return (CheckConfigurationWorkingCopy) tableViewer.getStructuredSelection() .getFirstElement(); } + /** + * Sets the configurations shown by the table. + * + * @param configs + * the configurations to show + */ public void setConfigs(CheckConfigurationWorkingCopy[] configs) { this.tableViewer.setInput(configs); this.tableViewer.refresh(); } + /** + * Sets the selected configuration. + * + * @param config + * the configuration to select + */ public void setSelection(CheckConfigurationWorkingCopy config) { this.tableViewer.setSelection(new StructuredSelection(config)); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorView.java index c819cea24..969313924 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditorView.java @@ -59,6 +59,18 @@ public final class CheckConfigurationWorkingSetEditorView extends Composite { /** The model for this view. */ private final CheckConfigurationWorkingSetEditorModel model; + /** + * Creates the working set editor view. + * + * @param parent + * the parent composite + * @param style + * the composite style bits + * @param model + * the model for this view + * @param buttonBarActions + * the button bar actions + */ public CheckConfigurationWorkingSetEditorView(Composite parent, int style, CheckConfigurationWorkingSetEditorModel model, ButtonBarActions buttonBarActions) { super(parent, style); @@ -102,22 +114,51 @@ public CheckConfigurationWorkingSetEditorView(Composite parent, int style, handleSelectionChanged(null); } + /** + * Returns the currently selected configuration. + * + * @return the selected configuration + */ public CheckConfigurationWorkingCopy getSelectedConfig() { return configTable.getSelection(); } + /** + * Sets the configurations displayed in the config table. + * + * @param configs + * the configurations to display + */ public void setConfigs(CheckConfigurationWorkingCopy[] configs) { configTable.setConfigs(configs); } + /** + * Sets the selected configuration in the config table. + * + * @param config + * the configuration to select + */ public void setSelection(CheckConfigurationWorkingCopy config) { configTable.setSelection(config); } + /** + * Refreshes the config table. + */ public void refresh() { configTable.refresh(); } + /** + * Creates the table viewer showing the projects using the configuration. + * + * @param parent + * the parent composite + * @param global + * whether the viewer applies to a global configuration + * @return the usage table viewer, or empty if not global + */ private static Optional makeUsageView(Composite parent, boolean global) { TableViewer usageView = null; if (global) { @@ -138,6 +179,12 @@ private static Optional makeUsageView(Composite parent, boolean glo return Optional.ofNullable(usageView); } + /** + * Handles the selection change in the config table. + * + * @param config + * the newly selected configuration + */ private void handleSelectionChanged(CheckConfigurationWorkingCopy config) { final boolean configSelected = config != null; if (configSelected) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModules.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModules.java index 8453b30b9..4e6bbd196 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModules.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModules.java @@ -55,6 +55,20 @@ public final class ConfiguredModules extends Composite { /** The currently selected rule group. */ private RuleGroupMetadata currentGroup; + /** + * Creates the configured modules composite. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param configurable + * whether the modules are configurable + * @param modules + * the modules to display + * @param callbacks + * the callbacks used by the composite + */ public ConfiguredModules(Composite parent, int style, boolean configurable, List modules, ConfiguredModulesCallbacks callbacks) { super(parent, style); @@ -83,10 +97,19 @@ public ConfiguredModules(Composite parent, int style, boolean configurable, GridDataFactory.swtDefaults().applyTo(buttons); } + /** + * Refreshes the table of configured modules. + */ public void refresh() { table.refresh(); } + /** + * Sets the currently selected rule group and refreshes the displayed modules. + * + * @param currentGroup + * the current rule group + */ public void setCurrentGroup(RuleGroupMetadata currentGroup) { this.currentGroup = currentGroup; this.configuredModulesGroup @@ -138,6 +161,12 @@ private static final class TableCheckStateProvider implements ICheckStateProvide /** Whether the table is configurable. */ private final boolean configurable; + /** + * Creates the check state provider. + * + * @param configurable + * whether the table is configurable + */ private TableCheckStateProvider(boolean configurable) { this.configurable = configurable; } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesButtons.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesButtons.java index d7e7e6e3a..fadf30a0c 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesButtons.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesButtons.java @@ -35,6 +35,20 @@ */ public class ConfiguredModulesButtons extends Composite { + /** + * Creates the Remove and Open buttons and wires them to the given actions. + * + * @param parent + * the parent composite + * @param style + * the style bits + * @param configurable + * whether the Remove button should be enabled + * @param removeModule + * the action run when the Remove button is selected + * @param editModule + * the action run when the Open button is selected + */ public ConfiguredModulesButtons(Composite parent, int style, boolean configurable, Runnable removeModule, Runnable editModule) { super(parent, style); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java index c016a89ad..4567e02a2 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ConfiguredModulesTable.java @@ -58,6 +58,24 @@ public final class ConfiguredModulesTable extends Composite { /** The checkbox table viewer for configured modules. */ private final CheckboxTableViewer tableViewer; + /** + * Creates the table of configured modules and wires it to the given callbacks. + * + * @param parent + * the parent composite + * @param style + * the style bits + * @param ruleGroupModuleFilter + * the viewer filter applied to the module table + * @param configurable + * whether the modules can be removed and their check state changed + * @param checkStateProvider + * the check state provider for the table + * @param callbacks + * the callbacks notified on user interaction with the table + * @param modules + * the modules to display in the table + */ public ConfiguredModulesTable(Composite parent, int style, ViewerFilter ruleGroupModuleFilter, boolean configurable, ICheckStateProvider checkStateProvider, ConfiguredModulesCallbacks callbacks, List modules) { @@ -114,6 +132,14 @@ public ConfiguredModulesTable(Composite parent, int style, ViewerFilter ruleGrou TableViewerEnhancer.enhance(tableViewer, getTableSettings(), tableColumnLayout); } + /** + * Creates the table columns for module name, severity and comment. + * + * @param layout + * the table column layout to which the column data is added + * @param table + * the table whose columns are created + */ private void createColumns(TableColumnLayout layout, Table table) { final TableViewerColumn col1 = new TableViewerColumn(tableViewer, SWT.NONE); col1.getColumn().setAlignment(SWT.CENTER); @@ -154,15 +180,29 @@ private void createColumns(TableColumnLayout layout, Table table) { table.setSortColumn(col2.getColumn()); } + /** + * Refreshes the table viewer to reflect the current module data. + */ public void refresh() { tableViewer.refresh(); } + /** + * Returns the modules currently selected in the table. + * + * @return the list of selected modules + */ @SuppressWarnings("unchecked") public List getSelectedModules() { return tableViewer.getStructuredSelection().toList(); } + /** + * Returns the dialog settings section for the configure dialog, creating it if it does not yet + * exist. + * + * @return the dialog settings section for the table + */ private static IDialogSettings getTableSettings() { final String concreteViewId = CheckConfigurationConfigureDialog.class.getName(); @@ -177,6 +217,13 @@ private static IDialogSettings getTableSettings() { return settings; } + /** + * Returns the given value or an empty string if it is null. + * + * @param value + * the value to convert, may be null + * @return the value, or an empty string if it was null + */ private static String nullSafeText(String value) { final String text; if (value != null) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialog.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialog.java index ba4eb8570..5756891b3 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialog.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialog.java @@ -205,6 +205,12 @@ private void initialize() { dialogView.setResolvableProperties(mResolvableProperties); } + /** + * Opens the editor for the given property or creates a new property when it is null. + * + * @param prop + * the property to edit or null to create a new one + */ private void openPropertyItemEditor(ResolvableProperty prop) { if (prop == null) { @@ -226,6 +232,12 @@ private void openPropertyItemEditor(ResolvableProperty prop) { } } + /** + * Removes the given resolvable properties after confirmation. + * + * @param resolvableProperties + * the resolvable properties to remove + */ private void removePropertyItems(List resolvableProperties) { final boolean confirm = MessageDialog.openQuestion(getShell(), Messages.ResolvablePropertiesDialog_titleRemoveConfirmation, @@ -236,6 +248,9 @@ private void removePropertyItems(List resolvableProperties) } } + /** + * Searches for unresolved properties and offers to add them to the dialog. + */ private void findPropertyItems() { final CheckConfigurationWorkingCopy clone = new CheckConfigurationWorkingCopy(mCheckConfig); clone.getResolvableProperties().clear(); @@ -289,6 +304,11 @@ private void findPropertyItems() { } } + /** + * Returns the dialog settings section for the properties table. + * + * @return the dialog settings + */ private static IDialogSettings getTableSettings() { final String concreteViewId = ResolvablePropertiesDialog.class.getName(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialogView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialogView.java index 190069168..22b247775 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialogView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/ResolvablePropertiesDialogView.java @@ -53,6 +53,21 @@ public final class ResolvablePropertiesDialogView extends Composite { /** The table viewer for resolvable properties. */ private final TableViewer mTableViewer; + /** + * Constructor building the table and the Add/Edit/Remove controls to manage resolvable + * properties. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits to apply to this composite + * @param tableSettings + * the dialog settings used to persist the table layout + * @param openPropertyItemEditor + * the callback invoked to open the property item editor + * @param removePropertyItems + * the callback invoked to remove the selected property items + */ public ResolvablePropertiesDialogView(Composite parent, int style, IDialogSettings tableSettings, Consumer openPropertyItemEditor, @@ -116,19 +131,42 @@ public ResolvablePropertiesDialogView(Composite parent, int style, .widgetSelectedAdapter(event -> removePropertyItems.accept(getSelectedProperties()))); } + /** + * Returns the resolvable properties currently selected in the table. + * + * @return the list of selected resolvable properties + */ @SuppressWarnings("unchecked") public List getSelectedProperties() { return mTableViewer.getStructuredSelection().toList(); } + /** + * Sets the resolvable properties to be shown in the table. + * + * @param resolvableProperties + * the resolvable properties to show + */ public void setResolvableProperties(List resolvableProperties) { mTableViewer.setInput(resolvableProperties); } + /** + * Refreshes the table viewer. + */ public void refresh() { mTableViewer.refresh(); } + /** + * Creates a push button with the given text and default layout data. + * + * @param parent + * the parent composite + * @param text + * the button text + * @return the newly-created button + */ private static Button createButton(Composite parent, String text) { final Button button = new Button(parent, SWT.PUSH); button.setText(text); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialog.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialog.java index c5c380965..20d4bffc7 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialog.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialog.java @@ -185,6 +185,9 @@ protected void createButtonsForButtonBar(Composite parent) { createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false); } + /** + * Initializes the dialog title, message and image. + */ private void initialize() { this.setTitle( diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogAdvancedSettings.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogAdvancedSettings.java index ed4cbfeca..39a7007c5 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogAdvancedSettings.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogAdvancedSettings.java @@ -55,6 +55,18 @@ public final class RuleConfigurationEditDialogAdvancedSettings extends Composite /** The map of custom message key to text field. */ private final Map mCustomMessages; + /** + * Creates the advanced settings composite. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param rule + * the rule to edit + * @param readonly + * whether the settings are read-only + */ public RuleConfigurationEditDialogAdvancedSettings(Composite parent, int style, Module rule, boolean readonly) { super(parent, style); @@ -111,23 +123,50 @@ public RuleConfigurationEditDialogAdvancedSettings(Composite parent, int style, mCommentText.setEnabled(!readonly); } + /** + * Returns the module comment. + * + * @return the module comment + */ public String getComment() { return mCommentText.getText(); } + /** + * Returns the module id. + * + * @return the module id + */ public String getId() { return mIdText.getText(); } + /** + * Returns the map of custom message keys to their values. + * + * @return the custom messages + */ public Map getCustomMessages() { return mCustomMessages.entrySet().stream() .collect(Collectors.toMap(Entry::getKey, entry -> entry.getValue().getText())); } + /** + * Resets the module comment. + */ public void resetComment() { mCommentText.setText(""); } + /** + * Creates a text field with the given label. + * + * @param parent + * the parent composite + * @param label + * the label text + * @return the created text field + */ private static Text createLabeledText(Composite parent, String label) { final Label commentLabel = new Label(parent, SWT.NULL); commentLabel.setText(label); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogGeneralSettings.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogGeneralSettings.java index bd0a92cd3..e9fd255a9 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogGeneralSettings.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/RuleConfigurationEditDialogGeneralSettings.java @@ -60,6 +60,18 @@ public final class RuleConfigurationEditDialogGeneralSettings extends Composite /** The list of configuration property widgets. */ private final List mConfigPropertyWidgets; + /** + * Creates the general settings composite. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param rule + * the rule to edit + * @param readonly + * whether the settings are read-only + */ public RuleConfigurationEditDialogGeneralSettings(Composite parent, int style, Module rule, boolean readonly) { super(parent, style); @@ -99,18 +111,37 @@ public RuleConfigurationEditDialogGeneralSettings(Composite parent, int style, M } } + /** + * Returns the selected severity. + * + * @return the selected severity + */ public Severity getSeverity() { return (Severity) mSeverityCombo.getStructuredSelection().getFirstElement(); } + /** + * Sets the selected severity. + * + * @param severity + * the severity to select + */ public void setSeverity(Severity severity) { mSeverityCombo.setSelection(new StructuredSelection(severity)); } + /** + * Restores the default values of all property widgets. + */ public void restoreProperties() { mConfigPropertyWidgets.forEach(IConfigPropertyWidget::restorePropertyDefault); } + /** + * Validates the property widgets and applies the values of the valid widgets. + * + * @return an error message if validation failed or an empty optional + */ public Optional validatePropertyWidgets() { Optional errorMessage = Optional.empty(); for (IConfigPropertyWidget widget : mConfigPropertyWidgets) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditorView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditorView.java index f039d7769..247d155c2 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditorView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ExternalFileConfigurationEditorView.java @@ -51,6 +51,14 @@ public final class ExternalFileConfigurationEditorView extends Composite { /** The protect config check box. */ private final Button mChkProtectConfig; + /** + * Constructor building the editor form for external file check configurations. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits to apply to this composite + */ public ExternalFileConfigurationEditorView(Composite parent, int style) { super(parent, style); GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false).margins(0, 0).applyTo(this); @@ -85,38 +93,92 @@ public ExternalFileConfigurationEditorView(Composite parent, int style) { GridDataFactory.create(GridData.FILL_HORIZONTAL).span(2, 1).applyTo(mChkProtectConfig); } + /** + * Returns the configuration name entered in the name text field. + * + * @return the configuration name + */ public String getConfigName() { return mConfigName.getText(); } + /** + * Returns the description entered in the description text field. + * + * @return the description + */ public String getDescription() { return mDescription.getText(); } + /** + * Returns the config file location entered in the location text field. + * + * @return the config file location + */ public String getConfigLocation() { return location.getText(); } + /** + * Returns whether the protect-config option is selected. + * + * @return true if the protect-config check box is selected, false otherwise + */ public boolean getProtectConfig() { return mChkProtectConfig.getSelection(); } + /** + * Sets the configuration name in the name text field. + * + * @param configName + * the configuration name to set + */ public void setConfigName(String configName) { mConfigName.setText(configName); } + /** + * Sets the description in the description text field. + * + * @param description + * the description to set + */ public void setDescription(String description) { mDescription.setText(description); } + /** + * Sets the config file location in the location text field. + * + * @param strLocation + * the config file location to set + */ public void setConfigLocation(String strLocation) { location.setText(strLocation); } + /** + * Sets the protect-config option in the check box. + * + * @param protectConfig + * true to select the protect-config check box, false otherwise + */ public void setProtectConfig(boolean protectConfig) { mChkProtectConfig.setSelection(protectConfig); } + /** + * Creates the location composite with a text field and a browse button that opens a file + * dialog. + * + * @param parent + * the parent composite + * @param shell + * the shell used as the parent of the file dialog + * @return the location text field + */ private static Text createLocationSection(Composite parent, Shell shell) { final Label lblConfigLocation = new Label(parent, SWT.NULL); lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java index 1721de42a..8ca8ee544 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditor.java @@ -97,6 +97,12 @@ public Control createEditorControl(Composite parent, final Shell shell) { return editorView; } + /** + * Imports a configuration from a file selected by the user. + * + * @param shell + * the shell to open the file dialog on + */ private void importConfig(Shell shell) { promptImportConfigFile(shell).ifPresent(configFileString -> { final ICheckConfiguration tmpSourceConfig = new CheckConfiguration("dummy", @@ -110,6 +116,13 @@ private void importConfig(Shell shell) { }); } + /** + * Prompts the user to select a configuration file to import. + * + * @param shell + * the shell to open the file dialog on + * @return the selected configuration file, or empty if none was chosen + */ private static Optional promptImportConfigFile(Shell shell) { final FileDialog fileDialog = new FileDialog(shell); fileDialog.setText(Messages.InternalConfigurationEditor_titleImportDialog); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditorView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditorView.java index 9d0c26c9e..02ce215fd 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditorView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/InternalConfigurationEditorView.java @@ -46,6 +46,16 @@ public final class InternalConfigurationEditorView extends Composite { /** The description text field. */ private final Text mDescription; + /** + * Creates the internal configuration editor view. + * + * @param parent + * the parent composite + * @param style + * the style of the composite + * @param importConfig + * the runnable executed on import + */ public InternalConfigurationEditorView(Composite parent, int style, Runnable importConfig) { super(parent, style); GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(this); @@ -86,22 +96,50 @@ public InternalConfigurationEditorView(Composite parent, int style, Runnable imp SelectionListener.widgetSelectedAdapter(event -> importConfig.run())); } + /** + * Returns the entered configuration name. + * + * @return the configuration name + */ public String getConfigName() { return mConfigName.getText(); } + /** + * Returns the entered description. + * + * @return the description + */ public String getDescription() { return mDescription.getText(); } + /** + * Sets the configuration name. + * + * @param configName + * the configuration name to set + */ public void setConfigName(String configName) { mConfigName.setText(configName); } + /** + * Sets the description. + * + * @param description + * the description to set + */ public void setDescription(String description) { mDescription.setText(description); } + /** + * Sets the configuration location. + * + * @param location + * the location to set + */ public void setConfigLocation(String location) { mLocation.setText(location); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java index 65a3c6eda..cabdd8112 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/ProjectConfigurationEditor.java @@ -155,6 +155,15 @@ public Control createEditorControl(Composite parent, final Shell parentShell) { return contents; } + /** + * Creates the location section with a text field and a browse button. + * + * @param parent + * the parent composite + * @param shell + * the shell used for the file selection dialog + * @return the text field displaying the selected location + */ private static Text createLocationSection(Composite parent, Shell shell) { final Label lblConfigLocation = new Label(parent, SWT.NULL); lblConfigLocation.setText(Messages.CheckConfigurationPropertiesDialog_lblLocation); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java index 45e46a183..c32c73969 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/RemoteConfigurationEditor.java @@ -136,6 +136,12 @@ public Control createEditorControl(Composite parent, final Shell shell) { return contents; } + /** + * Creates the credentials group of the editor. + * + * @param parent + * the parent composite + */ private void createCredentialsGroup(Composite parent) { final Group credentialsGroup = new Group(parent, SWT.NULL); credentialsGroup.setText(Messages.RemoteConfigurationEditor_titleCredentialsGroup); @@ -157,6 +163,12 @@ private void createCredentialsGroup(Composite parent) { GridDataFactory.fillDefaults().grab(true, false).applyTo(mPassword); } + /** + * Initializes the editor contents from the working copy. + * + * @param shell + * the parent shell + */ private void init(Shell shell) { if (mWorkingCopy.getName() != null) { mConfigName.setText(mWorkingCopy.getName()); @@ -231,6 +243,17 @@ public CheckConfigurationWorkingCopy getEditedWorkingCopy() throws CheckstylePlu return mWorkingCopy; } + /** + * Creates a cache file name for the given configuration name, time and extension. + * + * @param configName + * the configuration name + * @param time + * the current time in milliseconds + * @param extension + * the file extension + * @return the cache file name + */ private static String makeCacheFileName(String configName, long time, String extension) { return String.join("_", configName, String.valueOf(time), "cache.") + extension; } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/WorkspaceFileSelector.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/WorkspaceFileSelector.java index 44fc5a47d..8966f5f52 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/WorkspaceFileSelector.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/configtypes/WorkspaceFileSelector.java @@ -42,10 +42,21 @@ */ public final class WorkspaceFileSelector { + /** + * Utility class, cannot be instantiated. + */ private WorkspaceFileSelector() { } + /** + * Opens the selection dialog and returns the path of the selected Checkstyle configuration + * file. + * + * @param shell + * the parent shell + * @return the path of the selected file or an empty optional if nothing was selected + */ public static Optional select(Shell shell) { final ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(shell, new WorkbenchLabelProvider(), new WorkbenchContentProvider()); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java index 9e0be05a4..83cf91ff2 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java @@ -45,6 +45,14 @@ public abstract class AbstractConfigPropertyWidget implements IConfigPropertyWid /** The parent composite. */ private Composite mParent; + /** + * Creates the widget for the given property. + * + * @param parent + * the parent composite + * @param prop + * the config property + */ protected AbstractConfigPropertyWidget(Composite parent, ConfigProperty prop) { mParent = parent; mProp = prop; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetBoolean.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetBoolean.java index ef102516e..653b114a4 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetBoolean.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetBoolean.java @@ -49,6 +49,15 @@ private ConfigPropertyWidgetBoolean(Composite parent, ConfigProperty prop) { super(parent, prop); } + /** + * Creates a boolean widget for the given property. + * + * @param parent + * the parent composite + * @param prop + * the property + * @return the created widget + */ public static ConfigPropertyWidgetBoolean create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetBoolean(parent, prop); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFactory.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFactory.java index 62557a5fe..4ee05b048 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFactory.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFactory.java @@ -45,6 +45,9 @@ public final class ConfigPropertyWidgetFactory { ConfigPropertyWidgetFile::create, ConfigPropertyType.REGEX, ConfigPropertyWidgetRegex::create); + /** + * Creates the widget factory. + */ private ConfigPropertyWidgetFactory() { } @@ -76,6 +79,17 @@ public static IConfigPropertyWidget createWidget(Composite parent, ConfigPropert return widget; } + /** + * Returns the widget for the given configuration property type. + * + * @param parent + * the parent composite + * @param prop + * the property + * @param type + * the configuration property type + * @return the built widget + */ private static IConfigPropertyWidget getWidgetForConfigPropertyType(Composite parent, ConfigProperty prop, ConfigPropertyType type) { return REGISTRY.getOrDefault(type, ConfigPropertyWidgetString::create).create(parent, prop); @@ -86,6 +100,15 @@ private static IConfigPropertyWidget getWidgetForConfigPropertyType(Composite pa * */ public interface ConfigPropertyWidgetBuilder { + /** + * Creates a configuration property widget for the given property. + * + * @param parent + * the parent composite + * @param prop + * the property + * @return the created widget + */ IConfigPropertyWidget create(Composite parent, ConfigProperty prop); } } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFile.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFile.java index dcb4586f3..5f7919805 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFile.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetFile.java @@ -69,6 +69,15 @@ private ConfigPropertyWidgetFile(Composite parent, ConfigProperty prop) { super(parent, prop); } + /** + * Creates a file property widget. + * + * @param parent + * the parent composite + * @param prop + * the property + * @return the created widget + */ public static ConfigPropertyWidgetFile create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetFile(parent, prop); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetHidden.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetHidden.java index 11cf3fb1e..b5d70b2c8 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetHidden.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetHidden.java @@ -45,6 +45,15 @@ private ConfigPropertyWidgetHidden(Composite parent, ConfigProperty prop) { super(parent, prop); } + /** + * Creates a hidden property widget. + * + * @param parent + * the parent composite + * @param prop + * the property + * @return the created widget + */ public static ConfigPropertyWidgetHidden create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetHidden(parent, prop); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetInteger.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetInteger.java index 49a6c48ec..3566fa93b 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetInteger.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetInteger.java @@ -51,6 +51,15 @@ private ConfigPropertyWidgetInteger(Composite parent, ConfigProperty prop) { super(parent, prop); } + /** + * Creates a new integer property widget for the given property. + * + * @param parent + * the parent composite + * @param prop + * the configuration property + * @return the newly-created widget + */ public static ConfigPropertyWidgetInteger create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetInteger(parent, prop); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetMultiCheck.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetMultiCheck.java index d6f71b74b..d23526789 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetMultiCheck.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetMultiCheck.java @@ -89,6 +89,15 @@ private ConfigPropertyWidgetMultiCheck(Composite parent, ConfigProperty prop) { mTokens = new ArrayList<>(prop.getMetaData().getPropertyEnumeration()); } + /** + * Creates a multi check property widget. + * + * @param parent + * the parent composite + * @param prop + * the property + * @return the created widget + */ public static ConfigPropertyWidgetMultiCheck create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetMultiCheck(parent, prop); } @@ -141,6 +150,12 @@ public String getValue() { .collect(Collectors.joining(", ")); } + /** + * Installs or removes the sorter of the token table. + * + * @param sort + * true to sort the tokens, false otherwise + */ private void installSorter(boolean sort) { if (sort) { final Collator collator = Collator.getInstance(CheckstyleUIPlugin.getPlatformLocale()); @@ -174,6 +189,13 @@ public void restorePropertyDefault() { mTable.setCheckedElements(result.toArray()); } + /** + * Splits the given value into comma separated tokens. + * + * @param value + * the value to tokenize + * @return the list of tokens + */ private static List tokenize(String value) { final List result = new LinkedList<>(); final StringTokenizer tokenizer = new StringTokenizer(value, ","); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetRegex.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetRegex.java index d556194d8..f3ff5fa0f 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetRegex.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetRegex.java @@ -77,6 +77,15 @@ private ConfigPropertyWidgetRegex(Composite parent, ConfigProperty prop) { super(parent, prop); } + /** + * Creates a regex property widget. + * + * @param parent + * the parent composite + * @param prop + * the property + * @return the created widget + */ public static ConfigPropertyWidgetRegex create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetRegex(parent, prop); } @@ -154,6 +163,9 @@ public void validate() throws CheckstylePluginException { } } + /** + * Tests the regular expression against the test string and updates the background colors. + */ private void testRegex() { try { final Pattern pattern = Pattern.compile(mTextWidget.getText()); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetSingleSelect.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetSingleSelect.java index c4960f63f..76452e7a0 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetSingleSelect.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetSingleSelect.java @@ -52,6 +52,15 @@ private ConfigPropertyWidgetSingleSelect(Composite parent, ConfigProperty prop) super(parent, prop); } + /** + * Creates a single select property widget for the given parent and property. + * + * @param parent + * the parent composite + * @param prop + * the property to edit + * @return the created single select property widget + */ public static ConfigPropertyWidgetSingleSelect create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetSingleSelect(parent, prop); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetString.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetString.java index b1f1225b3..37aca0a20 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetString.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetString.java @@ -54,6 +54,15 @@ protected ConfigPropertyWidgetString(Composite parent, ConfigProperty prop) { super(parent, prop); } + /** + * Creates a new string property widget. + * + * @param parent + * the parent composite + * @param prop + * the property + * @return the created widget + */ public static ConfigPropertyWidgetString create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetString(parent, prop); } @@ -87,6 +96,13 @@ public String getValue() { return escape(result); } + /** + * Replaces escaped apostrophes with plain apostrophes for message properties. + * + * @param text + * the text to unescape + * @return the unescaped text + */ private String unescape(String text) { String escapedText = text; // custom messages use MessageFormat, single quote is escaped as 2 single quotes there @@ -96,6 +112,13 @@ private String unescape(String text) { return escapedText; } + /** + * Replaces plain apostrophes with escaped apostrophes for message properties. + * + * @param text + * the text to escape + * @return the escaped text + */ private String escape(String text) { String escapedText = text; if (XMLTags.MESSAGE_TAG.equals(getConfigProperty().getName())) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetStringArray.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetStringArray.java index 91bcf0998..9758f20df 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetStringArray.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/config/widgets/ConfigPropertyWidgetStringArray.java @@ -32,10 +32,27 @@ */ public final class ConfigPropertyWidgetStringArray extends ConfigPropertyWidgetString { + /** + * Constructor creating the string array property widget. + * + * @param parent + * the parent composite + * @param prop + * the configuration property + */ private ConfigPropertyWidgetStringArray(Composite parent, ConfigProperty prop) { super(parent, prop); } + /** + * Creates a new string array property widget for the given property. + * + * @param parent + * the parent composite + * @param prop + * the configuration property + * @return the newly-created widget + */ public static ConfigPropertyWidgetStringArray create(Composite parent, ConfigProperty prop) { return new ConfigPropertyWidgetStringArray(parent, prop); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java index 8f9987a40..79a2c8855 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePage.java @@ -228,6 +228,17 @@ public boolean performOk() { return true; } + /** + * Updates the boolean preference with the given selection. + * + * @param selection + * the new value of the preference + * @param preference + * the key of the preference to update + * @return true if the preference value changed, false otherwise + * @throws BackingStoreException + * if the preference could not be stored + */ private static boolean updateBooleanPreference(boolean selection, String preference) throws BackingStoreException { final boolean original = CheckstylePluginPrefs.getBoolean(preference); @@ -235,6 +246,19 @@ private static boolean updateBooleanPreference(boolean selection, String prefere return selection != original; } + /** + * Determines whether all projects need to be rebuilt after the preference change. + * + * @param includeRuleNamesHasChanged + * whether the {@code includeRuleNames} preference changed + * @param includeModuleIdHasChanged + * whether the {@code includeModuleId} preference changed + * @param limitMarkersHasChanged + * whether the {@code limitMarkers} preference changed + * @param markerLimitHasChanged + * whether the {@code markerLimit} preference changed + * @return true if any relevant preference changed or a full rebuild is required + */ private boolean needRebuildAllProjects(boolean includeRuleNamesHasChanged, boolean includeModuleIdHasChanged, boolean limitMarkersHasChanged, boolean markerLimitHasChanged) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageGeneralSettings.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageGeneralSettings.java index 4a073d602..ece445a10 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageGeneralSettings.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageGeneralSettings.java @@ -88,6 +88,16 @@ public final class CheckstylePreferencePageGeneralSettings extends Composite { /** The checkbox for running in background on full builds. */ private final Button mBackgroundFullBuild; + /** + * Creates the general settings section of the Checkstyle preference page. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param setRebuildAll + * the runnable to trigger a full rebuild + */ public CheckstylePreferencePageGeneralSettings(Composite parent, int style, Runnable setRebuildAll) { super(parent, style); @@ -153,6 +163,15 @@ public CheckstylePreferencePageGeneralSettings(Composite parent, int style, CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD)); } + /** + * Creates the rebuild section with the rebuild selection combo and the cache purge button. + * + * @param group + * the parent group + * @param setRebuildAll + * the runnable to trigger a full rebuild + * @return the rebuild preference combo + */ private static Combo createRebuildSection(Group group, Runnable setRebuildAll) { final Composite rebuildComposite = new Composite(group, SWT.NULL); GridLayoutFactory.swtDefaults().numColumns(REBUILD_SECTION_NUM_COLUMNS).margins(0, 0) @@ -187,6 +206,13 @@ private static Combo createRebuildSection(Group group, Runnable setRebuildAll) { return mRebuildIfNeeded; } + /** + * Creates the language selection combo. + * + * @param group + * the parent group + * @return the language selection combo + */ private static Combo createLanguageSetting(Group group) { final Composite langComposite = new Composite(group, SWT.NULL); RowLayoutFactory.fillDefaults().applyTo(langComposite); @@ -212,6 +238,17 @@ private static Combo createLanguageSetting(Group group) { return languageIf; } + /** + * Creates a checkbox with a rebuild note label. + * + * @param group + * the parent group + * @param text + * the checkbox label text + * @param selection + * the initial selection state + * @return the created checkbox button + */ private static Button makeCheckboxWithRebuildNoteLabel(Group group, String text, boolean selection) { final Composite composite = new Composite(group, SWT.NULL); @@ -221,6 +258,19 @@ private static Button makeCheckboxWithRebuildNoteLabel(Group group, String text, return button; } + /** + * Creates a button with the given label and selection state. + * + * @param parent + * the parent composite + * @param style + * the button style + * @param text + * the button label text + * @param selection + * the initial selection state + * @return the created button + */ private static Button makeButton(Composite parent, int style, String text, boolean selection) { final Button button = new Button(parent, style); button.setText(text); @@ -228,6 +278,12 @@ private static Button makeButton(Composite parent, int style, String text, boole return button; } + /** + * Adds a label with a rebuild hint tooltip to the given parent. + * + * @param parent + * the parent composite + */ private static void addRebuildNoteLabel(Composite parent) { final Label lblRebuildNote = new Label(parent, SWT.NULL); lblRebuildNote.setImage(CheckstyleUIPluginImages.HELP_ICON.getImage()); @@ -235,34 +291,74 @@ private static void addRebuildNoteLabel(Composite parent) { SWTUtil.addTooltipOnPressSupport(lblRebuildNote); } + /** + * Returns the selected language. + * + * @return the selected language + */ public String getLanguageIf() { return SUPPORTED_LANGUAGES.get(languageIf.getSelectionIndex()); } + /** + * Returns the selected rebuild preference. + * + * @return the selected rebuild preference + */ public String getRebuildIfNeeded() { return mRebuildIfNeeded.getItem(mRebuildIfNeeded.getSelectionIndex()); } + /** + * Returns whether to warn before losing filesets. + * + * @return true if the warning is enabled, false otherwise + */ public boolean getWarnBeforeLosingFilesets() { return mWarnBeforeLosingFilesets.getSelection(); } + /** + * Returns whether rule names are included in the report. + * + * @return true if rule names are included, false otherwise + */ public boolean getIncludeRuleNames() { return mIncludeRuleNamesButton.getSelection(); } + /** + * Returns whether module IDs are included in the report. + * + * @return true if module IDs are included, false otherwise + */ public boolean getIncludeModuleIdButton() { return mIncludeModuleIdButton.getSelection(); } + /** + * Returns whether the number of Checkstyle markers is limited. + * + * @return true if markers are limited, false otherwise + */ public boolean getLimitCheckstyleMarkers() { return mLimitCheckstyleMarkers.getSelection(); } + /** + * Returns the configured marker limit. + * + * @return the marker limit as text + */ public String getTxtMarkerLimit() { return mTxtMarkerLimit.getText(); } + /** + * Returns whether Checkstyle runs in the background on full builds. + * + * @return true if Checkstyle runs in the background, false otherwise + */ public boolean getBackgroundFullBuild() { return mBackgroundFullBuild.getSelection(); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageHeader.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageHeader.java index 2f5265ef9..31eac1371 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageHeader.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/preferences/CheckstylePreferencePageHeader.java @@ -42,6 +42,14 @@ public class CheckstylePreferencePageHeader extends Composite { private static final String CHECKSTYLE_VERSION = Main.class.getPackage().getImplementationVersion(); + /** + * Creates the preference page header. + * + * @param parent + * the parent composite + * @param style + * the widget style + */ public CheckstylePreferencePageHeader(Composite parent, int style) { super(parent, style); RowLayoutFactory.fillDefaults().applyTo(this); @@ -54,6 +62,12 @@ public CheckstylePreferencePageHeader(Composite parent, int style) { link.addListener(SWT.Selection, this::linkClicked); } + /** + * Handles the selection of a link. + * + * @param event + * the selection event + */ private void linkClicked(Event event) { String url = "https://checkstyle.org"; if (Character.isDigit(event.text.charAt(0))) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckConfigurationContentProvider.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckConfigurationContentProvider.java index 44fe6a24d..55d6b9916 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckConfigurationContentProvider.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckConfigurationContentProvider.java @@ -41,6 +41,9 @@ public final class CheckConfigurationContentProvider implements IStructuredConte public static final CheckConfigurationContentProvider INSTANCE = new CheckConfigurationContentProvider(); + /** + * Utility class, cannot be instantiated. + */ private CheckConfigurationContentProvider() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyApplyOperation.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyApplyOperation.java index 30e53e283..05b1766b9 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyApplyOperation.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyApplyOperation.java @@ -44,10 +44,26 @@ */ public final class CheckstylePropertyApplyOperation { + /** + * Private constructor to prevent instantiation. + */ private CheckstylePropertyApplyOperation() { } + /** + * Applies the changes made in the Checkstyle project property page. + * + * @param shell + * the shell for error dialogs + * @param projectConfig + * the project configuration to apply + * @param checkstyleEnabled + * whether Checkstyle is enabled + * @param checkstyleInitiallyEnabled + * whether Checkstyle was initially enabled + * @return true if the changes were applied + */ public static boolean apply(Shell shell, ProjectConfigurationWorkingCopy projectConfig, boolean checkstyleEnabled, boolean checkstyleInitiallyEnabled) { try { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java index bc5bbb52b..3aedf08e2 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPage.java @@ -102,6 +102,15 @@ public void setElement(IAdaptable element) { } } + /** + * Handles an error that occurred while opening the project configuration by logging it and + * resetting to a default configuration. + * + * @param error + * the error that occurred + * @param project + * the project being edited + */ private void handleConfigFileError(Exception error, IProject project) { CheckstyleLog.log(error, Messages.errorOpeningPropertiesPage); @@ -190,6 +199,16 @@ public boolean performOk() { */ private static final class LocalConfig extends Composite { + /** + * Creates the local configurations composite. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits + * @param workingSet + * the working set of local check configurations + */ private LocalConfig(Composite parent, int style, ICheckConfigurationWorkingSet workingSet) { super(parent, style); setLayout(new FillLayout()); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPageMainTab.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPageMainTab.java index b055ed7ae..77a0c9e2c 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPageMainTab.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/CheckstylePropertyPageMainTab.java @@ -57,6 +57,18 @@ public final class CheckstylePropertyPageMainTab extends Composite { /** The file sets editor. */ private IFileSetsEditor mFileSetsEditor; + /** + * Creates the main tab of the checkstyle property page. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param propertyPageContext + * the property page context + * @param mCheckstyleInitiallyActivated + * whether checkstyle is initially activated + */ public CheckstylePropertyPageMainTab(Composite parent, int style, PropertyPageContext propertyPageContext, boolean mCheckstyleInitiallyActivated) { super(parent, style); @@ -98,10 +110,18 @@ public CheckstylePropertyPageMainTab(Composite parent, int style, GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(filterArea); } + /** + * Returns whether checkstyle is enabled on the property page. + * + * @return whether checkstyle is enabled + */ public boolean isCheckstyleEnabled() { return mChkEnable.getSelection(); } + /** + * Refreshes the file sets editor. + */ public void refreshFileSetEditor() { mFileSetsEditor.refresh(); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java index b65c592f3..c121d1840 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditor.java @@ -91,6 +91,9 @@ public void refresh() { // NOOP } + /** + * Opens a dialog to create a new file set and adds it to the list. + */ private void addFileSet() { try { final FileSetEditDialog dialog = @@ -110,6 +113,12 @@ private void addFileSet() { } } + /** + * Opens a dialog to edit the given file set and updates it in the list. + * + * @param fileSet + * the file set to edit + */ private void editFileSet(FileSet fileSet) { if (fileSet != null) { try { @@ -132,6 +141,12 @@ private void editFileSet(FileSet fileSet) { } } + /** + * Removes the given file set from the list. + * + * @param fileSet + * the file set to remove + */ private void removeFileSet(FileSet fileSet) { if (fileSet != null) { mFileSets.remove(fileSet); @@ -140,6 +155,12 @@ private void removeFileSet(FileSet fileSet) { } } + /** + * Updates the enabled state of the file set whose checked state changed. + * + * @param event + * the check state change event + */ private void changeEnabledState(CheckStateChangedEvent event) { if (event.getElement() instanceof FileSet) { final FileSet fileSet = (FileSet) event.getElement(); @@ -157,6 +178,9 @@ public static final class FileSetLabelProvider extends LabelProvider /** The singleton instance. */ public static final FileSetLabelProvider INSTANCE = new FileSetLabelProvider(); + /** + * Creates the singleton file set label provider. + */ private FileSetLabelProvider() { } @@ -202,6 +226,9 @@ public static final class FileSetViewerSorter extends ViewerComparator { /** The singleton instance. */ public static final FileSetViewerSorter INSTANCE = new FileSetViewerSorter(); + /** + * Creates the singleton file set viewer sorter. + */ private FileSetViewerSorter() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorTableView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorTableView.java index f9bc6694b..96d4f374c 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorTableView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorTableView.java @@ -50,6 +50,20 @@ public final class ComplexFileSetsEditorTableView extends Composite { /** The checkbox table viewer. */ private final CheckboxTableViewer mViewer; + /** + * Creates the checkbox table view of file sets. + * + * @param parent + * the parent composite + * @param style + * the style of the composite + * @param changeEnabledState + * the listener for checkbox state changes + * @param editFileSet + * the callback for editing a file set + * @param mFileSets + * the file sets to display + */ public ComplexFileSetsEditorTableView(Composite parent, int style, ICheckStateListener changeEnabledState, Consumer editFileSet, List mFileSets) { @@ -70,18 +84,41 @@ public ComplexFileSetsEditorTableView(Composite parent, int style, mViewer.addCheckStateListener(changeEnabledState); } + /** + * Refreshes the table viewer. + */ public void refresh() { mViewer.refresh(); } + /** + * Sets the checked state of the given file set. + * + * @param fileSet + * the file set to change + * @param enabled + * the enabled state to set + */ public void setChecked(FileSet fileSet, boolean enabled) { mViewer.setChecked(fileSet, enabled); } + /** + * Returns the currently selected file set. + * + * @return the selected file set + */ public FileSet getSelectedFileSet() { return (FileSet) mViewer.getStructuredSelection().getFirstElement(); } + /** + * Creates the table for the file set viewer. + * + * @param parent + * the parent composite + * @return the created table + */ private static Table createTable(Composite parent) { final Table table = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION); GridDataFactory.create(GridData.FILL_BOTH).applyTo(table); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorView.java index 0b0713bc0..79f0f64e3 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/ComplexFileSetsEditorView.java @@ -46,6 +46,24 @@ public final class ComplexFileSetsEditorView extends Composite { /** The table viewer for file sets. */ private final ComplexFileSetsEditorTableView mViewer; + /** + * Creates the file sets editor view. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param changeEnabledState + * the listener notified when the enabled state of a file set changes + * @param editFileSet + * the consumer invoked to edit a file set + * @param addFileSet + * the runnable invoked to add a file set + * @param removeFileSet + * the consumer invoked to remove a file set + * @param mFileSets + * the list of file sets to display + */ public ComplexFileSetsEditorView(Composite parent, int style, ICheckStateListener changeEnabledState, Consumer editFileSet, Runnable addFileSet, Consumer removeFileSet, List mFileSets) { @@ -81,14 +99,34 @@ public ComplexFileSetsEditorView(Composite parent, int style, event -> removeFileSet.accept(mViewer.getSelectedFileSet())); } + /** + * Refreshes the file sets table. + */ public void refresh() { mViewer.refresh(); } + /** + * Sets the checked state of the given file set. + * + * @param fileSet + * the file set to check + * @param enabled + * true if the file set is enabled, false otherwise + */ public void setChecked(FileSet fileSet, boolean enabled) { mViewer.setChecked(fileSet, enabled); } + /** + * Creates a push button with the given label. + * + * @param parent + * the parent composite + * @param label + * the button label + * @return the created button + */ private static Button createPushButton(Composite parent, String label) { final Button button = new Button(parent, SWT.PUSH); button.setText(label); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternControl.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternControl.java index 0d0ab073c..978388977 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternControl.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternControl.java @@ -44,6 +44,17 @@ public final class FileMatchPatternControl extends Composite { /** The file match pattern table. */ private final FileMatchPatternTable table; + /** + * Constructor building the group with the file match pattern table and the buttons to edit + * them. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits to apply to this composite + * @param callbacks + * the callbacks invoked on user actions + */ public FileMatchPatternControl(Composite parent, int style, FileMatchPatternControlCallbacks callbacks) { super(parent, style); @@ -72,16 +83,33 @@ public FileMatchPatternControl(Composite parent, int style, toRunnable(callbacks.downFileMatchPattern)); } + /** + * Wraps the given callback into a runnable that consumes the currently selected file match + * pattern. + * + * @param callback + * the callback to wrap + * @return a runnable performing the callback with the selected pattern + */ private Runnable toRunnable(Consumer callback) { return () -> { callback.accept(table.getSelectedPattern()); }; } + /** + * Refreshes the file match pattern table. + */ public void refresh() { table.refresh(); } + /** + * Sets the file match patterns to be shown in the table. + * + * @param fileMatchPatterns + * the file match patterns to show + */ public void setInput(List fileMatchPatterns) { table.setInput(fileMatchPatterns); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java index dbdda9cc2..c528be6af 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileMatchPatternTable.java @@ -50,6 +50,16 @@ public final class FileMatchPatternTable extends Composite { /** The checkbox table viewer for patterns. */ private final CheckboxTableViewer mPatternViewer; + /** + * Creates the file match pattern table. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits + * @param callbacks + * the callbacks used to interact with the table + */ public FileMatchPatternTable(Composite parent, int style, FileMatchPatternControlCallbacks callbacks) { super(parent, style); @@ -78,18 +88,39 @@ public FileMatchPatternTable(Composite parent, int style, mPatternViewer.setCheckStateProvider(FileMatchPatternTableCheckStateProvider.INSTANCE); } + /** + * Returns the file match pattern currently selected in the table. + * + * @return the selected file match pattern + */ public FileMatchPattern getSelectedPattern() { return (FileMatchPattern) mPatternViewer.getStructuredSelection().getFirstElement(); } + /** + * Refreshes the displayed file match patterns. + */ public void refresh() { mPatternViewer.refresh(); } + /** + * Sets the file match patterns to be shown in the table. + * + * @param fileMatchPatterns + * the file match patterns to display + */ public void setInput(List fileMatchPatterns) { mPatternViewer.setInput(fileMatchPatterns); } + /** + * Creates the table widget used to display the file match patterns. + * + * @param parent + * the parent composite + * @return the created table + */ private static Table createTable(Composite parent) { final Table table = new Table(parent, SWT.CHECK | SWT.BORDER | SWT.FULL_SELECTION); table.setHeaderVisible(true); @@ -147,6 +178,9 @@ private static final class FileMatchPatternTableCheckStateProvider private static final FileMatchPatternTableCheckStateProvider INSTANCE = new FileMatchPatternTableCheckStateProvider(); + /** + * Hidden constructor of the singleton instance. + */ private FileMatchPatternTableCheckStateProvider() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java index 59dcc6b61..2271923d9 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialog.java @@ -198,6 +198,9 @@ protected void okPressed() { } } + /** + * Opens a dialog to create a new file match pattern and adds it to the file set. + */ private void addFileMatchPattern() { final FileMatchPatternEditDialog dialog = new FileMatchPatternEditDialog(getShell(), null); if (Window.OK == dialog.open()) { @@ -209,6 +212,12 @@ private void addFileMatchPattern() { } } + /** + * Opens a dialog to edit the given file match pattern and replaces it in the file set. + * + * @param pattern + * the file match pattern to edit + */ private void editFileMatchPattern(FileMatchPattern pattern) { if (pattern != null) { final FileMatchPatternEditDialog dialog = @@ -224,6 +233,12 @@ private void editFileMatchPattern(FileMatchPattern pattern) { } } + /** + * Removes the given file match pattern from the file set. + * + * @param pattern + * the file match pattern to remove + */ private void removeFileMatchPattern(FileMatchPattern pattern) { if (pattern != null) { mFileSet.getFileMatchPatterns().remove(pattern); @@ -231,6 +246,12 @@ private void removeFileMatchPattern(FileMatchPattern pattern) { } } + /** + * Moves the given file match pattern one position up in the file set. + * + * @param pattern + * the file match pattern to move up + */ private void upFileMatchPattern(FileMatchPattern pattern) { if (pattern != null) { final int index = mFileSet.getFileMatchPatterns().indexOf(pattern); @@ -242,6 +263,12 @@ private void upFileMatchPattern(FileMatchPattern pattern) { } } + /** + * Moves the given file match pattern one position down in the file set. + * + * @param pattern + * the file match pattern to move down + */ private void downFileMatchPattern(FileMatchPattern pattern) { if (pattern != null) { final int index = mFileSet.getFileMatchPatterns().indexOf(pattern); @@ -259,10 +286,16 @@ private void downFileMatchPattern(FileMatchPattern pattern) { } } + /** + * Refreshes the match area displaying the files matched by the current patterns. + */ private void refreshMatchArea() { dialogView.refreshMatchArea(); } + /** + * Opens a dialog to configure the check configuration of the file set. + */ private void configureFileSetConfig() { final CheckConfigurationWorkingCopy config = (CheckConfigurationWorkingCopy) mFileSet.getCheckConfig(); @@ -285,6 +318,15 @@ private void configureFileSetConfig() { } } + /** + * Recursively collects all files contained in the given container. + * + * @param container + * the container to collect files from + * @return the list of files found in the container + * @throws CoreException + * an error occurred while accessing the container members + */ private static List getFiles(IContainer container) throws CoreException { final LinkedList files = new LinkedList<>(); final LinkedList folders = new LinkedList<>(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogCommonArea.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogCommonArea.java index cd4f24a56..20bd26cbb 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogCommonArea.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogCommonArea.java @@ -53,6 +53,18 @@ public final class FileSetEditDialogCommonArea extends Composite { /** The combo viewer for check configuration selection. */ private final ComboViewer mComboViewer; + /** + * Creates the common area of the file set edit dialog. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param selectionChanged + * the consumer invoked when the check configuration selection changes + * @param configureFileSetConfig + * the runnable to configure the file set configuration + */ public FileSetEditDialogCommonArea(Composite parent, int style, Consumer selectionChanged, Runnable configureFileSetConfig) { super(parent, style); @@ -89,18 +101,41 @@ public FileSetEditDialogCommonArea(Composite parent, int style, GridDataFactory.swtDefaults().applyTo(mConfigureButton); } + /** + * Returns the file set name entered in the text field. + * + * @return the file set name + */ public String getText() { return this.mFileSetNameText.getText(); } + /** + * Sets the input for the check configuration combo viewer. + * + * @param configuration + * the project configuration working copy + */ public void setInput(ProjectConfigurationWorkingCopy configuration) { this.mComboViewer.setInput(configuration); } + /** + * Sets the text of the file set name text field. + * + * @param text + * the file set name + */ public void setText(String text) { this.mFileSetNameText.setText(text); } + /** + * Selects the given check configuration in the combo viewer. + * + * @param iCheckConfiguration + * the check configuration to select + */ public void setSelection(ICheckConfiguration iCheckConfiguration) { this.mComboViewer.setSelection(new StructuredSelection(iCheckConfiguration)); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogMatchedFilesPreview.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogMatchedFilesPreview.java index 23b17e3e2..19071f963 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogMatchedFilesPreview.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogMatchedFilesPreview.java @@ -58,6 +58,18 @@ public final class FileSetEditDialogMatchedFilesPreview extends Composite { /** The total number of project files. */ private int totalFileCount; + /** + * Creates the matched files preview composite. + * + * @param parent + * the parent composite + * @param style + * the style bits + * @param viewerFilter + * the filter selecting the files matched by the file set + * @param projectName + * the name of the project whose files are previewed + */ public FileSetEditDialogMatchedFilesPreview(Composite parent, int style, ViewerFilter viewerFilter, String projectName) { super(parent, style); @@ -93,14 +105,22 @@ public Image getImage(Object element) { matchesViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH)); } + /** + * Refreshes the preview and updates the match result summary. + */ public void refresh() { - matchesViewer.refresh(); matchGroup.setText(NLS.bind(Messages.FileSetEditDialog_titleTestResult, new String[] { projectName, Integer.toString(matchesViewer.getTable().getItemCount()), Integer.toString(totalFileCount), })); } + /** + * Sets the project files to be previewed and records the total file count. + * + * @param projectFiles + * the project files to display in the preview + */ public void setInput(List projectFiles) { matchesViewer.setInput(projectFiles); totalFileCount = projectFiles.size(); @@ -115,6 +135,12 @@ public static class FileSetEditDialogMatchedFilesPreviewFilter extends ViewerFil /** The file set to preview. */ private final FileSet fileSet; + /** + * Creates the preview filter for the given file set. + * + * @param fileSet + * the file set whose matches are previewed + */ public FileSetEditDialogMatchedFilesPreviewFilter(FileSet fileSet) { this.fileSet = fileSet; } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogView.java index 33eb4759e..da6625d9d 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetEditDialogView.java @@ -51,6 +51,25 @@ public final class FileSetEditDialogView extends Composite { /** The matched files preview area. */ private final FileSetEditDialogMatchedFilesPreview matchArea; + /** + * Constructor building the file set edit dialog view, laying out the common area, the file + * match pattern editor and the matched files preview. + * + * @param parent + * the parent composite + * @param style + * the SWT style bits to apply to this composite + * @param fileMatchPatternTableCallbacks + * the callbacks for the file match pattern table + * @param previewFilter + * the filter used by the matched files preview + * @param projectName + * the name of the project + * @param checkConfigSelectionChanged + * the callback invoked when the check config selection changes + * @param configureFileSetConfig + * the callback invoked to configure the file set config + */ public FileSetEditDialogView(Composite parent, int style, FileMatchPatternControlCallbacks fileMatchPatternTableCallbacks, FileSetEditDialogMatchedFilesPreviewFilter previewFilter, String projectName, @@ -80,23 +99,48 @@ public FileSetEditDialogView(Composite parent, int style, }); } + /** + * Refreshes the matched files preview area. + */ public void refreshMatchArea() { matchArea.refresh(); } + /** + * Sets the project files to be shown in the matched files preview. + * + * @param projectFiles + * the project files to show + */ public void setProjectFiles(List projectFiles) { matchArea.setInput(projectFiles); } + /** + * Refreshes the file match pattern table and the matched files preview. + */ public void refreshFileMatchPatternTable() { fileMatchPatternTable.refresh(); matchArea.refresh(); } + /** + * Sets the project configuration to be shown in the common area. + * + * @param configuration + * the project configuration to show + */ public void setProjectConfiguration(ProjectConfigurationWorkingCopy configuration) { commonArea.setInput(configuration); } + /** + * Sets the given file set, initializing the name, the check configuration selection and the + * file match patterns. + * + * @param fileSet + * the file set to display + */ public void setFileSet(FileSet fileSet) { // intitialize the name final String name; @@ -117,6 +161,11 @@ public void setFileSet(FileSet fileSet) { fileMatchPatternTable.setInput(fileSet.getFileMatchPatterns()); } + /** + * Returns the file set name entered in the common area. + * + * @return the file set name + */ public String getFileSetName() { return commonArea.getText(); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetsEditorFactory.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetsEditorFactory.java index 86a427636..454b4b7aa 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetsEditorFactory.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FileSetsEditorFactory.java @@ -28,10 +28,24 @@ */ public final class FileSetsEditorFactory { + /** + * Creates the factory. Private to prevent instantiation. + */ private FileSetsEditorFactory() { } + /** + * Creates the file sets editor matching the given configuration mode. + * + * @param shell + * the parent shell + * @param propertyPageContext + * the property page context + * @param useSimpleConfig + * whether to use the simple configuration mode + * @return the created file sets editor + */ public static IFileSetsEditor createEditor(Shell shell, PropertyPageContext propertyPageContext, boolean useSimpleConfig) { final IFileSetsEditor editor; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FilterSettings.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FilterSettings.java index 89ccbd0f9..adb51e854 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FilterSettings.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/FilterSettings.java @@ -58,6 +58,20 @@ public class FilterSettings extends Composite { /** Height in pixels of the filter list. */ private static final int FILTER_LIST_HEIGHT = 100; + /** + * Creates the filter settings composite. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param project + * the project + * @param filters + * the filters to configure + * @param markDirty + * callback to mark the property page as dirty + */ public FilterSettings(Composite parent, int style, IProject project, List filters, Runnable markDirty) { super(parent, style); @@ -104,6 +118,15 @@ public FilterSettings(Composite parent, int style, IProject project, List mParts; + /** + * Creates the job for the given opened parts. + * + * @param parts + * the opened workbench parts + */ PartsOpenedJob(Collection parts) { super(Messages.PartsOpenedJob_title); this.mParts = parts; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/filter/PackageFilterEditor.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/filter/PackageFilterEditor.java index 690fe04f8..cc882d6bf 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/filter/PackageFilterEditor.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/filter/PackageFilterEditor.java @@ -207,6 +207,13 @@ else if (parentElement instanceof IContainer) { return children.toArray(); } + /** + * Returns the immediate children of the given project. + * + * @param project + * the project + * @return the children of the project + */ private List handleProject(IProject project) { final List children = new ArrayList<>(); if (project.isAccessible()) { @@ -241,6 +248,13 @@ else if (!packageRoot.isArchive() return children; } + /** + * Returns the immediate children of the given container. + * + * @param container + * the container + * @return the children of the container + */ private List handleContainer(IContainer container) { final List children = new ArrayList<>(); if (container.isAccessible()) { @@ -421,6 +435,9 @@ public void widgetDefaultSelected(SelectionEvent e) { return composite; } + /** + * Adapts the checked state of the elements to the recursive exclude mode. + */ private void adaptRecurseBehaviour() { if (isRecursivelyExcludeSubTree()) { @@ -438,12 +455,27 @@ private void adaptRecurseBehaviour() { } } + /** + * Returns whether the given element is grayed. + * + * @param element + * the element + * @return whether the element is grayed + */ private boolean isGrayed(Object element) { final Object[] grayed = mViewer.getGrayedElements(); return Arrays.asList(grayed).contains(element); } + /** + * Gray checks the sub containers of the given container. + * + * @param container + * the container + * @param checked + * whether the sub elements should be checked + */ private void setSubElementsGrayedChecked(final IContainer container, final boolean checked) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/marker/MarkerPropertyPage.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/marker/MarkerPropertyPage.java index 0223730e0..72801b72e 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/marker/MarkerPropertyPage.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/properties/marker/MarkerPropertyPage.java @@ -54,6 +54,11 @@ public class MarkerPropertyPage extends PropertyPage { /** Message and description width in pixels. */ private static final int WIDTH = 300; + /** + * Returns the marker this property page is showing. + * + * @return the issue marker + */ private IMarker getIssue() { return (IMarker) getElement(); } @@ -78,6 +83,14 @@ protected Control createContents(Composite parent) { return composite; } + /** + * Creates the row showing the marker severity. + * + * @param composite + * the parent composite + * @throws CoreException + * if the marker attribute cannot be read + */ private void createSeverityText(final Composite composite) throws CoreException { new Label(composite, SWT.NONE) .setImage(getSeverityImage(getIssue().getAttribute(IMarker.SEVERITY, -1))); @@ -88,6 +101,15 @@ private void createSeverityText(final Composite composite) throws CoreException GridDataFactory.fillDefaults().hint(WIDTH, SWT.DEFAULT).applyTo(labelMessage); } + /** + * Creates the row showing the marker group. + * + * @param composite + * the parent composite + * @return the rule identity of the marker's module + * @throws CoreException + * if the marker attribute cannot be read + */ private RuleIdentity createGroupText(final Composite composite) throws CoreException { new Label(composite, SWT.NONE) .setImage(CheckstyleUIPluginImages.MODULEGROUP_ICON.getImage()); @@ -100,6 +122,14 @@ private RuleIdentity createGroupText(final Composite composite) throws CoreExcep return ruleIdentity; } + /** + * Creates the row showing the marker rule name. + * + * @param composite + * the parent composite + * @param ruleIdentity + * the rule identity to display + */ private void createRuleText(final Composite composite, RuleIdentity ruleIdentity) { new Label(composite, SWT.NONE).setImage(CheckstyleUIPluginImages.MODULE_ICON.getImage()); new Label(composite, SWT.NONE).setText(Messages.MarkerPropertyPage_Module); @@ -108,6 +138,12 @@ private void createRuleText(final Composite composite, RuleIdentity ruleIdentity labelRuleName.setText(ruleIdentity.ruleName()); } + /** + * Creates the row showing the marker id if present. + * + * @param composite + * the parent composite + */ private void createIdText(final Composite composite) { final var id = getIssue().getAttribute(CheckstyleMarker.MODULE_ID, null); if (!StringUtils.isEmpty(id)) { @@ -120,6 +156,14 @@ private void createIdText(final Composite composite) { } } + /** + * Creates the row showing the marker description. + * + * @param composite + * the parent composite + * @param ruleIdentity + * the rule identity to display the description of + */ private void createDescriptionText(final Composite composite, RuleIdentity ruleIdentity) { final Label descriptionLabel = new Label(composite, SWT.NONE); descriptionLabel.setText(Messages.MarkerPropertyPage_Description); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/AstQuickfixExecutor.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/AstQuickfixExecutor.java index c1391fe23..f61aaf58c 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/AstQuickfixExecutor.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/AstQuickfixExecutor.java @@ -60,10 +60,22 @@ */ public final class AstQuickfixExecutor { + /** + * Hidden constructor of the utility class. + */ private AstQuickfixExecutor() { } + /** + * Applies the correcting AST visitor of the quickfix to the compilation unit of the given + * problem marker and writes the changes back to the document. + * + * @param marker + * the problem marker to handle + * @param handleGetCorrectingASTVisitor + * function creating the correcting AST visitor for a line and offset + */ public static void run(IMarker marker, BiFunction handleGetCorrectingASTVisitor) { if (marker.getResource() instanceof IFile) { @@ -119,6 +131,13 @@ public static void run(IMarker marker, } } + /** + * Returns the compilation unit that owns the resource of the given marker. + * + * @param marker + * the problem marker + * @return the compilation unit or {@code null} if not resolvable + */ private static ICompilationUnit getCompilationUnit(IMarker marker) { ICompilationUnit compilationUnit = null; if (marker.getResource() instanceof IFile file && file.isAccessible() @@ -128,12 +147,31 @@ private static ICompilationUnit getCompilationUnit(IMarker marker) { return compilationUnit; } + /** + * Returns the character offset of the given marker within the text file buffer. + * + * @param textFileBuffer + * the text file buffer of the edited file + * @param marker + * the problem marker + * @return the offset of the marker or an empty optional if not found + */ private static Optional getOffset(ITextFileBuffer textFileBuffer, IMarker marker) { final IAnnotationModel annotationModel = textFileBuffer.getAnnotationModel(); return getMarkerAnnotation(annotationModel, marker).map(annotationModel::getPosition) .map(Position::getOffset); } + /** + * Finds the marker annotation corresponding to the given problem marker in the annotation + * model. + * + * @param annotationModel + * the annotation model to search + * @param marker + * the problem marker + * @return the marker annotation or an empty optional if not found + */ private static Optional getMarkerAnnotation(IAnnotationModel annotationModel, IMarker marker) { Optional result = Optional.empty(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java index 8921b1e7d..02691ff9a 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/CheckstyleQuickfixes.java @@ -56,10 +56,18 @@ public final class CheckstyleQuickfixes { /** The registered quickfixes. */ private final Collection quickfixes; + /** + * Constructor reading the registered quickfixes from the registry. + */ private CheckstyleQuickfixes() { quickfixes = readRegistry(); } + /** + * Returns the singleton instance of the registered quickfixes. + * + * @return the quickfixes instance + */ public static CheckstyleQuickfixes getInstance() { return LazyHolder.INSTANCE; } @@ -97,6 +105,13 @@ private Collection readRegistry() { return result; } + /** + * Instantiates the quickfix class registered for the given configuration element. + * + * @param element + * the configuration element describing the quickfix + * @return the quickfix resolution, or null if it could not be created + */ private ICheckstyleMarkerResolution toClass(IConfigurationElement element) { ICheckstyleMarkerResolution resolution = null; try { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/FixCheckstyleMarkersHandler.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/FixCheckstyleMarkersHandler.java index d3a5934b3..ecdd49ccf 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/FixCheckstyleMarkersHandler.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/FixCheckstyleMarkersHandler.java @@ -57,6 +57,11 @@ public Object execute(ExecutionEvent arg0) throws ExecutionException { return null; } + /** + * Returns the active text editor or null if none is active. + * + * @return the active text editor + */ private ITextEditor getActiveEditor() { ITextEditor activeEditor = null; final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/MarkerHelpContextProvider.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/MarkerHelpContextProvider.java index d21e3dd73..20b8f994b 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/MarkerHelpContextProvider.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/MarkerHelpContextProvider.java @@ -61,6 +61,13 @@ public String getHelpContextForMarker(IMarker marker) { return helpContext; } + /** + * Returns the module name stored in the given marker. + * + * @param marker + * the checkstyle marker + * @return the module name + */ private String getModule(IMarker marker) { return marker.getAttribute(CheckstyleMarker.MODULE_NAME, StringUtils.EMPTY); } @@ -142,6 +149,12 @@ private static final class CheckstyleHelpContext implements IContext { /** The module name. */ private final String moduleName; + /** + * Creates a help context for the given module name. + * + * @param moduleName + * the module name + */ private CheckstyleHelpContext(String moduleName) { this.moduleName = moduleName; } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/Messages.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/Messages.java index bc0573cc0..df9e92348 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/Messages.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/Messages.java @@ -113,6 +113,9 @@ public final class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + /** + * Private constructor to prevent instantiation. + */ private Messages() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java index d14b842ea..f822d98af 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/AvoidNestedBlocksQuickfix.java @@ -70,6 +70,12 @@ private final class AvoidNestedBlocksQuickfixAstVisitor extends ASTVisitor { /** The line info region. */ private final IRegion lineInfo; + /** + * Creates the AST visitor for the given line info. + * + * @param lineInfo + * the line info region + */ private AvoidNestedBlocksQuickfixAstVisitor(IRegion lineInfo) { this.lineInfo = lineInfo; } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/NeedBracesQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/NeedBracesQuickfix.java index cb1a2755a..58a16a6ef 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/NeedBracesQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/blocks/NeedBracesQuickfix.java @@ -72,6 +72,12 @@ private final class NeedBracesQuickfixAstVisitor extends ASTVisitor { /** The line info region. */ private final IRegion lineInfo; + /** + * Constructor storing the line info region. + * + * @param lineInfo + * the line info region + */ private NeedBracesQuickfixAstVisitor(IRegion lineInfo) { this.lineInfo = lineInfo; } @@ -161,6 +167,15 @@ private void bracifyIfStatement(IfStatement ifStatement) { } } + /** + * Creates a new block containing a copy of the given body statement. + * + * @param ast + * the AST used to create the block + * @param body + * the statement to copy into the block + * @return the bracified block + */ @SuppressWarnings("unchecked") private Block createBracifiedCopy(AST ast, Statement body) { final Block block = ast.newBlock(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/DefaultComesLastQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/DefaultComesLastQuickfix.java index bd0b8b415..98704749f 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/DefaultComesLastQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/DefaultComesLastQuickfix.java @@ -55,6 +55,13 @@ public boolean visit(SwitchCase node) { }; } + /** + * Moves the default case of the given switch case node, along with its statements, to the end + * of the switch statement. + * + * @param node + * the default switch case node to move + */ @SuppressWarnings("unchecked") private static void visitSwitchCase(SwitchCase node) { if (node.isDefault() && !isLastSwitchCase(node)) { @@ -83,6 +90,13 @@ private static void visitSwitchCase(SwitchCase node) { } } + /** + * Determines whether the given switch case is the last case of its switch statement. + * + * @param switchCase + * the switch case to test + * @return true if the case is the last one, false otherwise + */ private static boolean isLastSwitchCase(SwitchCase switchCase) { boolean isLastSwitchCase = true; final SwitchStatement switchStatement = (SwitchStatement) switchCase.getParent(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java index 9611bd5c5..e24909c4e 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/ExplicitInitializationQuickfix.java @@ -58,6 +58,12 @@ public boolean canFix(final IMarker marker) { return fixed; } + /** + * Retrieves the field name from the marker. + * + * @param marker + * the marker + */ private void retrieveFieldName(final IMarker marker) { try { final Map attributes = marker.getAttributes(); @@ -78,6 +84,12 @@ private void retrieveFieldName(final IMarker marker) { } } + /** + * Logs an error that occurred while retrieving the field name. + * + * @param error + * the exception + */ private void handleRetrieveFieldNameException(final Exception error) { CheckstyleLog.log(error, Messages.ExplicitInitializationQuickfix_errorMessageFieldName); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/FinalLocalVariableQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/FinalLocalVariableQuickfix.java index 2e8f0f8e3..06d713f61 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/FinalLocalVariableQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/FinalLocalVariableQuickfix.java @@ -71,6 +71,12 @@ private final class FinalLocalVariableQuickfixAstVisitor extends ASTVisitor { /** The actual offset where the problem marker starts. */ private final int markerStartOffset; + /** + * Creates the AST visitor for the given marker offset. + * + * @param markerStartOffset + * the offset where the problem marker starts + */ private FinalLocalVariableQuickfixAstVisitor(int markerStartOffset) { this.markerStartOffset = markerStartOffset; } @@ -87,6 +93,17 @@ public boolean visit(VariableDeclarationStatement node) { return visit(node, node.getModifiers(), node.modifiers()); } + /** + * Adds the final modifier to the visited node if it contains the marker offset. + * + * @param node + * the visited node + * @param bitModifiers + * the bitwise modifiers of the node + * @param modifiers + * the extended modifiers list to add the final modifier to + * @return true to continue visiting child nodes + */ private boolean visit(ASTNode node, int bitModifiers, List modifiers) { if (containsPosition(node, markerStartOffset) && !Modifier.isFinal(bitModifiers)) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/RequireThisQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/RequireThisQuickfix.java index 5ebaba31a..2f62a12ab 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/RequireThisQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/RequireThisQuickfix.java @@ -72,6 +72,17 @@ public boolean visit(final MethodInvocation node) { }; } + /** + * Finds a field access replacement for the given name. + * + * @param name + * the name to replace + * @param node + * the AST node to search in + * @param typeLevel + * the current type level + * @return the replacement expression or null + */ private Expression findFieldReplacement(final SimpleName name, final ASTNode node, int typeLevel) { Expression replacement = null; @@ -105,6 +116,15 @@ private Expression findFieldReplacement(final SimpleName name, final ASTNode nod return replacement; } + /** + * Creates a field access replacement qualified with this. + * + * @param type + * the type to qualify with or null + * @param name + * the name of the field + * @return the created field access + */ private FieldAccess createFieldAccessReplacement(final TypeDeclaration type, final SimpleName name) { final AST ast = name.getAST(); @@ -118,6 +138,19 @@ private FieldAccess createFieldAccessReplacement(final TypeDeclaration type, return fieldAccess; } + /** + * Finds a method invocation replacement for the given name. + * + * @param name + * the name to replace + * @param contextNode + * the AST node to search in + * @param node + * the original method invocation + * @param typeLevel + * the current type level + * @return the replacement expression or null + */ private Expression findMethodReplacement(final SimpleName name, ASTNode contextNode, final MethodInvocation node, int typeLevel) { Expression replacement = null; @@ -144,6 +177,15 @@ private Expression findMethodReplacement(final SimpleName name, ASTNode contextN return replacement; } + /** + * Creates a method invocation replacement qualified with this. + * + * @param type + * the type to qualify with or null + * @param origMethodInvocation + * the original method invocation + * @return the created method invocation + */ private Expression createMethodInvocationReplacement(final TypeDeclaration type, MethodInvocation origMethodInvocation) { final AST ast = origMethodInvocation.getAST(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/SimplifyBooleanReturnQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/SimplifyBooleanReturnQuickfix.java index 3065a9f37..f145962c2 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/SimplifyBooleanReturnQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/SimplifyBooleanReturnQuickfix.java @@ -94,6 +94,13 @@ public boolean visit(final IfStatement node) { }; } + /** + * Computes the replacement return statement for the given if statement. + * + * @param node + * the if statement to simplify + * @return the replacement statement or an empty optional if the structure is not as expected + */ private Optional computeReplacement(final IfStatement node) { final Optional isThenStatementTrue = isReturnStatementTrue(node.getThenStatement()); @@ -134,6 +141,13 @@ private Optional computeReplacement(final IfStatement node) { return optionalReplacement; } + /** + * Determines whether the given statement is a return of the boolean literal {@code true}. + * + * @param node + * the statement to inspect + * @return whether the statement returns {@code true}, or an empty optional if it does not + */ private static Optional isReturnStatementTrue(final Statement node) { Optional isReturnStatementTrue = Optional.empty(); if (node instanceof ReturnStatement returnStatement) { @@ -153,6 +167,13 @@ else if (node instanceof Block block) { return isReturnStatementTrue; } + /** + * Removes a leading 'not' operator from the given condition if present. + * + * @param condition + * the condition expression + * @return the condition without a leading 'not', or the same expression otherwise + */ private static Expression removeNotFromCondition(final Expression condition) { Expression fixedCondition = condition; if (condition instanceof PrefixExpression prefix @@ -162,6 +183,13 @@ private static Expression removeNotFromCondition(final Expression condition) { return fixedCondition; } + /** + * Determines whether parentheses can be omitted when negating the given condition. + * + * @param condition + * the condition expression + * @return whether the parentheses are not required for this expression type + */ private static boolean omitParantheses(final Expression condition) { return OMIT_PARANETHESES_CLASSES.contains(condition.getClass()); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/StringLiteralEqualityQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/StringLiteralEqualityQuickfix.java index 10ebad874..91cf4f5e3 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/StringLiteralEqualityQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/coding/StringLiteralEqualityQuickfix.java @@ -65,6 +65,15 @@ public boolean visit(InfixExpression node) { }; } + /** + * Computes the equals() based replacement expression for the given infix expression comparing a + * string literal. + * + * @param node + * the infix expression to replace + * @return an optional containing the replacement expression, or empty if no string literal + * operand is present + */ @SuppressWarnings("unchecked") private static Optional computeReplacement(InfixExpression node) { Optional replacement = Optional.empty(); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/DesignForExtensionQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/DesignForExtensionQuickfix.java index c6d414e7e..b48ad9359 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/DesignForExtensionQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/DesignForExtensionQuickfix.java @@ -74,6 +74,12 @@ private final class DesignForExtensionQuickfixAstVisitor extends ASTVisitor { /** The line info region. */ private final IRegion lineInfo; + /** + * Creates the AST visitor for the given line info region. + * + * @param lineInfo + * the line info region of the correction + */ private DesignForExtensionQuickfixAstVisitor(IRegion lineInfo) { this.lineInfo = lineInfo; } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/FinalClassQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/FinalClassQuickfix.java index 924233555..9638125dd 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/FinalClassQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/design/FinalClassQuickfix.java @@ -73,6 +73,12 @@ private final class FinalClassQuickfixAstVisitor extends ASTVisitor { /** The line info region. */ private final IRegion lineInfo; + /** + * Creates the AST visitor. + * + * @param lineInfo + * the line info region + */ private FinalClassQuickfixAstVisitor(IRegion lineInfo) { this.lineInfo = lineInfo; } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java index 190232a19..6870c4f08 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/misc/ArrayTypeStyleQuickfix.java @@ -74,6 +74,12 @@ private final class ArrayTypeStyleQuickfixAstVisitor extends ASTVisitor { /** The marker start offset. */ private final int markerStartOffset; + /** + * Creates the AST visitor. + * + * @param markerStartOffset + * the marker start offset + */ private ArrayTypeStyleQuickfixAstVisitor(int markerStartOffset) { this.markerStartOffset = markerStartOffset; } @@ -184,14 +190,36 @@ else if (isJavaStyle(node.getType())) { return true; } + /** + * Checks whether the given type is of Java array style. + * + * @param type + * the type to check + * @return true if the type is an array type + */ private boolean isJavaStyle(Type type) { return type instanceof ArrayType; } + /** + * Checks whether the given variable declaration uses C-style array brackets. + * + * @param decl + * the variable declaration to check + * @return true if the declaration uses C-style array brackets + */ private boolean isCStyle(VariableDeclaration decl) { return decl.getExtraDimensions() > 0; } + /** + * Checks whether any of the given variable declarations uses C-style array + * brackets. + * + * @param fragments + * the variable declarations to check + * @return true if any declaration uses C-style array brackets + */ private boolean isCStyle(List fragments) { boolean isCStyle = false; final Iterator iter = fragments.iterator(); @@ -205,6 +233,15 @@ private boolean isCStyle(List fragments) { return isCStyle; } + /** + * Creates a new array type with the given component type and dimensions. + * + * @param componentType + * the component type of the array + * @param dimensions + * the number of array dimensions + * @return the created array type + */ private ArrayType createArrayType(Type componentType, int dimensions) { final Type type = (Type) ASTNode.copySubtree(componentType.getAST(), componentType); return componentType.getAST().newArrayType(type, dimensions); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/Messages.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/Messages.java index e5bf8bd01..72346d190 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/Messages.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/Messages.java @@ -43,6 +43,9 @@ public final class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + /** + * Hidden constructor of the message bundle class. + */ private Messages() { } } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/ModifierOrderQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/ModifierOrderQuickfix.java index 4bef19c42..4833535b9 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/ModifierOrderQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/ModifierOrderQuickfix.java @@ -125,6 +125,12 @@ private static final class ModifierOrderQuickfixAstVisitor extends ASTVisitor { /** The marker start offset. */ private final int markerStartOffset; + /** + * Creates the modifier order quickfix AST visitor. + * + * @param markerStartOffset + * the start offset of the problem marker + */ private ModifierOrderQuickfixAstVisitor(int markerStartOffset) { this.markerStartOffset = markerStartOffset; } @@ -149,6 +155,13 @@ public boolean visit(AnnotationTypeMemberDeclaration node) { return visitBodyDecl(node); } + /** + * Reorders the modifiers of the given body declaration if the marker lies within them. + * + * @param node + * the body declaration to process + * @return whether the visitor should continue visiting child nodes + */ @SuppressWarnings("unchecked") private boolean visitBodyDecl(BodyDeclaration node) { final List modifiers = diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/RedundantModifierQuickfix.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/RedundantModifierQuickfix.java index 0e9619b00..ff099606e 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/RedundantModifierQuickfix.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/quickfixes/modifier/RedundantModifierQuickfix.java @@ -82,6 +82,14 @@ private final class RedundantModifierQuickfixAstVisitor extends ASTVisitor { /** The marker start offset. */ private final int markerStartOffset; + /** + * Creates the AST visitor. + * + * @param lineInfo + * the line info region + * @param markerStartOffset + * the marker start offset + */ private RedundantModifierQuickfixAstVisitor(IRegion lineInfo, int markerStartOffset) { this.lineInfo = lineInfo; this.markerStartOffset = markerStartOffset; @@ -173,6 +181,14 @@ public boolean visit(AnnotationTypeMemberDeclaration node) { return true; } + /** + * Removes the redundant modifiers from the given modifier list. + * + * @param modifiers + * the modifier nodes to process + * @param redundantModifierKeywords + * the modifier keywords to remove + */ private void deleteRedundantModifiers(List modifiers, List redundantModifierKeywords) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/Messages.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/Messages.java index fa5f6ad29..769ba0966 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/Messages.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/Messages.java @@ -147,6 +147,9 @@ public final class Messages extends NLS { NLS.initializeMessages(BUNDLE_NAME, Messages.class); } + /** + * Creates the messages class. Private to prevent instantiation. + */ private Messages() { } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/AbstractStatsView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/AbstractStatsView.java index ad5daa88d..f3d25facf 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/AbstractStatsView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/AbstractStatsView.java @@ -82,8 +82,20 @@ public abstract class AbstractStatsView extends ViewPart { // methods // + /** + * Initializes the view's menu. + * + * @param menu + * the menu manager + */ protected abstract void initMenu(IMenuManager menu); + /** + * Initializes the view's tool bar. + * + * @param tbm + * the tool bar manager + */ protected abstract void initToolBar(IToolBarManager tbm); /** diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsMainView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsMainView.java index 465070b25..87d228da1 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsMainView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsMainView.java @@ -69,6 +69,22 @@ public final class MarkerStatsMainView extends Composite { /** The detail table viewer. */ private final DetailTableViewer mDetailViewer; + /** + * Creates the marker statistics main view. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param providers + * the data providers + * @param site + * the workbench part site + * @param updateActions + * keeps the actions updated + * @param actions + * the marker statistics view actions + */ public MarkerStatsMainView(Composite parent, int style, MarkerStatsViewDataProviders providers, IWorkbenchPartSite site, Runnable updateActions, MarkerStatsViewActions actions) { super(parent, style); @@ -89,33 +105,64 @@ public MarkerStatsMainView(Composite parent, int style, MarkerStatsViewDataProvi mStackLayout.topControl = mMasterViewer; } + /** + * Sets the statistics shown by the view. + * + * @param stats + * the statistics + */ public void setStats(Stats stats) { mMasterViewer.setStats(stats); mDetailViewer.setStats(stats); } + /** + * Shows the master table as the top control. + */ public void setMasterAsTopControl() { toggleTopControl(mMasterViewer); } + /** + * Shows the detail table as the top control. + */ public void setDetailAsTopControl() { toggleTopControl(mDetailViewer); } + /** + * Sets the given control as the top control of the stack layout and refreshes it. + * + * @param control + * the control to show + */ private void toggleTopControl(AbstractStatTableViewer control) { mStackLayout.topControl = control; layout(); control.refresh(); } + /** + * Focuses the top control of the stack layout. + */ public void focusTopControl() { mStackLayout.topControl.setFocus(); } + /** + * Returns the currently selected marker. + * + * @return the selected marker or an empty optional + */ public Optional getSelectedMarker() { return mDetailViewer.getSelection(); } + /** + * Returns the currently selected marker category. + * + * @return the selected marker category or an empty optional + */ public Optional getSelectedMarkerCategory() { return mMasterViewer.getSelection(); } @@ -139,6 +186,14 @@ private static void hookContextMenu(final Collection actions, TableViewe site.registerContextMenu(menuMgr, viewer); } + /** + * Fills the given context menu with the provided actions. + * + * @param manager + * the menu manager + * @param actions + * the actions to add + */ private static void fillContextMenu(IMenuManager manager, Collection actions) { for (Object item : actions) { if (item instanceof IContributionItem contrib) { @@ -160,6 +215,22 @@ private static final class MainTableViewer extends AbstractStatTableViewer { @@ -243,6 +320,24 @@ private static final class DetailTableViewer extends AbstractStatTableViewer { @@ -347,6 +448,16 @@ private abstract static class AbstractStatTableViewer extends Composite { /** The selection class type. */ private final Class selectionClass; + /** + * Creates the base table viewer. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param selectionClass + * the type of selection handled by this viewer + */ private AbstractStatTableViewer(Composite parent, int style, Class selectionClass) { super(parent, style); this.selectionClass = selectionClass; @@ -354,12 +465,28 @@ private AbstractStatTableViewer(Composite parent, int style, Class selectionC setLayout(new FillLayout()); } + /** + * Returns the underlying table viewer. + * + * @return the table viewer + */ protected abstract TableViewer getTableViewer(); + /** + * Sets the statistics shown by this viewer. + * + * @param stats + * the statistics + */ public void setStats(Stats stats) { getTableViewer().setInput(stats); } + /** + * Returns the current selection of this viewer. + * + * @return the selected element or an empty optional + */ public Optional getSelection() { Optional selection = Optional.empty(); if (getTableViewer().getSelection() instanceof StructuredSelection structuredSelection @@ -369,6 +496,9 @@ public Optional getSelection() { return selection; } + /** + * Refreshes this viewer. + */ public void refresh() { getTableViewer().refresh(); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsView.java index c43b76913..fae36cf0a 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsView.java @@ -215,6 +215,9 @@ private void updateActions() { .setEnabled(mIsDrilledDown && !mMainSection.getSelectedMarker().isEmpty()); } + /** + * Drills back from the detail view to the master view. + */ private void drillBack() { mIsDrilledDown = false; detailContentProvider.setCurrentDetailCategory(null); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsViewDataProviders.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsViewDataProviders.java index b3bd365fe..19c10cffa 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsViewDataProviders.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/MarkerStatsViewDataProviders.java @@ -46,6 +46,12 @@ public record MarkerStatsViewDataProviders(MarkerStatsViewMasterDataProviders ma /** Section tag for detail view settings. */ private static final String TAG_SECTION_DETAIL = "detailView"; + /** + * Constructs a data providers record based on the given dialog settings. + * + * @param dialogSettings + * the dialog settings used to initialize the master and detail providers + */ public MarkerStatsViewDataProviders(IDialogSettings dialogSettings) { this(new MarkerStatsViewMasterDataProviders(dialogSettings), new MarkerStatsViewDetailDataProviders(dialogSettings)); @@ -62,10 +68,22 @@ public MarkerStatsViewDataProviders(IDialogSettings dialogSettings) { public record MarkerStatsViewMasterDataProviders(MasterContentProvider contentProvider, IDialogSettings dialogSettings) { + /** + * Constructs the master data provider record based on the given dialog settings. + * + * @param dialogSettings + * the dialog settings used to persist the master table layout + */ public MarkerStatsViewMasterDataProviders(IDialogSettings dialogSettings) { this(new MasterContentProvider(), dialogSettings); } + /** + * Returns the dialog settings section used to persist the master table layout, creating it + * if it does not yet exist. + * + * @return the dialog settings section for the master view + */ public IDialogSettings getTableSettings() { IDialogSettings settings = dialogSettings.getSection(TAG_SECTION_MASTER); if (settings == null) { @@ -86,10 +104,22 @@ public IDialogSettings getTableSettings() { public record MarkerStatsViewDetailDataProviders(DetailContentProvider contentProvider, IDialogSettings dialogSettings) { + /** + * Constructs the detail data provider record based on the given dialog settings. + * + * @param dialogSettings + * the dialog settings used to persist the detail table layout + */ public MarkerStatsViewDetailDataProviders(IDialogSettings dialogSettings) { this(new DetailContentProvider(), dialogSettings); } + /** + * Returns the dialog settings section used to persist the detail table layout, creating it + * if it does not yet exist. + * + * @return the dialog settings section for the detail view + */ public IDialogSettings getTableSettings() { IDialogSettings settings = dialogSettings.getSection(TAG_SECTION_DETAIL); if (settings == null) { @@ -108,6 +138,7 @@ public static final class MasterContentProvider implements IStructuredContentPro /** The current marker stats. */ private Object[] mCurrentMarkerStats; + /** Creates the master content provider. */ private MasterContentProvider() { } @@ -146,6 +177,7 @@ public static final class DetailContentProvider implements IStructuredContentPro /** The current detail category. */ private String currentDetailCategory; + /** Creates the detail content provider. */ private DetailContentProvider() { } @@ -183,6 +215,11 @@ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { mCurrentDetails = null; } + /** + * Returns the number of markers currently loaded for the selected detail category. + * + * @return the number of markers, or zero if none are loaded + */ public int getMarkerCount() { int count = 0; if (mCurrentDetails != null) { @@ -191,10 +228,21 @@ public int getMarkerCount() { return count; } + /** + * Returns the currently selected detail category. + * + * @return the current detail category + */ public String getCurrentDetailCategory() { return currentDetailCategory; } + /** + * Sets the current detail category, invalidating the cached details so they are reloaded. + * + * @param currentDetailCategory + * the detail category to select + */ public void setCurrentDetailCategory(String currentDetailCategory) { this.currentDetailCategory = currentDetailCategory; this.mCurrentDetails = null; diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/SelectionTool.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/SelectionTool.java index 2075d56d1..3531518ab 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/SelectionTool.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/SelectionTool.java @@ -41,10 +41,20 @@ */ public final class SelectionTool { + /** Prevents instantiation of this utility class. */ private SelectionTool() { } + /** + * Resolves the given workbench selection into the list of resources it affects. + * + * @param part + * the active workbench part providing the selection + * @param selection + * the current selection + * @return the list of resources affected by the selection + */ public static List resolveSelection(IWorkbenchPart part, ISelection selection) { List resources = Collections.emptyList(); if (part instanceof IEditorPart editor) { @@ -70,6 +80,13 @@ else if (object instanceof IAdaptable adaptable) { return resources; } + /** + * Returns the resource adapted from the given adaptable object, if any. + * + * @param adaptable + * the object to adapt + * @return the adapted resource, or an empty optional if none could be adapted + */ private static Optional considerAdaptable(IAdaptable adaptable) { IResource resource = adaptable.getAdapter(IResource.class); if (resource == null) { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilter.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilter.java index 398417e70..ac85d04df 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilter.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilter.java @@ -134,6 +134,13 @@ public record CheckstyleMarkerFilter(boolean enabled, int onResource, IWorkingSe // methods // + /** + * Creates a copy of this filter focusing on the given resources. + * + * @param resources + * the focused resources + * @return the new filter + */ public CheckstyleMarkerFilter withFocusResources(IResource[] resources) { return new CheckstyleMarkerFilter(enabled, onResource, workingSet, selectBySeverity, severity, filterByRegex, filterRegex, resources); @@ -218,6 +225,13 @@ public static CheckstyleMarkerFilter restoreState(IDialogSettings dialogSettings mSeverity, filterByRegex, filterRegex, focusResource); } + /** + * Parses the given setting as an integer. + * + * @param setting + * the setting to parse + * @return the parsed value or an empty optional + */ private static Optional tryParseInt(String setting) { Optional parsed; try { @@ -229,6 +243,15 @@ private static Optional tryParseInt(String setting) { return parsed; } + /** + * Finds a setting with the given key in the dialog settings. + * + * @param dialogSettings + * the dialog settings + * @param key + * the key to look up + * @return the setting value or an empty optional + */ private static Optional findSetting(IDialogSettings dialogSettings, String key) { return Optional.ofNullable(dialogSettings) .flatMap(settings -> Optional.ofNullable(settings.get(key))); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java index ac4c6e694..7b7fb6501 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialog.java @@ -116,6 +116,9 @@ protected Control createDialogArea(Composite parent) { return composite; } + /** + * Opens the dialog to edit the regular expressions used for filtering. + */ private void editRegularExpressions() { final List regex = new ArrayList<>(mRegularExpressions); final CheckstyleMarkerFilterRegexDialog regexDialog = @@ -217,6 +220,9 @@ private void initRegexLabel() { dialogView.setRegexLabel(buf.toString()); } + /** + * Opens the working set selection dialog and updates the selected working set. + */ private void selectWorkingSet() { final IWorkingSetSelectionDialog dialog = PlatformUI.getWorkbench().getWorkingSetManager() .createWorkingSetSelectionDialog(getShell(), false); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialogView.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialogView.java index 158c0beca..6116cdb6c 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialogView.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterDialogView.java @@ -54,6 +54,18 @@ public final class CheckstyleMarkerFilterDialogView extends Composite { /** The edit regex button. */ private final Button mBtnEditRegex; + /** + * Creates the checkstyle marker filter dialog view. + * + * @param parent + * the parent composite + * @param style + * the widget style + * @param selectWorkingSet + * callback to select a working set + * @param editRegularExpressions + * callback to edit the regular expressions + */ public CheckstyleMarkerFilterDialogView(Composite parent, int style, Runnable selectWorkingSet, Runnable editRegularExpressions) { super(parent, style); @@ -87,6 +99,19 @@ public CheckstyleMarkerFilterDialogView(Composite parent, int style, Runnable se SelectionListener.widgetSelectedAdapter(event -> editRegularExpressions.run())); } + /** + * Creates a button applying the given grid data factory. + * + * @param parent + * the parent composite + * @param style + * the button style + * @param text + * the button text + * @param gridDataFactory + * the grid data factory to apply + * @return the created button + */ private static Button createButton(Composite parent, int style, String text, GridDataFactory gridDataFactory) { final Button button = new Button(parent, style); @@ -106,6 +131,20 @@ private void updateControlState() { mBtnEditRegex.setEnabled(mChkFilterEnabled.getSelection()); } + /** + * Sets the filter state of the view. + * + * @param enabled + * whether the filter is enabled + * @param onResource + * the resource filter type + * @param selectBySeverity + * whether to filter by severity + * @param severity + * the severity + * @param filterByRegex + * whether to filter by regular expression + */ public void set(boolean enabled, int onResource, boolean selectBySeverity, int severity, boolean filterByRegex) { mChkFilterEnabled.setSelection(enabled); @@ -114,30 +153,67 @@ public void set(boolean enabled, int onResource, boolean selectBySeverity, int s updateControlState(); } + /** + * Sets the working set label. + * + * @param label + * the working set label + */ public void setWorkingSetLabel(String label) { resourceFilterGroup.setWorkingSetLabel(label); } + /** + * Sets the regular expression label. + * + * @param label + * the regular expression label + */ public void setRegexLabel(String label) { mLblRegexFilter.setText(label); } + /** + * Returns whether the filter is enabled. + * + * @return whether the filter is enabled + */ public boolean getFilterEnabled() { return mChkFilterEnabled.getSelection(); } + /** + * Returns the resource filter type. + * + * @return the resource filter type + */ public int getOnResource() { return resourceFilterGroup.getOnResource(); } + /** + * Returns the selected severity. + * + * @return the selected severity + */ public int getSeverity() { return resourceFilterGroup.getSeverity(); } + /** + * Returns whether to filter by severity. + * + * @return whether to filter by severity + */ public boolean getSelectBySeverity() { return resourceFilterGroup.getSelectBySeverity(); } + /** + * Returns whether to filter by regular expression. + * + * @return whether to filter by regular expression + */ public boolean getSelectByRegex() { return mChkSelectByRegex.getSelection(); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterRegexDialog.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterRegexDialog.java index 782d87249..a3c824fee 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterRegexDialog.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterRegexDialog.java @@ -118,6 +118,13 @@ protected Control createDialogArea(Composite parent) { return main; } + /** + * Creates the add and remove buttons for the dialog. + * + * @param parent + * the parent composite + * @return the composite holding the buttons + */ private Composite createButtons(Composite parent) { final Composite buttons = new Composite(parent, SWT.NONE); final GridLayout layout = new GridLayout(1, false); @@ -167,6 +174,14 @@ protected void configureShell(Shell shell) { shell.setText(Messages.CheckstyleMarkerFilterDialog_titleRegexEditor); } + /** + * Checks whether the given text is a valid regular expression, showing an error message when it + * is not. + * + * @param text + * the text to validate + * @return true if the text is a valid pattern, false otherwise + */ private boolean checkPatternValidity(String text) { boolean valid; try { diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterResourceFilterGroup.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterResourceFilterGroup.java index e8dc348e8..7e2cf317a 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterResourceFilterGroup.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/stats/views/internal/CheckstyleMarkerFilterResourceFilterGroup.java @@ -70,6 +70,18 @@ public final class CheckstyleMarkerFilterResourceFilterGroup extends Composite { /** The severity info checkbox. */ private final Button mChkSeverityInfo; + /** + * Creates the marker filter resource filter group. + * + * @param parent + * the parent composite + * @param style + * the composite style bits + * @param updateControlState + * runnable invoked when the control state should be updated + * @param selectWorkingSet + * runnable invoked to select a working set + */ public CheckstyleMarkerFilterResourceFilterGroup(Composite parent, int style, Runnable updateControlState, Runnable selectWorkingSet) { super(parent, style); @@ -133,6 +145,16 @@ public CheckstyleMarkerFilterResourceFilterGroup(Composite parent, int style, Messages.CheckstyleMarkerFilterDialog_btnSeverityInfo, GridDataFactory.swtDefaults()); } + /** + * Sets the filter fields to reflect the given filter settings. + * + * @param onResource + * the resource restriction flag + * @param selectBySeverity + * whether to restrict filter by severity + * @param severity + * the severity bit mask + */ public void setFromFilter(int onResource, boolean selectBySeverity, int severity) { mRadioOnAnyResource.setSelection(onResource == CheckstyleMarkerFilter.ON_ANY_RESOURCE); mRadioAnyResourceInSameProject @@ -150,6 +172,12 @@ public void setFromFilter(int onResource, boolean selectBySeverity, int severity mChkSeverityInfo.setSelection((severity & CheckstyleMarkerFilter.SEVERITY_INFO) > 0); } + /** + * Enables or disables the filter widgets. + * + * @param enabled + * true to enable, false to disable + */ public void propagateEnabled(boolean enabled) { mFilterComposite.setEnabled(enabled); mRadioOnAnyResource.setEnabled(enabled); @@ -166,10 +194,21 @@ public void propagateEnabled(boolean enabled) { mChkSeverityInfo.setEnabled(enabled && mChkSeverityEnabled.getSelection()); } + /** + * Sets the text of the selected working set label. + * + * @param text + * the text to display + */ public void setWorkingSetLabel(String text) { mLblSelectedWorkingSet.setText(text); } + /** + * Returns the selected resource restriction. + * + * @return the selected resource restriction + */ public int getOnResource() { final int onResource; if (mRadioSelectedResource.getSelection()) { @@ -190,6 +229,11 @@ else if (mRadioSelectedWorkingSet.getSelection()) { return onResource; } + /** + * Returns the selected marker severities as a bit mask. + * + * @return the selected marker severities bit mask + */ public int getSeverity() { int severity = 0; if (mChkSeverityError.getSelection()) { @@ -204,10 +248,28 @@ public int getSeverity() { return severity; } + /** + * Returns whether filtering is restricted by severity. + * + * @return true if filtering is restricted by severity + */ public boolean getSelectBySeverity() { return mChkSeverityEnabled.getSelection(); } + /** + * Creates a button with the given text and applies the layout data. + * + * @param parent + * the parent composite + * @param style + * the button style bits + * @param text + * the button text + * @param gridDataFactory + * the layout data factory to apply + * @return the created button + */ private static Button createButton(Composite parent, int style, String text, GridDataFactory gridDataFactory) { final Button button = new Button(parent, style); diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/HtmlUtil.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/HtmlUtil.java index 3f7450dec..2911cc822 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/HtmlUtil.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/HtmlUtil.java @@ -33,6 +33,7 @@ public final class HtmlUtil { private static final Pattern PATTERN_INLINE_CODE = Pattern.compile(Pattern.quote("{@code ") + "([^}]*?)" + Pattern.quote("}")); + /** Prevents instantiation of this utility class. */ private HtmlUtil() { } @@ -57,6 +58,13 @@ public static String getDescriptionHtml(String description) { return buf.toString(); } + /** + * Converts inline code tags in the given HTML text to {@code } elements. + * + * @param html + * the HTML text to convert + * @return the converted HTML text + */ private static String convertInlineCodeTags(String html) { return PATTERN_INLINE_CODE.matcher(html).replaceAll("$1"); } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/InternalBrowser.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/InternalBrowser.java index cf9c9f9a6..b204eeb55 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/InternalBrowser.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/InternalBrowser.java @@ -35,6 +35,9 @@ */ public final class InternalBrowser { + /** + * Private constructor to prevent instantiation. + */ private InternalBrowser() { // utility class } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/regex/RegexCompletionProposalFactory.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/regex/RegexCompletionProposalFactory.java index 794d3b070..a4ca567fe 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/regex/RegexCompletionProposalFactory.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/regex/RegexCompletionProposalFactory.java @@ -32,6 +32,9 @@ */ public final class RegexCompletionProposalFactory { + /** + * Creates the proposal factory. + */ private RegexCompletionProposalFactory() { // factory } diff --git a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/table/TableViewerEnhancer.java b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/table/TableViewerEnhancer.java index 97d23c626..383f3f382 100644 --- a/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/table/TableViewerEnhancer.java +++ b/net.sf.eclipsecs.ui/src/main/java/net/sf/eclipsecs/ui/util/table/TableViewerEnhancer.java @@ -69,6 +69,7 @@ public final class TableViewerEnhancer { /** Integer constant for the reverse sort direction value. */ private static final int DIRECTION_REVERSE = -1; + /** Prevents instantiation of this utility class. */ private TableViewerEnhancer() { } @@ -88,6 +89,17 @@ public static void setColumnComparator(TableColumn column, column.setData(WIDGET_DATA_COLUMN_COMPARATOR, comparator); } + /** + * Enhances the given table viewer with sortable columns, column width persistence and state + * restoration. + * + * @param tableViewer + * the table viewer to enhance + * @param tableSettings + * the dialog settings used to persist the table state + * @param tableColumnLayout + * the table column layout used to restore the column widths + */ public static void enhance(TableViewer tableViewer, IDialogSettings tableSettings, TableColumnLayout tableColumnLayout) { final Table table = tableViewer.getTable(); @@ -138,6 +150,16 @@ public static void enhance(TableViewer tableViewer, IDialogSettings tableSetting } } + /** + * Toggles or applies the sort column and direction when a column is selected for sorting. + * + * @param columns + * the table columns + * @param colIndex + * the index of the selected column + * @param table + * the table + */ private static void handleSortColumn(TableColumn[] columns, int colIndex, Table table) { if (columns[colIndex] == table.getSortColumn()) { setSortDirection(table, getSortDirection(table) * -1); @@ -148,6 +170,18 @@ private static void handleSortColumn(TableColumn[] columns, int colIndex, Table } } + /** + * Returns the integer value stored for the given setting, falling back to the default when it + * cannot be parsed. + * + * @param tableSettings + * the dialog settings + * @param setting + * the key of the setting to read + * @param def + * the default value to return when the setting is missing or invalid + * @return the stored integer value or the default + */ private static int getIntSetting(IDialogSettings tableSettings, String setting, int def) { int value; try { @@ -185,6 +219,13 @@ private static void saveState(Table table, IDialogSettings tableSettings) { tableSettings.put(TAG_CURRENT_SELECTION, table.getSelectionIndex()); } + /** + * Returns the direction of the current table sort as a constant. + * + * @param table + * the table + * @return the sort direction constant + */ private static int getSortDirection(Table table) { final int direction; if (table.getSortDirection() == SWT.DOWN) { @@ -196,6 +237,14 @@ private static int getSortDirection(Table table) { return direction; } + /** + * Sets the direction of the table sort based on the given sort direction constant. + * + * @param table + * the table + * @param sortDirection + * the sort direction constant to apply + */ private static void setSortDirection(Table table, int sortDirection) { final int direction; if (sortDirection == DIRECTION_FORWARD) {