Skip to content

Commit 5eb3aa8

Browse files
joaodinissfclaude
andcommitted
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) <noreply@anthropic.com>
1 parent 43928c2 commit 5eb3aa8

11 files changed

Lines changed: 24 additions & 28 deletions

File tree

com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ protected void execute(final IProgressMonitor monitor) throws CoreException, Inv
325325
IFile file = IResourcesSetupUtil.createFile(resourceURI.toPlatformString(true), contents);
326326
getFiles().add(file);
327327
} catch (IOException e) {
328-
LOGGER.error("failed adding file to workspace: " + fileName, e);
328+
LOGGER.error("failed adding file to workspace: {}", fileName, e);
329329
fail("Error adding file " + fileName + " to workspace: " + e.getMessage());
330330
}
331331
}

com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/configuration/CheckConfigurationStoreService.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private String getCode(final IMarker marker) {
9090
try {
9191
return (String) marker.getAttribute(Issue.CODE_KEY);
9292
} catch (CoreException e) {
93-
LOGGER.error("Could not get code for marker: " + marker, e); //$NON-NLS-1$
93+
LOGGER.error("Could not get code for marker: {}", marker, e); //$NON-NLS-1$
9494
return null;
9595
}
9696
}
@@ -99,7 +99,7 @@ private URI getUri(final IMarker marker) {
9999
try {
100100
return URI.createURI((String) marker.getAttribute(Issue.URI_KEY));
101101
} catch (CoreException e) {
102-
LOGGER.error("Could not get uri for marker: " + marker, e); //$NON-NLS-1$
102+
LOGGER.error("Could not get uri for marker: {}", marker, e); //$NON-NLS-1$
103103
return null;
104104
}
105105
}
@@ -111,7 +111,7 @@ private String getLanguage(final URI uri) {
111111
if (resourceServiceProvider != null) {
112112
return resourceServiceProvider.get(Injector.class).getInstance(Key.get(String.class, Names.named(Constants.LANGUAGE_NAME)));
113113
} else {
114-
LOGGER.error("Could not fetch a ResourceServiceProvider for URI: " + uri); //$NON-NLS-1$
114+
LOGGER.error("Could not fetch a ResourceServiceProvider for URI: {}", uri); //$NON-NLS-1$
115115
}
116116
} else {
117117
LOGGER.warn("Could not fetch eResource from issue: URI to problem is null"); //$NON-NLS-1$

com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/context/AbstractCheckContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private boolean checkIssueCodePredicates(final EObject context, final String iss
7373
// caught and disabled by the usual check infrastructure.
7474
} catch (Exception e) {
7575
// CHECKSTYLE:CHECK-ON IllegalCatch
76-
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$
76+
LOGGER.error("Failed to execute predicate {} for issue code {}. Removing predicate for this issue code.", method.getName(), issueCode, e); //$NON-NLS-1$
7777
predicatesForIssueCode.remove(issueCode, method);
7878
}
7979
}

