The full blown resolver method. All other method invocation methods delegate to this. The method may be static or dynamic unless staticOnly is set (in which case object may be null). If staticOnly is set then only static methods will be located. This method performs caching (caches disco
(BshClassManager bcm, Class clas, String name, Class[] types, boolean staticOnly)
| 420 | * @return the method or null if no matching method was found. |
| 421 | */ |
| 422 | protected static Method resolveJavaMethod(BshClassManager bcm, Class clas, String name, Class[] types, boolean staticOnly) throws UtilEvalError { |
| 423 | if (clas == null) { |
| 424 | throw new InterpreterError("null class"); |
| 425 | } |
| 426 | |
| 427 | // Lookup previously cached method |
| 428 | Method method = null; |
| 429 | if (bcm == null) { |
| 430 | Interpreter.debug("resolveJavaMethod UNOPTIMIZED lookup"); |
| 431 | } else { |
| 432 | method = bcm.getResolvedMethod(clas, name, types, staticOnly); |
| 433 | } |
| 434 | |
| 435 | if (method == null) { |
| 436 | boolean publicOnly = !Capabilities.haveAccessibility(); |
| 437 | // Searching for the method may, itself be a priviledged action |
| 438 | try { |
| 439 | method = findOverloadedMethod(clas, name, types, publicOnly); |
| 440 | } catch (SecurityException e) { |
| 441 | throw new UtilTargetError("Security Exception while searching methods of: " + clas, e); |
| 442 | } |
| 443 | |
| 444 | checkFoundStaticMethod(method, staticOnly, clas); |
| 445 | |
| 446 | // This is the first time we've seen this method, set accessibility if needed |
| 447 | if ((method != null) && !isPublic(method)) { |
| 448 | if (publicOnly) { |
| 449 | Interpreter.debug("resolveJavaMethod - no accessible method found"); |
| 450 | method = null; |
| 451 | } else { |
| 452 | Interpreter.debug("resolveJavaMethod - setting method accessible"); |
| 453 | try { |
| 454 | method.setAccessible(true); |
| 455 | } catch (final SecurityException e) { |
| 456 | Interpreter.debug("resolveJavaMethod - setting accessible failed: " + e); |
| 457 | method = null; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | // If succeeded cache the resolved method. |
| 463 | if (method != null && bcm != null) { |
| 464 | bcm.cacheResolvedMethod(clas, types, method); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | return method; |
| 469 | } |
| 470 | |
| 471 | |
| 472 | /** |
no test coverage detected