@@ -297,10 +297,13 @@ public static MethodSymbol getSymbol(MethodTree tree) {
297
297
}
298
298
299
299
/** Gets the method symbol for a new class. */
300
- @ Nullable
301
300
public static MethodSymbol getSymbol (NewClassTree tree ) {
302
301
Symbol sym = ((JCNewClass ) tree ).constructor ;
303
- return sym instanceof MethodSymbol ? (MethodSymbol ) sym : null ;
302
+ if (!(sym instanceof MethodSymbol )) {
303
+ // Defensive. Would only occur if there are errors in the AST.
304
+ throw new IllegalArgumentException (tree .toString ());
305
+ }
306
+ return (MethodSymbol ) sym ;
304
307
}
305
308
306
309
/** Gets the symbol for a variable. */
@@ -309,21 +312,23 @@ public static VarSymbol getSymbol(VariableTree tree) {
309
312
}
310
313
311
314
/** Gets the symbol for a method invocation. */
312
- @ Nullable
313
315
public static MethodSymbol getSymbol (MethodInvocationTree tree ) {
314
316
Symbol sym = ASTHelpers .getSymbol (tree .getMethodSelect ());
315
317
if (!(sym instanceof MethodSymbol )) {
316
318
// Defensive. Would only occur if there are errors in the AST.
317
- return null ;
319
+ throw new IllegalArgumentException ( tree . toString ()) ;
318
320
}
319
321
return (MethodSymbol ) sym ;
320
322
}
321
323
322
324
/** Gets the symbol for a member reference. */
323
- @ Nullable
324
325
public static MethodSymbol getSymbol (MemberReferenceTree tree ) {
325
326
Symbol sym = ((JCMemberReference ) tree ).sym ;
326
- return sym instanceof MethodSymbol ? (MethodSymbol ) sym : null ;
327
+ if (!(sym instanceof MethodSymbol )) {
328
+ // Defensive. Would only occur if there are errors in the AST.
329
+ throw new IllegalArgumentException (tree .toString ());
330
+ }
331
+ return (MethodSymbol ) sym ;
327
332
}
328
333
329
334
/* Checks whether an expression requires parentheses. */
0 commit comments