PageRenderTime 62ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/AjaxMinDll/JavaScript/while.cs

#
C# | 85 lines | 59 code | 9 blank | 17 comment | 7 complexity | 0ae5db65fe72607ff07d6db07bf814b7 MD5 | raw file
  1. // while.cs
  2. //
  3. // Copyright 2010 Microsoft Corporation
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. using System.Collections.Generic;
  17. namespace Microsoft.Ajax.Utilities
  18. {
  19. public sealed class WhileNode : IterationStatement
  20. {
  21. private AstNode m_condition;
  22. public AstNode Condition
  23. {
  24. get { return m_condition; }
  25. set
  26. {
  27. ReplaceNode(ref m_condition, value);
  28. }
  29. }
  30. public override Context TerminatingContext
  31. {
  32. get
  33. {
  34. // if we have one, return it. If not, return what the body has (if any)
  35. return base.TerminatingContext ?? Body.IfNotNull(b => b.TerminatingContext);
  36. }
  37. }
  38. public WhileNode(Context context)
  39. : base(context)
  40. {
  41. }
  42. public override void Accept(IVisitor visitor)
  43. {
  44. if (visitor != null)
  45. {
  46. visitor.Visit(this);
  47. }
  48. }
  49. public override IEnumerable<AstNode> Children
  50. {
  51. get
  52. {
  53. return EnumerateNonNullNodes(Condition, Body);
  54. }
  55. }
  56. public override bool ReplaceChild(AstNode oldNode, AstNode newNode)
  57. {
  58. if (Condition == oldNode)
  59. {
  60. Condition = newNode;
  61. return true;
  62. }
  63. if (Body == oldNode)
  64. {
  65. Body = ForceToBlock(newNode);
  66. return true;
  67. }
  68. return false;
  69. }
  70. internal override bool EncloseBlock(EncloseBlockType type)
  71. {
  72. // pass the query on to the body
  73. return Body == null ? false : Body.EncloseBlock(type);
  74. }
  75. }
  76. }