62 /** 1.4 introduced assert. */
63 JDK1_4("1.4"),
64
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 covers the to be determined language features that will be added in JDK 10. */
82 JDK10("10");
83
84 private static final Context.Key<Source> sourceKey = new Context.Key<>();
85
86 public static Source instance(Context context) {
87 Source instance = context.get(sourceKey);
88 if (instance == null) {
89 Options options = Options.instance(context);
90 String sourceString = options.get(SOURCE);
91 if (sourceString != null) instance = lookup(sourceString);
92 if (instance == null) instance = DEFAULT;
93 context.put(sourceKey, instance);
94 }
95 return instance;
96 }
97
98 public final String name;
99
100 private static final Map<String,Source> tab = new HashMap<>();
101 static {
102 for (Source s : values()) {
103 tab.put(s.name, s);
104 }
105 tab.put("1.5", JDK5); // Make 5 an alias for 1.5
106 tab.put("1.6", JDK6); // Make 6 an alias for 1.6
107 tab.put("1.7", JDK7); // Make 7 an alias for 1.7
108 tab.put("1.8", JDK8); // Make 8 an alias for 1.8
109 tab.put("1.9", JDK9); // Make 9 an alias for 1.9
110 tab.put("1.10", JDK10); // Make 10 an alias for 1.10
111 }
112
113 private Source(String name) {
114 this.name = name;
115 }
116
117 public static final Source MIN = Source.JDK6;
118
119 private static final Source MAX = values()[values().length - 1];
120
121 public static final Source DEFAULT = MAX;
122
123 public static Source lookup(String name) {
124 return tab.get(name);
125 }
126
127 public Target requiredTarget() {
128 if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
129 if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
130 if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
131 if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
132 if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
133 if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
134 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
135 return Target.JDK1_1;
136 }
137
138 /**
139 * Models a feature of the Java programming language. Each feature can be associated with a
140 * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
141 * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
142 */
143 public enum Feature {
144
145 DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
146 MULTICATCH(JDK7, Fragments.FeatureMulticatch, DiagKind.PLURAL),
147 IMPROVED_RETHROW_ANALYSIS(JDK7),
230 public static SourceVersion toSourceVersion(Source source) {
231 switch(source) {
232 case JDK1_2:
233 return RELEASE_2;
234 case JDK1_3:
235 return RELEASE_3;
236 case JDK1_4:
237 return RELEASE_4;
238 case JDK5:
239 return RELEASE_5;
240 case JDK6:
241 return RELEASE_6;
242 case JDK7:
243 return RELEASE_7;
244 case JDK8:
245 return RELEASE_8;
246 case JDK9:
247 return RELEASE_9;
248 case JDK10:
249 return RELEASE_10;
250 default:
251 return null;
252 }
253 }
254 }
|
62 /** 1.4 introduced assert. */
63 JDK1_4("1.4"),
64
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 covers the to be determined language features that will be added in JDK 10. */
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()) {
106 tab.put(s.name, s);
107 }
108 tab.put("1.5", JDK5); // Make 5 an alias for 1.5
109 tab.put("1.6", JDK6); // Make 6 an alias for 1.6
110 tab.put("1.7", JDK7); // Make 7 an alias for 1.7
111 tab.put("1.8", JDK8); // Make 8 an alias for 1.8
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),
152 IMPROVED_RETHROW_ANALYSIS(JDK7),
235 public static SourceVersion toSourceVersion(Source source) {
236 switch(source) {
237 case JDK1_2:
238 return RELEASE_2;
239 case JDK1_3:
240 return RELEASE_3;
241 case JDK1_4:
242 return RELEASE_4;
243 case JDK5:
244 return RELEASE_5;
245 case JDK6:
246 return RELEASE_6;
247 case JDK7:
248 return RELEASE_7;
249 case JDK8:
250 return RELEASE_8;
251 case JDK9:
252 return RELEASE_9;
253 case JDK10:
254 return RELEASE_10;
255 case JDK11:
256 return RELEASE_11;
257 default:
258 return null;
259 }
260 }
261 }
|