public JNode VisitUsingStatement(UsingStatement node) { var st3 = Visit(node.ResourceAcquisition); JVariableDeclarationStatement stVar; if (st3 is JExpression) { stVar = J.Var("$r" + VariableResourceCounter++, node.Resolve().Type.JAccess(), (JExpression)st3).Statement(); } else { stVar = (JVariableDeclarationStatement)st3; } var trySt = VisitStatement(node.EmbeddedStatement); var st2 = new JTryStatement { TryBlock = trySt.ToBlock(), FinallyBlock = J.Block() }; //var resource = node.ResourceAcquisition; //var decl = resource as VariableDeclarationStatement; //if (decl == null || decl.Variables.Count == 0) // throw new Exception("using statement is supported only with the var keyword in javascript. Example: using(var g = new MyDisposable()){}"); foreach (var dr in stVar.Declaration.Declarators) { st2.FinallyBlock.Add(J.Member(dr.Name).Member("Dispose").Invoke().Statement()); } return(J.Block().Add(stVar).Add(st2)); //TODO: get rid of block }
public JNode VisitTryCatchStatement(TryCatchStatement node) { var node2 = new JTryStatement { TryBlock = (JBlock)Visit(node.TryBlock) }; if (node.CatchClauses != null && node.CatchClauses.Count > 0) { if (node.CatchClauses.Count > 1) { throw new CompilerException(node, "Client code may not have more than one catch clause, due to JavaScript limitation"); } node2.CatchClause = (JCatchClause)Visit(node.CatchClauses.First()); } if (node.FinallyBlock != null) { node2.FinallyBlock = (JBlock)Visit(node.FinallyBlock); } return(node2); }
public void VisitTryStatement(JTryStatement node) { Write("try"); if (OpenBraceInNewLine) { WriteLine(); } Visit(node.TryBlock); if (node.CatchClause != null) { Visit(node.CatchClause); } if (node.FinallyBlock != null) { Write("finally"); if (OpenBraceInNewLine) { WriteLine(); } Visit(node.FinallyBlock); } }