d6a394da0c80afaf128b0da0c526c7405f62b94d
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / PHPDocument.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
4 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
5 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
6 import org.eclipse.jface.resource.ImageDescriptor;
7 import org.eclipse.jface.text.Position;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 /**
13  * It's a php document.
14  * This class is an outlineable object
15  * It will contains html and php
16  * @author Matthieu Casanova
17  */
18 public class PHPDocument implements OutlineableWithChildren {
19
20   /**
21    * The nodes.
22    * It will include html nodes or php nodes
23    */
24   public AstNode[] nodes;
25
26   public char[] name;
27
28   /** The parent of the object. */
29   public Object parent;
30
31   /** The outlineable children (those will be in the node array too. */
32   private ArrayList children = new ArrayList();
33
34   private Position position;
35   /**
36    * Create the PHPDocument.
37    * @param parent the parent object (it should be null isn't it ?)
38    */
39   public PHPDocument(Object parent, char[] name) {
40     this.parent = parent;
41     this.name = name;
42     position = new Position(1,name.length);
43   }
44
45   /**
46    * Return the php document as String.
47    * @return  a string representation of the object.
48    */
49   public String toString() {
50     final StringBuffer buff = new StringBuffer();
51     AstNode node;
52     if (nodes != null) {
53       int i;
54       for (i = 0; i < nodes.length; i++) {
55         node = nodes[i];
56         if (node == null) {
57           break;
58         }
59         buff.append(node.toString(0));
60         if (node instanceof HTMLCode) {
61           buff.append("\n");
62         } else {
63           buff.append(";\n");
64         }
65       }
66     }
67     return buff.toString();
68   }
69
70   /**
71    * Add an outlineable object.
72    * @param o the new outlineable
73    * @return does the addition worked ?
74    */
75   public boolean add(Outlineable o) {
76     return children.add(o);
77   }
78
79   /**
80    * Return the outlineable at the index.
81    * @param index the index
82    * @return an outlineable object
83    */
84   public Outlineable get(int index) {
85     return (Outlineable) children.get(index);
86   }
87
88   /**
89    * The number of outlineable children.
90    * @return the number of children that are outlineable
91    */
92   public int size() {
93     return children.size();
94   }
95
96   /**
97    * This will return the image for the outline of the object.
98    * @return an image
99    */
100   public ImageDescriptor getImage() {
101     return PHPUiImages.DESC_CLASS;
102   }
103
104   /**
105    * Get the parent of the object.
106    * @return the parent of the object
107    */
108   public Object getParent() {
109     return parent;
110   }
111
112   public Position getPosition() {
113     return position;
114   }
115
116   public List getList() {
117     return children;
118   }
119 }