From 74ae41a3408424e410518282b225c16a3b390c1f Mon Sep 17 00:00:00 2001 From: kpoorman Date: Mon, 2 Oct 2023 13:52:52 -0700 Subject: [PATCH] not ready for consumption at the moment. Signed-off-by: kpoorman --- .../classes/experiments/AutoCallable.cls | 57 +++++++++++++++++++ .../experiments/AutoCallable.cls-meta.xml | 5 ++ 2 files changed, 62 insertions(+) create mode 100644 force-app/main/default/classes/experiments/AutoCallable.cls create mode 100644 force-app/main/default/classes/experiments/AutoCallable.cls-meta.xml diff --git a/force-app/main/default/classes/experiments/AutoCallable.cls b/force-app/main/default/classes/experiments/AutoCallable.cls new file mode 100644 index 00000000..534c8984 --- /dev/null +++ b/force-app/main/default/classes/experiments/AutoCallable.cls @@ -0,0 +1,57 @@ +/** + * Created by kpoorman on 10/2/23. + */ + +public with sharing class AutoCallable { + public Map> 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> methodMap = new Map>(); + 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 methodInfo = new Map(); + 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 { + } +} diff --git a/force-app/main/default/classes/experiments/AutoCallable.cls-meta.xml b/force-app/main/default/classes/experiments/AutoCallable.cls-meta.xml new file mode 100644 index 00000000..7a518297 --- /dev/null +++ b/force-app/main/default/classes/experiments/AutoCallable.cls-meta.xml @@ -0,0 +1,5 @@ + + + 58.0 + Active +