system/src/sc/lang/java/ForVarStatement.java
public Statement transformToJS() {
      Object dataType = expression.getTypeDeclaration();
      boolean isArray = ModelUtil.isArray(dataType);

      expression.transformToJS();
      statement.transformToJS();

      ForControlStatement newFor = new ForControlStatement();
      SemanticNodeList init = new SemanticNodeList();
      String loopVar = "_i";
      String arrVal = "_lv";
      int ct = countNestedForVarLoops();
      if (ct != 0) {
         loopVar += ct;
         arrVal += ct;
      }
      SemanticNodeList<Definition> forInitVal = new SemanticNodeList<Definition>();
      Statement toInsert;
      Statement toPrepend;
      if (isArray) {
         VariableStatement vs = VariableStatement.create(ClassType.createStarted(Object.class, "var"), loopVar, "=", IntegerLiteral.create(0));
         forInitVal.add(vs);
         newFor.setProperty("forInit", forInitVal);
         Expression loopExpr = (Expression) expression.deepCopy(ISemanticNode.CopyNormal, null);
         toPrepend = VariableStatement.create(ClassType.createStarted(Object.class, "var"), arrVal, "=", loopExpr);
         newFor.setProperty("condition", ConditionalExpression.create(IdentifierExpression.create(loopVar), "<", IdentifierExpression.create(arrVal, "length")));
         SemanticNodeList<Expression> repeatVal = new SemanticNodeList<Expression>();
         repeatVal.add(PostfixUnaryExpression.create(loopVar, "++"));
         newFor.setProperty("repeat", repeatVal);
         toInsert = VariableStatement.create(ClassType.createStarted(Object.class, "var"), identifier, "=", SelectorExpression.create((Expression) expression.deepCopy(ISemanticNode.CopyNormal, null), ArraySelector.create(IdentifierExpression.create(loopVar))));
      }
      else {
         SelectorExpression selExpr;
         SemanticNodeList args = new SemanticNodeList();
         // Selector expressions can't chain off of other selector expressions so need to use the existing one and just add to it.
         if (expression instanceof SelectorExpression) {
            selExpr = (SelectorExpression) expression.deepCopy(ISemanticNode.CopyNormal, null);
            selExpr.selectors.add(VariableSelector.create("iterator", args));
         }
         else {
            selExpr = SelectorExpression.create((Expression) expression.deepCopy(ISemanticNode.CopyNormal, null), VariableSelector.create("iterator", args));
         }

         VariableStatement vs = VariableStatement.create(ClassType.createStarted(Object.class, "var"), loopVar, "=", selExpr);
         forInitVal.add(vs);
         newFor.setProperty("forInit", forInitVal);
         newFor.setProperty("condition", IdentifierExpression.createMethodCall(new SemanticNodeList(), loopVar, "hasNext"));
         toInsert = VariableStatement.create(ClassType.createStarted(Object.class, "var"), identifier, "=", IdentifierExpression.createMethodCall(new SemanticNodeList(), loopVar, "next"));
         toPrepend = null;
      }
      BlockStatement bst;
      if (statement instanceof BlockStatement) {
         bst = (BlockStatement) statement;
         bst.addStatementAt(0, toInsert);
      }
      else {
         bst = new BlockStatement();
         bst.addStatementAt(0, toInsert);
         bst.addStatementAt(1, statement);
      }
      newFor.setProperty("statement", bst);

      if (toPrepend != null) {
         BlockStatement outerBS = new BlockStatement();
         outerBS.addStatementAt(0, toPrepend);
         outerBS.addStatementAt(1, newFor);
         parentNode.replaceChild(this, outerBS);
         return outerBS;
      }
      else {
         parentNode.replaceChild(this, newFor);
         return newFor;
      }
   }
