@Override protected JavaClassDesc computeValue(Class<?> type) { return new JavaClassDesc(type); } };
public Collection<String> getJNIMethodNames(boolean onlyStatic) { return Collections.unmodifiableCollection((onlyStatic ? getJNIMembers().staticMethods : getJNIMembers().methods).keySet()); }
/** * Looks up public constructor in this class. * * @return method descriptor or {@code null} if there is no public constructor */ public JavaMethodDesc lookupConstructor() { return getMembers().constructor; }
public JavaFieldDesc lookupField(String name, boolean onlyStatic) { return onlyStatic ? lookupStaticField(name) : lookupField(name); }
boolean internal = false; JavaClassDesc classDesc = JavaClassDesc.forClass(clazz); JavaMethodDesc foundMethod = classDesc.lookupMethod(name, onlyStatic); if (foundMethod != null) { readable = true; invocable = true; } else if (isJNIName(name)) { foundMethod = classDesc.lookupMethodByJNIName(name, onlyStatic); if (foundMethod != null) { readable = true; JavaFieldDesc foundField = classDesc.lookupField(name, onlyStatic); if (foundField != null) { readable = true;
@CompilerDirectives.TruffleBoundary static JavaMethodDesc findMethod(Class<?> clazz, String name, boolean onlyStatic) { if (TruffleOptions.AOT) { return null; } JavaClassDesc classDesc = JavaClassDesc.forClass(clazz); JavaMethodDesc foundMethod = classDesc.lookupMethod(name, onlyStatic); if (foundMethod == null && isJNIName(name)) { foundMethod = classDesc.lookupMethodByJNIName(name, onlyStatic); } return foundMethod; }
@CompilerDirectives.TruffleBoundary static String[] findUniquePublicMemberNames(Class<?> clazz, boolean onlyStatic, boolean includeInternal) throws SecurityException { JavaClassDesc classDesc = JavaClassDesc.forClass(clazz); EconomicSet<String> names = EconomicSet.create(); names.addAll(classDesc.getFieldNames(onlyStatic)); names.addAll(classDesc.getMethodNames(onlyStatic, includeInternal)); if (onlyStatic) { names.add("class"); if (Modifier.isPublic(clazz.getModifiers())) { // no support for non-static member types now for (Class<?> t : clazz.getClasses()) { if (!isStaticTypeOrInterface(t)) { continue; } names.add(t.getSimpleName()); } } } return names.toArray(new String[names.size()]); }
@CompilerDirectives.TruffleBoundary static JavaFieldDesc findField(Class<?> clazz, String name, boolean onlyStatic) { JavaClassDesc classDesc = JavaClassDesc.forClass(clazz); return classDesc.lookupField(name, onlyStatic); }
@Specialization(replaces = "doCached") static JavaMethodDesc doUncached(Class<?> clazz) { return JavaClassDesc.forClass(clazz).getFunctionalMethod(); } }
@Specialization(replaces = "doCached") static JavaMethodDesc doUncached(Class<?> clazz) { return JavaClassDesc.forClass(clazz).lookupConstructor(); } }
static Method functionalInterfaceMethod(Class<?> functionalInterface) { if (!functionalInterface.isInterface()) { return null; } final Method[] methods = functionalInterface.getMethods(); if (methods.length == 1) { return methods[0]; } Method found = null; for (Method m : methods) { if (Modifier.isAbstract(m.getModifiers()) && !JavaClassDesc.isObjectMethodOverride(m)) { if (found != null) { return null; } found = m; } } return found; }
private static String findFunctionalInterfaceMethodName(Class<?> clazz) { for (Class<?> iface : clazz.getInterfaces()) { if (Modifier.isPublic(iface.getModifiers()) && iface.isAnnotationPresent(FunctionalInterface.class)) { for (Method m : iface.getMethods()) { if (Modifier.isAbstract(m.getModifiers()) && !isObjectMethodOverride(m)) { return m.getName(); } } } } Class<?> superclass = clazz.getSuperclass(); if (superclass != null && superclass != Object.class) { return findFunctionalInterfaceMethodName(superclass); } return null; } }
public JavaMethodDesc getFunctionalMethod() { return getMembers().functionalMethod; }
public JavaMethodDesc lookupMethodByJNIName(String jniName, boolean onlyStatic) { return onlyStatic ? getJNIMembers().staticMethods.get(jniName) : getJNIMembers().methods.get(jniName); }
/** * Looks up a public non-static method in this class. * * @param name method name * @return method descriptor or {@code null} if there is no such method */ public JavaMethodDesc lookupMethod(String name) { return getMembers().methods.get(name); }
/** * Looks up a public static method in this class. * * @param name method name * @return method descriptor or {@code null} if there is no such method */ public JavaMethodDesc lookupStaticMethod(String name) { return getMembers().staticMethods.get(name); }
/** * Looks up a public non-static field in this class. * * @param name field name * @return field or {@code null} if there is no such field */ public JavaFieldDesc lookupField(String name) { return getMembers().fields.get(name); }
/** * Looks up a public static field in this class. * * @param name field name * @return field or {@code null} if there is no such field */ public JavaFieldDesc lookupStaticField(String name) { return getMembers().staticFields.get(name); }
public Collection<String> getFieldNames(boolean onlyStatic) { return Collections.unmodifiableCollection((onlyStatic ? getMembers().staticFields : getMembers().fields).keySet()); }
public Collection<String> getMethodNames(boolean onlyStatic, boolean includeInternal) { Map<String, JavaMethodDesc> methods = onlyStatic ? getMembers().staticMethods : getMembers().methods; if (includeInternal || onlyStatic) { return Collections.unmodifiableCollection(methods.keySet()); } else { Collection<String> methodNames = new ArrayList<>(methods.size()); for (Map.Entry<String, JavaMethodDesc> entry : methods.entrySet()) { if (!entry.getValue().isInternal()) { methodNames.add(entry.getKey()); } } return methodNames; } }