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