Skip to content

Commit 0cfcee8

Browse files
joaodinissfclaude
andcommitted
refactor: convert log calls to parameterized logging in DDK builder/generator/UI
Replace string concatenation and NLS.bind in log calls with parameterized {} placeholders. Use Supplier/method-refs for lazy argument evaluation. Add NOPMD suppressions for ITraceSet.trace() and Supplier method-refs not recognized by PMD. Add org.apache.logging.log4j.util to OSGi manifests. Modules: xtext.builder, xtext.expression, xtext.generator, xtext.ui, xtext.test.core Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a2cd3fe commit 0cfcee8

File tree

13 files changed

+34
-38
lines changed

13 files changed

+34
-38
lines changed

com.avaloq.tools.ddk.xtext.builder/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,6 @@ Export-Package: com.avaloq.tools.ddk.xtext.builder,
1616
com.avaloq.tools.ddk.xtext.builder.resourceloader,
1717
com.avaloq.tools.ddk.xtext.builder.tracing,
1818
com.avaloq.tools.ddk.xtext.extensions
19+
Import-Package: org.apache.logging.log4j,
20+
org.apache.logging.log4j.util
1921
Automatic-Module-Name: com.avaloq.tools.ddk.xtext.builder

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/CachingStateBasedContainerManager.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ public void descriptionsChanged(final Event event) {
122122
public List<IContainer> getVisibleContainers(final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) {
123123
String root = internalGetContainerHandle(desc, resourceDescriptions);
124124
if (root == null) {
125-
if (LOGGER.isDebugEnabled()) {
126-
LOGGER.debug("Cannot find IContainer for: " + desc.getURI()); //$NON-NLS-1$
127-
}
125+
LOGGER.debug("Cannot find IContainer for: {}", desc::getURI); //$NON-NLS-1$
128126
return Collections.emptyList();
129127
}
130128
List<String> handles = getState(resourceDescriptions).getVisibleContainerHandles(root);

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/MonitoredClusteringBuilderState.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public class MonitoredClusteringBuilderState extends ClusteringBuilderState
132132

133133
private static final int COMMIT_WARN_WAIT_SEC = 30;
134134

135-
private static final String FAILED_TO_SAVE_BINARY = "Failed to save binary for "; //$NON-NLS-1$
135+
private static final String FAILED_TO_SAVE_BINARY_LOG = "Failed to save binary for {}"; //$NON-NLS-1$
136136

137137
/** Class-wide logger. */
138138
private static final Logger LOGGER = LogManager.getLogger(MonitoredClusteringBuilderState.class);
@@ -642,7 +642,7 @@ public boolean isCanceled() {
642642
final long memoryDelta = Runtime.getRuntime().freeMemory() - initialMemory;
643643
final int resourceSetSizeDelta = resourceSet.getResources().size() - initialResourceSetSize;
644644
final long timeDelta = System.nanoTime() - initialTime;
645-
traceSet.trace(ResourceLinkingMemoryEvent.class, changedURI, memoryDelta, resourceSetSizeDelta, timeDelta);
645+
traceSet.trace(ResourceLinkingMemoryEvent.class, changedURI, memoryDelta, resourceSetSizeDelta, timeDelta); // NOPMD GuardLogStatement - not a logger call
646646
}
647647
watchdog.reportWorkEnded(index, index + queue.size());
648648
}
@@ -727,9 +727,9 @@ protected void storeBinaryResource(final Resource resource, final BuildData buil
727727
} catch (RejectedExecutionException e) {
728728
String errorMessage = "Unable to submit a new task to store a binary resource."; //$NON-NLS-1$
729729
if (binaryStorageExecutor.isShutdown()) {
730-
LOGGER.info(errorMessage + " The worker pool has shut down."); //$NON-NLS-1$
730+
LOGGER.info("{} The worker pool has shut down.", errorMessage); //$NON-NLS-1$
731731
} else {
732-
LOGGER.error(errorMessage + " Exception information: " + e.getMessage()); //$NON-NLS-1$
732+
LOGGER.error("{} Exception information: {}", errorMessage, e.getMessage()); //$NON-NLS-1$
733733
}
734734
}
735735
}
@@ -751,12 +751,12 @@ protected void doStoreBinaryResource(final Resource resource, final BuildData bu
751751
LOGGER.info("saving binary taking longer than expected ({} ms): {}", elapsedMillis, resource.getURI()); //$NON-NLS-1$
752752
}
753753
} catch (WrappedException ex) {
754-
LOGGER.error(FAILED_TO_SAVE_BINARY + resource.getURI(), ex.exception());
754+
LOGGER.error(FAILED_TO_SAVE_BINARY_LOG, resource.getURI(), ex.exception());
755755

756756
// CHECKSTYLE:OFF
757757
} catch (Throwable ex) {
758758
// CHECKSTYLE:ON
759-
LOGGER.error(FAILED_TO_SAVE_BINARY + resource.getURI(), ex);
759+
LOGGER.error(FAILED_TO_SAVE_BINARY_LOG, resource.getURI(), ex);
760760
}
761761
}
762762

