2 * $RCSfile: JSElement.java,v $
5 * CH-1700 Fribourg, Switzerland
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
15 * Revision 1.2 2004/02/27 18:28:10 cell
16 * Make model elements platform objects so they are automatically adapted
18 * Revision 1.1 2004/02/26 02:25:42 agfitzp
19 * renamed packages to match xml & css
21 * Revision 1.1 2004/02/05 03:10:08 agfitzp
24 * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp
25 * Experimental work for Classes view
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.
30 * Revision 1.1 2003/05/28 15:17:12 agfitzp
31 * net.sourceforge.phpeclipse.js.core 0.0.1 code base
33 *========================================================================
36 package net.sourceforge.phpeclipse.js.core.model;
38 import java.util.LinkedList;
39 import java.util.List;
41 import org.eclipse.core.resources.IFile;
42 import org.eclipse.core.runtime.PlatformObject;
49 abstract public class JSElement extends PlatformObject
50 implements JSElementCategories
53 protected String name;
55 protected int numberOfLines;
58 protected JSElement parent;
59 protected List children;
62 * Creates a new JSElement and stores parent element and location in the text.
64 * @param aName text corresponding to the func
65 * @param offset the offset into the text
66 * @param length the length of the element
68 public JSElement(IFile aFile, String aName, int offset, int length)
74 this.children = new LinkedList();
78 * Method declared on IWorkbenchAdapter
83 public String getLabel(Object o)
89 * Returns the number of characters in this section.
92 public int getLength()
98 * Returns the number of lines in the element.
100 * @return the number of lines in the element
102 public int getNumberOfLines()
104 return numberOfLines;
108 * Returns the offset of this section in the file.
111 public int getStart()
117 * Sets the number of lines in the element
119 * @param newNumberOfLines the number of lines in the element
121 public void setNumberOfLines(int newNumberOfLines)
123 numberOfLines = newNumberOfLines;
127 * @see java.lang.Object#toString()
129 public String toString()
131 return getLabel(this);
135 * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object)
137 public Object[] getChildren(Object o)
139 Object[] result = new Object[children.size()];
140 return children.toArray(result);
144 * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(Object)
146 public Object getParent(Object o)
153 * @return A category enumeration for sub-types.
155 abstract public int category();
160 public String getName()
168 public int getOffset()
176 public JSElement getParent()
184 protected void setParent(JSElement element)
193 public boolean sharesParentWith(JSElement anElement)
196 return anElement.getParent() == null;
199 return parent.equals(anElement.getParent());
206 public boolean equals(JSElement anElement)
208 return sharesParentWith(anElement) && name.equals(anElement.getName());
212 * @return Returns the file.
214 public IFile getFile() {
219 * @param file The file to set.
221 protected void setFile(IFile file) {