Skip to content

Commit

Permalink
not ready for consumption at the moment.
Browse files Browse the repository at this point in the history
Signed-off-by: kpoorman <kjp@codefriar.com>
  • Loading branch information
codefriar committed Oct 2, 2023
1 parent 9760b4d commit 74ae41a
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
57 changes: 57 additions & 0 deletions force-app/main/default/classes/experiments/AutoCallable.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* Created by kpoorman on 10/2/23.
*/

public with sharing class AutoCallable {
public Map<String, Map<String, Object>> findCallableMethods(
String className
) {
if (!isValidClass(className)) {
throw new AutoCallableException('Invalid Class Name');
}

ApexClass apexClass = [
SELECT Id, Name, Body
FROM ApexClass
WHERE Name = :className
WITH SYSTEM_MODE
];
Pattern publicMethodSignatureMatcher = Pattern.compile(
'public\\s+(?!static\\s+)(\\w+)\\s+(\\w+)\\s*\\([^\\)]*\\)'
);
Matcher publicMethodSignatures = publicMethodSignatureMatcher.matcher(
apexClass.Body
);
Map<String, Map<String, Object>> methodMap = new Map<String, Map<String, Object>>();
while (publicMethodSignatures.find()) {
System.debug(
'#### found Signature ' + publicMethodSignatures.group()
);
String methodSignature = publicMethodSignatures.group();
methodSignature = methodSignature.replace('(', ' ')
.replace(')', '');
System.debug('#### methodSignature without () ' + methodSignature);
String[] parts = methodSignature.split(' ', 3);

String methodReturnType = parts[1];
System.debug('#### methodReturnType ' + methodReturnType);
String methodName = parts[2];
System.debug('#### methodName ' + methodName);
String methodParams = parts[3] != null ? parts[3] : '';
System.debug('#### methodParams ' + methodParams);
Map<String, Object> methodInfo = new Map<String, Object>();
methodInfo.put('name', methodName);
methodInfo.put('params', methodParams);
methodMap.put(methodName, methodInfo);
}
return methodMap;
}

public Boolean isValidClass(String className) {
Type isType = Type.forName(className);
return isType != null;
}

public class AutoCallableException extends Exception {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<status>Active</status>
</ApexClass>

0 comments on commit 74ae41a

Please sign in to comment.