Skip to content

Commit

Permalink
Fixes complications (#39)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hammerhai authored Jan 8, 2021
1 parent facb5df commit 5c0616a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/com/yusufcihan/DynamicComponents/DynamicComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]", "");
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5c0616a

Please sign in to comment.