Support for addition operator with XMLish operands. Fix for #208
diff --git a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
index 0b98f44..bfbdc2b 100644
--- a/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
+++ b/compiler-jx/src/main/java/org/apache/royale/compiler/internal/codegen/js/jx/BinaryOperatorEmitter.java
@@ -44,6 +44,8 @@
import org.apache.royale.compiler.tree.as.*;
import org.apache.royale.compiler.utils.ASNodeUtils;
+import java.util.ArrayList;
+
public class BinaryOperatorEmitter extends JSSubEmitter implements
ISubEmitter<IBinaryOperatorNode>
{
@@ -562,8 +564,12 @@
}
else getWalker().walk(node.getLeftOperandNode());
startMapping(node, node.getLeftOperandNode());
-
- if (id != ASTNodeID.Op_CommaID)
+ boolean xmlAdd = false;
+ if (id == ASTNodeID.Op_AddID && SemanticUtils.isXMLish(node.getLeftOperandNode(),getProject()) && SemanticUtils.isXMLish(node.getRightOperandNode(),getProject())) {
+ //we need to use 'plus' method instead of '+'
+ xmlAdd = true;
+ }
+ if (id != ASTNodeID.Op_CommaID && !xmlAdd)
write(ASEmitterTokens.SPACE);
// (erikdebruin) rewrite 'a &&= b' to 'a = a && b'
@@ -585,7 +591,11 @@
}
else
{
- write(node.getOperator().getOperatorText());
+ if (xmlAdd) {
+ write(".plus(");
+ } else {
+ write(node.getOperator().getOperatorText());
+ }
}
write(ASEmitterTokens.SPACE);
@@ -612,6 +622,9 @@
write(".propertyNames()");
}
}
+ if (xmlAdd) {
+ write(")");
+ }
}
if (ASNodeUtils.hasParenOpen(node))
diff --git a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
index d22d291..7973e71 100644
--- a/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
+++ b/compiler/src/main/java/org/apache/royale/compiler/internal/semantics/SemanticUtils.java
@@ -1002,6 +1002,9 @@
//method call on XML or XMLList instance
return resolvedDef;
}
+ } else {
+ resolvedDef = functionCall.resolveType(project);
+ if (resolvedDef != null && isXMLish(resolvedDef, project)) return resolvedDef;
}
}
return null;
@@ -1018,6 +1021,11 @@
//private/protected member inside the XML or XMLList class
return resolvedDef;
}
+ } else {
+ resolvedDef = identifierNode.resolveType(project);
+ if (resolvedDef != null && isXMLish(resolvedDef, project)) {
+ return resolvedDef;
+ }
}
}
if (iNode instanceof IMemberAccessExpressionNode)
@@ -1033,6 +1041,19 @@
* Determine if the definition passed in is one of the XML types (XML or
* XMLList) These classes are unrelated, but behave in similar manners.
*
+ * @param iNode the {@link IExpressionNode} to check
+ * @param project the {@link ICompilerProject} in which to look up types
+ * @return true if definition is the built-in XML or XMLList type.
+ */
+ public static boolean isXMLish(IExpressionNode iNode, ICompilerProject project)
+ {
+ return isXMLish(resolveXML(iNode, project), project);
+ }
+
+ /**
+ * Determine if the definition passed in is one of the XML types (XML or
+ * XMLList) These classes are unrelated, but behave in similar manners.
+ *
* @param def the {@link IDefinition} to check
* @param project the {@link ICompilerProject} in which to look up types
* @return true if definition is the built-in XML or XMLList type.
@@ -1042,7 +1063,7 @@
IDefinition xmlDef = project.getBuiltinType(IASLanguageConstants.BuiltinType.XML);
IDefinition xmlListDef = project.getBuiltinType(IASLanguageConstants.BuiltinType.XMLLIST);
return (xmlDef != null && def == xmlDef) ||
- (xmlListDef != null && def == xmlListDef);
+ (xmlListDef != null && def == xmlListDef);
}
/**