X-Git-Url: http://git.phpeclipse.com 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 2adfda1..6d9d031 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java @@ -18,10 +18,9 @@ import java.util.Comparator; import java.util.List; import java.util.TreeSet; +import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; +import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; -import net.sourceforge.phpdt.internal.compiler.parser.Parser; -import net.sourceforge.phpdt.internal.compiler.parser.PHPSegment; -import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren; import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry; import net.sourceforge.phpeclipse.PHPeclipsePlugin; @@ -39,28 +38,29 @@ import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; -import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + +import test.PHPParserManager; +import test.PHPParserSuperclass; /** * A content outline page which always represents the functions of the * connected PHPEditor. */ -public class PHPContentOutlinePage extends ContentOutlinePage { +public class PHPContentOutlinePage extends AbstractContentOutlinePage { private static final String ERROR = "error"; //$NON-NLS-1$ private static final String WARNING = "warning"; //$NON-NLS-1$ 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 ((PHPSegment) o1).toString().compareToIgnoreCase(((PHPSegment) o2).toString()); + return ((Outlineable) o1).toString().compareToIgnoreCase(((Outlineable) o2).toString()); } } @@ -81,7 +81,7 @@ public class PHPContentOutlinePage extends ContentOutlinePage { // StringBuffer identifier = new StringBuffer(); // while (i < textLength) { // c = text.charAt(i++); - // if (Character.isJavaIdentifierPart(c) || (c == '$')) { + // if (Scanner.isPHPIdentifierPart(c) || (c == '$')) { // identifier.append(c); // } else if ((i == firstIndex + 1) && (c == '$')) { // identifier.append(c); @@ -100,19 +100,18 @@ public class PHPContentOutlinePage extends ContentOutlinePage { String name; int index; String text = document.get(); - Parser parser = new Parser(null); + PHPParserSuperclass parser = PHPParserManager.getParser(null); PHPOutlineInfo outlineInfo = parser.parseInfo(fInput, text); fVariables = outlineInfo.getVariables(); - PHPSegmentWithChildren declarations = outlineInfo.getDeclarations(); - PHPSegment temp; + OutlineableWithChildren declarations = outlineInfo.getDeclarations(); + Outlineable temp; for (int i = 0; i < declarations.size(); i++) { temp = declarations.get(i); fContent.add(temp); } Collections.sort(fContent, new SegmentComparator()); - } /* @@ -183,8 +182,8 @@ public class PHPContentOutlinePage extends ContentOutlinePage { * @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; } @@ -193,8 +192,8 @@ public class PHPContentOutlinePage extends ContentOutlinePage { * @see ITreeContentProvider#getParent(Object) */ public Object getParent(Object element) { - if (element instanceof PHPSegment) { - return ((PHPSegment) element).getParent(); + if (element instanceof Outlineable) { + return ((Outlineable) element).getParent(); } return null; } @@ -205,8 +204,8 @@ public class PHPContentOutlinePage extends ContentOutlinePage { 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]; } }; @@ -216,7 +215,6 @@ public class PHPContentOutlinePage extends ContentOutlinePage { public OutlineLabelProvider() { fRegistry = PHPeclipsePlugin.getImageDescriptorRegistry(); - ; } /** * The LabelProvider implementation of this @@ -224,26 +222,25 @@ public class PHPContentOutlinePage extends ContentOutlinePage { * override. */ public Image getImage(Object element) { - if (element instanceof PHPSegment) { - ImageDescriptor descriptor = ((PHPSegment) element).getImage(); + if (element instanceof Outlineable) { + ImageDescriptor descriptor = ((Outlineable) element).getImage(); return fRegistry.get(descriptor); } return null; } } - protected Object fInput; protected IDocumentProvider fDocumentProvider; protected ITextEditor fTextEditor; protected PHPEditor fEditor; - protected ContentProvider contentProvider; + protected ContentProvider fContentProvider; /** * Creates a content outline page using the given provider and the given editor. */ public PHPContentOutlinePage(IDocumentProvider provider, ITextEditor editor) { super(); - contentProvider = null; + fContentProvider = null; fDocumentProvider = provider; fTextEditor = editor; if (editor instanceof PHPEditor) @@ -259,8 +256,8 @@ public class PHPContentOutlinePage extends ContentOutlinePage { TreeViewer viewer = getTreeViewer(); - contentProvider = new ContentProvider(); - viewer.setContentProvider(contentProvider); + fContentProvider = new ContentProvider(); + viewer.setContentProvider(fContentProvider); viewer.setLabelProvider(new OutlineLabelProvider()); viewer.addSelectionChangedListener(this); @@ -280,7 +277,7 @@ public class PHPContentOutlinePage extends ContentOutlinePage { if (selection.isEmpty()) fTextEditor.resetHighlightRange(); else { - PHPSegment segment = (PHPSegment) ((IStructuredSelection) selection).getFirstElement(); + Outlineable segment = (Outlineable) ((IStructuredSelection) selection).getFirstElement(); int start = segment.getPosition().getOffset(); int length = segment.getPosition().getLength(); try { @@ -290,35 +287,10 @@ public class PHPContentOutlinePage extends ContentOutlinePage { } } } - - /** - * Sets the input of the outline page - */ - public void setInput(Object input) { - fInput = input; - update(); - } - - /** - * Updates the outline page. - */ - public void update() { - TreeViewer viewer = getTreeViewer(); - - if (viewer != null) { - Control control = viewer.getControl(); - if (control != null && !control.isDisposed()) { - control.setRedraw(false); - viewer.setInput(fInput); - viewer.expandAll(); - control.setRedraw(true); - } - } - } public Object[] getVariables() { - if (contentProvider != null) { - return contentProvider.getVariables(); + if (fContentProvider != null) { + return fContentProvider.getVariables(); } return null; }