logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1585249 - in /logging/log4j/log4j2/trunk/log4j-plugin-processor/src: main/java/org/apache/logging/log4j/core/config/plugins/processor/ test/java/org/apache/logging/log4j/core/config/plugins/processor/
Date Sun, 06 Apr 2014 05:36:30 GMT
Author: mattsicker
Date: Sun Apr  6 05:36:30 2014
New Revision: 1585249

URL: http://svn.apache.org/r1585249
Log:
Fix problem with nested plugin classes.

Modified:
    logging/log4j/log4j2/trunk/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java
    logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/FakePlugin.java
    logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java

Modified: logging/log4j/log4j2/trunk/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java?rev=1585249&r1=1585248&r2=1585249&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-plugin-processor/src/main/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessor.java
Sun Apr  6 05:36:30 2014
@@ -35,6 +35,7 @@ import javax.lang.model.SourceVersion;
 import javax.lang.model.element.Element;
 import javax.lang.model.element.ElementVisitor;
 import javax.lang.model.element.TypeElement;
+import javax.lang.model.util.Elements;
 import javax.lang.model.util.SimpleElementVisitor6;
 import javax.tools.FileObject;
 import org.apache.logging.log4j.core.config.plugins.Plugin;
@@ -62,10 +63,6 @@ public class PluginProcessor extends Abs
 
     private final ConcurrentMap<String, ConcurrentMap<String, PluginEntry>> pluginCategories
=
             new ConcurrentHashMap<String, ConcurrentMap<String, PluginEntry>>();
-    private final ElementVisitor<PluginEntry, Plugin> pluginVisitor =
-            new PluginElementVisitor();
-    private final ElementVisitor<Collection<PluginEntry>, Plugin> pluginAliasesVisitor
=
-            new PluginAliasesElementVisitor();
 
     @Override
     public boolean process(final Set<? extends TypeElement> annotations, final RoundEnvironment
roundEnv) {
@@ -88,6 +85,11 @@ public class PluginProcessor extends Abs
     }
 
     private void collectPlugins(final Iterable<? extends Element> elements) {
+        final Elements elementUtils = processingEnv.getElementUtils();
+        final ElementVisitor<PluginEntry, Plugin> pluginVisitor =
+                new PluginElementVisitor(elementUtils);
+        final ElementVisitor<Collection<PluginEntry>, Plugin> pluginAliasesVisitor
=
+                new PluginAliasesElementVisitor(elementUtils);
         for (final Element element : elements) {
             final Plugin plugin = element.getAnnotation(Plugin.class);
             final PluginEntry entry = element.accept(pluginVisitor, plugin);
@@ -128,6 +130,13 @@ public class PluginProcessor extends Abs
      * ElementVisitor to scan the Plugin annotation.
      */
     private static class PluginElementVisitor extends SimpleElementVisitor6<PluginEntry,
Plugin> {
+
+        private final Elements elements;
+
+        private PluginElementVisitor(final Elements elements) {
+            this.elements = elements;
+        }
+
         @Override
         public PluginEntry visitType(final TypeElement e, final Plugin plugin) {
             if (plugin == null) {
@@ -135,7 +144,7 @@ public class PluginProcessor extends Abs
             }
             final PluginEntry entry = new PluginEntry();
             entry.setKey(plugin.name().toLowerCase());
-            entry.setClassName(e.getQualifiedName().toString());
+            entry.setClassName(elements.getBinaryName(e).toString());
             entry.setName(Plugin.EMPTY.equals(plugin.elementType()) ? plugin.name() : plugin.elementType());
             entry.setPrintable(plugin.printObject());
             entry.setDefer(plugin.deferChildren());
@@ -148,8 +157,12 @@ public class PluginProcessor extends Abs
      * ElementVisitor to scan the PluginAliases annotation.
      */
     private static class PluginAliasesElementVisitor extends SimpleElementVisitor6<Collection<PluginEntry>,
Plugin> {
-        protected PluginAliasesElementVisitor() {
+
+        private final Elements elements;
+
+        private PluginAliasesElementVisitor(final Elements elements) {
             super(Collections.<PluginEntry>emptyList());
+            this.elements = elements;
         }
 
         @Override
@@ -162,7 +175,7 @@ public class PluginProcessor extends Abs
             for (final String alias : aliases.value()) {
                 final PluginEntry entry = new PluginEntry();
                 entry.setKey(alias.toLowerCase());
-                entry.setClassName(e.getQualifiedName().toString());
+                entry.setClassName(elements.getBinaryName(e).toString());
                 entry.setName(Plugin.EMPTY.equals(plugin.elementType()) ? alias : plugin.elementType());
                 entry.setPrintable(plugin.printObject());
                 entry.setDefer(plugin.deferChildren());

Modified: logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/FakePlugin.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/FakePlugin.java?rev=1585249&r1=1585248&r2=1585249&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/FakePlugin.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/FakePlugin.java
Sun Apr  6 05:36:30 2014
@@ -26,4 +26,8 @@ import org.apache.logging.log4j.core.con
 @Plugin(name = "Fake", category = "Test")
 @PluginAliases({"AnotherFake", "StillFake"})
 public class FakePlugin {
+
+    @Plugin(name = "Nested", category = "Test")
+    public static class Nested {
+    }
 }

Modified: logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java?rev=1585249&r1=1585248&r2=1585249&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-plugin-processor/src/test/java/org/apache/logging/log4j/core/config/plugins/processor/PluginProcessorTest.java
Sun Apr  6 05:36:30 2014
@@ -103,9 +103,22 @@ public class PluginProcessorTest {
         assertNotNull("The plugin '" + name.toLowerCase() + "' was not found.", fake);
         assertEquals(FakePlugin.class.getName(), fake.getClassName());
         assertEquals(name.toLowerCase(), fake.getKey());
-        assertEquals("", p.elementType());
+        assertEquals(Plugin.EMPTY, p.elementType());
         assertEquals(name, fake.getName());
         assertEquals(p.printObject(), fake.isPrintable());
         assertEquals(p.deferChildren(), fake.isDefer());
     }
+
+    @Test
+    public void testNestedPlugin() throws Exception {
+        final Plugin p = FakePlugin.Nested.class.getAnnotation(Plugin.class);
+        final PluginEntry nested = pluginCategories.get(p.category()).get(p.name().toLowerCase());
+        assertNotNull(nested);
+        assertEquals(p.name().toLowerCase(), nested.getKey());
+        assertEquals(FakePlugin.Nested.class.getName(), nested.getClassName());
+        assertEquals(p.name(), nested.getName());
+        assertEquals(Plugin.EMPTY, p.elementType());
+        assertEquals(p.printObject(), nested.isPrintable());
+        assertEquals(p.deferChildren(), nested.isDefer());
+    }
 }



Mime
View raw message