com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/issue/AbstractCheckImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public abstract class AbstractCheckImpl implements ICheckValidatorImpl {
4040
protected void logCheckMethodFailure(final String rule, final EObject object, final Exception e) {
4141
final Throwable cause = e instanceof InvocationTargetException ? ((InvocationTargetException) e).getTargetException() : e;
4242
final Resource res = object.eResource();
43-
LOGGER.error("Permanently disabling check method " + rule + " for context " + object.getClass().getName() + " because of failure" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
44-
+ (res != null ? " in " + res.getURI() : ""), cause); //$NON-NLS-1$ //$NON-NLS-2$
43+
LOGGER.error("Permanently disabling check method {} for context {} because of failure{}", rule, object.getClass().getName(), //$NON-NLS-1$
44+
(res != null ? " in " + res.getURI() : ""), cause); //$NON-NLS-1$ //$NON-NLS-2$
4545
}
4646

4747
/**

com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/label/CheckRuleLabelProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private static Map<String, String> merge(final Stream<? extends Map<String, Stri
109109
final Map<String, String> mergedMap = new HashMap<String, String>();
110110
maps.map(Map::entrySet).flatMap(Set::stream).forEach(entry -> {
111111
if (null != mergedMap.putIfAbsent(entry.getKey(), entry.getValue())) {
112-
LOGGER.warn("Non-unique Check issue code found: " + entry.getKey()); //$NON-NLS-1$
112+
LOGGER.warn("Non-unique Check issue code found: {}", entry.getKey()); //$NON-NLS-1$
113113
}
114114
});
115115
return mergedMap;

com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/validation/AbstractCheckValidator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.eclipse.emf.common.util.DiagnosticChain;
2020
import org.eclipse.emf.ecore.EClass;
2121
import org.eclipse.emf.ecore.EObject;
22-
import org.eclipse.osgi.util.NLS;
2322
import org.eclipse.xtext.validation.AbstractInjectableValidator;
2423

2524
import com.avaloq.tools.ddk.check.runtime.issue.ICheckValidatorImpl;
@@ -83,7 +82,7 @@ protected Iterable<? extends ICheckValidatorImpl> internalCollectValidators(fina
8382
if (language == null) {
8483
throw new IllegalArgumentException("Input language cannot be null"); //$NON-NLS-1$
8584
} else if (injector == null) {
86-
LOGGER.debug(NLS.bind("No injector found for {0}. Could not inject registered validators.", language)); //$NON-NLS-1$
85+
LOGGER.debug("No injector found for {}. Could not inject registered validators.", language); //$NON-NLS-1$
8786
}
8887

8988
final List<ICheckValidatorImpl> result = Lists.newArrayList();
@@ -98,7 +97,7 @@ protected Iterable<? extends ICheckValidatorImpl> internalCollectValidators(fina
9897
// CHECKSTYLE:OFF
9998
} catch (Exception e) {
10099
// CHECKSTYLE:ON
101-
LOGGER.error("failed to inject validator " + validator, e); //$NON-NLS-1$
100+
LOGGER.error("failed to inject validator {}", validator, e); //$NON-NLS-1$
102101
}
103102
}
104103
}

com.avaloq.tools.ddk.check.runtime.ui/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui,
1212
org.eclipse.ui.ide
1313
Bundle-RequiredExecutionEnvironment: JavaSE-21
1414
Bundle-ActivationPolicy: lazy
15-
Import-Package: org.apache.logging.log4j
15+
Import-Package: org.apache.logging.log4j,
16+
org.apache.logging.log4j.util
1617
Export-Package: com.avaloq.tools.ddk.check.runtime.ui.editor,
1718
com.avaloq.tools.ddk.check.runtime.ui.editor.model,
1819
com.avaloq.tools.ddk.check.runtime.ui.quickfix,

com.avaloq.tools.ddk.check.runtime.ui/src/com/avaloq/tools/ddk/check/runtime/ui/validation/CheckMarkerUpdateJob.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*******************************************************************************/
1111
package com.avaloq.tools.ddk.check.runtime.ui.validation;
1212

13-
import java.text.MessageFormat;
1413
import java.util.Collection;
1514
import java.util.Set;
1615

@@ -95,9 +94,7 @@ private IFile getFileFromStorageMapper(final IStorage2UriMapper storage2UriMappe
9594
return (IFile) storage.getFirst();
9695
}
9796
}
98-
if (LOGGER.isDebugEnabled()) {
99-
LOGGER.debug(MessageFormat.format("Could not find storage for URI {0}", fileUri.toString())); //$NON-NLS-1$
100-
}
97+
LOGGER.debug("Could not find storage for URI {}", fileUri::toString); //$NON-NLS-1$
10198
return null;
10299
}
103100

