< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Target.java

Print this page




  32 import com.sun.tools.javac.util.*;
  33 
  34 import static com.sun.tools.javac.main.Option.TARGET;
  35 
  36 /** The classfile version target.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  */
  43 public enum Target {
  44     JDK1_1("1.1", 45, 3),
  45     JDK1_2("1.2", 46, 0),
  46     JDK1_3("1.3", 47, 0),
  47 
  48     /** J2SE1.4 = Merlin. */
  49     JDK1_4("1.4", 48, 0),
  50 
  51     /** JDK 5, codename Tiger. */
  52     JDK1_5("1.5", 49, 0),
  53 
  54     /** JDK 6. */
  55     JDK1_6("1.6", 50, 0),
  56 
  57     /** JDK 7. */
  58     JDK1_7("1.7", 51, 0),
  59 
  60     /** JDK 8. */
  61     JDK1_8("1.8", 52, 0),
  62 
  63     /** JDK 9. */
  64     JDK1_9("1.9", 53, 0),
  65 
  66     /** JDK 10. */
  67     JDK1_10("1.10", 54, 0),
  68 
  69     /** JDK 11. */
  70     JDK1_11("11", 55, 0),
  71 
  72     /** JDK 12. */
  73     JDK1_12("12", 56, 0);
  74 
  75     private static final Context.Key<Target> targetKey = new Context.Key<>();
  76 
  77     public static Target instance(Context context) {
  78         Target instance = context.get(targetKey);
  79         if (instance == null) {
  80             Options options = Options.instance(context);
  81             String targetString = options.get(TARGET);
  82             if (targetString != null) instance = lookup(targetString);
  83             if (instance == null) instance = DEFAULT;
  84             context.put(targetKey, instance);
  85         }
  86         return instance;
  87     }
  88 
  89     public static final Target MIN = Target.JDK1_6;
  90 
  91     private static final Target MAX = values()[values().length - 1];
  92 
  93     private static final Map<String,Target> tab = new HashMap<>();
  94     static {
  95         for (Target t : values()) {
  96             tab.put(t.name, t);
  97         }
  98         tab.put("5", JDK1_5);
  99         tab.put("6", JDK1_6);
 100         tab.put("7", JDK1_7);
 101         tab.put("8", JDK1_8);
 102         tab.put("9", JDK1_9);
 103         tab.put("10", JDK1_10);
 104         tab.put("11", JDK1_11);
 105         tab.put("12", JDK1_12);
 106     }
 107 
 108     public final String name;
 109     public final int majorVersion;
 110     public final int minorVersion;
 111     private Target(String name, int majorVersion, int minorVersion) {
 112         this.name = name;
 113         this.majorVersion = majorVersion;
 114         this.minorVersion = minorVersion;
 115     }
 116 
 117     public static final Target DEFAULT = values()[values().length - 1];
 118 
 119     public static Target lookup(String name) {
 120         return tab.get(name);




 121     }
 122 
 123     /** Return the character to be used in constructing synthetic
 124      *  identifiers, where not specified by the JLS.
 125      */
 126     public char syntheticNameChar() {
 127         return '$';
 128     }
 129 
 130     /** Does the VM support an invokedynamic instruction?
 131      */
 132     public boolean hasInvokedynamic() {
 133         return compareTo(JDK1_7) >= 0;
 134     }
 135 
 136     /** Does the target JDK contains the java.util.Objects class?
 137      */
 138     public boolean hasObjects() {
 139         return compareTo(JDK1_7) >= 0;
 140     }




  32 import com.sun.tools.javac.util.*;
  33 
  34 import static com.sun.tools.javac.main.Option.TARGET;
  35 
  36 /** The classfile version target.
  37  *
  38  *  <p><b>This is NOT part of any supported API.
  39  *  If you write code that depends on this, you do so at your own risk.
  40  *  This code and its internal interfaces are subject to change or
  41  *  deletion without notice.</b>
  42  */
  43 public enum Target {
  44     JDK1_1("1.1", 45, 3),
  45     JDK1_2("1.2", 46, 0),
  46     JDK1_3("1.3", 47, 0),
  47 
  48     /** J2SE1.4 = Merlin. */
  49     JDK1_4("1.4", 48, 0),
  50 
  51     /** JDK 5, codename Tiger. */
  52     JDK1_5("5", 49, 0),
  53 
  54     /** JDK 6. */
  55     JDK1_6("6", 50, 0),
  56 
  57     /** JDK 7. */
  58     JDK1_7("7", 51, 0),
  59 
  60     /** JDK 8. */
  61     JDK1_8("8", 52, 0),
  62 
  63     /** JDK 9. */
  64     JDK1_9("9", 53, 0),
  65 
  66     /** JDK 10. */
  67     JDK1_10("10", 54, 0),
  68 
  69     /** JDK 11. */
  70     JDK1_11("11", 55, 0),
  71 
  72     /** JDK 12. */
  73     JDK1_12("12", 56, 0);
  74 
  75     private static final Context.Key<Target> targetKey = new Context.Key<>();
  76 
  77     public static Target instance(Context context) {
  78         Target instance = context.get(targetKey);
  79         if (instance == null) {
  80             Options options = Options.instance(context);
  81             String targetString = options.get(TARGET);
  82             if (targetString != null) instance = lookup(targetString);
  83             if (instance == null) instance = DEFAULT;
  84             context.put(targetKey, instance);
  85         }
  86         return instance;
  87     }
  88 
  89     public static final Target MIN = Target.JDK1_6;
  90 
  91     private static final Target MAX = values()[values().length - 1];
  92 
  93     private static final Map<String,Target> tab = new HashMap<>();
  94     static {
  95         for (Target t : values()) {
  96             tab.put(t.name, t);
  97         }
  98         tab.put("1.5", JDK1_5);
  99         tab.put("1.6", JDK1_6);
 100         tab.put("1.7", JDK1_7);
 101         tab.put("1.8", JDK1_8);
 102         tab.put("1.9", JDK1_9);
 103         tab.put("1.10", JDK1_10);


 104     }
 105 
 106     public final String name;
 107     public final int majorVersion;
 108     public final int minorVersion;
 109     private Target(String name, int majorVersion, int minorVersion) {
 110         this.name = name;
 111         this.majorVersion = majorVersion;
 112         this.minorVersion = minorVersion;
 113     }
 114 
 115     public static final Target DEFAULT = values()[values().length - 1];
 116 
 117     public static Target lookup(String name) {
 118         return tab.get(name);
 119     }
 120 
 121     public boolean isSupported() {
 122         return this.compareTo(MIN) >= 0;
 123     }
 124 
 125     /** Return the character to be used in constructing synthetic
 126      *  identifiers, where not specified by the JLS.
 127      */
 128     public char syntheticNameChar() {
 129         return '$';
 130     }
 131 
 132     /** Does the VM support an invokedynamic instruction?
 133      */
 134     public boolean hasInvokedynamic() {
 135         return compareTo(JDK1_7) >= 0;
 136     }
 137 
 138     /** Does the target JDK contains the java.util.Objects class?
 139      */
 140     public boolean hasObjects() {
 141         return compareTo(JDK1_7) >= 0;
 142     }


< prev index next >