2 * $RCSfile: JSElement.java,v $
5 * CH-1700 Fribourg, Switzerland
8 *========================================================================
9 * Modifications history
10 *========================================================================
11 * $Log: not supported by cvs2svn $
12 * Revision 1.2 2004/02/27 18:28:10 cell
13 * Make model elements platform objects so they are automatically adapted
15 * Revision 1.1 2004/02/26 02:25:42 agfitzp
16 * renamed packages to match xml & css
18 * Revision 1.1 2004/02/05 03:10:08 agfitzp
21 * Revision 1.1.2.1 2003/12/12 21:37:24 agfitzp
22 * Experimental work for Classes view
24 * Revision 1.2 2003/05/30 20:53:08 agfitzp
25 * 0.0.2 : Outlining is now done as the user types. Some other bug fixes.
27 * Revision 1.1 2003/05/28 15:17:12 agfitzp
28 * net.sourceforge.phpeclipse.js.core 0.0.1 code base
30 *========================================================================
33 package net.sourceforge.phpeclipse.js.core.model;
35 import java.util.List;
36 import java.util.LinkedList;
38 import org.eclipse.core.resources.IFile;
39 import org.eclipse.core.runtime.PlatformObject;
46 abstract public class JSElement extends PlatformObject
47 implements JSElementCategories
50 protected String name;
52 protected int numberOfLines;
55 protected JSElement parent;
56 protected List children;
59 * Creates a new JSElement and stores parent element and location in the text.
61 * @param aName text corresponding to the func
62 * @param offset the offset into the text
63 * @param length the length of the element
65 public JSElement(IFile aFile, String aName, int offset, int length)
71 this.children = new LinkedList();
75 * Method declared on IWorkbenchAdapter
80 public String getLabel(Object o)
86 * Returns the number of characters in this section.
89 public int getLength()
95 * Returns the number of lines in the element.
97 * @return the number of lines in the element
99 public int getNumberOfLines()
101 return numberOfLines;
105 * Returns the offset of this section in the file.
108 public int getStart()
114 * Sets the number of lines in the element
116 * @param newNumberOfLines the number of lines in the element
118 public void setNumberOfLines(int newNumberOfLines)
120 numberOfLines = newNumberOfLines;
124 * @see java.lang.Object#toString()
126 public String toString()
128 return getLabel(this);
132 * @see org.eclipse.ui.model.IWorkbenchAdapter#getChildren(Object)
134 public Object[] getChildren(Object o)
136 Object[] result = new Object[children.size()];
137 return children.toArray(result);
141 * @see org.eclipse.ui.model.IWorkbenchAdapter#getParent(Object)
143 public Object getParent(Object o)
150 * @return A category enumeration for sub-types.
152 abstract public int category();
157 public String getName()
165 public int getOffset()
173 public JSElement getParent()
181 protected void setParent(JSElement element)
190 public boolean sharesParentWith(JSElement anElement)
193 return anElement.getParent() == null;
196 return parent.equals(anElement.getParent());
203 public boolean equals(JSElement anElement)
205 return sharesParentWith(anElement) && name.equals(anElement.getName());
209 * @return Returns the file.
211 public IFile getFile() {
216 * @param file The file to set.
218 protected void setFile(IFile file) {