20
20
import javax .tools .DiagnosticCollector ;
21
21
import javax .tools .DiagnosticListener ;
22
22
import javax .tools .JavaFileObject ;
23
+ import org .checkerframework .javacutil .UserError ;
23
24
24
25
/**
25
26
* This class contains static methods that parse Java code.
@@ -210,7 +211,14 @@ public static JavacParseResult<CompilationUnitTree> parseCompilationUnit(JavaFil
210
211
new JavacFileManager (context , true , StandardCharsets .UTF_8 )) {
211
212
212
213
Log .instance (context ).useSource (source );
213
- ParserFactory parserFactory = ParserFactory .instance (context );
214
+ ParserFactory parserFactory ;
215
+ try {
216
+ parserFactory = ParserFactory .instance (context );
217
+ } catch (IllegalAccessError e ) {
218
+ throw new UserError (
219
+ "Provide `--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED` along with"
220
+ + " any other `--add-exports` in the Checker Framework invocation." );
221
+ }
214
222
JavacParser parser = parserFactory .newParser (source .getCharContent (false ), true , true , true );
215
223
CompilationUnitTree cu = parser .parseCompilationUnit ();
216
224
((JCCompilationUnit ) cu ).sourcefile = source ;
@@ -244,7 +252,14 @@ public static JavacParseResult<ExpressionTree> parseExpression(JavaFileObject so
244
252
new JavacFileManager (context , true , StandardCharsets .UTF_8 )) {
245
253
246
254
Log .instance (context ).useSource (source );
247
- ParserFactory parserFactory = ParserFactory .instance (context );
255
+ ParserFactory parserFactory ;
256
+ try {
257
+ parserFactory = ParserFactory .instance (context );
258
+ } catch (IllegalAccessError e ) {
259
+ throw new UserError (
260
+ "Provide `--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED` along with"
261
+ + " any other `--add-exports` in the Checker Framework invocation." );
262
+ }
248
263
JavacParser parser = parserFactory .newParser (source .getCharContent (false ), true , true , true );
249
264
ExpressionTree eTree = parser .parseExpression ();
250
265
return new JavacParseResult <ExpressionTree >(eTree , diagnostics .getDiagnostics ());
@@ -270,7 +285,14 @@ public static JavacParseResult<ExpressionTree> parseTypeUse(JavaFileObject sourc
270
285
new JavacFileManager (context , true , StandardCharsets .UTF_8 )) {
271
286
272
287
Log .instance (context ).useSource (source );
273
- ParserFactory parserFactory = ParserFactory .instance (context );
288
+ ParserFactory parserFactory ;
289
+ try {
290
+ parserFactory = ParserFactory .instance (context );
291
+ } catch (IllegalAccessError e ) {
292
+ throw new UserError (
293
+ "Provide `--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED` along with"
294
+ + " any other `--add-exports` in the Checker Framework invocation." );
295
+ }
274
296
JavacParser parser = parserFactory .newParser (source .getCharContent (false ), true , true , true );
275
297
ExpressionTree eTree = parser .parseType ();
276
298
return new JavacParseResult <ExpressionTree >(eTree , diagnostics .getDiagnostics ());
0 commit comments