/* * (non-Javadoc) * @see * com.aptana.editor.js.parsing.ast.JSTreeWalker#visit(com.aptana.editor.js.parsing.ast.JSArithmeticOperatorNode) */ @Override public void visit(JSBinaryArithmeticOperatorNode node) { String type = JSTypeConstants.NUMBER_TYPE; if (node.getNodeType() == IJSNodeTypes.ADD) { IParseNode lhs = node.getLeftHandSide(); IParseNode rhs = node.getRightHandSide(); // NOTE: Iterate down the tree until we find the first non-addition node or the first string while (lhs.getNodeType() == IJSNodeTypes.ADD) { rhs = lhs.getLastChild(); lhs = lhs.getFirstChild(); if (rhs instanceof JSStringNode) { break; } } if (lhs instanceof JSStringNode || rhs instanceof JSStringNode) { type = JSTypeConstants.STRING_TYPE; } else { List<String> lhsTypes = this.getTypes(lhs); List<String> rhsTypes = this.getTypes(rhs); if (lhsTypes.contains(JSTypeConstants.STRING_TYPE) || rhsTypes.contains(JSTypeConstants.STRING_TYPE)) { type = JSTypeConstants.STRING_TYPE; } } } this.addType(type); }
/** * A private helper function for {@link #toTreeString(IParseNode)} * * @param buffer * @param node */ private static void toTreeString(List<String> buffer, IParseNode node) { // TODO: Move to an iterative (non-recursive) implementation if this gets used outside of unit // testing buffer.add("("); // $NON-NLS-1$ buffer.add(node.getElementName()); if (node.hasChildren()) { IParseNode lastChild = node.getLastChild(); buffer.add(" "); // $NON-NLS-1$ for (IParseNode child : node) { toTreeString(buffer, child); if (child != lastChild) { buffer.add(" "); // $NON-NLS-1$ } } } buffer.add(")"); // $NON-NLS-1$ }