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 local-variable syntax for lambda parameters */
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()) {
119
120 private Source(String name) {
121 this.name = name;
122 }
123
124 public static final Source MIN = Source.JDK7;
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 boolean isSupported() {
135 return this.compareTo(MIN) >= 0;
136 }
137
138 public Target requiredTarget() {
139 if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
140 if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
141 if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
142 if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
143 if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
144 if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
145 if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
146 if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
147 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
148 return Target.JDK1_1;
149 }
150
151 /**
152 * Models a feature of the Java programming language. Each feature can be associated with a
153 * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
154 * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
155 */
156 public enum Feature {
157
158 DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
165 DEFAULT_METHODS(JDK8, Fragments.FeatureDefaultMethods, DiagKind.PLURAL),
166 STATIC_INTERFACE_METHODS(JDK8, Fragments.FeatureStaticIntfMethods, DiagKind.PLURAL),
167 STATIC_INTERFACE_METHODS_INVOKE(JDK8, Fragments.FeatureStaticIntfMethodInvoke, DiagKind.PLURAL),
168 STRICT_METHOD_CLASH_CHECK(JDK8),
169 EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
170 TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
171 ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
172 REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
173 INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
174 GRAPH_INFERENCE(JDK8),
175 FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
176 POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
177 MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
178 PRIVATE_SAFE_VARARGS(JDK9),
179 DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
180 UNDERSCORE_IDENTIFIER(MIN, JDK8),
181 PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
182 LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
183 VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
184 IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
185 SWITCH_MULTIPLE_CASE_LABELS(JDK12, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
186 SWITCH_RULE(JDK12, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
187 SWITCH_EXPRESSION(JDK12, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
188 RAW_STRING_LITERALS(JDK12, Fragments.FeatureRawStringLiterals, DiagKind.PLURAL);
189
190 enum DiagKind {
191 NORMAL,
192 PLURAL;
193 }
194
195 private final Source minLevel;
196 private final Source maxLevel;
197 private final Fragment optFragment;
198 private final DiagKind optKind;
199
200 Feature(Source minLevel) {
201 this(minLevel, null, null);
202 }
203
204 Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
205 this(minLevel, MAX, optFragment, optKind);
206 }
207
208 Feature(Source minLevel, Source maxLevel) {
253 case JDK1_3:
254 return RELEASE_3;
255 case JDK1_4:
256 return RELEASE_4;
257 case JDK5:
258 return RELEASE_5;
259 case JDK6:
260 return RELEASE_6;
261 case JDK7:
262 return RELEASE_7;
263 case JDK8:
264 return RELEASE_8;
265 case JDK9:
266 return RELEASE_9;
267 case JDK10:
268 return RELEASE_10;
269 case JDK11:
270 return RELEASE_11;
271 case JDK12:
272 return RELEASE_12;
273 default:
274 return null;
275 }
276 }
277 }
|
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 local-variable syntax for lambda parameters */
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 /** 13 covers the to be determined language features that will be added in JDK 13. */
91 JDK13("13");
92
93 private static final Context.Key<Source> sourceKey = new Context.Key<>();
94
95 public static Source instance(Context context) {
96 Source instance = context.get(sourceKey);
97 if (instance == null) {
98 Options options = Options.instance(context);
99 String sourceString = options.get(SOURCE);
100 if (sourceString != null) instance = lookup(sourceString);
101 if (instance == null) instance = DEFAULT;
102 context.put(sourceKey, instance);
103 }
104 return instance;
105 }
106
107 public final String name;
108
109 private static final Map<String,Source> tab = new HashMap<>();
110 static {
111 for (Source s : values()) {
122
123 private Source(String name) {
124 this.name = name;
125 }
126
127 public static final Source MIN = Source.JDK7;
128
129 private static final Source MAX = values()[values().length - 1];
130
131 public static final Source DEFAULT = MAX;
132
133 public static Source lookup(String name) {
134 return tab.get(name);
135 }
136
137 public boolean isSupported() {
138 return this.compareTo(MIN) >= 0;
139 }
140
141 public Target requiredTarget() {
142 if (this.compareTo(JDK13) >= 0) return Target.JDK1_13;
143 if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
144 if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
145 if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
146 if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
147 if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
148 if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
149 if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
150 if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
151 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
152 return Target.JDK1_1;
153 }
154
155 /**
156 * Models a feature of the Java programming language. Each feature can be associated with a
157 * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
158 * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
159 */
160 public enum Feature {
161
162 DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
169 DEFAULT_METHODS(JDK8, Fragments.FeatureDefaultMethods, DiagKind.PLURAL),
170 STATIC_INTERFACE_METHODS(JDK8, Fragments.FeatureStaticIntfMethods, DiagKind.PLURAL),
171 STATIC_INTERFACE_METHODS_INVOKE(JDK8, Fragments.FeatureStaticIntfMethodInvoke, DiagKind.PLURAL),
172 STRICT_METHOD_CLASH_CHECK(JDK8),
173 EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
174 TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
175 ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
176 REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
177 INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
178 GRAPH_INFERENCE(JDK8),
179 FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
180 POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
181 MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
182 PRIVATE_SAFE_VARARGS(JDK9),
183 DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
184 UNDERSCORE_IDENTIFIER(MIN, JDK8),
185 PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
186 LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
187 VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
188 IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
189 SWITCH_MULTIPLE_CASE_LABELS(JDK13, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
190 SWITCH_RULE(JDK13, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
191 SWITCH_EXPRESSION(JDK13, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
192 RAW_STRING_LITERALS(JDK13, Fragments.FeatureRawStringLiterals, DiagKind.PLURAL);
193
194 enum DiagKind {
195 NORMAL,
196 PLURAL;
197 }
198
199 private final Source minLevel;
200 private final Source maxLevel;
201 private final Fragment optFragment;
202 private final DiagKind optKind;
203
204 Feature(Source minLevel) {
205 this(minLevel, null, null);
206 }
207
208 Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
209 this(minLevel, MAX, optFragment, optKind);
210 }
211
212 Feature(Source minLevel, Source maxLevel) {
257 case JDK1_3:
258 return RELEASE_3;
259 case JDK1_4:
260 return RELEASE_4;
261 case JDK5:
262 return RELEASE_5;
263 case JDK6:
264 return RELEASE_6;
265 case JDK7:
266 return RELEASE_7;
267 case JDK8:
268 return RELEASE_8;
269 case JDK9:
270 return RELEASE_9;
271 case JDK10:
272 return RELEASE_10;
273 case JDK11:
274 return RELEASE_11;
275 case JDK12:
276 return RELEASE_12;
277 case JDK13:
278 return RELEASE_13;
279 default:
280 return null;
281 }
282 }
283 }
|