Organized imports
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.core / src / net / sourceforge / phpeclipse / js / core / model / JSElement.java
1 /*
2  * $RCSfile: JSElement.java,v $
3  *
4  * Copyright 2002
5  * CH-1700 Fribourg, Switzerland
6  * All rights reserved.
7  *
8  *========================================================================
9  * Modifications history
10  *========================================================================
11  * $Log: not supported by cvs2svn $
12  * Revision 1.1  2004/09/02 18:14:39  jsurfer
13  * intial source from ttp://www.sf.net/projects/wdte
14  *
15  * Revision 1.2  2004/02/27 18:28:10  cell
16  * Make model elements platform objects so they are automatically adapted
17  *
18  * Revision 1.1  2004/02/26 02:25:42  agfitzp
19  * renamed packages to match xml & css
20  *
21  * Revision 1.1  2004/02/05 03:10:08  agfitzp
22  * Initial Submission
23  *
24  * Revision 1.1.2.1  2003/12/12 21:37:24  agfitzp
25  * Experimental work for Classes view
26  *
27  * Revision 1.2  2003/05/30 20:53:08  agfitzp
28  * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
29  *
30  * Revision 1.1  2003/05/28 15:17:12  agfitzp
31  * net.sourceforge.phpeclipse.js.core 0.0.1 code base
32  *
33  *========================================================================
34 */
35
36 package net.sourceforge.phpeclipse.js.core.model;
37
38 import java.util.LinkedList;
39 import java.util.List;
40
41 import org.eclipse.core.resources.IFile;
42 import org.eclipse.core.runtime.PlatformObject;
43
44 /**
45  * DOCUMENT ME!
46  * 
47  * @author Addi 
48  */
49 abstract public class JSElement extends PlatformObject
50         implements JSElementCategories
51 {
52         protected IFile file;
53         protected String name;
54         protected int offset;
55         protected int numberOfLines;
56         protected int length;
57
58         protected JSElement parent;
59         protected List children;
60
61         /**
62          * Creates a new JSElement and stores parent element and location in the text.
63          * 
64          * @param aName text corresponding to the func
65          * @param offset  the offset into the text
66          * @param length  the length of the element
67          */
68         public JSElement(IFile aFile, String aName, int offset, int length)
69         {
70                 this.file = aFile;
71                 this.name = aName;
72                 this.offset = offset;
73                 this.length = length;
74                 this.children = new LinkedList();
75         }
76
77         /**
78          * Method declared on IWorkbenchAdapter
79          * @param o
80          * 
81          * @return
82          */
83         public String getLabel(Object o)
84         {
85                 return name;
86         }
87
88         /**
89          * Returns the number of characters in this section.
90          * @return
91          */
92         public int getLength()
93         {
94                 return length;
95         }
96
97         /**
98          * Returns the number of lines in the element.
99          * 
100          * @return the number of lines in the element
101          */
102         public int getNumberOfLines()
103         {
104                 return numberOfLines;
105         }
106
107         /**
108          * Returns the offset of this section in the file.
109          * @return
110          */
111         public int getStart()
112         {
113                 return offset;
114         }
115
116         /**
117          * Sets the number of lines in the element
118          * 
119          * @param newNumberOfLines  the number of lines in the element
120          */
121         public void setNumberOfLines(int newNumberOfLines)
122         {
123                 numberOfLines = newNumberOfLines;
124         }
125
126         /**
127          * @see java.lang.Object#toString()
128          */
129         public String toString()
130         {
131                 return getLabel(this);
132         }
133
134         /**
135          * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object)
136          */
137         public Object[] getChildren(Object o)
138         {
139                 Object[] result = new Object[children.size()];
140                 return children.toArray(result);
141         }
142
143         /**
144          * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(Object)
145          */
146         public Object getParent(Object o)
147         {
148                 return null;
149         }
150         
151         /**
152          * 
153          * @return A category enumeration for sub-types.
154          */
155         abstract public int category();
156
157         /**
158          * @return
159          */
160         public String getName()
161         {
162                 return name;
163         }
164
165         /**
166          * @return
167          */
168         public int getOffset()
169         {
170                 return offset;
171         }
172
173         /**
174          * @return
175          */
176         public JSElement getParent()
177         {
178                 return parent;
179         }
180
181         /**
182          * @param element
183          */
184         protected void setParent(JSElement element)
185         {
186                 parent = element;
187         }
188
189         /**
190          * @param anElement
191          * @return
192          */
193         public boolean sharesParentWith(JSElement anElement)
194         {
195                 if(parent == null) {
196                         return anElement.getParent() == null;
197                 }
198                 
199                 return parent.equals(anElement.getParent());
200         }
201
202         /**
203          * @param anElement
204          * @return
205          */
206         public boolean equals(JSElement anElement)
207         {
208                 return sharesParentWith(anElement) && name.equals(anElement.getName());
209         }
210
211         /**
212          * @return Returns the file.
213          */
214         public IFile getFile() {
215                 return file;
216         }
217
218         /**
219          * @param file The file to set.
220          */
221         protected void setFile(IFile file) {
222                 this.file = file;
223         }
224
225 }