Find the nearest enclosing class with native methods.
(Class<?> cls)
| 1572 | |
| 1573 | /** Find the nearest enclosing class with native methods. */ |
| 1574 | static Class<?> findDirectMappedClass(Class<?> cls) { |
| 1575 | Method[] methods = cls.getDeclaredMethods(); |
| 1576 | for (Method m : methods) { |
| 1577 | if ((m.getModifiers() & Modifier.NATIVE) != 0) { |
| 1578 | return cls; |
| 1579 | } |
| 1580 | } |
| 1581 | int idx = cls.getName().lastIndexOf("$"); |
| 1582 | if (idx != -1) { |
| 1583 | String name = cls.getName().substring(0, idx); |
| 1584 | try { |
| 1585 | return findDirectMappedClass(Class.forName(name, true, cls.getClassLoader())); |
| 1586 | } catch(ClassNotFoundException e) { |
| 1587 | // ignored |
| 1588 | } |
| 1589 | } |
| 1590 | throw new IllegalArgumentException("Can't determine class with native methods from the current context (" + cls + ")"); |
| 1591 | } |
| 1592 | |
| 1593 | /** Try to determine the class context in which a {@link #register(String)} call |
| 1594 | was made. |