Skip to content

Commit 64aef31

Browse files
joaodinissfclaude
andcommitted
refactor: convert log calls to parameterized logging in DDK core
Replace string concatenation, NLS.bind, and MessageFormat.format in log calls with parameterized {} placeholders. Use Supplier/method-refs for lazy argument evaluation. Extract duplicate format strings to constants. Add org.apache.logging.log4j.util to OSGi manifest. Modules: xtext, typesystem Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5c3417f commit 64aef31

18 files changed

Lines changed: 41 additions & 57 deletions

com.avaloq.tools.ddk.typesystem/src/com/avaloq/tools/ddk/typesystem/AbstractTypeProvider.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,10 @@ public <E> E get(final Object key, final Resource resource, final Provider<E> pr
154154
@SuppressWarnings("unchecked")
155155
ImmutableLinkedItem<E> linkedItem = (ImmutableLinkedItem<E>) key;
156156
if (!(linkedItem.object instanceof EObject)) {
157-
if (LOGGER.isDebugEnabled()) {
158-
LOGGER.debug("cache skip: " + element); //$NON-NLS-1$
159-
}
157+
LOGGER.debug("cache skip: {}", element); //$NON-NLS-1$
160158
return element;
161159
}
162-
if (LOGGER.isDebugEnabled()) {
163-
LOGGER.debug("cache: " + element); //$NON-NLS-1$
164-
}
160+
LOGGER.debug("cache: {}", element); //$NON-NLS-1$
165161
adapter.set(composedKey, element);
166162
} else {
167163
cacheHit(adapter);
@@ -263,9 +259,7 @@ public IType get() {
263259
return doComputation(t);
264260
}
265261
});
266-
if (LOGGER.isDebugEnabled()) {
267-
LOGGER.debug("cache hit: " + hit[0] + " for: " + t); //$NON-NLS-1$ //$NON-NLS-2$
268-
}
262+
LOGGER.debug("cache hit: {} for: {}", hit[0], t); //$NON-NLS-1$
269263
return result;
270264
} else {
271265
if (computationData.resourceLeftOrCyclic) {

com.avaloq.tools.ddk.typesystem/src/com/avaloq/tools/ddk/typesystem/BuiltInTypeModelAccess.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private synchronized void load() {
117117
// We *do* want to catch any exception here because we are in construction and need to initialize with something
118118
} catch (Exception ex) {
119119
// CHECKSTYLE:CHECK-ON IllegalCatch
120-
LOGGER.error("Error loading metamodel from " + modelURI, ex); //$NON-NLS-1$
120+
LOGGER.error("Error loading metamodel from {}", modelURI, ex); //$NON-NLS-1$
121121
// Create an empty model...
122122
model = BuiltInTypeModelPackage.eINSTANCE.getBuiltInTypeModelFactory().createBuiltInTypeModel();
123123
}
@@ -128,7 +128,7 @@ private synchronized void load() {
128128
if (!Strings.isEmpty(typeName)) {
129129
internalTypesByName.put(typeName, type);
130130
} else {
131-
LOGGER.error("incomplete internal type in " + MODEL_LOCATION); //$NON-NLS-1$
131+
LOGGER.error("incomplete internal type in {}", MODEL_LOCATION); //$NON-NLS-1$
132132
}
133133
}
134134
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Export-Package: com.avaloq.tools.ddk.xtext.build,
4545
com.avaloq.tools.ddk.xtext.tracing,
4646
com.avaloq.tools.ddk.xtext.util,
4747
com.avaloq.tools.ddk.xtext.validation
48-
Import-Package: org.apache.logging.log4j
48+
Import-Package: org.apache.logging.log4j,
49+
org.apache.logging.log4j.util
4950
Automatic-Module-Name: com.avaloq.tools.ddk.xtext
5051

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/formatting/ExtendedFormattingConfigBasedStream.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ private List<ElementLocator> handleParametrizedLocators(final List<ElementLocato
366366
// CHECKSTYLE:OFF if the locator activator fails, simply disable the locator instead of completely failing to format a source
367367
} catch (Exception e) {
368368
// CHECKSTYLE:ON
369-
LOGGER.error(NLS.bind("Failed to calculate the parameter for the paramterized locator for {0}", semanticNodeType), e); //$NON-NLS-1$
369+
LOGGER.error("Failed to calculate the parameter for the parameterized locator for {}", semanticNodeType, e); //$NON-NLS-1$
370370
}
371371
}
372372
}
@@ -432,7 +432,7 @@ private boolean isActive(final IConditionalLocator locator) {
432432
// CHECKSTYLE:OFF if the locator activator fails, simply disable the locator instead of completely failing to format a source
433433
} catch (Exception e) {
434434
// CHECKSTYLE:ON
435-
LOGGER.error(NLS.bind("Failed to execute the locator activator for {0}", semanticNodeType), e); //$NON-NLS-1$
435+
LOGGER.error("Failed to execute the locator activator for {}", semanticNodeType, e); //$NON-NLS-1$
436436
}
437437
}
438438
return isActive;

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/linking/DefaultCrossReferenceHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public boolean exportReference(final EObject context, final EReference reference
6969
return false;
7070
} else if (!target.eIsProxy()) {
7171
if (target.eResource() == null) {
72-
LOGGER.error("Reference from " + EcoreUtil.getURI(context) + " to " + target + " cannot be exported as target is not contained in a resource."); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
72+
LOGGER.error("Reference from {} to {} cannot be exported as target is not contained in a resource.", EcoreUtil.getURI(context), target); //$NON-NLS-1$
7373
return false;
7474
}
7575
return context.eResource() != target.eResource();

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/linking/LazyLinkingResource2.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ public synchronized EObject getEObject(final String uriFragment) {
154154
Triple<EObject, EReference, INode> refInfo = getEncoder().decode(this, uriFragment);
155155
EReference reference = refInfo.getSecond();
156156
EObject context = refInfo.getFirst();
157-
LOGGER.debug("Failed unexpected attempt to resolve reference during indexing " + context.eClass().getName() + "#" //$NON-NLS-1$ //$NON-NLS-2$
158-
+ reference.getName() + " for object " + EcoreUtil.getURI(context), new RuntimeException()); //$NON-NLS-1$
157+
LOGGER.debug("Failed unexpected attempt to resolve reference during indexing {}#{} for object {}", //$NON-NLS-1$
158+
context.eClass().getName(), reference.getName(), EcoreUtil.getURI(context), new RuntimeException());
159159
}
160160
rs.getLoadOptions().put(MARK_UNRESOLVABLE_XREFS, Boolean.TRUE);
161161
}
@@ -172,8 +172,7 @@ public synchronized EObject getEObject(final String uriFragment) {
172172
Triple<EObject, EReference, INode> triple = getEncoder().decode(this, uriFragment);
173173
INode node = triple.getThird();
174174
final String nodeName = getLinkingHelper().getCrossRefNodeAsString(node, true);
175-
LOGGER.error("Resolution of uriFragment '" + uriFragment + "' in the resource '" + this.getURI() + "' node_name " + nodeName //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
176-
+ " line " + node.getStartLine() + " offset " + node.getOffset() + " failed.", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
175+
LOGGER.error("Resolution of uriFragment '{}' in the resource '{}' node_name {} line {} offset {} failed.", uriFragment, this.getURI(), nodeName, node.getStartLine(), node.getOffset(), e); //$NON-NLS-1$
177176
logged = true;
178177
}
179178
// CHECKSTYLE:OFF
@@ -182,7 +181,7 @@ public synchronized EObject getEObject(final String uriFragment) {
182181
// ignore
183182
}
184183
if (!logged) {
185-
LOGGER.error("Resolution of uriFragment '" + uriFragment + "' in the resource '" + this.getURI() + "' failed.", e); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
184+
LOGGER.error("Resolution of uriFragment '{}' in the resource '{}' failed.", uriFragment, this.getURI(), e); //$NON-NLS-1$
186185
}
187186
throw e;
188187
}

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/linking/LinkingService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ private IEObjectDescription safeGetSingleElement(final EObject context, final ER
199199
try {
200200
return getSingleElement(context, ref, qualifiedLinkName);
201201
} catch (Exception e) { // IllegalCatchCheck OFF
202-
LOGGER.error("Exception in getSingleElement for " + qualifiedLinkName.toString() + " at " + EObjectUtil.getLocationString(context), e); //$NON-NLS-1$ //$NON-NLS-2$
202+
LOGGER.error("Exception in getSingleElement for {} at {}", qualifiedLinkName, EObjectUtil.getLocationString(context), e); //$NON-NLS-1$
203203
}
204204
return null;
205205
}

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/modelinference/ExtendableInferredModelAssociator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected void inferTargetModel(final EObject eObject, final IAcceptor<EObject>
3939
// CHECKSTYLE:OFF
4040
} catch (RuntimeException e) {
4141
// CHECKSTYLE:ON
42-
LOGGER.error("Failed to install additional derived state for resource " + eObject.eResource().getURI(), e); //$NON-NLS-1$
42+
LOGGER.error("Failed to install additional derived state for resource {}", eObject.eResource().getURI(), e); //$NON-NLS-1$
4343
}
4444
}
4545

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/modelinference/InferredModelAssociator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public final void installDerivedState(final DerivedStateAwareResource resource,
206206
// CHECKSTYLE:OFF
207207
} catch (RuntimeException e) {
208208
// CHECKSTYLE:ON
209-
LOGGER.error("Failed to install derived state for resource " + resource.getURI(), e); //$NON-NLS-1$
209+
LOGGER.error("Failed to install derived state for resource {}", resource.getURI(), e); //$NON-NLS-1$
210210
} finally {
211211
inferenceStack.pop();
212212
}

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/resource/AbstractCachingResourceDescriptionManager.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public abstract class AbstractCachingResourceDescriptionManager extends DerivedS
6161
/** Class-wide logger. */
6262
private static final Logger LOGGER = LogManager.getLogger(AbstractCachingResourceDescriptionManager.class);
6363

