Package org.hisrc.jscm.codemodel.expression

Examples of org.hisrc.jscm.codemodel.expression.JSVariable


    f.identifier(value.getName());

    f.openRoundBracket();
    for (int index = 0; index < value.getParameters().size(); index++) {
      final JSVariable parameter = value.getParameters().get(index);
      if (index > 0) {
        f.comma().whiteSpace();
      }
      f.identifier(parameter.getName());
    }
    f.closeRoundBracket();
    f.whiteSpace();
    f.openCurlyBracket().lineTerminator();
View Full Code Here


      f.identifier(value.getName());
    }

    f.openRoundBracket();
    for (int index = 0; index < value.getParameters().size(); index++) {
      final JSVariable parameter = value.getParameters().get(index);
      if (index > 0) {
        f.comma().whiteSpace();
      }
      f.identifier(parameter.getName());
    }
    f.closeRoundBracket().whiteSpace();
    f.openCurlyBracket().lineTerminator();

    final CodeWriter fi = f.indented();
View Full Code Here

    return unmodifiableParameters;
  }

  public JSVariable parameter(String name) {
    Validate.notNull(name);
    JSVariable parameter = new VariableImpl(getCodeModel(), name);
    this.parameters.add(parameter);
    return parameter;
  }
View Full Code Here

      return body;
    }

    public JSVariable parameter(String name) {
      Validate.notNull(name);
      JSVariable parameter = new VariableImpl(getCodeModel(), name);
      this.parameters.add(parameter);
      return parameter;
    }
View Full Code Here

    JSProgram program = codeModel.program();
    // Add a function declaration
    JSFunctionDeclaration factorial = program
        .functionDeclaration("factorial");
    // Add a function parameter
    JSVariable x = factorial.parameter("x");
    // Create an integer literal
    JSDecimalIntegerLiteral one = codeModel.integer(1);
    // Add a return statement to the function body
    factorial.getBody()._return(
        x.le(one).cond(
            one,
            x.mul(factorial.getFunctionExpression().i()
                .args(x.minus(one)))));

    // Write the program code to the System.out
    new CodeWriter(System.out).program(program);

    final Writer stringWriter = new StringWriter();
View Full Code Here

    JSCodeModel codeModel = new CodeModelImpl();

    JSProgram program = codeModel.program();
    JSFunctionDeclaration f = program.functionDeclaration("f");

    JSVariable x = f.parameter("x");
    JSVariable y = f.parameter("y");

    JSFunctionBody body = f.getBody();

    JSBlock assignmentExpressions = body.block();

    assignmentExpressions.expression(x.assign(y));
    assignmentExpressions.expression(x.mulAssign(y));
    assignmentExpressions.expression(x.divAssign(y));
    assignmentExpressions.expression(x.modAssign(y));
    assignmentExpressions.expression(x.plusAssign(y));
    assignmentExpressions.expression(x.minusAssign(y));
    assignmentExpressions.expression(x.shlAssign(y));
    assignmentExpressions.expression(x.shrAssign(y));
    assignmentExpressions.expression(x.shrzAssign(y));
    assignmentExpressions.expression(x.bandAssign(y));
    assignmentExpressions.expression(x.borAssign(y));
    assignmentExpressions.expression(x.xorAssign(y));

    JSBlock conditionalExpressions = assignmentExpressions.block();
    conditionalExpressions.expression(x.cond(y, y.not()));

    JSBlock logicalORExpressions = conditionalExpressions.block();
    logicalORExpressions.expression(x.or(y));

    JSBlock logicalANDExpressions = logicalORExpressions.block();
    logicalANDExpressions.expression(x.and(y));

    JSBlock bitwiseORExpressions = logicalANDExpressions.block();
    bitwiseORExpressions.expression(x.bor(y));

    JSBlock bitwiseXORExpressions = bitwiseORExpressions.block();
    bitwiseXORExpressions.expression(x.xor(y));

    JSBlock bitwiseANDExpressions = bitwiseXORExpressions.block();

    bitwiseANDExpressions.expression(x.band(y));

    JSBlock equalityExpressions = bitwiseANDExpressions.block();
    equalityExpressions.expression(x.eq(y));
    equalityExpressions.expression(x.ne(y));
    equalityExpressions.expression(x.eeq(y));
    equalityExpressions.expression(x.nee(y));

    JSBlock relationalExpressions = equalityExpressions.block();

    relationalExpressions.expression(x.lt(y));
    relationalExpressions.expression(x.gt(y));
    relationalExpressions.expression(x.le(y));
    relationalExpressions.expression(x.ge(y));
    relationalExpressions.expression(x._instanceof(y));
    relationalExpressions.expression(x.in(y));

    JSBlock shiftExpressions = relationalExpressions.block();

    shiftExpressions.expression(x.shl(y));
    shiftExpressions.expression(x.shr(y));
    shiftExpressions.expression(x.shrz(y));

    JSBlock additiveExpressions = shiftExpressions.block();

    additiveExpressions.expression(x.plus(y));
    additiveExpressions.expression(x.minus(y));

    JSBlock multiplicativeExpressions = additiveExpressions.block();

    multiplicativeExpressions.expression(x);
    multiplicativeExpressions.expression(x.mul(y));
    multiplicativeExpressions.expression(x.div(y));
    multiplicativeExpressions.expression(x.mod(y));

    JSBlock unaryExpressions = multiplicativeExpressions.block();

    unaryExpressions.expression(x.delete());
    unaryExpressions.expression(x._void());
    unaryExpressions.expression(x.typeof());
    unaryExpressions.expression(x.preIncr());
    unaryExpressions.expression(x.preDecr());
    unaryExpressions.expression(x.positive());
    unaryExpressions.expression(x.negative());
    unaryExpressions.expression(x.complement());
    unaryExpressions.expression(x.not());

    JSBlock postfixExpressions = unaryExpressions.block();

    postfixExpressions.expression(x.postIncr());
    postfixExpressions.expression(x.postDecr());

    JSBlock leftHandSideExpressions = postfixExpressions.block();

    JSBlock callExpressions = leftHandSideExpressions.block();

    callExpressions.expression(x.i().args(y).args(y).args(y));
    callExpressions.expression(x.i().args(y));
    callExpressions.expression(x.i().args(y, y, y));
    callExpressions.expression(x.i().args(y).i()
        .args(codeModel.integer(0), codeModel.integer(1)));

    callExpressions.expression(x.i().args(y).e(codeModel.integer(0)));
    callExpressions.expression(x.i().args(y).p("zero"));
    callExpressions.expression(x.i().args(y).p(codeModel.integer(0)));
    callExpressions.expression(x.i().args(y).p(codeModel.string("two")));

    JSBlock newExpressions = leftHandSideExpressions.block();

    newExpressions.expression(x._new());

    JSBlock memberExpressions = newExpressions.block();

    memberExpressions.expression(codeModel.function());
    JSFunctionExpression.Function foo = codeModel.function("foo");
    JSVariable a = foo.parameter("a");
    JSVariable b = foo.parameter("b");
    JSVariable c = foo.parameter("c");
    foo.getBody().expression(a.plus(b));
    foo.getBody()._return(c);
    memberExpressions.expression(foo);
    memberExpressions.expression(x.e(codeModel.integer(0)));
    memberExpressions.expression(x.p("zero"));
