This is an automated email from the ASF dual-hosted git repository. mattsicker pushed a commit to branch feature/3.x/name-alias-provider in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit d6efce81ad217a8d25c687e758eb985882dbccfe Author: Matt Sicker <msic...@apple.com> AuthorDate: Thu Aug 7 14:58:01 2025 -0500 Avoid use of Keys::getName where unneeded --- .../java/org/apache/logging/log4j/plugins/di/KeyTest.java | 11 +++++------ .../java/org/apache/logging/log4j/plugins/di/Key.java | 5 +---- .../logging/log4j/plugins/util/OrderedComparator.java | 15 +++++---------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java index 0bdf724977..77020f6be6 100644 --- a/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java +++ b/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/KeyTest.java @@ -45,9 +45,6 @@ class KeyTest { @Test void forClass() { final Key<AnnotatedClass> key = Key.forClass(AnnotatedClass.class); - assertEquals("namespace", key.getNamespace()); - assertEquals("name", key.getName()); - assertEquals(Named.class, key.getQualifierType()); assertThat(key.getOrder()).isPresent().hasValue(42); assertEquals(AnnotatedClass.class, key.getType()); assertEquals(AnnotatedClass.class, key.getRawType()); @@ -113,6 +110,11 @@ class KeyTest { } static class CustomQualifierNameProvider implements AnnotatedElementNameProvider<CustomQualifier> { + @Override + public Class<CustomQualifier> annotationType() { + return CustomQualifier.class; + } + @Override public Optional<String> getSpecifiedName(final CustomQualifier annotation) { return Optional.of(annotation.value()); @@ -130,9 +132,6 @@ class KeyTest { @Test void classWithCustomQualifierAndNamespace() { final Key<LogicallyAnnotatedClass> key = Key.forClass(LogicallyAnnotatedClass.class); - assertEquals("logical", key.getNamespace()); - assertEquals("class", key.getName()); - assertEquals(CustomQualifier.class, key.getQualifierType()); assertThat(key.getOrder()).isEmpty(); assertEquals(LogicallyAnnotatedClass.class, key.getType()); assertEquals(LogicallyAnnotatedClass.class, key.getRawType()); diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Key.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Key.java index 4afff8e19e..dda0b9eafb 100644 --- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Key.java +++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/di/Key.java @@ -303,10 +303,7 @@ public class Key<T> implements StringBuilderFormattable, Comparable<Key<T>> { * Creates a Key for the class. */ public static <T> Key<T> forClass(final Class<T> clazz) { - final Builder<T> builder = Key.builder(clazz) - .setQualifierType(getQualifierType(clazz)) - .setName(Keys.getName(clazz)) - .setNamespace(Keys.getNamespace(clazz)); + final Builder<T> builder = Key.builder(clazz); AnnotationUtil.getOrder(clazz).ifPresent(builder::setOrder); return builder.get(); } diff --git a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/OrderedComparator.java b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/OrderedComparator.java index 990178873e..08d2e008fa 100644 --- a/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/OrderedComparator.java +++ b/log4j-plugins/src/main/java/org/apache/logging/log4j/plugins/util/OrderedComparator.java @@ -17,19 +17,17 @@ package org.apache.logging.log4j.plugins.util; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.AnnotatedType; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.Comparator; import java.util.OptionalInt; import org.apache.logging.log4j.plugins.Ordered; -import org.apache.logging.log4j.plugins.di.Keys; import org.apache.logging.log4j.plugins.internal.util.AnnotationUtil; import org.apache.logging.log4j.util.Strings; /** - * Comparator for annotated elements using {@link Ordered} followed by their name from {@link Keys#getName}. + * Comparator for annotated elements using {@link Ordered} followed by their element name. */ public class OrderedComparator implements Comparator<AnnotatedElement> { public static final OrderedComparator INSTANCE = new OrderedComparator(); @@ -55,19 +53,16 @@ public class OrderedComparator implements Comparator<AnnotatedElement> { private static String getName(final AnnotatedElement element) { if (element instanceof Class<?> clazz) { - return Keys.getName(clazz); + return clazz.getName(); } if (element instanceof Field field) { - return Keys.getName(field); + return field.getName(); } if (element instanceof Parameter parameter) { - return Keys.getName(parameter); + return parameter.getName(); } if (element instanceof Method method) { - return Keys.getName(method); - } - if (element instanceof AnnotatedType annotatedType) { - return Keys.getName(annotatedType); + return method.getName(); } return Strings.EMPTY; }