MCPcopy Create free account
hub / github.com/java-native-access/jna / findDirectMappedClass

Method findDirectMappedClass

src/com/sun/jna/Native.java:1574–1591  ·  view source on GitHub ↗

Find the nearest enclosing class with native methods.

(Class<?> cls)

Source from the content-addressed store, hash-verified

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.

Callers 5

registerMethod · 0.95
unregisterMethod · 0.95
getNativeLibraryMethod · 0.95

Calls 2

getModifiersMethod · 0.80
getNameMethod · 0.65

Tested by 2