changeset 22754:94a6bb5a58f2

OptionValues should be public or package
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Wed, 16 Dec 2015 20:18:20 -0800
parents 8c8c7e8b7ab2
children 0b9cc0259f5a
files jvmci/jdk.vm.ci.options.processor/src/jdk/vm/ci/options/processor/OptionProcessor.java
diffstat 1 files changed, 10 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/jvmci/jdk.vm.ci.options.processor/src/jdk/vm/ci/options/processor/OptionProcessor.java	Wed Dec 16 16:08:05 2015 -0800
+++ b/jvmci/jdk.vm.ci.options.processor/src/jdk/vm/ci/options/processor/OptionProcessor.java	Wed Dec 16 20:18:20 2015 -0800
@@ -79,6 +79,10 @@
             processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be static", element);
             return;
         }
+        if (element.getModifiers().contains(Modifier.PRIVATE)) {
+            processingEnv.getMessager().printMessage(Kind.ERROR, "Option field cannot be private", element);
+            return;
+        }
 
         Option annotation = element.getAnnotation(Option.class);
         assert annotation != null;
@@ -108,6 +112,10 @@
             processingEnv.getMessager().printMessage(Kind.ERROR, "Option field must be static", element);
             return;
         }
+        if (field.getModifiers().contains(Modifier.PRIVATE)) {
+            processingEnv.getMessager().printMessage(Kind.ERROR, "Option field cannot be private", element);
+            return;
+        }
 
         String help = annotation.help();
         if (help.length() != 0) {
@@ -187,7 +195,6 @@
 
             String desc = OptionDescriptor.class.getSimpleName();
 
-            boolean needPrivateFieldAccessor = false;
             int i = 0;
             Collections.sort(info.options);
 
@@ -203,8 +210,7 @@
                 String name = option.name;
                 String optionValue;
                 if (option.field.getModifiers().contains(Modifier.PRIVATE)) {
-                    needPrivateFieldAccessor = true;
-                    optionValue = "field(" + option.declaringClass + ".class, \"" + option.field.getSimpleName() + "\")";
+                    throw new InternalError();
                 } else {
                     optionValue = option.declaringClass + "." + option.field.getSimpleName();
                 }
@@ -230,8 +236,7 @@
             for (OptionInfo option : info.options) {
                 String optionValue;
                 if (option.field.getModifiers().contains(Modifier.PRIVATE)) {
-                    needPrivateFieldAccessor = true;
-                    optionValue = "field(" + option.declaringClass + ".class, \"" + option.field.getSimpleName() + "\")";
+                    throw new InternalError();
                 } else {
                     optionValue = option.declaringClass + "." + option.field.getSimpleName();
                 }
@@ -248,17 +253,6 @@
             out.println("        // CheckStyle: resume line length check");
             out.println("        return options.iterator();");
             out.println("    }");
-            if (needPrivateFieldAccessor) {
-                out.println("    private static " + OptionValue.class.getSimpleName() + "<?> field(Class<?> declaringClass, String fieldName) {");
-                out.println("        try {");
-                out.println("            java.lang.reflect.Field field = declaringClass.getDeclaredField(fieldName);");
-                out.println("            field.setAccessible(true);");
-                out.println("            return (" + OptionValue.class.getSimpleName() + "<?>) field.get(null);");
-                out.println("        } catch (Exception e) {");
-                out.println("            throw (InternalError) new InternalError().initCause(e);");
-                out.println("        }");
-                out.println("    }");
-            }
             out.println("}");
         }
     }