Reflection with my UI library

In my UI library, all javascript actions are parsed and values from other components can be retrieved with a syntax like:
[icode]$[getLayer(2).getText()][/icode] which would get the component on layer 2 and (since it’s an EditField component), would get the text for it

Here is how I call the method via reflection:

Matcher matcher = Pattern.compile("\\$\\[(.*?)\\]").matcher(string); //  format $[getLayer(3).getValue()]
		while (matcher.find()) {
			String match = matcher.group();
			String nmatch = match.substring(2, match.length() - 1);
			String[] methodData = nmatch.split("\\.");
			int layer = Integer.parseInt(methodData[0].substring(9, methodData[0].length() - 1));
			String fullMethod = methodData[1];
			String[] fullMethodData = fullMethod.split("\\(");
			String method = fullMethodData[0];
//			String args = fullMethodData[1].substring(0, fullMethodData[1].length() - 1);
			Component component = ui.getLayer(layer);
			String value = "";
			try {
				Method reflectedMethod = component.getClass().getDeclaredMethod(method, null);
				reflectedMethod.setAccessible(true);
				value = String.valueOf(reflectedMethod.invoke(component)); // method is called, but returns a blank string
				System.out.println("'" + value + "'"); // just debug
			} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
				e.printStackTrace();
			}
			System.out.println(match + " --> " + value); // just debug
			string = string.replace(match, value);
		}
		return string;

Any help would be appreciated :slight_smile:

CopyableCougar4