PageRenderTime 51ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/AS2Haxe/src/ca/scotthyndman/as2haxe/dom/ASArrayAccess.java

http://actionscripttohaxe.googlecode.com/
Java | 156 lines | 79 code | 22 blank | 55 comment | 11 complexity | 600ee26e8700743c57f584a53e070394 MD5 | raw file
  1. package ca.scotthyndman.as2haxe.dom;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import ca.scotthyndman.as2haxe.dom.visitor.IVisitor;
  5. /**
  6. * Represents array access
  7. */
  8. public class ASArrayAccess extends ASExpression {
  9. /**
  10. * The "array" structural property of this node type.
  11. */
  12. public static final ASChildPropertyDescriptor ARRAY_PROPERTY = new ASChildPropertyDescriptor(
  13. ASArrayAccess.class, "array", ASExpression.class, true);
  14. /**
  15. * The "index" structural property of this node type.
  16. */
  17. public static final ASChildPropertyDescriptor INDEX_PROPERTY = new ASChildPropertyDescriptor(
  18. ASArrayAccess.class, "index", ASExpression.class, true);
  19. /** The array */
  20. private ASExpression array;
  21. /** The index */
  22. private ASExpression index;
  23. /**
  24. * Constructs a new instance of ASArrayAccess
  25. *
  26. * @param ast
  27. * The abstract syntax tree that owns this element
  28. */
  29. public ASArrayAccess(AST ast) {
  30. super(ast);
  31. }
  32. /**
  33. * @param array
  34. * the array to set
  35. */
  36. public void setArray(ASExpression array) {
  37. ASTNode oldChild = this.array;
  38. preReplaceChild(oldChild, array, ARRAY_PROPERTY);
  39. this.array = array;
  40. postReplaceChild(oldChild, array, ARRAY_PROPERTY);
  41. }
  42. /**
  43. * @return the array
  44. */
  45. public ASExpression getArray() {
  46. return array;
  47. }
  48. /**
  49. * @param index
  50. * the index to set
  51. */
  52. public void setIndex(ASExpression index) {
  53. if (index == null) {
  54. throw new IllegalArgumentException();
  55. }
  56. // an ArrayAccess may occur inside an Expression
  57. // must check cycles
  58. ASTNode oldChild = this.index;
  59. preReplaceChild(oldChild, index, INDEX_PROPERTY);
  60. this.index = index;
  61. postReplaceChild(oldChild, index, INDEX_PROPERTY);
  62. }
  63. /**
  64. * @return the index
  65. */
  66. public ASExpression getIndex() {
  67. return index;
  68. }
  69. // ===== INTERNAL GET/SET
  70. /*
  71. * (omit javadoc for this method) Method declared on ASTNode.
  72. */
  73. final ASTNode internalGetSetChildProperty(
  74. ASChildPropertyDescriptor property, boolean get, ASTNode child) {
  75. if (property == ARRAY_PROPERTY) {
  76. if (get) {
  77. return getArray();
  78. } else {
  79. setArray((ASExpression) child);
  80. return null;
  81. }
  82. }
  83. if (property == INDEX_PROPERTY) {
  84. if (get) {
  85. return getIndex();
  86. } else {
  87. setIndex((ASExpression) child);
  88. return null;
  89. }
  90. }
  91. // allow default implementation to flag the error
  92. return super.internalGetSetChildProperty(property, get, child);
  93. }
  94. // ===== TO STRING AND VISITOR
  95. /**
  96. * Returns a string representation of the object.
  97. */
  98. @Override
  99. public String toString() {
  100. return getArray().toString() + "[" + getIndex().toString() + "]";
  101. }
  102. @Override
  103. public void accept(IVisitor as2Visitor, boolean recursive) {
  104. recursive = as2Visitor.visit(this);
  105. if (recursive) {
  106. getArray().accept(as2Visitor, recursive);
  107. getIndex().accept(as2Visitor, recursive);
  108. }
  109. }
  110. // ======= STATIC CONSTRUCTION
  111. /**
  112. * Returns a list of structural property descriptors for this node type.
  113. * Clients must not modify the result.
  114. *
  115. * @return a list of property descriptors (element type:
  116. * {@link ASPropertyDescriptor})
  117. *
  118. */
  119. public static List propertyDescriptors() {
  120. return PROPERTY_DESCRIPTORS;
  121. }
  122. /**
  123. * A list of property descriptors (element type:
  124. * {@link StructuralPropertyDescriptor}), or null if uninitialized.
  125. */
  126. private static final List<ASPropertyDescriptor> PROPERTY_DESCRIPTORS;
  127. static {
  128. List<Object> properyList = new ArrayList<Object>(3);
  129. createPropertyList(ASArrayAccess.class, properyList);
  130. addProperty(ARRAY_PROPERTY, properyList);
  131. addProperty(INDEX_PROPERTY, properyList);
  132. PROPERTY_DESCRIPTORS = reapPropertyList(properyList);
  133. }
  134. }