@@ -1205,7 +1205,7 @@ protected void flushChanges(final ResourceDescriptionsData newData) {
12051205
}
12061206
long flushTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - time);
12071207
if (flushTime > COMMIT_WARN_WAIT_SEC) {
1208-
LOGGER.warn("Flushing of the database changes took " + flushTime + " seconds."); //$NON-NLS-1$//$NON-NLS-2$
1208+
LOGGER.warn("Flushing of the database changes took {} seconds.", flushTime); //$NON-NLS-1$
12091209
}
12101210
}
12111211
}
@@ -1299,7 +1299,7 @@ protected void queueAffectedResources(final Set<URI> allRemainingURIs, final IRe
12991299
// CHECKSTYLE:CHECK-OFF IllegalCatch - Failing here means the build fails completely
13001300
} catch (Throwable t) {
13011301
// CHECKSTYLE:CHECK-ON IllegalCatch
1302-
LOGGER.warn(manager.getClass().getSimpleName() + " failed to enqueue the affected resources", t); //$NON-NLS-1$
1302+
LOGGER.warn("{} failed to enqueue the affected resources", manager.getClass().getSimpleName(), t); //$NON-NLS-1$
13031303
}
13041304
progressMonitor.worked(1);
13051305
if (allRemainingURIs.isEmpty()) {

com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/RebuildingXtextBuilder.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,9 @@ protected IProject[] build(final int kind, final Map args, final IProgressMonito
161161
@Override
162162
protected void doBuild(final ToBeBuilt toBeBuilt, final IProgressMonitor monitor, final BuildType type) throws CoreException {
163163
if (!toBeBuilt.getToBeDeleted().isEmpty() || !toBeBuilt.getToBeUpdated().isEmpty()) {
164-
if (LOGGER.isDebugEnabled()) {
165-
LOGGER.debug("Starting " + type.name() + " build:" + "\ndeleted(" + toBeBuilt.getToBeDeleted().size() + ")=" + toBeBuilt.getToBeDeleted().toString()
166-
+ "\nupdated(" + toBeBuilt.getToBeUpdated().size() + ")=" + toBeBuilt.getToBeUpdated().toString());
167-
}
164+
LOGGER.debug("Starting {} build:\ndeleted({})={}\nupdated({})={}", type::name, // NOPMD GuardLogStatement - all args are Suppliers
165+
toBeBuilt.getToBeDeleted()::size, toBeBuilt.getToBeDeleted()::toString,
166+
toBeBuilt.getToBeUpdated()::size, toBeBuilt.getToBeUpdated()::toString);
168167

169168
SubMonitor progress = SubMonitor.convert(monitor, 1 + 1 + 1); // build + participant + rebuild
170169

@@ -194,11 +193,9 @@ protected void doBuild(final ToBeBuilt toBeBuilt, final IProgressMonitor monitor
194193
}
195194
resourceSet.getResources().clear();
196195
resourceSet.eAdapters().clear();
197-
if (LOGGER.isDebugEnabled()) {
198-
LOGGER.debug("Build done.");
199-
}
200-
} else if (LOGGER.isDebugEnabled()) {
201-
LOGGER.debug("Ignoring empty " + type.name() + " build.");
196+
LOGGER.debug("Build done.");
197+
} else {
198+
LOGGER.debug("Ignoring empty {} build.", type::name);
202199
}
203200
}
204201
}

com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/CompilationContext.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public boolean isType(final String name) {
223223
public String javaType(final String name) {
224224
Type type = findType(name);
225225
if (type == null) {
226-
LOGGER.warn("No type found for " + name);
226+
LOGGER.warn("No type found for {}", name);
227227
return name;
228228
}
229229
return javaType(type);
@@ -320,7 +320,7 @@ public String getQualifiedTypeName(final String typeName) {
320320
}
321321
// CHECKSTYLE:OFF
322322
} catch (final Exception e) {
323-
LOGGER.warn(NLS.bind("Could not determine qualified type name for {0}", typeName), e); //$NON-NLS-1$
323+
LOGGER.warn("Could not determine qualified type name for {}", typeName, e); //$NON-NLS-1$
324324
}
325325
// CHECKSTYLE:ON
326326

@@ -343,7 +343,7 @@ public EClass getEClass(final Type type) {
343343
// CHECKSTYLE:OFF
344344
} catch (Exception e) {
345345
// CHECKSTYLE:ON
346-
LOGGER.error("Could not determine EClass for " + type, e);
346+
LOGGER.error("Could not determine EClass for {}", type, e);
347347
}
348348
}
349349
return null;

com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/GenModelUtil2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public static GenModel findGenModel(final EModelElement eModelElement, final Res
127127
// CHECKSTYLE:CHECK-OFF IllegalCatch
128128
} catch (RuntimeException e) {
129129
// CHECKSTYLE:CHECK-ON IllegalCatch
130-
LOGGER.error(NLS.bind("Exception in findGenModel ({0})", eModelElement), e); //$NON-NLS-1$
130+
LOGGER.error("Exception in findGenModel ({})", eModelElement, e); //$NON-NLS-1$
131131
}
132132

133133
return null;

com.avaloq.tools.ddk.xtext.generator/META-INF/MANIFEST.MF

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,7 @@ Export-Package: com.avaloq.tools.ddk.xtext.generator.builder,
3535
com.avaloq.tools.ddk.xtext.generator.resourceFactory,
3636
com.avaloq.tools.ddk.xtext.generator.ide.contentAssist,
3737
com.avaloq.tools.ddk.xtext.generator.parser.common
38+
Import-Package: org.apache.logging.log4j,
39+
org.apache.logging.log4j.util
3840
Eclipse-ExtensibleAPI: true
3941
Automatic-Module-Name: com.avaloq.tools.ddk.xtext.generator

com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void printViolations(final String srcGenPath) {
254254
}
255255
if (problemsReported) {
256256
LOGGER.error("REJECTED KEYWORDS BY ID RULES DETECTED.");
257-
LOGGER.error("Read " + fileName + " !");
257+
LOGGER.error("Read {} !", fileName);
258258
writer.println();
259259
writer.println("(!) Problems were detected: neither reserved words nor keywords, but rejected by identifier rules");
260260
writer.println("Use " + Path.fromPortableString(getReportFileName(srcGenPath)).lastSegment() + " to find out why these words are keywords.");
@@ -448,7 +448,7 @@ public void printReport(final String srcGenPath) {
448448
PrintWriter docuWriter = new PrintWriter(new File(docuFileName), StandardCharsets.UTF_8);
449449
docuWriter.print(new CombinedGrammarReportBuilder(grammarExtensions).getDocumentation(grammar, parserRules, enumRules));
450450
docuWriter.close();
451-
LOGGER.info("report on keywords is written into " + fileName);
451+
LOGGER.info("report on keywords is written into {}", fileName);
452452
} catch (IOException e) {
453453
throw new UncheckedIOException(e);
454454
}

com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/util/CustomClassAwareEcoreGenerator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public JControlModel getJControlModel() {
103103
return jControlModel;
104104
}
105105
};
106-
LOGGER.info("generating EMF code for " + this.genModel);
106+
LOGGER.info("generating EMF code for {}", this.genModel);
107107
generator.getAdapterFactoryDescriptorRegistry().addDescriptor(GenModelPackage.eNS_URI, new GeneratorAdapterDescriptor(getTypeMapper(), getLineDelimiter()));
108108
generator.setInput(model);
109109

@@ -170,7 +170,7 @@ public void preInvoke() {
170170
}
171171
}
172172
}
173-
LOGGER.info("Registered source path to discover custom classes: " + Joiner.on(", ").join(this.srcPaths));
173+
LOGGER.info("Registered source path to discover custom classes: {}", () -> Joiner.on(", ").join(this.srcPaths));
174174
}
175175

