Package org.mozilla.javascript.ast

Examples of org.mozilla.javascript.ast.ExpressionStatement


                        tmlScriptVarDec.setValue(value);
                        tmlScriptVarDec.setOffset(declaration.getAbsolutePosition());
                       
                        tmlScriptScope.getVariableDeclarations().add(tmlScriptVarDec);
                    } else if (node instanceof ExpressionStatement) {
                        ExpressionStatement expressionStatement = (ExpressionStatement) node;
                        String source = expressionStatement.getExpression().toSource();
                        if (source != null && source.contains("=")) {
                            String name = source.substring(0, source.indexOf("=")).trim();
                            String value = source.substring(source.indexOf("=") + 1).trim();
                           
                            TMLScriptVariableDeclaration tmlScriptVarDec = new TMLScriptVariableDeclaration(tmlScriptScope, name);
                            tmlScriptVarDec.setValue(value);
                            tmlScriptVarDec.setOffset(expressionStatement.getAbsolutePosition());
                            tmlScriptVarDec.setTmlVariable(true);
                           
                            tmlScriptScope.getVariableDeclarations().add(tmlScriptVarDec);
                        }
                    }
View Full Code Here


                boolean result = lookupProperty(propertyName);
                if (result) {
                    return false;
                }
            } else if (node instanceof ExpressionStatement) {
                ExpressionStatement statement = (ExpressionStatement)node;
                if (statement.getExpression() instanceof StringLiteral) {
                    _type = "java.lang.String";
                    //_skipJSWrapping = true;
                    return false;
                } else if (statement.getExpression() instanceof org.mozilla.javascript.ast.NumberLiteral) {
                    _type = "java.lang.Double";
                    //_skipJSWrapping = true;
                    return false;
                } else if (statement.getExpression() instanceof ArrayLiteral) {
                    _type = "java.lang.Object[]";
                    //_skipJSWrapping = true;
                    return false;
                } else if (statement.getExpression() instanceof ElementGet) {
                    String source = statement.getExpression().toSource();
                    source = source.substring(0, source.indexOf("["));
                    String propertyName =  source;
                    boolean result = lookupProperty(propertyName);
                    if (result) {
                        if (_type != null && _type.contains("[")) {
View Full Code Here

public class BranchStatementBuilderTest {
    private BranchStatementBuilder builder = new BranchStatementBuilder();

    @Test
    public void shouldBuildLineAndConditionInitialisation() {
        ExpressionStatement statement = builder.buildLineAndConditionInitialisation("test.js", 4, 2, 12, 15, "x < calc('7')");
        assertThat(statement.toSource(), equalTo("_$jscoverage['test.js'].branchData['4'][2].init(12, 15, 'x < calc(\\'7\\')');\n"));
    }
View Full Code Here

        assertThat(builder.removeInstrumentation("x++;\n  _$jscoverage['/dir/code.js'].lineData[100]++;\n"), equalTo("x++;\n"));
    }

    @Test
    public void shouldRemoveInstrumentationFromSourceInInitialisation() {
        ExpressionStatement statement = builder.buildLineAndConditionInitialisation("test.js", 4, 2, 12, 15,
                "  x++;\n" +
                "  _$jscoverage['/dir/code.js'].lineData[100]++;\n" +
                "  x++;\n" +
                "  _$jscoverage['/dir/code.js'].someOtherData[101]++;\n");
        assertThat(statement.toSource(), equalTo("_$jscoverage['test.js'].branchData['4'][2].init(12, 15, '  x++;\\n  x++;\\n');\n"));
    }
View Full Code Here

        assertThat(statement.toSource(), equalTo("_$jscoverage['test.js'].branchData['4'][2].init(12, 15, '  x++;\\n  x++;\\n');\n"));
    }

    @Test
    public void shouldBuildLineAndConditionCall() {
        ExpressionStatement statement = builder.buildLineAndConditionCall("test.js", 4, 2);
        assertThat(statement.toSource(), equalTo("_$jscoverage['test.js'].branchData['4'][2].ranCondition(result);\n"));
    }
View Full Code Here

    private StatementBuilder builder = new StatementBuilder();
    private SortedSet<Integer> validLines = new TreeSet<Integer>();

    @Test
    public void shouldCreateInstrumentationStatement() {
        ExpressionStatement statement = builder.buildInstrumentationStatement(7, "/dir/file.js", validLines);

        assertThat("_$jscoverage['/dir/file.js'].lineData[7]++;\n", equalTo(statement.toSource()));
        assertThat(validLines, hasItem(7));
    }
View Full Code Here

        builder.buildInstrumentationStatement(0, "/dir/file.js", validLines);
    }

    @Test
    public void shouldCreateFunctionInstrumentationStatement() {
        ExpressionStatement statement = builder.buildFunctionInstrumentationStatement(7, "/dir/file.js");

        assertThat("_$jscoverage['/dir/file.js'].functionData[7]++;\n", equalTo(statement.toSource()));
    }
View Full Code Here

    return u;
  }

  @Override
  public AstNode expressionStatement(AstNode expr) {
    ExpressionStatement e = new ExpressionStatement();
    e.setExpression(expr);
    return e;
  }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ast.ExpressionStatement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.