1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 13 import java.util.HashMap ; 14 import java.util.Map ; 15 import java.util.Set ; 16 17 import org.eclipse.jface.text.BadLocationException; 18 import org.eclipse.jface.text.IDocument; 19 import org.eclipse.jface.text.Position; 20 import org.eclipse.pde.core.plugin.IExtensions; 21 import org.eclipse.pde.core.plugin.IPluginExtension; 22 import org.eclipse.pde.internal.core.text.IDocumentNode; 23 import org.eclipse.pde.internal.core.text.IEditingModel; 24 import org.eclipse.pde.internal.core.text.plugin.PluginModel; 25 import org.eclipse.pde.internal.ui.editor.AbstractFoldingStructureProvider; 26 import org.eclipse.pde.internal.ui.editor.PDESourcePage; 27 28 public class PluginFoldingStructureProvider extends AbstractFoldingStructureProvider { 29 30 private Map fPositionToElement = new HashMap (); 31 32 public PluginFoldingStructureProvider(PDESourcePage editor, IEditingModel model) { 33 super(editor, model); 34 } 35 36 public void addFoldingRegions(Set currentRegions, IEditingModel model) 37 throws BadLocationException { 38 IExtensions extensions = ((PluginModel) model).getExtensions(); 39 IPluginExtension[] pluginExtensions = extensions.getExtensions(); 40 41 42 addFoldingRegions(currentRegions, pluginExtensions, model.getDocument()); 43 } 44 45 private void addFoldingRegions(Set regions, IPluginExtension[] nodes, IDocument document) throws BadLocationException { 46 for(int i = 0; i < nodes.length; i++) { 47 IDocumentNode element = (IDocumentNode) nodes[i]; 48 int startLine = document.getLineOfOffset(element.getOffset()); 49 int endLine = document.getLineOfOffset(element.getOffset() + element.getLength()); 50 if (startLine < endLine) { 51 int start = document.getLineOffset(startLine); 52 int end = document.getLineOffset(endLine) + document.getLineLength(endLine); 53 Position position = new Position(start, end - start); 54 regions.add(position); 55 fPositionToElement.put(position, element); 56 } 57 IDocumentNode[] children = element.getChildNodes(); 58 if (children != null) { 59 addFoldingRegions(regions, children, document); 60 } 61 } 62 } 63 64 private void addFoldingRegions(Set regions, IDocumentNode[] nodes, IDocument document) throws BadLocationException { 65 for(int i = 0; i < nodes.length; i++) { 66 IDocumentNode element = nodes[i]; 67 int startLine = document.getLineOfOffset(element.getOffset()); 68 int endLine = document.getLineOfOffset(element.getOffset() + element.getLength()); 69 if (startLine < endLine) { 70 int start = document.getLineOffset(startLine); 71 int end = document.getLineOffset(endLine) + document.getLineLength(endLine); 72 Position position = new Position(start, end - start); 73 regions.add(position); 74 fPositionToElement.put(position, element); 75 } 76 IDocumentNode[] children = element.getChildNodes(); 77 if (children != null) { 78 addFoldingRegions(regions, children, document); 79 } 80 } 81 } 82 83 } 84 | Popular Tags |