From 5c0616ad263fb3728ea6557ba0fae1b74a849cf0 Mon Sep 17 00:00:00 2001 From: Nathan <43486313+StormiFire@users.noreply.github.com> Date: Fri, 8 Jan 2021 14:00:37 -0500 Subject: [PATCH] Fixes complications (#39) * Fixes complications Fixes issue #38 and Regex removing symbols from the class names that may be required to identify the component. * Fixes build error * Fixes improper class name * Let's try again * Modify invalid component error --- .../DynamicComponents/DynamicComponents.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java index db387a9..6fac1e7 100644 --- a/src/com/yusufcihan/DynamicComponents/DynamicComponents.java +++ b/src/com/yusufcihan/DynamicComponents/DynamicComponents.java @@ -46,8 +46,8 @@ helpUrl = "https://github.com/ysfchn/DynamicComponents-AI2/blob/main/README.md", iconName = "aiwebres/icon.png", nonVisible = true, - version = 7, - versionName = "2.2.0" + version = 8, + versionName = "2.2.1" ) @SimpleObject(external = true) public class DynamicComponents extends AndroidNonvisibleComponent { @@ -84,6 +84,21 @@ public boolean exists(Component component) { public boolean exists(String id) { return COMPONENTS.containsKey(id); } + + public String getClassName(Object componentName) { + String regex = "[^.$@a-zA-Z0-9]"; + String componentNameString = componentName.toString().replaceAll(regex, ""); + + if (componentName instanceof String && componentNameString.contains(".")) { + return componentNameString; + } else if (componentName instanceof String) { + return BASE + componentNameString; + } else if (componentName instanceof Component) { + return componentName.getClass().getName().replaceAll(regex, ""); + } else { + throw new YailRuntimeError("Component is invalid.", "DynamicComponents"); + } + } public Method getMethod(Method[] methods, String name, int parameterCount) { name = name.replaceAll("[^a-zA-Z0-9]", ""); @@ -188,11 +203,10 @@ public void ChangeId(String id, String newId) { @SimpleFunction(description = "Creates a new dynamic component.") public void Create(final AndroidViewComponent in, Object componentName, final String id) throws Exception { - componentName = componentName.toString().replaceAll("[^a-zA-Z0-9]", ""); if (!COMPONENTS.containsKey(id)) { lastUsedId = id; - String mClassName = BASE + componentName; + String mClassName = UTIL_INSTANCE.getClassName(componentName); Class mClass = Class.forName(mClassName); final Constructor mConstructor = mClass.getConstructor(ComponentContainer.class);