/** Javascript does not support the foo(x : collection) syntax of Java so this will convert it to a regular ForControlStatement which is supported */
Javascript does not support the foo(x : collection) syntax of Java so this will convert it to a regular ForControlStatement which is supported
Javascript does not support the foo ( x : collection ) syntax of Java so this will convert it to a regular ForControlStatement which is supported
public Statement transformToJS() {
      Object dataType = expression.getTypeDeclaration();
      boolean isArray = ModelUtil.isArray(dataType);
      expression.transformToJS();
      statement.transformToJS();
      ForControlStatement newFor = new ForControlStatement();
      SemanticNodeList init = new SemanticNodeList();
      String loopVar = "_i";
      String arrVal = "_lv";
      int ct = countNestedForVarLoops();
      if (ct != 0) {
         loopVar += ct;
         arrVal += ct;
      }
      SemanticNodeList<Definition> forInitVal = new SemanticNodeList<Definition>();
      Statement toInsert;
      Statement toPrepend;
      if (isArray) {
         VariableStatement vs = VariableStatement.create(ClassType.createStarted(Object.class, "var"), loopVar, "=", IntegerLiteral.create(0));
         forInitVal.add(vs);
         newFor.setProperty("forInit", forInitVal);
         Expression loopExpr = (Expression) expression.deepCopy(ISemanticNode.CopyNormal, null);
         toPrepend = VariableStatement.create(ClassType.createStarted(Object.class, "var"), arrVal, "=", loopExpr);
         newFor.setProperty("condition", ConditionalExpression.create(IdentifierExpression.create(loopVar), "<", IdentifierExpression.create(arrVal, "length")));
         SemanticNodeList<Expression> repeatVal = new SemanticNodeList<Expression>();
         repeatVal.add(PostfixUnaryExpression.create(loopVar, "++"));
         newFor.setProperty("repeat", repeatVal);
         toInsert = VariableStatement.create(ClassType.createStarted(Object.class, "var"), identifier, "=", SelectorExpression.create((Expression) expression.deepCopy(ISemanticNode.CopyNormal, null), ArraySelector.create(IdentifierExpression.create(loopVar))));
      }
      else {
         SelectorExpression selExpr;
         SemanticNodeList args = new SemanticNodeList();
         if (expression instanceof SelectorExpression) {
            selExpr = (SelectorExpression) expression.deepCopy(ISemanticNode.CopyNormal, null);
            selExpr.selectors.add(VariableSelector.create("iterator", args));
         }
         else {
            selExpr = SelectorExpression.create((Expression) expression.deepCopy(ISemanticNode.CopyNormal, null), VariableSelector.create("iterator", args));
         }
         VariableStatement vs = VariableStatement.create(ClassType.createStarted(Object.class, "var"), loopVar, "=", selExpr);
         forInitVal.add(vs);
         newFor.setProperty("forInit", forInitVal);
         newFor.setProperty("condition", IdentifierExpression.createMethodCall(new SemanticNodeList(), loopVar, "hasNext"));
         toInsert = VariableStatement.create(ClassType.createStarted(Object.class, "var"), identifier, "=", IdentifierExpression.createMethodCall(new SemanticNodeList(), loopVar, "next"));
         toPrepend = null;
      }
      BlockStatement bst;
      if (statement instanceof BlockStatement) {
         bst = (BlockStatement) statement;
         bst.addStatementAt(0, toInsert);
      }
      else {
         bst = new BlockStatement();
         bst.addStatementAt(0, toInsert);
         bst.addStatementAt(1, statement);
      }
      newFor.setProperty("statement", bst);
      if (toPrepend != null) {
         BlockStatement outerBS = new BlockStatement();
         outerBS.addStatementAt(0, toPrepend);
         outerBS.addStatementAt(1, newFor);
         parentNode.replaceChild(this, outerBS);
         return outerBS;
      }
      else {
         parentNode.replaceChild(this, newFor);
         return newFor;
      }
   }
