< prev index next >

src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java

Print this page




  65     /** 1.5 introduced generics, attributes, foreach, boxing, static import,
  66      *  covariant return, enums, varargs, et al. */
  67     JDK5("5"),
  68 
  69     /** 1.6 reports encoding problems as errors instead of warnings. */
  70     JDK6("6"),
  71 
  72     /** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */
  73     JDK7("7"),
  74 
  75     /** 1.8 lambda expressions and default methods. */
  76     JDK8("8"),
  77 
  78     /** 1.9 modularity. */
  79     JDK9("9"),
  80 
  81     /** 1.10 local-variable type inference (var). */
  82     JDK10("10"),
  83 
  84     /** 1.11 covers the to be determined language features that will be added in JDK 11. */
  85     JDK11("11");



  86 
  87     private static final Context.Key<Source> sourceKey = new Context.Key<>();
  88 
  89     public static Source instance(Context context) {
  90         Source instance = context.get(sourceKey);
  91         if (instance == null) {
  92             Options options = Options.instance(context);
  93             String sourceString = options.get(SOURCE);
  94             if (sourceString != null) instance = lookup(sourceString);
  95             if (instance == null) instance = DEFAULT;
  96             context.put(sourceKey, instance);
  97         }
  98         return instance;
  99     }
 100 
 101     public final String name;
 102 
 103     private static final Map<String,Source> tab = new HashMap<>();
 104     static {
 105         for (Source s : values()) {


 112         tab.put("1.9", JDK9); // Make 9 an alias for 1.9
 113         tab.put("1.10", JDK10); // Make 10 an alias for 1.10
 114         // Decline to make 1.11 an alias for 11.
 115     }
 116 
 117     private Source(String name) {
 118         this.name = name;
 119     }
 120 
 121     public static final Source MIN = Source.JDK6;
 122 
 123     private static final Source MAX = values()[values().length - 1];
 124 
 125     public static final Source DEFAULT = MAX;
 126 
 127     public static Source lookup(String name) {
 128         return tab.get(name);
 129     }
 130 
 131     public Target requiredTarget() {

 132         if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
 133         if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
 134         if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
 135         if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
 136         if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
 137         if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
 138         if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
 139         if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
 140         return Target.JDK1_1;
 141     }
 142 
 143     /**
 144      * Models a feature of the Java programming language. Each feature can be associated with a
 145      * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
 146      * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
 147      */
 148     public enum Feature {
 149 
 150         DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
 151         MULTICATCH(JDK7, Fragments.FeatureMulticatch, DiagKind.PLURAL),


 248         case JDK1_2:
 249             return RELEASE_2;
 250         case JDK1_3:
 251             return RELEASE_3;
 252         case JDK1_4:
 253             return RELEASE_4;
 254         case JDK5:
 255             return RELEASE_5;
 256         case JDK6:
 257             return RELEASE_6;
 258         case JDK7:
 259             return RELEASE_7;
 260         case JDK8:
 261             return RELEASE_8;
 262         case JDK9:
 263             return RELEASE_9;
 264         case JDK10:
 265             return RELEASE_10;
 266         case JDK11:
 267             return RELEASE_11;


 268         default:
 269             return null;
 270         }
 271     }
 272 }


  65     /** 1.5 introduced generics, attributes, foreach, boxing, static import,
  66      *  covariant return, enums, varargs, et al. */
  67     JDK5("5"),
  68 
  69     /** 1.6 reports encoding problems as errors instead of warnings. */
  70     JDK6("6"),
  71 
  72     /** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */
  73     JDK7("7"),
  74 
  75     /** 1.8 lambda expressions and default methods. */
  76     JDK8("8"),
  77 
  78     /** 1.9 modularity. */
  79     JDK9("9"),
  80 
  81     /** 1.10 local-variable type inference (var). */
  82     JDK10("10"),
  83 
  84     /** 1.11 covers the to be determined language features that will be added in JDK 11. */
  85     JDK11("11"),
  86 
  87     /** 12 covers the to be determined language features that will be added in JDK 12. */
  88     JDK12("12");
  89 
  90     private static final Context.Key<Source> sourceKey = new Context.Key<>();
  91 
  92     public static Source instance(Context context) {
  93         Source instance = context.get(sourceKey);
  94         if (instance == null) {
  95             Options options = Options.instance(context);
  96             String sourceString = options.get(SOURCE);
  97             if (sourceString != null) instance = lookup(sourceString);
  98             if (instance == null) instance = DEFAULT;
  99             context.put(sourceKey, instance);
 100         }
 101         return instance;
 102     }
 103 
 104     public final String name;
 105 
 106     private static final Map<String,Source> tab = new HashMap<>();
 107     static {
 108         for (Source s : values()) {


 115         tab.put("1.9", JDK9); // Make 9 an alias for 1.9
 116         tab.put("1.10", JDK10); // Make 10 an alias for 1.10
 117         // Decline to make 1.11 an alias for 11.
 118     }
 119 
 120     private Source(String name) {
 121         this.name = name;
 122     }
 123 
 124     public static final Source MIN = Source.JDK6;
 125 
 126     private static final Source MAX = values()[values().length - 1];
 127 
 128     public static final Source DEFAULT = MAX;
 129 
 130     public static Source lookup(String name) {
 131         return tab.get(name);
 132     }
 133 
 134     public Target requiredTarget() {
 135         if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
 136         if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
 137         if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
 138         if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
 139         if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
 140         if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
 141         if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
 142         if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
 143         if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
 144         return Target.JDK1_1;
 145     }
 146 
 147     /**
 148      * Models a feature of the Java programming language. Each feature can be associated with a
 149      * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
 150      * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
 151      */
 152     public enum Feature {
 153 
 154         DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
 155         MULTICATCH(JDK7, Fragments.FeatureMulticatch, DiagKind.PLURAL),


 252         case JDK1_2:
 253             return RELEASE_2;
 254         case JDK1_3:
 255             return RELEASE_3;
 256         case JDK1_4:
 257             return RELEASE_4;
 258         case JDK5:
 259             return RELEASE_5;
 260         case JDK6:
 261             return RELEASE_6;
 262         case JDK7:
 263             return RELEASE_7;
 264         case JDK8:
 265             return RELEASE_8;
 266         case JDK9:
 267             return RELEASE_9;
 268         case JDK10:
 269             return RELEASE_10;
 270         case JDK11:
 271             return RELEASE_11;
 272         case JDK12:
 273             return RELEASE_12;
 274         default:
 275             return null;
 276         }
 277     }
 278 }
< prev index next >