Package org.hisrc.jscm.codemodel

Examples of org.hisrc.jscm.codemodel.JSFunctionBody


    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));
View Full Code Here


    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());

      body._while(x.lt(y)).expression(x.postIncr());
      body._while(x.lt(y)).block().expression(x.postIncr());
    }

    {
      JSLabelledStatement labelledStatement = body.label("label0");
      JSLabel label0 = labelledStatement.getLabel();
      labelledStatement.block()._break(label0);

      body._continue();
      body._continue(label0);

      body._break();
      body._break(label0);
    }
    {
      body._return();
      body._return(x);
      body.with(x).expression(y.postIncr());
      body.with(x).block().expression(y.postIncr());
    }
    {
      JSSwitchStatement _switch0 = body._switch(x);
      JSCaseClause _case00 = _switch0._case(codeModel.integer(0));
      _case00.empty();
      _case00._return(codeModel.integer(1));

      JSSwitchStatement _switch1 = body._switch(x);
      JSCaseClause _case10 = _switch1._case(codeModel.integer(0));
      _case10.empty();
      _case10._return(codeModel.integer(1));
      JSDefaultClause _default1 = _switch1._default();
      _default1.empty();
      _default1._return(codeModel.integer(2));

      JSSwitchStatement _switch2 = body._switch(x);
      JSCaseClause _case20 = _switch2._case(codeModel.integer(0));
      _case20.expression(x.postIncr());
      _case20._return(codeModel.integer(1));
      JSDefaultClause _default2 = _switch2._default();
      _default2.empty();
      _default2._return(codeModel.integer(2));
      JSCaseClause _case22 = _switch2._case(codeModel.integer(2));
      _case22.empty();
      _case22._return(codeModel.integer(3));

    }

    {
      body._throw(x);
    }

    {
      JSTryStatement tryCatch0 = body.tryCatch("e");
      tryCatch0.getBody().expression(y.preIncr());
      tryCatch0.getCatch()._throw(tryCatch0.getException());

      JSTryStatement tryFinally0 = body.tryFinally();
      tryFinally0.getBody().expression(y.preIncr());
      tryFinally0.getFinally()._return(codeModel._boolean(true));

      JSTryStatement tryCatchFinally = body.tryCatchFinally("e");
      tryCatchFinally.getBody().expression(y.preIncr());
      tryCatchFinally.getCatch()._throw(tryCatchFinally.getException());
      tryCatchFinally.getFinally()._return(codeModel._boolean(true));
    }

    {
      body.debugger();
    }

    // f.acceptSourceElementVisitor(new SourceElementWriter(out));
    out.program(program);
  }
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",
View Full Code Here

TOP

Related Classes of org.hisrc.jscm.codemodel.JSFunctionBody

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.