From: kpouer Date: Sun, 8 Jun 2003 00:07:25 +0000 (+0000) Subject: *** empty log message *** X-Git-Url: http://secure.phpeclipse.com?hp=40b9a3dcdde67b29099fd3efa4ae504a0e3dc9f7 *** empty log message *** --- diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java index 18f52c1..fccd134 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java @@ -8,6 +8,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.Position; import java.util.ArrayList; +import java.util.List; /** @@ -68,6 +69,7 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr super(sourceStart, sourceEnd); this.parent = parent; this.name = name; + position = new Position(sourceStart, name.length); } public void addMethod(MethodDeclaration method) { @@ -166,10 +168,19 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr } 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; + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java index e08010d..5c3a64e 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/MethodDeclaration.java @@ -9,6 +9,7 @@ import org.eclipse.jface.text.Position; import java.util.Hashtable; import java.util.Enumeration; import java.util.ArrayList; +import java.util.List; /** * A Method declaration. @@ -64,27 +65,7 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild } 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(); } /** @@ -135,10 +116,33 @@ public class MethodDeclaration extends Statement implements OutlineableWithChild } 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; + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java index b2f523d..249daaf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/PHPDocument.java @@ -7,6 +7,7 @@ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.text.Position; import java.util.ArrayList; +import java.util.List; /** * It's a php document. @@ -22,18 +23,22 @@ public class PHPDocument implements OutlineableWithChildren { */ 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); } /** @@ -99,7 +104,10 @@ public class PHPDocument implements OutlineableWithChildren { } public Position getPosition() { - //todo : check this - return null; + return position; + } + + public List getList() { + return children; } } \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java index 6d01007..5a709fd 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/VariableDeclaration.java @@ -96,6 +96,10 @@ public class VariableDeclaration extends AbstractVariableDeclaration implements return parent; } + public String toString() { + return toStringExpression(); + } + /** * Get the image of a variable. * @return the image that represents a php variable diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/OutlineableWithChildren.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/OutlineableWithChildren.java index 430a136..c7bfd79 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/OutlineableWithChildren.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/OutlineableWithChildren.java @@ -1,7 +1,9 @@ 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 { @@ -10,4 +12,6 @@ public interface OutlineableWithChildren extends Outlineable { Outlineable get(int index); int size(); + + List getList(); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java index ca2b95a..b091a43 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java @@ -27,10 +27,7 @@ import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry; 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; @@ -56,10 +53,10 @@ public class PHPContentOutlinePage extends AbstractContentOutlinePage { 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()); @@ -184,8 +181,8 @@ public class PHPContentOutlinePage extends AbstractContentOutlinePage { * @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; } @@ -206,8 +203,8 @@ public class PHPContentOutlinePage extends AbstractContentOutlinePage { 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]; } }; diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.java b/net.sourceforge.phpeclipse/src/test/PHPParser.java index a25a5b4..4440696 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.java @@ -101,7 +101,8 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon } 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) { @@ -111,9 +112,9 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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); } @@ -629,11 +630,9 @@ public final class PHPParser extends PHPParserSuperclass implements PHPParserCon 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; diff --git a/net.sourceforge.phpeclipse/src/test/PHPParser.jj b/net.sourceforge.phpeclipse/src/test/PHPParser.jj index baab0b4..e9930a3 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParser.jj +++ b/net.sourceforge.phpeclipse/src/test/PHPParser.jj @@ -122,7 +122,8 @@ public final class PHPParser extends PHPParserSuperclass { } 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) { @@ -132,9 +133,9 @@ public final class PHPParser extends PHPParserSuperclass { 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); } @@ -766,9 +767,8 @@ void ClassBodyDeclaration(ClassDeclaration classDeclaration) : FieldDeclaration field; } { - method = MethodDeclaration() {method.setParent(classDeclaration); - classDeclaration.addMethod(method);} -| field = FieldDeclaration() {classDeclaration.addVariable(field);} + method = MethodDeclaration() {method.setParent(classDeclaration);} +| field = FieldDeclaration() } /**