64+
private static final String LOG_AFFECTED_BY = "{} is affected by {}"; //$NON-NLS-1$
65+
6466
/** Cache key for the resource description of a resource. */
6567
public static final String CACHE_KEY = DefaultResourceDescriptionManager.class.getName() + "#getResourceDescription"; //$NON-NLS-1$
6668

@@ -154,9 +156,7 @@ public boolean isAffected(final Collection<Delta> deltas, final IResourceDescrip
154156
final URI deltaURI = delta.getUri();// NOPMD - potentially could be lost due to call on getNew() after
155157
// deleted resources are no longer visible resources so we test them, too.
156158
if (delta.getNew() == null && isReferencedBy(delta, candidate, context)) {
157-
if (LOGGER.isDebugEnabled()) {
158-
LOGGER.debug(candidate.getURI() + " is affected by " + delta.getUri()); //$NON-NLS-1$
159-
}
159+
LOGGER.debug(LOG_AFFECTED_BY, candidate::getURI, delta::getUri);
160160
return true;
161161
}
162162

@@ -165,9 +165,7 @@ public boolean isAffected(final Collection<Delta> deltas, final IResourceDescrip
165165
for (IContainer container : containers) {
166166
if (container.getResourceDescription(deltaURI) != null) {
167167
if (isReferencedBy(delta, candidate, context)) {
168-
if (LOGGER.isDebugEnabled()) { // NOPMD AvoidDeeplyNestedIfStmts
169-
LOGGER.debug(candidate.getURI() + " is affected by " + delta.getUri()); //$NON-NLS-1$
170-
}
168+
LOGGER.debug(LOG_AFFECTED_BY, candidate::getURI, delta::getUri);
171169
return true;
172170
}
173171
break;
@@ -370,9 +368,7 @@ public boolean isAffected(final Delta delta, final IResourceDescription candidat
370368
if (delta.getUri().equals(candidate.getURI())) {
371369
// If the delta is for ourselves, we're always affected; otherwise the dirty state manager may omit to update the editor
372370
// state.
373-
if (LOGGER.isDebugEnabled()) {
374-
LOGGER.debug(delta.getUri() + " is the same as " + candidate.getURI()); //$NON-NLS-1$
375-
}
371+
LOGGER.debug("{} is the same as {}", delta::getUri, candidate::getURI); //$NON-NLS-1$
376372
return true;
377373
}
378374
if (!delta.haveEObjectDescriptionsChanged()) {
@@ -396,15 +392,15 @@ public boolean isAffected(final Delta delta, final IResourceDescription candidat
396392
boolean disjointResolved = Collections.disjoint(resolvedNames, resolvedAndUnresolvedNames.getFirst());
397393
if (!disjointResolved && LOGGER.isDebugEnabled()) {
398394
resolvedNames.retainAll(getImportedNames(candidate));
399-
LOGGER.debug("resolved names imported by " + candidate.getURI() + " are exported by " + delta.getUri() + " intersection:" + resolvedNames.toString()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
395+
LOGGER.debug("resolved names imported by {} are exported by {} intersection:{}", candidate::getURI, delta::getUri, resolvedNames::toString); //$NON-NLS-1$
400396
}
401397
if (!disjointResolved) {
402398
return true;
403399
}
404400
boolean disjointUnresolved = Collections.disjoint(unresolvedNames, resolvedAndUnresolvedNames.getSecond());
405401
if (!disjointUnresolved && LOGGER.isDebugEnabled()) {
406402
unresolvedNames.retainAll(getImportedNames(candidate));
407-
LOGGER.debug("unrevolved names imported by " + candidate.getURI() + " are exported by " + delta.getUri() + " intersection:" + unresolvedNames.toString()); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
403+
LOGGER.debug("unresolved names imported by {} are exported by {} intersection:{}", candidate::getURI, delta::getUri, unresolvedNames::toString); //$NON-NLS-1$
408404
}
409405
return !disjointUnresolved;
410406
}

0 commit comments

Comments
 (0)