changeset 393:01f878b94d95

@CompilerControl lists should avoid duplicates, makes them shorter.
author shade
date Wed, 12 Feb 2014 16:03:06 +0400
parents ffe2342401fb
children 545012959ccb
files jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java
diffstat 1 files changed, 16 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java	Wed Feb 12 15:43:55 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/processor/internal/CompilerControlProcessor.java	Wed Feb 12 16:03:06 2014 +0400
@@ -37,12 +37,20 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
 
 public class CompilerControlProcessor implements SubProcessor {
 
     private final List<String> lines = new ArrayList<String>();
-    private final List<Element> defaultForceInline = new ArrayList<Element>();
+    private final Set<Element> defaultForceInline = new TreeSet<Element>(new Comparator<Element>() {
+        @Override
+        public int compare(Element o1, Element o2) {
+            return getName(o1).compareTo(getName(o2));
+        }
+    });
 
     public void defaultForceInline(Element element) {
         defaultForceInline.add(element);
@@ -57,12 +65,12 @@
                 }
 
                 CompilerControl.Mode command = ann.value();
-                addLine(processingEnv, element, command);
+                lines.add(command.command() + "," + getName(element));
             }
 
             for (Element element : defaultForceInline) {
                 if (element.getAnnotation(CompilerControl.class) != null) continue;
-                addLine(processingEnv, element, CompilerControl.Mode.INLINE);
+                lines.add(CompilerControl.Mode.INLINE.command() + "," + getName(element));
             }
         } catch (Throwable t) {
             processingEnv.getMessager().printMessage(Kind.ERROR, "Annotation processor had thrown exception: " + t);
@@ -88,19 +96,15 @@
         }
     }
 
-    private void addLine(ProcessingEnvironment processingEnv, Element element, CompilerControl.Mode command) {
+    private static String getName(Element element) {
         switch (element.getKind()) {
             case CLASS:
-                lines.add(command.command() + "," + ((TypeElement)element).getQualifiedName().toString().replaceAll("\\.", "/") + ".*");
-                break;
+                return ((TypeElement)element).getQualifiedName().toString().replaceAll("\\.", "/") + ".*";
             case METHOD:
-                lines.add(command.command() + "," + ((TypeElement)element.getEnclosingElement()).getQualifiedName().toString().replaceAll("\\.", "/") + "." + element.getSimpleName().toString());
-                break;
+                return ((TypeElement)element.getEnclosingElement()).getQualifiedName().toString().replaceAll("\\.", "/") + "." + element.getSimpleName().toString();
             default:
-                processingEnv.getMessager().printMessage(Kind.ERROR,
-                        "@" + CompilerControl.class.getSimpleName() + " annotation is placed within " +
-                                "unexpected target",
-                        element);
+                throw new GenerationException("@" + CompilerControl.class.getSimpleName() + " annotation is placed within " +
+                                "unexpected target", element);
         }
     }