Android Question List of functions in a given code module?

wonder

Expert
Licensed User
Longtime User
Is there any (Reflection) code that produces the output below?

INPUT (code module / class):
B4X:
Sub Process_Globals
    ...
    ...
End Sub

Sub Method_A
    ...
End Sub

Public Sub Method_B
    ...
End Sub

Private Sub Method_C
    ...
End Sub

Public Sub ShowFunctions(module as Object)
    'magic code goes here
End Sub

OUTPUT:
B4X:
ShowFunctions(Me)

'Public:
'- Method_A
'- Method_B
'- ShowFunctions
'Private:
'- Method_C

If there is no way to show the private ones, no problem for me.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Here:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim methods As Map = GetMethods("starter")
   For Each k As String In methods.Keys
     Log(k)
   Next
End Sub

Sub GetMethods(clsName As String) As Map
   Dim jo As JavaObject
   Dim cls As String = Application.PackageName & "." & clsName.ToLowerCase
   jo.InitializeStatic(cls)
   Try
     jo.RunMethod("NA", Null) 'ignore the error message in the logs
   Catch
   End Try 'ignore
   Dim r As Reflector
   r.Target = r.GetStaticField("anywheresoftware.b4j.object.JavaObject", "methodCache")
   Dim jo As JavaObject = r.GetField("cache")
   jo = jo.RunMethod("get", Array(cls))
   Dim m As Map
   m.Initialize
   Dim mm As JavaObject = m
   mm.RunMethod("putAll", Array(jo))
   Dim m2 As Map
   m2.Initialize
   For Each k As String In m.Keys
     If k.StartsWith("_") Then
       m2.Put(k.SubString(1), m.Get(k))
     End If
   Next
   Return m2
End Sub
 
Upvote 0
Top