From e2a288878a1238fc121611041f64d6188679d95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Mon, 6 Apr 2026 22:22:20 +0200 Subject: [PATCH] refactor: convert log calls to parameterized logging in Check framework Replace string concatenation, NLS.bind, and MessageFormat.format in log calls with parameterized {} placeholders. Use Supplier/method-refs for lazy argument evaluation where appropriate. Modules: check.core.test, check.runtime.core, check.runtime.ui, check.ui, checkcfg.core Co-Authored-By: Claude Opus 4.6 (1M context) --- .../check/core/test/AbstractCheckTestCase.java | 2 +- .../CheckConfigurationStoreService.java | 6 +++--- .../runtime/context/AbstractCheckContext.java | 2 +- .../check/runtime/issue/AbstractCheckImpl.java | 4 ++-- .../runtime/label/CheckRuleLabelProvider.java | 2 +- .../validation/AbstractCheckValidator.java | 5 ++--- .../META-INF/MANIFEST.MF | 3 ++- .../ui/validation/CheckMarkerUpdateJob.java | 15 +++++---------- .../check/ui/builder/util/CheckProjectHelper.java | 5 +++-- .../ddk/check/ui/popup/actions/DeployJob.java | 6 +++--- .../avaloq/tools/ddk/checkcfg/CheckCfgUtil.java | 2 +- 11 files changed, 24 insertions(+), 28 deletions(-) diff --git a/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java b/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java index 5f61ec19aa..0e87745530 100644 --- a/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java +++ b/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java @@ -325,7 +325,7 @@ protected void execute(final IProgressMonitor monitor) throws CoreException, Inv IFile file = IResourcesSetupUtil.createFile(resourceURI.toPlatformString(true), contents); getFiles().add(file); } catch (IOException e) { - LOGGER.error("failed adding file to workspace: " + fileName, e); + LOGGER.error("failed adding file to workspace: {}", fileName, e); fail("Error adding file " + fileName + " to workspace: " + e.getMessage()); } } diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckConfigurationStoreService.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckConfigurationStoreService.java index a1773a1e1b..a3ae486a25 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckConfigurationStoreService.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckConfigurationStoreService.java @@ -90,7 +90,7 @@ private String getCode(final IMarker marker) { try { return (String) marker.getAttribute(Issue.CODE_KEY); } catch (CoreException e) { - LOGGER.error("Could not get code for marker: " + marker, e); //$NON-NLS-1$ + LOGGER.error("Could not get code for marker: {}", marker, e); //$NON-NLS-1$ return null; } } @@ -99,7 +99,7 @@ private URI getUri(final IMarker marker) { try { return URI.createURI((String) marker.getAttribute(Issue.URI_KEY)); } catch (CoreException e) { - LOGGER.error("Could not get uri for marker: " + marker, e); //$NON-NLS-1$ + LOGGER.error("Could not get uri for marker: {}", marker, e); //$NON-NLS-1$ return null; } } @@ -111,7 +111,7 @@ private String getLanguage(final URI uri) { if (resourceServiceProvider != null) { return resourceServiceProvider.get(Injector.class).getInstance(Key.get(String.class, Names.named(Constants.LANGUAGE_NAME))); } else { - LOGGER.error("Could not fetch a ResourceServiceProvider for URI: " + uri); //$NON-NLS-1$ + LOGGER.error("Could not fetch a ResourceServiceProvider for URI: {}", uri); //$NON-NLS-1$ } } else { LOGGER.warn("Could not fetch eResource from issue: URI to problem is null"); //$NON-NLS-1$ diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/context/AbstractCheckContext.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/context/AbstractCheckContext.java index c899fd4a46..4951c6be94 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/context/AbstractCheckContext.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/context/AbstractCheckContext.java @@ -73,7 +73,7 @@ private boolean checkIssueCodePredicates(final EObject context, final String iss // caught and disabled by the usual check infrastructure. } catch (Exception e) { // CHECKSTYLE:CHECK-ON IllegalCatch - LOGGER.error("Failed to execute predicate " + method.getName() + " for issue code " + issueCode + ". Removing predicate for this issue code.", e); //$NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$ + LOGGER.error("Failed to execute predicate {} for issue code {}. Removing predicate for this issue code.", method.getName(), issueCode, e); //$NON-NLS-1$ predicatesForIssueCode.remove(issueCode, method); } } diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/issue/AbstractCheckImpl.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/issue/AbstractCheckImpl.java index e8191ba037..353a3b5fe2 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/issue/AbstractCheckImpl.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/issue/AbstractCheckImpl.java @@ -40,8 +40,8 @@ public abstract class AbstractCheckImpl implements ICheckValidatorImpl { protected void logCheckMethodFailure(final String rule, final EObject object, final Exception e) { final Throwable cause = e instanceof InvocationTargetException ? ((InvocationTargetException) e).getTargetException() : e; final Resource res = object.eResource(); - LOGGER.error("Permanently disabling check method " + rule + " for context " + object.getClass().getName() + " because of failure" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - + (res != null ? " in " + res.getURI() : ""), cause); //$NON-NLS-1$ //$NON-NLS-2$ + LOGGER.error("Permanently disabling check method {} for context {} because of failure{}", rule, object.getClass().getName(), //$NON-NLS-1$ + (res != null ? " in " + res.getURI() : ""), cause); //$NON-NLS-1$ //$NON-NLS-2$ } /** diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java index 60fe7c1802..d42fdf6995 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java @@ -109,7 +109,7 @@ private static Map merge(final Stream mergedMap = new HashMap(); maps.map(Map::entrySet).flatMap(Set::stream).forEach(entry -> { if (null != mergedMap.putIfAbsent(entry.getKey(), entry.getValue())) { - LOGGER.warn("Non-unique Check issue code found: " + entry.getKey()); //$NON-NLS-1$ + LOGGER.warn("Non-unique Check issue code found: {}", entry.getKey()); //$NON-NLS-1$ } }); return mergedMap; diff --git a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/validation/AbstractCheckValidator.java b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/validation/AbstractCheckValidator.java index 42ff9e2b7b..607eca1c01 100644 --- a/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/validation/AbstractCheckValidator.java +++ b/com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/validation/AbstractCheckValidator.java @@ -19,7 +19,6 @@ import org.eclipse.emf.common.util.DiagnosticChain; import org.eclipse.emf.ecore.EClass; import org.eclipse.emf.ecore.EObject; -import org.eclipse.osgi.util.NLS; import org.eclipse.xtext.validation.AbstractInjectableValidator; import com.avaloq.tools.ddk.check.runtime.issue.ICheckValidatorImpl; @@ -83,7 +82,7 @@ protected Iterable internalCollectValidators(fina if (language == null) { throw new IllegalArgumentException("Input language cannot be null"); //$NON-NLS-1$ } else if (injector == null) { - LOGGER.debug(NLS.bind("No injector found for {0}. Could not inject registered validators.", language)); //$NON-NLS-1$ + LOGGER.debug("No injector found for {}. Could not inject registered validators.", language); //$NON-NLS-1$ } final List result = Lists.newArrayList(); @@ -98,7 +97,7 @@ protected Iterable internalCollectValidators(fina // CHECKSTYLE:OFF } catch (Exception e) { // CHECKSTYLE:ON - LOGGER.error("failed to inject validator " + validator, e); //$NON-NLS-1$ + LOGGER.error("failed to inject validator {}", validator, e); //$NON-NLS-1$ } } } diff --git a/com.avaloq.tools.ddk.check.runtime.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.check.runtime.ui/META-INF/MANIFEST.MF index 3c08ad0c5a..9c6c6d7886 100644 --- a/com.avaloq.tools.ddk.check.runtime.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.check.runtime.ui/META-INF/MANIFEST.MF @@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui, org.eclipse.ui.ide Bundle-RequiredExecutionEnvironment: JavaSE-21 Bundle-ActivationPolicy: lazy -Import-Package: org.apache.logging.log4j +Import-Package: org.apache.logging.log4j, + org.apache.logging.log4j.util Export-Package: com.avaloq.tools.ddk.check.runtime.ui.editor, com.avaloq.tools.ddk.check.runtime.ui.editor.model, com.avaloq.tools.ddk.check.runtime.ui.quickfix, diff --git a/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/validation/CheckMarkerUpdateJob.java b/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/validation/CheckMarkerUpdateJob.java index 1386d6e9b5..ecd395e298 100644 --- a/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/validation/CheckMarkerUpdateJob.java +++ b/com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/validation/CheckMarkerUpdateJob.java @@ -10,7 +10,6 @@ *******************************************************************************/ package com.avaloq.tools.ddk.check.runtime.ui.validation; -import java.text.MessageFormat; import java.util.Collection; import java.util.Set; @@ -95,9 +94,7 @@ private IFile getFileFromStorageMapper(final IStorage2UriMapper storage2UriMappe return (IFile) storage.getFirst(); } } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(MessageFormat.format("Could not find storage for URI {0}", fileUri.toString())); //$NON-NLS-1$ - } + LOGGER.debug("Could not find storage for URI {}", fileUri::toString); //$NON-NLS-1$ return null; } @@ -135,9 +132,7 @@ protected IStatus run(final IProgressMonitor monitor) { final IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(uri); if (serviceProvider == null) { // This may happen for non-Xtext resources in ice entities - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(MessageFormat.format("Could not validate {0}: no resource service provider found", uri.toString())); //$NON-NLS-1$ - } + LOGGER.debug("Could not validate {}: no resource service provider found", uri::toString); //$NON-NLS-1$ continue; // Skip to next URI } @@ -152,7 +147,7 @@ protected IStatus run(final IProgressMonitor monitor) { } if (resourceValidator == null) { - LOGGER.error(MessageFormat.format("Could not validate {0}: no resource validator found", iFile.getName())); //$NON-NLS-1$ + LOGGER.error("Could not validate {}: no resource validator found", iFile.getName()); //$NON-NLS-1$ } else if (iFile != null) { monitor.subTask("loading " + iFile.getName()); //$NON-NLS-1$ @@ -175,11 +170,11 @@ protected IStatus run(final IProgressMonitor monitor) { // CHECKSTYLE:OFF } catch (final RuntimeException e) { // CHECKSTYLE:ON - LOGGER.error(MessageFormat.format("{0} could not be validated.", iFile.getName()), e); //$NON-NLS-1$ + LOGGER.error("{} could not be validated.", iFile.getName(), e); //$NON-NLS-1$ } finally { if (eResource != null) { validateAndCreateMarkers(resourceValidator, markerCreator, iFile, eResource, monitor); - LOGGER.debug("Validated " + uri); //$NON-NLS-1$ + LOGGER.debug("Validated {}", uri); //$NON-NLS-1$ if (loaded) { // NOPMD // unload any resource that was previously loaded as part of this loop. eResource.unload(); diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java index 1a904cbce5..16f5799ccb 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java @@ -52,6 +52,7 @@ public class CheckProjectHelper { private static final Logger LOGGER = LogManager.getLogger(CheckProjectHelper.class); + private static final String LOG_PLUGIN_PATH_ERROR = "Could not determine plugin path for catalog {}"; @Inject private IStorage2UriMapper mapper; @@ -90,7 +91,7 @@ public String getCatalogPluginPath(final CheckCatalog catalog) { String result = packageFragment.getElementName().replace('.', '/'); return result + '/' + file.getName(); } catch (JavaModelException e) { - LOGGER.error("Could not determine plugin path for catalog " + catalog.getName(), e); + LOGGER.error(LOG_PLUGIN_PATH_ERROR, catalog.getName(), e); } return null; } @@ -114,7 +115,7 @@ public String getCatalogQualifiedName(final CheckCatalog catalog) { final String fileNameWithoutExtension = file.getName().substring(0, file.getName().length() - (file.getFileExtension().length() + 1)); return packageFragment.getElementName() + '.' + fileNameWithoutExtension; } catch (JavaModelException e) { - LOGGER.error("Could not determine plugin path for catalog " + catalog.getName(), e); + LOGGER.error(LOG_PLUGIN_PATH_ERROR, catalog.getName(), e); } return null; } diff --git a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java index 3d02494f8b..a26d38b76e 100644 --- a/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java +++ b/com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java @@ -101,7 +101,7 @@ protected IStatus run(final IProgressMonitor monitor) { return new Status(Status.ERROR, Activator.getPluginId(), Messages.DeployJob_CouldNotDeployCheckBundle, e); } - LOGGER.info(NLS.bind("Generated bundle from project {0} deployed.", project.getName())); //$NON-NLS-1$ + LOGGER.info("Generated bundle from project {} deployed.", project.getName()); //$NON-NLS-1$ try { deployCheckConfiguration(); @@ -109,7 +109,7 @@ protected IStatus run(final IProgressMonitor monitor) { return new Status(Status.ERROR, Activator.getPluginId(), Messages.DeployJob_CannotDeployMoreThanOneCheckConfiguration, e); } - LOGGER.info(NLS.bind("Check configuration for project {0} deployed.", project.getName())); //$NON-NLS-1$ + LOGGER.info("Check configuration for project {} deployed.", project.getName()); //$NON-NLS-1$ return Status.OK_STATUS; } @@ -146,7 +146,7 @@ private void deployCheckBundle() throws DeployException { } } - LOGGER.info(NLS.bind("Starting the bundle {0} generated from the project {1}", bundleLocation, project.getName())); //$NON-NLS-1$ + LOGGER.info("Starting the bundle {} generated from the project {}", bundleLocation, project.getName()); //$NON-NLS-1$ try { managedBundle = bundleContext.installBundle(bundleLocation, Files.asByteSource(jar).openStream()); managedBundle.start(); diff --git a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/CheckCfgUtil.java b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/CheckCfgUtil.java index 5bb04e8d6f..27385e209b 100644 --- a/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/CheckCfgUtil.java +++ b/com.avaloq.tools.ddk.checkcfg.core/src/com/avaloq/tools/ddk/checkcfg/CheckCfgUtil.java @@ -82,7 +82,7 @@ public static Collection getAllPropertyContribut try { contributions.add((ICheckCfgPropertySpecification) element.createExecutableExtension(PROPERTY_EXECUTABLE_EXTENSION_ATTRIBUTE)); } catch (CoreException e) { - LOGGER.warn("Failed to instantiate property from " + element.getContributor(), e); //$NON-NLS-1$ + LOGGER.warn("Failed to instantiate property from {}", element.getContributor(), e); //$NON-NLS-1$ } } } else {