View Full Code Here

    JSGlobalVariable window1 = codeModel.globalVariable("window");
    Assert.assertSame(window, window1);

    JSFunctionDeclaration f = program.functionDeclaration("f");

    JSVariable x = f.parameter("x");
    JSVariable y = f.parameter("y");

    JSFunctionBody body = f.getBody();

    {
      body.functionDeclaration("g").getBody().functionDeclaration("h")
          .getBody().functionDeclaration("i");
      body.expression(window.p("open").i()
          .args(codeModel._this()));
      body.block();
      body.block().block();
      body.block().block();
      body.block().block().block().block();
      body.block().block().block().block().debugger();
    }
    {
      body.var("a").getVariable();
      body.var("b", codeModel.string("b"));

      body.var("c", codeModel.string("c")).comma("d")
          .comma("e", codeModel.string("e"));
    }
    body.empty();
    {
      {
        body._if(x.gt(y))._then()._return();
      }
      {
        body._if(x.gt(y))._then().block()._return();
      }

      {
        JSIfStatement _if = body._if(x.le(y));
        _if._then()._return(x.mul(y));
        _if._else()._return(x.plus(x));
      }
      {
        JSIfStatement _if = body._if(x.le(y));
        _if._then().block()._return(x.mul(y));
        _if._else().block()._return(x.plus(x));
      }
      {
        JSIfStatement _if = body._if(x.le(y));
        _if._then().block()._return(x.mul(y));
        _if._else()._if(x.eq(y))._then()._return(x.plus(x));
      }
    }

    {

      body._for().test(x.lt(y)).update(x.postIncr())
          .expression(y.preIncr());
      body._for().update(x.postIncr()).expression(y.preIncr());
      body._for().test(x.lt(y)).expression(y.preIncr());
      body._for()._break();
      body._for(x.assign(codeModel.integer(0))).test(x.lt(y))
          .update(x.postIncr()).expression(y.preIncr());
      body.forIn(x, y).block().expression(x.postDecr());

      JSForVarStatement _forVar0 = body.forVar("x0");
      Assert.assertNull(_forVar0.getExpression());
      JSVariable x0 = _forVar0.getVariable();
      _forVar0.comma("x1").comma("x2", codeModel.integer(10));
      _forVar0.test(x0.lt(codeModel.integer(5))).update(x0.postIncr())
          .expression(y.plusAssign(x0));

      JSForVarStatement _forVar1 = body
          .forVar("x1", codeModel.integer(0));
      Assert.assertNotNull(_forVar1.getExpression());
      JSVariable x1 = _forVar1.getVariable();
      _forVar1.test(x1.lt(codeModel.integer(5))).update(x1.postIncr())
          .expression(y.plusAssign(x1));

      JSForVarInStatement _forVarIn = body.forVarIn("x3", y);
      JSVariable x3 = _forVarIn.getVariable();
      _forVarIn.expression(y.plusAssign(x3));

      body.doWhile(x.lt(y)).expression(x.postIncr());
      body.doWhile(x.lt(y)).block().expression(x.postIncr());
View Full Code Here

      _Prototype.append("Version", codeModel.string("1.6.1"));
    }
    {
      final Function function = codeModel.function();
      JSFunctionBody body = function.getBody();
      JSVariable $ua = body.var("ua",
          $navigator.p("userAgent")).getVariable();
      JSVariable $isOpera = body.var(
          "isOpera",
          $Object.p("prototype").p("toString")
              .i("call").args($window.p("opera"))
              .eq(codeModel.string("[object Opera]")))
          .getVariable();
      body._return(codeModel
          .object()
          .append("IE",
              $window.p("attachEvent").not().not()
                  .and($isOpera.not()))
          .append("Opera", $isOpera)
          .append("WebKit",
              $ua.i("indexOf")
                  .args(codeModel.string("AppleWebKit/"))
                  .gt(codeModel.integer(-1)))
          .append("Gecko",
              $ua.i("indexOf")
                  .args(codeModel.string("Gecko"))
                  .gt(codeModel.integer(-1))
                  .and($ua.i("indexOf")
                      .args(codeModel.string("KHTML"))
                      .eeq(codeModel.integer(-1))))
      // Regexps are not supported at the moment
      // append("MobileSafari",
      // codeModel.regexp("/Apple.*Mobile.*Safari/").call("test").args($ua))
      );

      _Prototype.append("Browser", function.brackets().i());
    }

    {
      final JSObjectLiteral _BrowserFeatures = codeModel.object();
      _Prototype.append("BrowserFeatures", _BrowserFeatures);

      _BrowserFeatures.append("XPath", $document.p("evaluate")
          .not().not());
      _BrowserFeatures.append("SelectorsAPI",
          $document.p("querySelector").not().not());
      {
        final Function _ElementExtensions = codeModel.function();

        JSVariable $constructor = _ElementExtensions
            .getBody()
            .var(
                "constructor",
                $window.p("Element").or(
                    $window.p("HTMLElement")))
            .getVariable();
        _ElementExtensions.getBody()._return(
            $constructor.and($constructor.p("prototype"))
                .brackets().not().not());
        _BrowserFeatures.append("ElementExtensions", _ElementExtensions
            .brackets().i());
      }

      {
        final Function f = codeModel.function();
        _BrowserFeatures.append("SpecificElementExtensions", f
            .brackets().i());
        JSFunctionBody b = f.getBody();
        b._if($window.p("HTMLDivElement").typeof()
            .nee(codeModel.string("undefined")))._then()
            ._return(codeModel._boolean(true));

        JSVariable $div = b.var(
            "div",
            $document.i("createElement").args(
                codeModel.string("div"))).getVariable();
        JSVariable $form = b.var(
            "form",
            $document.i("createElement").args(
                codeModel.string("form"))).getVariable();

        JSVariable $isSupported = b.var("isSupported",
            codeModel._boolean(false)).getVariable();

        b._if($div.e(codeModel.string("__proto__")).and(
            $div.e(codeModel.string("__proto__"))
                .nee($form.e(codeModel
                    .string("__proto__"))).brackets()))
            ._then()
            .block()
            .expression(
                $isSupported.assign(codeModel._boolean(true)));

        b.expression($div.assign($form.assign(codeModel._null())));
        b._return($isSupported);
      }

    }
    {
      _Prototype.append("ScriptFragment",
          codeModel.string("<script[^>]*>([\\S\\s]*?)</script>"));
      // <script[^>]*>([\\S\\s]*?)<\/script>
    }
    {
      // o.append("JSONFilter",
      // codeModel.regexp("/^\\/\\*-secure-([\\s\\S]*)\\*\\/\\s*$/"));
    }
    {
      _Prototype.append("emptyFunction", codeModel.function());
    }
    {
      final Function _K = codeModel.function();
      JSVariable $x = _K.parameter("x");
      _K.getBody()._return($x);
      _Prototype.append("K", _K);
    }

    final CodeWriter systemOutCodeWriter = new CodeWriter(System.out);
View Full Code Here

TOP

Related Classes of org.hisrc.jscm.codemodel.expression.JSVariable

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.