You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@royale.apache.org by jo...@apache.org on 2021/02/18 23:15:22 UTC

[royale-compiler] 07/08: playerglobal-source-gen: fix issue where XML/XMLList methods should accept * instead of a specific type

This is an automated email from the ASF dual-hosted git repository.

joshtynjala pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/royale-compiler.git

commit 70c1c9a610da2518634515f759240f3f413775ef
Author: Josh Tynjala <jo...@apache.org>
AuthorDate: Thu Feb 18 12:49:00 2021 -0800

    playerglobal-source-gen: fix issue where XML/XMLList methods should accept * instead of a specific type
    
    The docs here are wrong and don't match the compiler behavior
---
 .../apache/royale/playerglobal/PlayerglobalSourceGen.java | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/playerglobal-source-gen/src/main/java/org/apache/royale/playerglobal/PlayerglobalSourceGen.java b/playerglobal-source-gen/src/main/java/org/apache/royale/playerglobal/PlayerglobalSourceGen.java
index 88f1449..5d0ae34 100644
--- a/playerglobal-source-gen/src/main/java/org/apache/royale/playerglobal/PlayerglobalSourceGen.java
+++ b/playerglobal-source-gen/src/main/java/org/apache/royale/playerglobal/PlayerglobalSourceGen.java
@@ -67,6 +67,10 @@ class PlayerglobalSourceGen {
 	}
 
 	private static final List<String> VECTOR_SUFFIXES = Arrays.asList("$double", "$int", "$uint", "$object");
+	private static final List<String> XML_ANY_METHODS = Arrays.asList("addNamespace", "appendChild", "attribute",
+			"child", "contains", "descendants", "elements", "insertChildAfter", "insertChildBefore", "namespace",
+			"prependChild", "processingInstructions", "removeNamespace", "replace", "setChildren", "setName",
+			"setNamespace");
 
 	private File sourceFolder;
 	private File targetFolder;
@@ -958,10 +962,18 @@ class PlayerglobalSourceGen {
 		}
 	}
 
+	private boolean isXMLMethodThatNeedsParamsTypedAsAny(String contextClassName, String contextFunctionName) {
+		if (!"XML".equals(contextClassName) && !"XMLList".equals(contextClassName)) {
+			return false;
+		}
+		return XML_ANY_METHODS.contains(contextFunctionName);
+	}
+
 	private void parseParameters(List<Element> apiParamElements, String contextClassName, String contextFunctionName,
 			StringBuilder functionBuilder) throws Exception {
 		boolean isXMLConstructor = ("XML".equals(contextClassName) && "XML".equals(contextFunctionName))
 				|| ("XMLList".equals(contextClassName) && "XMLList".equals(contextFunctionName));
+		boolean forceAnyType = isXMLMethodThatNeedsParamsTypedAsAny(contextClassName, contextFunctionName);
 		for (int i = 0; i < apiParamElements.size(); i++) {
 			if (i > 0) {
 				functionBuilder.append(", ");
@@ -990,6 +1002,9 @@ class PlayerglobalSourceGen {
 					paramType = apiOperationClassifierElement.getTextTrim();
 					paramType = paramType.replace(":", ".");
 				}
+				if (forceAnyType) {
+					paramType = "*";
+				}
 				if (paramType != null) {
 					functionBuilder.append(":");
 					functionBuilder.append(paramType);