79 JDK9("9"),
80
81 /** 1.10 local-variable type inference (var). */
82 JDK10("10"),
83
84 /** 1.11 local-variable syntax for lambda parameters */
85 JDK11("11"),
86
87 /** 12, no language features; switch expression in preview */
88 JDK12("12"),
89
90 /**
91 * 13, no language features; text blocks and revised switch
92 * expressions in preview
93 */
94 JDK13("13"),
95
96 /**
97 * 14, switch expressions
98 */
99 JDK14("14");
100
101 private static final Context.Key<Source> sourceKey = new Context.Key<>();
102
103 public static Source instance(Context context) {
104 Source instance = context.get(sourceKey);
105 if (instance == null) {
106 Options options = Options.instance(context);
107 String sourceString = options.get(SOURCE);
108 if (sourceString != null) instance = lookup(sourceString);
109 if (instance == null) instance = DEFAULT;
110 context.put(sourceKey, instance);
111 }
112 return instance;
113 }
114
115 public final String name;
116
117 private static final Map<String,Source> tab = new HashMap<>();
118 static {
119 for (Source s : values()) {
130
131 private Source(String name) {
132 this.name = name;
133 }
134
135 public static final Source MIN = Source.JDK7;
136
137 private static final Source MAX = values()[values().length - 1];
138
139 public static final Source DEFAULT = MAX;
140
141 public static Source lookup(String name) {
142 return tab.get(name);
143 }
144
145 public boolean isSupported() {
146 return this.compareTo(MIN) >= 0;
147 }
148
149 public Target requiredTarget() {
150 if (this.compareTo(JDK14) >= 0) return Target.JDK1_14;
151 if (this.compareTo(JDK13) >= 0) return Target.JDK1_13;
152 if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
153 if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
154 if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
155 if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
156 if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
157 if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
158 if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
159 if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
160 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
161 return Target.JDK1_1;
162 }
163
164 /**
165 * Models a feature of the Java programming language. Each feature can be associated with a
166 * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
167 * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
168 */
169 public enum Feature {
181 STRICT_METHOD_CLASH_CHECK(JDK8),
182 EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
183 TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
184 ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
185 REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
186 INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
187 GRAPH_INFERENCE(JDK8),
188 FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
189 POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
190 MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
191 PRIVATE_SAFE_VARARGS(JDK9),
192 DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
193 UNDERSCORE_IDENTIFIER(MIN, JDK8),
194 PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
195 LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
196 VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
197 IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
198 SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
199 SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
200 SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
201 TEXT_BLOCKS(JDK14, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
202 PATTERN_MATCHING_IN_INSTANCEOF(JDK14, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
203 REIFIABLE_TYPES_INSTANCEOF(JDK14, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
204 RECORDS(JDK14, Fragments.FeatureRecords, DiagKind.PLURAL),
205 ;
206
207 enum DiagKind {
208 NORMAL,
209 PLURAL;
210 }
211
212 private final Source minLevel;
213 private final Source maxLevel;
214 private final Fragment optFragment;
215 private final DiagKind optKind;
216
217 Feature(Source minLevel) {
218 this(minLevel, null, null);
219 }
220
221 Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
222 this(minLevel, MAX, optFragment, optKind);
223 }
224
274 case JDK5:
275 return RELEASE_5;
276 case JDK6:
277 return RELEASE_6;
278 case JDK7:
279 return RELEASE_7;
280 case JDK8:
281 return RELEASE_8;
282 case JDK9:
283 return RELEASE_9;
284 case JDK10:
285 return RELEASE_10;
286 case JDK11:
287 return RELEASE_11;
288 case JDK12:
289 return RELEASE_12;
290 case JDK13:
291 return RELEASE_13;
292 case JDK14:
293 return RELEASE_14;
294 default:
295 return null;
296 }
297 }
298 }
|
79 JDK9("9"),
80
81 /** 1.10 local-variable type inference (var). */
82 JDK10("10"),
83
84 /** 1.11 local-variable syntax for lambda parameters */
85 JDK11("11"),
86
87 /** 12, no language features; switch expression in preview */
88 JDK12("12"),
89
90 /**
91 * 13, no language features; text blocks and revised switch
92 * expressions in preview
93 */
94 JDK13("13"),
95
96 /**
97 * 14, switch expressions
98 */
99 JDK14("14"),
100
101 /**
102 * 15, tbd
103 */
104 JDK15("15");
105
106 private static final Context.Key<Source> sourceKey = new Context.Key<>();
107
108 public static Source instance(Context context) {
109 Source instance = context.get(sourceKey);
110 if (instance == null) {
111 Options options = Options.instance(context);
112 String sourceString = options.get(SOURCE);
113 if (sourceString != null) instance = lookup(sourceString);
114 if (instance == null) instance = DEFAULT;
115 context.put(sourceKey, instance);
116 }
117 return instance;
118 }
119
120 public final String name;
121
122 private static final Map<String,Source> tab = new HashMap<>();
123 static {
124 for (Source s : values()) {
135
136 private Source(String name) {
137 this.name = name;
138 }
139
140 public static final Source MIN = Source.JDK7;
141
142 private static final Source MAX = values()[values().length - 1];
143
144 public static final Source DEFAULT = MAX;
145
146 public static Source lookup(String name) {
147 return tab.get(name);
148 }
149
150 public boolean isSupported() {
151 return this.compareTo(MIN) >= 0;
152 }
153
154 public Target requiredTarget() {
155 if (this.compareTo(JDK15) >= 0) return Target.JDK1_15;
156 if (this.compareTo(JDK14) >= 0) return Target.JDK1_14;
157 if (this.compareTo(JDK13) >= 0) return Target.JDK1_13;
158 if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
159 if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
160 if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
161 if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
162 if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
163 if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
164 if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
165 if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
166 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
167 return Target.JDK1_1;
168 }
169
170 /**
171 * Models a feature of the Java programming language. Each feature can be associated with a
172 * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
173 * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
174 */
175 public enum Feature {
187 STRICT_METHOD_CLASH_CHECK(JDK8),
188 EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
189 TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
190 ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
191 REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
192 INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
193 GRAPH_INFERENCE(JDK8),
194 FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
195 POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
196 MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
197 PRIVATE_SAFE_VARARGS(JDK9),
198 DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
199 UNDERSCORE_IDENTIFIER(MIN, JDK8),
200 PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
201 LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
202 VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
203 IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
204 SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
205 SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
206 SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
207 TEXT_BLOCKS(JDK15, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
208 PATTERN_MATCHING_IN_INSTANCEOF(JDK15, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
209 REIFIABLE_TYPES_INSTANCEOF(JDK15, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
210 RECORDS(JDK15, Fragments.FeatureRecords, DiagKind.PLURAL),
211 ;
212
213 enum DiagKind {
214 NORMAL,
215 PLURAL;
216 }
217
218 private final Source minLevel;
219 private final Source maxLevel;
220 private final Fragment optFragment;
221 private final DiagKind optKind;
222
223 Feature(Source minLevel) {
224 this(minLevel, null, null);
225 }
226
227 Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
228 this(minLevel, MAX, optFragment, optKind);
229 }
230
280 case JDK5:
281 return RELEASE_5;
282 case JDK6:
283 return RELEASE_6;
284 case JDK7:
285 return RELEASE_7;
286 case JDK8:
287 return RELEASE_8;
288 case JDK9:
289 return RELEASE_9;
290 case JDK10:
291 return RELEASE_10;
292 case JDK11:
293 return RELEASE_11;
294 case JDK12:
295 return RELEASE_12;
296 case JDK13:
297 return RELEASE_13;
298 case JDK14:
299 return RELEASE_14;
300 case JDK15:
301 return RELEASE_15;
302 default:
303 return null;
304 }
305 }
306 }
|