org.mozilla.javascript.Token Java Examples
The following examples show how to use
org.mozilla.javascript.Token.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ForLoop.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append("for ("); sb.append(initializer.toSource(0)); sb.append("; "); sb.append(condition.toSource(0)); sb.append("; "); sb.append(increment.toSource(0)); sb.append(") "); if (body.getType() == Token.BLOCK) { sb.append(body.toSource(depth).trim()).append("\n"); } else { sb.append("\n").append(body.toSource(depth+1)); } return sb.toString(); }
Example #2
Source File: ExpressionParserUtility.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * compile outer column expression * @param refNode * @param tree * @param columnExprList * @throws BirtException */ private void compileOuterColRef( Node refNode, ScriptNode tree, List columnExprList ) throws BirtException { int level = compileOuterColRefExpr( refNode ); if ( level == -1 ) { compileComplexExpr( refNode, tree, columnExprList ); } else { Node nextNode = refNode.getLastChild( ); if ( nextNode.getType( ) == Token.STRING ) { ColumnBinding info = new ColumnBinding( nextNode.getString( ), "", level ); columnExprList.add( info ); } } return; }
Example #3
Source File: UnaryExpression.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); int type = getType(); if (!isPostfix) { sb.append(operatorToString(type)); if (type == Token.TYPEOF || type == Token.DELPROP || type == Token.VOID) { sb.append(" "); } } sb.append(operand.toSource()); if (isPostfix) { sb.append(operatorToString(type)); } return sb.toString(); }
Example #4
Source File: ParserTest.java From astor with GNU General Public License v2.0 | 6 votes |
public void testLinenoGetProp() { AstRoot root = parse("\nfoo.bar"); ExpressionStatement st = (ExpressionStatement) root.getFirstChild(); AstNode n = st.getExpression(); assertTrue(n instanceof PropertyGet); assertEquals(Token.GETPROP, n.getType()); assertEquals(1, n.getLineno()); PropertyGet getprop = (PropertyGet) n; AstNode m = getprop.getRight(); assertTrue(m instanceof Name); assertEquals(Token.NAME, m.getType()); // used to be Token.STRING! assertEquals(1, m.getLineno()); }
Example #5
Source File: ForLoop.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append("for ("); sb.append(initializer.toSource(0)); sb.append("; "); sb.append(condition.toSource(0)); sb.append("; "); sb.append(increment.toSource(0)); sb.append(") "); if (body.getType() == Token.BLOCK) { sb.append(body.toSource(depth).trim()).append("\n"); } else { sb.append("\n").append(body.toSource(depth+1)); } return sb.toString(); }
Example #6
Source File: KeywordLiteral.java From astor with GNU General Public License v2.0 | 6 votes |
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); switch (getType()) { case Token.THIS: sb.append("this"); break; case Token.NULL: sb.append("null"); break; case Token.TRUE: sb.append("true"); break; case Token.FALSE: sb.append("false"); break; case Token.DEBUGGER: sb.append("debugger;\n"); break; default: throw new IllegalStateException("Invalid keyword literal type: " + getType()); } return sb.toString(); }
Example #7
Source File: ExpressionCompiler.java From birt with Eclipse Public License 1.0 | 6 votes |
protected AggregateExpression compileAggregateExpr( Context context, Node parent, Node callNode ) throws DataException { assert( callNode.getType() == Token.CALL ); IAggrFunction aggregation = getAggregationFunction( callNode ); // not an aggregation function being called, then it's considered // a complex expression if( aggregation == null ) return null; AggregateExpression aggregateExpression = new AggregateExpression( aggregation ); extractArguments( context, aggregateExpression, callNode ); replaceAggregateNode( aggregateExpression, parent, callNode ); return aggregateExpression; }
Example #8
Source File: ForInLoop.java From JsDroidCmd with Mozilla Public License 2.0 | 6 votes |
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append("for "); if (isForEach()) { sb.append("each "); } sb.append("("); sb.append(iterator.toSource(0)); if (isForOf) { sb.append(" of "); } else { sb.append(" in "); } sb.append(iteratedObject.toSource(0)); sb.append(") "); if (body.getType() == Token.BLOCK) { sb.append(body.toSource(depth).trim()).append("\n"); } else { sb.append("\n").append(body.toSource(depth+1)); } return sb.toString(); }
Example #9
Source File: VariableInitializer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Sets the node type. * @throws IllegalArgumentException if {@code nodeType} is not one of * {@link Token#VAR}, {@link Token#CONST}, or {@link Token#LET} */ public void setNodeType(int nodeType) { if (nodeType != Token.VAR && nodeType != Token.CONST && nodeType != Token.LET) throw new IllegalArgumentException("invalid node type"); setType(nodeType); }
Example #10
Source File: ExpressionCompiler.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * @param aggregateExpression * @param parent * @param aggregateCallNode * @throws DataException */ private void replaceAggregateNode( AggregateExpression aggregateExpression, Node parent, Node aggregateCallNode ) throws DataException { if( registry == null ) throw new DataException( ResourceConstants.INVALID_CALL_AGGR ); // replace the aggregate CALL node with _aggr_value[<aggregateId>] int aggregateId = registry.register( aggregateExpression ); Node newFirstChild = Node.newString( Token.NAME, AGGR_VALUE ); Node newSecondChild = Node.newNumber( aggregateId ); Node aggregateNode = new Node( Token.GETELEM, newFirstChild, newSecondChild ); parent.replaceChild( aggregateCallNode, aggregateNode ); }
Example #11
Source File: WithStatement.java From astor with GNU General Public License v2.0 | 5 votes |
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append("with ("); sb.append(expression.toSource(0)); sb.append(") "); if (statement.getType() == Token.BLOCK) { sb.append(statement.toSource(depth).trim()); sb.append("\n"); } else { sb.append("\n").append(statement.toSource(depth + 1)); } return sb.toString(); }
Example #12
Source File: KeywordLiteral.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Sets node token type * @throws IllegalArgumentException if {@code nodeType} is unsupported */ @Override public KeywordLiteral setType(int nodeType) { if (!(nodeType == Token.THIS || nodeType == Token.NULL || nodeType == Token.TRUE || nodeType == Token.FALSE || nodeType == Token.DEBUGGER)) throw new IllegalArgumentException("Invalid node type: " + nodeType); type = nodeType; return this; }
Example #13
Source File: ScriptNode.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
void addSymbol(Symbol symbol) { if (variableNames != null) codeBug(); if (symbol.getDeclType() == Token.LP) { paramCount++; } symbols.add(symbol); }
Example #14
Source File: Jump.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
public void setFinally(Node finallyTarget) { if (type != Token.TRY) codeBug(); if (finallyTarget.getType() != Token.TARGET) codeBug(); if (target2 != null) codeBug(); //only once target2 = finallyTarget; }
Example #15
Source File: InfixExpression.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override public boolean hasSideEffects() { // the null-checks are for malformed expressions in IDE-mode switch (getType()) { case Token.COMMA: return right != null && right.hasSideEffects(); case Token.AND: case Token.OR: return left != null && left.hasSideEffects() || (right != null && right.hasSideEffects()); default: return super.hasSideEffects(); } }
Example #16
Source File: ObjectProperty.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Sets the node type. Must be one of * {@link Token#COLON}, {@link Token#GET}, or {@link Token#SET}. * @throws IllegalArgumentException if {@code nodeType} is invalid */ public void setNodeType(int nodeType) { if (nodeType != Token.COLON && nodeType != Token.GET && nodeType != Token.SET) throw new IllegalArgumentException("invalid node type: " + nodeType); setType(nodeType); }
Example #17
Source File: ExpressionParserUtility.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * compile the expression from a script tree * * @param expression * @param context * @param tree * @param columnExprList * @throws BirtException */ private void CompiledExprFromTree( String expression, Context context, ScriptNode tree, List columnExprList ) throws BirtException { if ( tree.getFirstChild( ) == tree.getLastChild( ) ) { if ( tree.getFirstChild( ).getType( ) == Token.FUNCTION ) { int index = getFunctionIndex( tree.getFirstChild( ).getString( ), tree ); compileFunctionNode( tree.getFunctionNode( index ), tree, columnExprList ); } else { // A single expression if ( tree.getFirstChild( ).getType( ) != Token.EXPR_RESULT && tree.getFirstChild( ).getType( ) != Token.EXPR_VOID && tree.getFirstChild( ).getType( ) != Token.BLOCK && tree.getFirstChild( ).getType( ) != Token.SCRIPT) { // This should never happen? throw new CoreException( pluginId, ResourceConstants.INVALID_EXPRESSION ); } Node exprNode = tree.getFirstChild( ); processChild( exprNode, tree, columnExprList ); } } else { compileComplexExpr( tree, tree, columnExprList ); } }
Example #18
Source File: AstNode.java From astor with GNU General Public License v2.0 | 5 votes |
public boolean visit(AstNode node) { int tt = node.getType(); String name = Token.typeToName(tt); buffer.append(node.getAbsolutePosition()).append("\t"); buffer.append(makeIndent(node.depth())); buffer.append(name).append(" "); buffer.append(node.getPosition()).append(" "); buffer.append(node.getLength()); if (tt == Token.NAME) { buffer.append(" ").append(((Name)node).getIdentifier()); } buffer.append("\n"); return true; // process kids }
Example #19
Source File: AstRoot.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
/** * Debugging function to check that the parser has set the parent * link for every node in the tree. * @throws IllegalStateException if a parent link is missing */ public void checkParentLinks() { this.visit(new NodeVisitor() { public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } }); }
Example #20
Source File: ObjectProperty.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
/** * Sets the node type. Must be one of * {@link Token#COLON}, {@link Token#GET}, or {@link Token#SET}. * @throws IllegalArgumentException if {@code nodeType} is invalid */ public void setNodeType(int nodeType) { if (nodeType != Token.COLON && nodeType != Token.GET && nodeType != Token.SET && nodeType != Token.METHOD) throw new IllegalArgumentException("invalid node type: " + nodeType); setType(nodeType); }
Example #21
Source File: VariableDeclaration.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Sets the node type and returns this node. * @throws IllegalArgumentException if {@code declType} is invalid */ @Override public org.mozilla.javascript.Node setType(int type) { if (type != Token.VAR && type != Token.CONST && type != Token.LET) throw new IllegalArgumentException("invalid decl type: " + type); return super.setType(type); }
Example #22
Source File: ExpressionUtility.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * if the Node is row Node, return true * * @param refNode * @return */ private static boolean getDirectColRefExpr( Node refNode ) { assert ( refNode.getType( ) == Token.GETPROP || refNode.getType( ) == Token.GETELEM ); Node rowName = refNode.getFirstChild( ); assert ( rowName != null ); if ( rowName.getType( ) != Token.NAME ) return false; String str = rowName.getString( ); assert ( str != null ); if ( !str.equals( STRING_ROW ) ) return false; Node rowColumn = rowName.getNext( ); assert ( rowColumn != null ); if ( refNode.getType( ) == Token.GETPROP && rowColumn.getType( ) == Token.STRING ) { return true; } else if ( refNode.getType( ) == Token.GETELEM ) { if ( rowColumn.getType( ) == Token.NUMBER || rowColumn.getType( ) == Token.STRING ) return true; } return false; }
Example #23
Source File: JavascriptTestability.java From testability-explorer with Apache License 2.0 | 5 votes |
public boolean visit(AstNode node) { if (node.getType() == Token.FUNCTION) { if (node.getEnclosingFunction() != null) { count++; } } return true; }
Example #24
Source File: VariableDeclaration.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
/** * Sets the node type and returns this node. * @throws IllegalArgumentException if {@code declType} is invalid */ @Override public org.mozilla.javascript.Node setType(int type) { if (type != Token.VAR && type != Token.CONST && type != Token.LET) throw new IllegalArgumentException("invalid decl type: " + type); return super.setType(type); }
Example #25
Source File: AstRoot.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Debugging function to check that the parser has set the parent * link for every node in the tree. * @throws IllegalStateException if a parent link is missing */ public void checkParentLinks() { this.visit(new NodeVisitor() { public boolean visit(AstNode node) { int type = node.getType(); if (type == Token.SCRIPT) return true; if (node.getParent() == null) throw new IllegalStateException ("No parent for node: " + node + "\n" + node.toSource(0)); return true; } }); }
Example #26
Source File: WithStatement.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
@Override public String toSource(int depth) { StringBuilder sb = new StringBuilder(); sb.append(makeIndent(depth)); sb.append("with ("); sb.append(expression.toSource(0)); sb.append(") "); if (statement.getType() == Token.BLOCK) { sb.append(statement.toSource(depth).trim()); sb.append("\n"); } else { sb.append("\n").append(statement.toSource(depth + 1)); } return sb.toString(); }
Example #27
Source File: Symbol.java From JsDroidCmd with Mozilla Public License 2.0 | 5 votes |
/** * Sets symbol declaration type */ public void setDeclType(int declType) { if (!(declType == Token.FUNCTION || declType == Token.LP || declType == Token.VAR || declType == Token.LET || declType == Token.CONST)) throw new IllegalArgumentException("Invalid declType: " + declType); this.declType = declType; }
Example #28
Source File: MultiPassExpressionCompiler.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * replace the aggregate node with AGGR_VALUE <id> * * @param registry * @param aggregateExpression * @param parent * @param aggregateCallNode * @throws DataException */ private void replaceAggregateNode( int registry, Node parent, Node aggregateCallNode ) throws DataException { if ( registry < 0 ) throw new DataException( ResourceConstants.INVALID_CALL_AGGR ); int aggregateId = registry; Node newFirstChild = Node.newString( Token.NAME, AGGR_VALUE ); Node newSecondChild = Node.newNumber( aggregateId ); Node aggregateNode = new Node( Token.GETELEM, newFirstChild, newSecondChild ); parent.replaceChild( aggregateCallNode, aggregateNode ); }
Example #29
Source File: ExpressionParserUtility.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * * @param callNode * @param tree * @param columnExprList * @throws BirtException */ private void compileAggregationFunction( Node callNode, ScriptNode tree, List columnExprList ) throws BirtException { Node firstChild = callNode.getFirstChild( ); if ( firstChild.getType( ) != Token.GETPROP ) return; Node getPropLeftChild = firstChild.getFirstChild( ); if ( getPropLeftChild.getType( ) == Token.NAME && getPropLeftChild.getString( ).equals( TOTAL ) ) hasAggregation = true; compileComplexExpr( firstChild, tree, columnExprList ); }
Example #30
Source File: ParserTest.java From rhino-android with Apache License 2.0 | 5 votes |
public void testLinenoCall() { AstRoot root = parse("\nfoo(123);"); ExpressionStatement st = (ExpressionStatement) root.getFirstChild(); AstNode n = st.getExpression(); assertTrue(n instanceof FunctionCall); assertEquals(Token.CALL, n.getType()); assertEquals(1, n.getLineno()); }