From 9e75394b565f3d7f02edc8501dbdd10696e1fed3 Mon Sep 17 00:00:00 2001 From: Calixte Bonsart Date: Tue, 21 Apr 2026 18:53:14 -0400 Subject: [PATCH] Issue #451: add DesignForExtension to checkstyle config --- config/checkstyle-checks.xml | 9 ++++++- .../AbstractConfigurationType.java | 26 ++++++++++++++++++- .../transformer/CheckstyleFileWriter.java | 2 +- .../sample/checks/MethodLimitCheck.java | 2 +- .../ui/ApplicationStartedHandler.java | 2 +- .../CheckConfigurationWorkingSetEditor.java | 2 +- .../widgets/AbstractConfigPropertyWidget.java | 17 ++++++------ .../quickfixes/AbstractQuickfixTestCase.java | 4 +-- 8 files changed, 47 insertions(+), 17 deletions(-) diff --git a/config/checkstyle-checks.xml b/config/checkstyle-checks.xml index ea26192f8..9cecd89dd 100644 --- a/config/checkstyle-checks.xml +++ b/config/checkstyle-checks.xml @@ -331,7 +331,14 @@ - + + + + + + diff --git a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/configtypes/AbstractConfigurationType.java b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/configtypes/AbstractConfigurationType.java index 7007a0a66..03ea6ff4e 100644 --- a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/configtypes/AbstractConfigurationType.java +++ b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/config/configtypes/AbstractConfigurationType.java @@ -157,6 +157,19 @@ public CheckstyleConfigurationFile getCheckstyleConfiguration( return data; } + /** + * Retrieves the bytes of an additional properties bundle associated with the Checkstyle + * configuration. + *

+ * This method attempts to find a .properties file with the same base name as the + * provided configuration URL. + *

+ * + * @param checkConfigURL + * the URL of the Checkstyle configuration file + * @return an optional containing the bytes of the properties bundle, or empty if it cannot be + * loaded + */ protected Optional getAdditionPropertiesBundleBytes(URL checkConfigURL) { String location = checkConfigURL.toString(); @@ -189,8 +202,10 @@ protected Optional getAdditionPropertiesBundleBytes(URL checkConfigURL) * Gets the property resolver for this configuration type used to expand property values within * the checkstyle configuration. * - * @param checkConfiguration + * @param config * the actual check configuration + * @param configFile + * the checkstyle configuration file * @return the property resolver * @throws IOException * error creating the property resolver @@ -223,6 +238,15 @@ protected PropertyResolver getPropertyResolver(ICheckConfiguration config, return multiResolver; } + /** + * Reads and returns all bytes from the provided URLConnection. + * + * @param connection + * the connection to read from + * @return the byte array containing the data from the connection + * @throws IOException + * if an I/O error occurs while reading from the connection + */ protected byte[] getBytesFromURLConnection(URLConnection connection) throws IOException { try (InputStream in = connection.getInputStream()) { return ByteStreams.toByteArray(in); diff --git a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java index f47873c91..3e150e970 100644 --- a/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java +++ b/net.sf.eclipsecs.core/src/net/sf/eclipsecs/core/transformer/CheckstyleFileWriter.java @@ -33,7 +33,7 @@ * * */ -public class CheckstyleFileWriter { +public final class CheckstyleFileWriter { /** An object containing all settings for the checkstyle-file. */ private final CheckstyleSetting mCheckstyleSetting; diff --git a/net.sf.eclipsecs.sample/src/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java b/net.sf.eclipsecs.sample/src/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java index f70cdf2a8..96d6add5a 100644 --- a/net.sf.eclipsecs.sample/src/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java +++ b/net.sf.eclipsecs.sample/src/net/sf/eclipsecs/sample/checks/MethodLimitCheck.java @@ -24,7 +24,7 @@ import com.puppycrawl.tools.checkstyle.api.DetailAST; import com.puppycrawl.tools.checkstyle.api.TokenTypes; -public class MethodLimitCheck extends AbstractCheck { +public final class MethodLimitCheck extends AbstractCheck { private int max = 30; diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/ApplicationStartedHandler.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/ApplicationStartedHandler.java index 9871437d2..0d3e292fe 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/ApplicationStartedHandler.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/ApplicationStartedHandler.java @@ -45,7 +45,7 @@ * Event handler being called when the eclipse application has started. */ @Component(property = EventConstants.EVENT_TOPIC + "=" + UIEvents.UILifeCycle.APP_STARTUP_COMPLETE) -public class ApplicationStartedHandler implements EventHandler { +public final class ApplicationStartedHandler implements EventHandler { private final CheckFileOnOpenPartListener mPartListener = new CheckFileOnOpenPartListener(); diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java index ebea5b912..ac5e79894 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/CheckConfigurationWorkingSetEditor.java @@ -76,7 +76,7 @@ * This class provides the editor GUI for a check configuration working set. * */ -public class CheckConfigurationWorkingSetEditor { +public final class CheckConfigurationWorkingSetEditor { // // attributes diff --git a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java index 8355190ec..539ae66a3 100644 --- a/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java +++ b/net.sf.eclipsecs.ui/src/net/sf/eclipsecs/ui/config/widgets/AbstractConfigPropertyWidget.java @@ -91,16 +91,15 @@ public void setEnabled(boolean enabled) { mValueWidget.setEnabled(enabled); } + /** + * Figure out an initial value for the property. This will be, + * in order of precedence: + * 1) the existing value + * 2) a default value overriding the checkstyle default + * 3) the checkstyle default value, if specified + * 4) blank + */ protected String getInitValue() { - // - // Figure out an initial value for the property. This will be, - // in order of precedence: - // - // 1) the existing value - // 2) a default value overriding the checkstyle default - // 3) the checkstyle default value, if specified - // 4) blank - // String initValue = null; if (mProp != null) { initValue = mProp.getValue(); diff --git a/net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/AbstractQuickfixTestCase.java b/net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/AbstractQuickfixTestCase.java index b8cd07a30..233b727a0 100644 --- a/net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/AbstractQuickfixTestCase.java +++ b/net.sf.eclipsecs.ui/test/net/sf/eclipsecs/ui/quickfixes/AbstractQuickfixTestCase.java @@ -47,7 +47,7 @@ public abstract class AbstractQuickfixTestCase { - protected void testQuickfix(final String testDataXml, final AbstractASTResolution quickfix) + protected final void testQuickfix(final String testDataXml, final AbstractASTResolution quickfix) throws Exception { try (InputStream stream = getClass().getResourceAsStream(testDataXml)) { assertThat(stream).withFailMessage(() -> "Cannot find resource " + testDataXml + " in package " @@ -56,7 +56,7 @@ protected void testQuickfix(final String testDataXml, final AbstractASTResolutio } } - protected void testQuickfix(InputStream testdataStream, AbstractASTResolution quickfix) + private void testQuickfix(InputStream testdataStream, AbstractASTResolution quickfix) throws Exception { QuickfixTestData[] testdata = getTestData(testdataStream);