@@ -135,9 +132,7 @@ protected IStatus run(final IProgressMonitor monitor) {
135132
final IResourceServiceProvider serviceProvider = serviceProviderRegistry.getResourceServiceProvider(uri);
136133
if (serviceProvider == null) {
137134
// This may happen for non-Xtext resources in ice entities
138-
if (LOGGER.isDebugEnabled()) {
139-
LOGGER.debug(MessageFormat.format("Could not validate {0}: no resource service provider found", uri.toString())); //$NON-NLS-1$
140-
}
135+
LOGGER.debug("Could not validate {}: no resource service provider found", uri::toString); //$NON-NLS-1$
141136
continue; // Skip to next URI
142137
}
143138

@@ -152,7 +147,7 @@ protected IStatus run(final IProgressMonitor monitor) {
152147
}
153148

154149
if (resourceValidator == null) {
155-
LOGGER.error(MessageFormat.format("Could not validate {0}: no resource validator found", iFile.getName())); //$NON-NLS-1$
150+
LOGGER.error("Could not validate {}: no resource validator found", iFile.getName()); //$NON-NLS-1$
156151
} else if (iFile != null) {
157152
monitor.subTask("loading " + iFile.getName()); //$NON-NLS-1$
158153

@@ -175,11 +170,11 @@ protected IStatus run(final IProgressMonitor monitor) {
175170
// CHECKSTYLE:OFF
176171
} catch (final RuntimeException e) {
177172
// CHECKSTYLE:ON
178-
LOGGER.error(MessageFormat.format("{0} could not be validated.", iFile.getName()), e); //$NON-NLS-1$
173+
LOGGER.error("{} could not be validated.", iFile.getName(), e); //$NON-NLS-1$
179174
} finally {
180175
if (eResource != null) {
181176
validateAndCreateMarkers(resourceValidator, markerCreator, iFile, eResource, monitor);
182-
LOGGER.debug("Validated " + uri); //$NON-NLS-1$
177+
LOGGER.debug("Validated {}", uri); //$NON-NLS-1$
183178
if (loaded) { // NOPMD
184179
// unload any resource that was previously loaded as part of this loop.
185180
eResource.unload();

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckProjectHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
public class CheckProjectHelper {
5353

5454
private static final Logger LOGGER = LogManager.getLogger(CheckProjectHelper.class);
55+
private static final String LOG_PLUGIN_PATH_ERROR = "Could not determine plugin path for catalog {}";
5556

5657
@Inject
5758
private IStorage2UriMapper mapper;
@@ -90,7 +91,7 @@ public String getCatalogPluginPath(final CheckCatalog catalog) {
9091
String result = packageFragment.getElementName().replace('.', '/');
9192
return result + '/' + file.getName();
9293
} catch (JavaModelException e) {
93-
LOGGER.error("Could not determine plugin path for catalog " + catalog.getName(), e);
94+
LOGGER.error(LOG_PLUGIN_PATH_ERROR, catalog.getName(), e);
9495
}
9596
return null;
9697
}
@@ -114,7 +115,7 @@ public String getCatalogQualifiedName(final CheckCatalog catalog) {
114115
final String fileNameWithoutExtension = file.getName().substring(0, file.getName().length() - (file.getFileExtension().length() + 1));
115116
return packageFragment.getElementName() + '.' + fileNameWithoutExtension;
116117
} catch (JavaModelException e) {
117-
LOGGER.error("Could not determine plugin path for catalog " + catalog.getName(), e);
118+
LOGGER.error(LOG_PLUGIN_PATH_ERROR, catalog.getName(), e);
118119
}
119120
return null;
120121
}

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/popup/actions/DeployJob.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,15 @@ protected IStatus run(final IProgressMonitor monitor) {
101101
return new Status(Status.ERROR, Activator.getPluginId(), Messages.DeployJob_CouldNotDeployCheckBundle, e);
102102
}
103103

104-
LOGGER.info(NLS.bind("Generated bundle from project {0} deployed.", project.getName())); //$NON-NLS-1$
104+
LOGGER.info("Generated bundle from project {} deployed.", project.getName()); //$NON-NLS-1$
105105

106106
try {
107107
deployCheckConfiguration();
108108
} catch (DeployException e) {
109109
return new Status(Status.ERROR, Activator.getPluginId(), Messages.DeployJob_CannotDeployMoreThanOneCheckConfiguration, e);
110110
}
111111

112-
LOGGER.info(NLS.bind("Check configuration for project {0} deployed.", project.getName())); //$NON-NLS-1$
112+
LOGGER.info("Check configuration for project {} deployed.", project.getName()); //$NON-NLS-1$
113113

114114
return Status.OK_STATUS;
115115
}
@@ -146,7 +146,7 @@ private void deployCheckBundle() throws DeployException {
146146
}
147147
}
148148

149-
LOGGER.info(NLS.bind("Starting the bundle {0} generated from the project {1}", bundleLocation, project.getName())); //$NON-NLS-1$
149+
LOGGER.info("Starting the bundle {} generated from the project {}", bundleLocation, project.getName()); //$NON-NLS-1$
150150
try {
151151
managedBundle = bundleContext.installBundle(bundleLocation, Files.asByteSource(jar).openStream());
152152
managedBundle.start();

0 commit comments

Comments
 (0)