public Statement transformToJS ( ) { Object dataType = expression . getTypeDeclaration ( ) ; boolean isArray = ModelUtil . isArray ( dataType ) ; expression . transformToJS ( ) ; statement . transformToJS ( ) ; ForControlStatement newFor = new ForControlStatement ( ) ; SemanticNodeList init = new SemanticNodeList ( ) ; String loopVar = "_i" ; String arrVal = "_lv" ; int ct = countNestedForVarLoops ( ) ; if ( ct != 0 ) { loopVar += ct ; arrVal += ct ; } SemanticNodeList < Definition > forInitVal = new SemanticNodeList < Definition > ( ) ; Statement toInsert ; Statement toPrepend ; if ( isArray ) { VariableStatement vs = VariableStatement . create ( ClassType . createStarted ( Object . class , "var" ) , loopVar , "=" , IntegerLiteral . create ( 0 ) ) ; forInitVal . add ( vs ) ; newFor . setProperty ( "forInit" , forInitVal ) ; Expression loopExpr = ( Expression ) expression . deepCopy ( ISemanticNode . CopyNormal , null ) ; toPrepend = VariableStatement . create ( ClassType . createStarted ( Object . class , "var" ) , arrVal , "=" , loopExpr ) ; newFor . setProperty ( "condition" , ConditionalExpression . create ( IdentifierExpression . create ( loopVar ) , "<" , IdentifierExpression . create ( arrVal , "length" ) ) ) ; SemanticNodeList < Expression > repeatVal = new SemanticNodeList < Expression > ( ) ; repeatVal . add ( PostfixUnaryExpression . create ( loopVar , "++" ) ) ; newFor . setProperty ( "repeat" , repeatVal ) ; toInsert = VariableStatement . create ( ClassType . createStarted ( Object . class , "var" ) , identifier , "=" , SelectorExpression . create ( ( Expression ) expression . deepCopy ( ISemanticNode . CopyNormal , null ) , ArraySelector . create ( IdentifierExpression . create ( loopVar ) ) ) ) ; } else { SelectorExpression selExpr ; SemanticNodeList args = new SemanticNodeList ( ) ; if ( expression instanceof SelectorExpression ) { selExpr = ( SelectorExpression ) expression . deepCopy ( ISemanticNode . CopyNormal , null ) ; selExpr . selectors . add ( VariableSelector . create ( "iterator" , args ) ) ; } else { selExpr = SelectorExpression . create ( ( Expression ) expression . deepCopy ( ISemanticNode . CopyNormal , null ) , VariableSelector . create ( "iterator" , args ) ) ; } VariableStatement vs = VariableStatement . create ( ClassType . createStarted ( Object . class , "var" ) , loopVar , "=" , selExpr ) ; forInitVal . add ( vs ) ; newFor . setProperty ( "forInit" , forInitVal ) ; newFor . setProperty ( "condition" , IdentifierExpression . createMethodCall ( new SemanticNodeList ( ) , loopVar , "hasNext" ) ) ; toInsert = VariableStatement . create ( ClassType . createStarted ( Object . class , "var" ) , identifier , "=" , IdentifierExpression . createMethodCall ( new SemanticNodeList ( ) , loopVar , "next" ) ) ; toPrepend = null ; } BlockStatement bst ; if ( statement instanceof BlockStatement ) { bst = ( BlockStatement ) statement ; bst . addStatementAt ( 0 , toInsert ) ; } else { bst = new BlockStatement ( ) ; bst . addStatementAt ( 0 , toInsert ) ; bst . addStatementAt ( 1 , statement ) ; } newFor . setProperty ( "statement" , bst ) ; if ( toPrepend != null ) { BlockStatement outerBS = new BlockStatement ( ) ; outerBS . addStatementAt ( 0 , toPrepend ) ; outerBS . addStatementAt ( 1 , newFor ) ; parentNode . replaceChild ( this , outerBS ) ; return outerBS ; } else { parentNode . replaceChild ( this , newFor ) ; return newFor ; } }
Javascript does not support the foo(x : collection) syntax of Java so this will convert it to a regular ForControlStatement which is supported
Javascript does not support the foo ( x : collection ) syntax of Java so this will convert it to a regular ForControlStatement which is supported
// Selector expressions can't chain off of other selector expressions so need to use the existing one and just add to it.