royale-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aha...@apache.org
Subject [royale-compiler] 03/03: handle simple XML expressions. Sometimes we don't get an XMLLiteralNode, just a plain LiteralNode.
Date Wed, 08 Aug 2018 17:39:23 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit f60899dbd4c81fbef43769a3977f09d636f6bafe
Author: Alex Harui <aharui@apache.org>
AuthorDate: Wed Aug 8 10:39:01 2018 -0700

    handle simple XML expressions.  Sometimes we don't get an XMLLiteralNode, just a plain
LiteralNode.
---
 .../internal/codegen/js/jx/LiteralEmitter.java     | 124 +++++++++++----------
 1 file changed, 68 insertions(+), 56 deletions(-)

diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
index 467e587..6c79341 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/LiteralEmitter.java
@@ -75,67 +75,79 @@ public class LiteralEmitter extends JSSubEmitter implements
                         }
                     }
                 }
-                XMLLiteralNode xmlNode = (XMLLiteralNode) node;
-                if (jsx)
+                if (node instanceof XMLLiteralNode)
                 {
-                    emitJSX(xmlNode);
-                    return;
+                    XMLLiteralNode xmlNode = (XMLLiteralNode) node;
+	                if (jsx)
+	                {
+	                    emitJSX(xmlNode);
+	                    return;
+	                }
+	                else
+	                {
+	                    newlineReplacement = "\\\\\n";
+	                    if (xmlNode.getContentsNode().getChildCount() == 1)
+	                    {
+	                        if (s.contains("'"))
+	                            s = "\"" + s + "\"";
+	                        else
+	                            s = "'" + s + "'";
+	                    }
+	                    else
+	                    {
+	                        StringBuilder sb = new StringBuilder();
+	                        // probably contains {initializers}
+	                        boolean inAttribute = false;
+	                        int n = xmlNode.getContentsNode().getChildCount();
+	                        for (int i = 0; i < n; i++)
+	                        {
+	                            if (i > 0)
+	                                sb.append(" + ");
+	                            IASNode child = xmlNode.getContentsNode().getChild(i);
+	                            if (child instanceof LiteralNode)
+	                            {
+	                                s = ((LiteralNode)child).getValue(true);
+	                                if (s.contains("'"))
+	                                    sb.append("\"" + s + "\"");
+	                                else
+	                                    sb.append("'" + s + "'");
+	                            }
+	                            else
+	                            {
+	                                s = getEmitter().stringifyNode(child);
+	                                if (inAttribute)
+	                                {
+	                                    sb.append("'\"' + ");
+	
+	                                    sb.append(s);
+	
+	                                    sb.append(" + '\"'");
+	                                }
+	                                else
+	                                    sb.append(s);
+	                            }
+	                            inAttribute = s.endsWith("=");
+	                        }
+	                        s = sb.toString();
+	                    }
+	                    char c = s.charAt(0);
+	                    if (c == '"')
+	                    {
+	                        s = s.substring(1, s.length() - 1);
+	                        s = s.replace("\"", "__QUOTE_PLACEHOLDER__");
+	                        s = "\"" + s + "\"";
+	                    }
+	                    // use formatQualifiedName to get XML in the usedNames dependencies
+	                    s = "new " + getEmitter().formatQualifiedName("XML") + "( " + s + ")";
+	                }
                 }
                 else
                 {
-                    newlineReplacement = "\\\\\n";
-                    if (xmlNode.getContentsNode().getChildCount() == 1)
-                    {
-                        if (s.contains("'"))
-                            s = "\"" + s + "\"";
-                        else
-                            s = "'" + s + "'";
-                    }
-                    else
-                    {
-                        StringBuilder sb = new StringBuilder();
-                        // probably contains {initializers}
-                        boolean inAttribute = false;
-                        int n = xmlNode.getContentsNode().getChildCount();
-                        for (int i = 0; i < n; i++)
-                        {
-                            if (i > 0)
-                                sb.append(" + ");
-                            IASNode child = xmlNode.getContentsNode().getChild(i);
-                            if (child instanceof LiteralNode)
-                            {
-                                s = ((LiteralNode)child).getValue(true);
-                                if (s.contains("'"))
-                                    sb.append("\"" + s + "\"");
-                                else
-                                    sb.append("'" + s + "'");
-                            }
-                            else
-                            {
-                                s = getEmitter().stringifyNode(child);
-                                if (inAttribute)
-                                {
-                                    sb.append("'\"' + ");
-
-                                    sb.append(s);
-
-                                    sb.append(" + '\"'");
-                                }
-                                else
-                                    sb.append(s);
-                            }
-                            inAttribute = s.endsWith("=");
-                        }
-                        s = sb.toString();
-                    }
-                    char c = s.charAt(0);
-                    if (c == '"')
-                    {
-                        s = s.substring(1, s.length() - 1);
-                        s = s.replace("\"", "__QUOTE_PLACEHOLDER__");
+                	s = node.getValue();
+                    if (s.contains("'"))
                         s = "\"" + s + "\"";
-                    }
-                    // use formatQualifiedName to get XML in the usedNames dependencies
+                    else
+                        s = "'" + s + "'";
                     s = "new " + getEmitter().formatQualifiedName("XML") + "( " + s + ")";
                 }
             }


Mime
View raw message