176176
/**
@@ -187,8 +187,7 @@ private void addSourcePathForPlugin(final String pluginId) {
187187
}
188188
URI createURI = URI.createURI(path);
189189
if (!URIConverter.INSTANCE.exists(createURI, null)) {
190-
LOGGER.warn("Cannot access path '" + path
191-
+ "'. Make sure to checkout all parent languages before running the workflow. Otherwise custom implementations (*ImplCustom) will not be considered.");
190+
LOGGER.warn("Cannot access path '{}'. Make sure to checkout all parent languages before running the workflow. Otherwise custom implementations (*ImplCustom) will not be considered.", path);
192191
}
193192
this.srcPaths.add(path);
194193
}

com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/generator/AbstractGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/**
6161
* A base class for xtext generator tests. Allows creating a project and adding files.
6262
*/
63-
@SuppressWarnings({"PMD.AbstractClassWithoutAbstractMethod", "restriction", "nls"})
63+
@SuppressWarnings({"PMD.AbstractClassWithoutAbstractMethod", "nls"})
6464
public abstract class AbstractGeneratorTest {
6565
private static final String MESSAGE_GENERATED_FILE_MUST_EXIST = "Generated file ''{0}'' must exist.";
6666
private static final String MESSAGE_GENERATED_CODE_MUST_BE_CORRECT = "Generated contents of ''{0}'' must be correct.";
@@ -320,7 +320,7 @@ protected void execute(final IProgressMonitor monitor) throws CoreException, Inv
320320
URI resourceURI = URI.createPlatformResourceURI(getFullFileName(projectName, outputFileName), true);
321321
IResourcesSetupUtil.createFile(resourceURI.toPlatformString(true), contents);
322322
} catch (IOException e) {
323-
LOGGER.error("failed adding file to workspace: " + outputFileName, e); //$NON-NLS-1$
323+
LOGGER.error("failed adding file to workspace: {}", outputFileName, e); //$NON-NLS-1$
324324
Assert.fail("Error adding file " + outputFileName + " to workspace: " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
325325
}
326326
}

0 commit comments

Comments
 (0)