First try for AST structure. A lot of things to change
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / PHPDocument.java
diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java
new file mode 100644 (file)
index 0000000..c01d085
--- /dev/null
@@ -0,0 +1,91 @@
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
+import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
+import net.sourceforge.phpdt.internal.ui.PHPUiImages;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+import java.util.ArrayList;
+
+/**
+ * It's a php document.
+ * It will contains html and php
+ * @author Matthieu Casanova
+ */
+public class PHPDocument implements OutlineableWithChildren {
+
+  /**
+   * The nodes.
+   * It will include html nodes or php nodes
+   */
+  public AstNode[] nodes;
+
+  /** The parent of the object */
+  public Object parent;
+
+  /** The outlineable children (those will be in the node array too. */
+  private ArrayList children = new ArrayList();
+
+  /**
+   * Create the PHPDocument.
+   */
+  public PHPDocument(Object parent) {
+    this.parent = parent;
+  }
+
+  /**
+   * Return the php document as String.
+   * @return  a string representation of the object.
+   */
+  public String toString() {
+    final StringBuffer buff = new StringBuffer();
+    AstNode node;
+    int i;
+    for (i = 0; i < nodes.length; i++) {
+      node = nodes[i];
+      if (node == null) {
+        break;
+      }
+      buff.append(node);
+    }
+    return buff.toString();
+  }
+
+  /**
+   * Add an outlineable object.
+   * @param o the new outlineable
+   * @return does the addition worked ?
+   */
+  public boolean add(Outlineable o) {
+    return children.add(o);
+  }
+
+  /**
+   * Return the outlineable at the index.
+   * @param index the index
+   * @return an outlineable object
+   */
+  public Outlineable get(int index) {
+    return (Outlineable) children.get(index);
+  }
+
+  /**
+   * The number of outlineable children
+   * @return
+   */
+  public int size() {
+    return children.size();
+  }
+
+  /**
+   * This will return the image for the outline of the object.
+   * @return an image
+   */
+  public ImageDescriptor getImage() {
+    return PHPUiImages.DESC_CLASS;
+  }
+
+  public Object getParent() {
+    return parent;
+  }
+}
\ No newline at end of file