From 1d43e4753fed8f5d80ad81d36e0b3a1831983138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dinis=20Ferreira?= Date: Mon, 6 Apr 2026 22:23:17 +0200 Subject: [PATCH] refactor: convert log calls to parameterized logging in DDK builder/generator/UI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces string concatenation, `NLS.bind`, and `MessageFormat.format` in `LOGGER.x(...)` calls with parameterized `{}` placeholders, using `Supplier`/method-refs for lazy argument evaluation. Adds `org.apache.logging.log4j.util` to OSGi manifests for the `Supplier` import, consolidating with the existing `Import-Package` directive (each affected manifest had a duplicate `Import-Package:` header that this fixes). Drops the dead `org.apache.log4j` (Log4j 1) import from `xtext.builder`'s manifest — no source references it. Modules touched: `xtext.builder`, `xtext.generator`, `xtext.ui`. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../META-INF/MANIFEST.MF | 3 ++- .../CachingStateBasedContainerManager.java | 4 +--- .../builder/MonitoredClusteringBuilderState.java | 16 ++++++++-------- .../xtext/builder/RebuildingXtextBuilder.java | 15 ++++++--------- .../expression/generator/CompilationContext.java | 6 +++--- .../expression/generator/GenModelUtil2.java | 2 +- .../META-INF/MANIFEST.MF | 3 ++- .../parser/antlr/KeywordAnalysisHelper.java | 4 ++-- .../util/CustomClassAwareEcoreGenerator.java | 7 +++---- .../META-INF/MANIFEST.MF | 3 ++- .../model/ResponsiveXtextDocumentProvider.java | 6 +----- .../ddk/xtext/ui/util/RuntimeProjectUtil.java | 2 +- 12 files changed, 32 insertions(+), 39 deletions(-) diff --git a/com.avaloq.tools.ddk.xtext.builder/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.xtext.builder/META-INF/MANIFEST.MF index e467650ea9..61d0ff8259 100644 --- a/com.avaloq.tools.ddk.xtext.builder/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.xtext.builder/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Require-Bundle: org.eclipse.xtext.builder, com.avaloq.tools.ddk.xtext, org.eclipse.xtext.common.types.ui Bundle-RequiredExecutionEnvironment: JavaSE-21 -Import-Package: org.apache.logging.log4j, org.apache.log4j +Import-Package: org.apache.logging.log4j, + org.apache.logging.log4j.util Export-Package: com.avaloq.tools.ddk.xtext.builder, com.avaloq.tools.ddk.xtext.builder.layered, com.avaloq.tools.ddk.xtext.builder.resourceloader, diff --git a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/CachingStateBasedContainerManager.java b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/CachingStateBasedContainerManager.java index c61ad8844b..c8769ea63f 100644 --- a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/CachingStateBasedContainerManager.java +++ b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/CachingStateBasedContainerManager.java @@ -122,9 +122,7 @@ public void descriptionsChanged(final Event event) { public List getVisibleContainers(final IResourceDescription desc, final IResourceDescriptions resourceDescriptions) { String root = internalGetContainerHandle(desc, resourceDescriptions); if (root == null) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Cannot find IContainer for: " + desc.getURI()); //$NON-NLS-1$ - } + LOGGER.debug("Cannot find IContainer for: {}", desc::getURI); //$NON-NLS-1$ return Collections.emptyList(); } List handles = getState(resourceDescriptions).getVisibleContainerHandles(root); diff --git a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/MonitoredClusteringBuilderState.java b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/MonitoredClusteringBuilderState.java index 065bd47624..c5cb389fb3 100644 --- a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/MonitoredClusteringBuilderState.java +++ b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/MonitoredClusteringBuilderState.java @@ -132,7 +132,7 @@ public class MonitoredClusteringBuilderState extends ClusteringBuilderState private static final int COMMIT_WARN_WAIT_SEC = 30; - private static final String FAILED_TO_SAVE_BINARY = "Failed to save binary for "; //$NON-NLS-1$ + private static final String FAILED_TO_SAVE_BINARY_LOG = "Failed to save binary for {}"; //$NON-NLS-1$ /** Class-wide logger. */ private static final Logger LOGGER = LogManager.getLogger(MonitoredClusteringBuilderState.class); @@ -642,7 +642,7 @@ public boolean isCanceled() { final long memoryDelta = Runtime.getRuntime().freeMemory() - initialMemory; final int resourceSetSizeDelta = resourceSet.getResources().size() - initialResourceSetSize; final long timeDelta = System.nanoTime() - initialTime; - traceSet.trace(ResourceLinkingMemoryEvent.class, changedURI, memoryDelta, resourceSetSizeDelta, timeDelta); + traceSet.trace(ResourceLinkingMemoryEvent.class, changedURI, memoryDelta, resourceSetSizeDelta, timeDelta); // NOPMD GuardLogStatement - not a logger call } watchdog.reportWorkEnded(index, index + queue.size()); } @@ -727,9 +727,9 @@ protected void storeBinaryResource(final Resource resource, final BuildData buil } catch (RejectedExecutionException e) { String errorMessage = "Unable to submit a new task to store a binary resource."; //$NON-NLS-1$ if (binaryStorageExecutor.isShutdown()) { - LOGGER.info(errorMessage + " The worker pool has shut down."); //$NON-NLS-1$ + LOGGER.info("{} The worker pool has shut down.", errorMessage); //$NON-NLS-1$ } else { - LOGGER.error(errorMessage + " Exception information: " + e.getMessage()); //$NON-NLS-1$ + LOGGER.error("{} Exception information: {}", errorMessage, e.getMessage()); //$NON-NLS-1$ } } } @@ -751,12 +751,12 @@ protected void doStoreBinaryResource(final Resource resource, final BuildData bu LOGGER.info("saving binary taking longer than expected ({} ms): {}", elapsedMillis, resource.getURI()); //$NON-NLS-1$ } } catch (WrappedException ex) { - LOGGER.error(FAILED_TO_SAVE_BINARY + resource.getURI(), ex.exception()); + LOGGER.error(FAILED_TO_SAVE_BINARY_LOG, resource.getURI(), ex.exception()); // CHECKSTYLE:OFF } catch (Throwable ex) { // CHECKSTYLE:ON - LOGGER.error(FAILED_TO_SAVE_BINARY + resource.getURI(), ex); + LOGGER.error(FAILED_TO_SAVE_BINARY_LOG, resource.getURI(), ex); } } @@ -1205,7 +1205,7 @@ protected void flushChanges(final ResourceDescriptionsData newData) { } long flushTime = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis() - time); if (flushTime > COMMIT_WARN_WAIT_SEC) { - LOGGER.warn("Flushing of the database changes took " + flushTime + " seconds."); //$NON-NLS-1$//$NON-NLS-2$ + LOGGER.warn("Flushing of the database changes took {} seconds.", flushTime); //$NON-NLS-1$ } } } @@ -1299,7 +1299,7 @@ protected void queueAffectedResources(final Set allRemainingURIs, final IRe // CHECKSTYLE:CHECK-OFF IllegalCatch - Failing here means the build fails completely } catch (Throwable t) { // CHECKSTYLE:CHECK-ON IllegalCatch - LOGGER.warn(manager.getClass().getSimpleName() + " failed to enqueue the affected resources", t); //$NON-NLS-1$ + LOGGER.warn("{} failed to enqueue the affected resources", manager.getClass().getSimpleName(), t); //$NON-NLS-1$ } progressMonitor.worked(1); if (allRemainingURIs.isEmpty()) { diff --git a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/RebuildingXtextBuilder.java b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/RebuildingXtextBuilder.java index aaece21560..00333d8fd4 100644 --- a/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/RebuildingXtextBuilder.java +++ b/com.avaloq.tools.ddk.xtext.builder/src/com/avaloq/tools/ddk/xtext/builder/RebuildingXtextBuilder.java @@ -161,10 +161,9 @@ protected IProject[] build(final int kind, final Map args, final IProgressMonito @Override protected void doBuild(final ToBeBuilt toBeBuilt, final IProgressMonitor monitor, final BuildType type) throws CoreException { if (!toBeBuilt.getToBeDeleted().isEmpty() || !toBeBuilt.getToBeUpdated().isEmpty()) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Starting " + type.name() + " build:" + "\ndeleted(" + toBeBuilt.getToBeDeleted().size() + ")=" + toBeBuilt.getToBeDeleted().toString() - + "\nupdated(" + toBeBuilt.getToBeUpdated().size() + ")=" + toBeBuilt.getToBeUpdated().toString()); - } + LOGGER.debug("Starting {} build:\ndeleted({})={}\nupdated({})={}", type::name, // NOPMD GuardLogStatement - all args are Suppliers + toBeBuilt.getToBeDeleted()::size, toBeBuilt.getToBeDeleted()::toString, + toBeBuilt.getToBeUpdated()::size, toBeBuilt.getToBeUpdated()::toString); SubMonitor progress = SubMonitor.convert(monitor, 1 + 1 + 1); // build + participant + rebuild @@ -194,11 +193,9 @@ protected void doBuild(final ToBeBuilt toBeBuilt, final IProgressMonitor monitor } resourceSet.getResources().clear(); resourceSet.eAdapters().clear(); - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Build done."); - } - } else if (LOGGER.isDebugEnabled()) { - LOGGER.debug("Ignoring empty " + type.name() + " build."); + LOGGER.debug("Build done."); + } else { + LOGGER.debug("Ignoring empty {} build.", type::name); } } } diff --git a/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/CompilationContext.java b/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/CompilationContext.java index 57002584e7..5fe6882a82 100644 --- a/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/CompilationContext.java +++ b/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/CompilationContext.java @@ -223,7 +223,7 @@ public boolean isType(final String name) { public String javaType(final String name) { Type type = findType(name); if (type == null) { - LOGGER.warn("No type found for " + name); + LOGGER.warn("No type found for {}", name); return name; } return javaType(type); @@ -320,7 +320,7 @@ public String getQualifiedTypeName(final String typeName) { } // CHECKSTYLE:OFF } catch (final Exception e) { - LOGGER.warn(NLS.bind("Could not determine qualified type name for {0}", typeName), e); //$NON-NLS-1$ + LOGGER.warn("Could not determine qualified type name for {}", typeName, e); //$NON-NLS-1$ } // CHECKSTYLE:ON @@ -343,7 +343,7 @@ public EClass getEClass(final Type type) { // CHECKSTYLE:OFF } catch (Exception e) { // CHECKSTYLE:ON - LOGGER.error("Could not determine EClass for " + type, e); + LOGGER.error("Could not determine EClass for {}", type, e); } } return null; diff --git a/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/GenModelUtil2.java b/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/GenModelUtil2.java index a6558d5b36..3f4e77d852 100644 --- a/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/GenModelUtil2.java +++ b/com.avaloq.tools.ddk.xtext.expression/src/com/avaloq/tools/ddk/xtext/expression/generator/GenModelUtil2.java @@ -127,7 +127,7 @@ public static GenModel findGenModel(final EModelElement eModelElement, final Res // CHECKSTYLE:CHECK-OFF IllegalCatch } catch (RuntimeException e) { // CHECKSTYLE:CHECK-ON IllegalCatch - LOGGER.error(NLS.bind("Exception in findGenModel ({0})", eModelElement), e); //$NON-NLS-1$ + LOGGER.error("Exception in findGenModel ({})", eModelElement, e); //$NON-NLS-1$ } return null; diff --git a/com.avaloq.tools.ddk.xtext.generator/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.xtext.generator/META-INF/MANIFEST.MF index 9df5066465..93bca8bfeb 100644 --- a/com.avaloq.tools.ddk.xtext.generator/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.xtext.generator/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.jface, org.eclipse.jdt.core, org.eclipse.compare, org.eclipse.xtext.xbase -Import-Package: org.apache.logging.log4j +Import-Package: org.apache.logging.log4j, + org.apache.logging.log4j.util Export-Package: com.avaloq.tools.ddk.xtext.generator.builder, com.avaloq.tools.ddk.xtext.generator.ecore, com.avaloq.tools.ddk.xtext.generator.expression, diff --git a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java index df2f1f457c..a92cb100ef 100644 --- a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java +++ b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/parser/antlr/KeywordAnalysisHelper.java @@ -254,7 +254,7 @@ public void printViolations(final String srcGenPath) { } if (problemsReported) { LOGGER.error("REJECTED KEYWORDS BY ID RULES DETECTED."); - LOGGER.error("Read " + fileName + " !"); + LOGGER.error("Read {} !", fileName); writer.println(); writer.println("(!) Problems were detected: neither reserved words nor keywords, but rejected by identifier rules"); 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) { PrintWriter docuWriter = new PrintWriter(new File(docuFileName), StandardCharsets.UTF_8); docuWriter.print(new CombinedGrammarReportBuilder(grammarExtensions).getDocumentation(grammar, parserRules, enumRules)); docuWriter.close(); - LOGGER.info("report on keywords is written into " + fileName); + LOGGER.info("report on keywords is written into {}", fileName); } catch (IOException e) { throw new UncheckedIOException(e); } diff --git a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/util/CustomClassAwareEcoreGenerator.java b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/util/CustomClassAwareEcoreGenerator.java index bd7042e350..e33d519c83 100644 --- a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/util/CustomClassAwareEcoreGenerator.java +++ b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/util/CustomClassAwareEcoreGenerator.java @@ -103,7 +103,7 @@ public JControlModel getJControlModel() { return jControlModel; } }; - LOGGER.info("generating EMF code for " + this.genModel); + LOGGER.info("generating EMF code for {}", this.genModel); generator.getAdapterFactoryDescriptorRegistry().addDescriptor(GenModelPackage.eNS_URI, new GeneratorAdapterDescriptor(getTypeMapper(), getLineDelimiter())); generator.setInput(model); @@ -170,7 +170,7 @@ public void preInvoke() { } } } - LOGGER.info("Registered source path to discover custom classes: " + Joiner.on(", ").join(this.srcPaths)); + LOGGER.info("Registered source path to discover custom classes: {}", () -> Joiner.on(", ").join(this.srcPaths)); } /** @@ -187,8 +187,7 @@ private void addSourcePathForPlugin(final String pluginId) { } URI createURI = URI.createURI(path); if (!URIConverter.INSTANCE.exists(createURI, null)) { - LOGGER.warn("Cannot access path '" + path - + "'. Make sure to checkout all parent languages before running the workflow. Otherwise custom implementations (*ImplCustom) will not be considered."); + 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); } this.srcPaths.add(path); } diff --git a/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF b/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF index ab4357c564..783ec2f6aa 100644 --- a/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF +++ b/com.avaloq.tools.ddk.xtext.ui/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: com.avaloq.tools.ddk.xtext, com.google.guava, com.avaloq.tools.ddk.xtext.ide, com.avaloq.tools.ddk -Import-Package: org.apache.logging.log4j +Import-Package: org.apache.logging.log4j, + org.apache.logging.log4j.util Export-Package: com.avaloq.tools.ddk.xtext.ui, com.avaloq.tools.ddk.xtext.ui.editor, com.avaloq.tools.ddk.xtext.ui.editor.findrefs, diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/model/ResponsiveXtextDocumentProvider.java b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/model/ResponsiveXtextDocumentProvider.java index a16be18a0a..9571bd8964 100644 --- a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/model/ResponsiveXtextDocumentProvider.java +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/editor/model/ResponsiveXtextDocumentProvider.java @@ -19,7 +19,6 @@ import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; -import org.eclipse.osgi.util.NLS; import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.eclipse.xtext.Constants; import org.eclipse.xtext.ui.editor.model.XtextDocument; @@ -81,11 +80,8 @@ protected void disconnected() { * the event */ @Override - @SuppressWarnings("PMD.UnnecessaryVarargsArrayCreation") public void propertyChange(final PropertyChangeEvent event) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(NLS.bind("Preference Change: {0} => {1} -> {2}", new Object[] {event.getProperty(), event.getOldValue(), event.getNewValue()})); //$NON-NLS-1$ - } + LOGGER.debug("Preference Change: {} => {} -> {}", event::getProperty, event::getOldValue, event::getNewValue); //$NON-NLS-1$ for (Iterator i = getConnectedElements(); i.hasNext();) { ((XtextDocument) getDocument(i.next())).checkAndUpdateAnnotations(); diff --git a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/util/RuntimeProjectUtil.java b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/util/RuntimeProjectUtil.java index 7731027edd..55bb1553c5 100644 --- a/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/util/RuntimeProjectUtil.java +++ b/com.avaloq.tools.ddk.xtext.ui/src/com/avaloq/tools/ddk/xtext/ui/util/RuntimeProjectUtil.java @@ -62,7 +62,7 @@ public boolean apply(final Pair input) { return (IFile) fileStorage.getFirst(); } catch (NoSuchElementException e) { - LOGGER.debug("Cannot find file storage for " + uri); //$NON-NLS-1$ + LOGGER.debug("Cannot find file storage for {}", uri); //$NON-NLS-1$ return null; } }