use of com.servoy.j2db.scripting.annotations.AnnotationManagerReflection in project servoy-client by Servoy.
the class DefaultJavaScope method getJsFunctions.
public static Map<String, NativeJavaMethod> getJsFunctions(Class<?> clazz) {
Map<String, NativeJavaMethod> jsFunctions = new HashMap<String, NativeJavaMethod>();
try {
for (Method method : clazz.getMethods()) {
String name = null;
if (// $NON-NLS-1$
method.getName().startsWith("js_")) {
name = method.getName().substring(3);
} else if (// $NON-NLS-1$
method.getName().startsWith("jsFunction_")) {
name = method.getName().substring(11);
} else {
AnnotationManagerReflection annotationManager = AnnotationManagerReflection.getInstance();
JSReadonlyProperty jsReadonlyProperty = annotationManager.getAnnotation(method, clazz, JSReadonlyProperty.class);
if (jsReadonlyProperty != null) {
name = jsReadonlyProperty.property();
if (name == null || name.length() == 0) {
name = method.getName();
}
} else if (annotationManager.isAnnotationPresent(method, clazz, JSFunction.class)) {
name = method.getName();
}
}
if (name != null) {
NativeJavaMethod nativeJavaMethod = jsFunctions.get(name);
if (nativeJavaMethod == null) {
nativeJavaMethod = new NativeJavaMethod(method, name);
} else {
nativeJavaMethod = new NativeJavaMethod(Utils.arrayAdd(nativeJavaMethod.getMethods(), new MemberBox(method), true), name);
}
jsFunctions.put(name, nativeJavaMethod);
}
}
} catch (Exception e) {
Debug.error(e);
}
return jsFunctions;
}
Aggregations