import org.eclipse.jface.text.Position;
import java.util.ArrayList;
+import java.util.List;
/**
super(sourceStart, sourceEnd);
this.parent = parent;
this.name = name;
+ position = new Position(sourceStart, name.length);
}
public void addMethod(MethodDeclaration method) {
}
public String toString() {
- return toStringHeader();
+ final StringBuffer buff = new StringBuffer(new String(name));//$NON-NLS-1$
+ if (superclass != null) {
+ buff.append(":"); //$NON-NLS-1$
+ buff.append(superclass);
+ }
+ return buff.toString();
}
public Position getPosition() {
return position;
}
+
+ public List getList() {
+ return children;
+ }
}
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.ArrayList;
+import java.util.List;
/**
* A Method declaration.
}
public String toStringHeader() {
- StringBuffer buff = new StringBuffer();
- buff.append("function ");//$NON-NLS-1$
- if (reference) {
- buff.append('&');//$NON-NLS-1$
- }
- buff.append(name).append("(");//$NON-NLS-1$
-
- if (arguments != null) {
- Enumeration values = arguments.elements();
- int i = 0;
- while (values.hasMoreElements()) {
- VariableDeclaration o = (VariableDeclaration) values.nextElement();
- buff.append(o.toStringExpression());
- if (i != (arguments.size() - 1)) {
- buff.append(", "); //$NON-NLS-1$
- }
- i++;
- }
- }
- buff.append(")"); //$NON-NLS-1$
- return buff.toString();
+ return "function " + toString();
}
/**
}
public String toString() {
- return toStringHeader();
+ StringBuffer buff = new StringBuffer();
+ if (reference) {
+ buff.append("&");//$NON-NLS-1$
+ }
+ buff.append(name).append("(");//$NON-NLS-1$
+
+ if (arguments != null) {
+ Enumeration values = arguments.elements();
+ int i = 0;
+ while (values.hasMoreElements()) {
+ VariableDeclaration o = (VariableDeclaration) values.nextElement();
+ buff.append(o.toStringExpression());
+ if (i != (arguments.size() - 1)) {
+ buff.append(", "); //$NON-NLS-1$
+ }
+ i++;
+ }
+ }
+ buff.append(")"); //$NON-NLS-1$
+ return buff.toString();
}
public Position getPosition() {
return position;
}
+
+ public List getList() {
+ return children;
+ }
}
import org.eclipse.jface.text.Position;
import java.util.ArrayList;
+import java.util.List;
/**
* It's a php document.
*/
public AstNode[] nodes;
+ public char[] name;
/** The parent of the object. */
public Object parent;
/** The outlineable children (those will be in the node array too. */
private ArrayList children = new ArrayList();
+ private Position position;
/**
* Create the PHPDocument.
* @param parent the parent object (it should be null isn't it ?)
*/
- public PHPDocument(Object parent) {
+ public PHPDocument(Object parent, char[] name) {
this.parent = parent;
+ this.name = name;
+ position = new Position(1,name.length);
}
/**
}
public Position getPosition() {
- //todo : check this
- return null;
+ return position;
+ }
+
+ public List getList() {
+ return children;
}
}
\ No newline at end of file
return parent;
}
+ public String toString() {
+ return toStringExpression();
+ }
+
/**
* Get the image of a variable.
* @return the image that represents a php variable
package net.sourceforge.phpdt.internal.compiler.parser;
+import java.util.List;
+
/**
- * The interface that will describe an object that can have children
+ * The interface that will describe an object that can have children.
* @author Matthieu Casanova
*/
public interface OutlineableWithChildren extends Outlineable {
Outlineable get(int index);
int size();
+
+ List getList();
}
import net.sourceforge.phpeclipse.PHPeclipsePlugin;
import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IPositionUpdater;
+import org.eclipse.jface.text.*;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeContentProvider;
protected static class SegmentComparator implements Comparator {
public int compare(Object o1, Object o2) {
- if (o1 instanceof PHPSegmentWithChildren && !(o2 instanceof PHPSegmentWithChildren)) {
+ if (o1 instanceof OutlineableWithChildren && !(o2 instanceof OutlineableWithChildren)) {
return 1;
}
- if (o2 instanceof PHPSegmentWithChildren && !(o1 instanceof PHPSegmentWithChildren)) {
+ if (o2 instanceof OutlineableWithChildren && !(o1 instanceof OutlineableWithChildren)) {
return -1;
}
return ((Outlineable) o1).toString().compareToIgnoreCase(((Outlineable) o2).toString());
* @see ITreeContentProvider#hasChildren(Object)
*/
public boolean hasChildren(Object element) {
- if (element instanceof PHPSegmentWithChildren) {
- return !((PHPSegmentWithChildren) element).getList().isEmpty();
+ if (element instanceof OutlineableWithChildren) {
+ return !((OutlineableWithChildren) element).getList().isEmpty();
}
return element == fInput;
}
public Object[] getChildren(Object element) {
if (element == fInput)
return fContent.toArray();
- if (element instanceof PHPSegmentWithChildren)
- return ((PHPSegmentWithChildren) element).getList().toArray();
+ if (element instanceof OutlineableWithChildren)
+ return ((OutlineableWithChildren) element).getList().toArray();
return new Object[0];
}
};
}
public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
- currentSegment = new PHPDocument(parent);
+ phpDocument = new PHPDocument(parent,"_root".toCharArray());
+ currentSegment = phpDocument;
outlineInfo = new PHPOutlineInfo(parent, currentSegment);
final StringReader stream = new StringReader(s);
if (jj_input_stream == null) {
init();
try {
parse();
- phpDocument = new PHPDocument(null);
phpDocument.nodes = new AstNode[nodes.length];
System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
+ phpDocument.toString();
} catch (ParseException e) {
processParseException(e);
}
case FUNCTION:
method = MethodDeclaration();
method.setParent(classDeclaration);
- classDeclaration.addMethod(method);
break;
case VAR:
field = FieldDeclaration();
- classDeclaration.addVariable(field);
break;
default:
jj_la1[8] = jj_gen;
}
public final PHPOutlineInfo parseInfo(final Object parent, final String s) {
- currentSegment = new PHPDocument(parent);
+ phpDocument = new PHPDocument(parent,"_root".toCharArray());
+ currentSegment = phpDocument;
outlineInfo = new PHPOutlineInfo(parent, currentSegment);
final StringReader stream = new StringReader(s);
if (jj_input_stream == null) {
init();
try {
parse();
- phpDocument = new PHPDocument(null);
phpDocument.nodes = new AstNode[nodes.length];
System.arraycopy(nodes,0,phpDocument.nodes,0,nodes.length);
+ phpDocument.toString();
} catch (ParseException e) {
processParseException(e);
}
FieldDeclaration field;
}
{
- method = MethodDeclaration() {method.setParent(classDeclaration);
- classDeclaration.addMethod(method);}
-| field = FieldDeclaration() {classDeclaration.addVariable(field);}
+ method = MethodDeclaration() {method.setParent(classDeclaration);}
+| field = FieldDeclaration()
}
/**