adding getStructuredDocumentRegions() API (and unit test)
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocument.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocument.java
index 1fa5125..14bc3fa 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocument.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocument.java
@@ -107,11 +107,33 @@
*/
RegionParser getParser();
- IStructuredDocumentRegion getRegionAtCharacterOffset(int offset);
-
+ /**
+ * @deprecated use getStructuredDocumentRegions()
+ * @return
+ */
IStructuredDocumentRegionList getRegionList();
-
+ /**
+ * Returns the <code>IStructuredDocumentRegion</code> at the given character offset.
+ * @param offset
+ * @return the <code>IStructuredDocumentRegion</code> at the given character offset.
+ */
+ IStructuredDocumentRegion getRegionAtCharacterOffset(int offset);
+
+ /**
+ * Returns <code>IStructuredDocumentRegion</code>s in the specified range.
+ * @param offset
+ * @param length
+ * @return <code>IStructuredDocumentRegion</code>s in the specified range.
+ */
+ IStructuredDocumentRegion[] getStructuredDocumentRegions(int offset, int length);
+
+ /**
+ * Returns all <code>IStructuredDocumentRegion</code>s in the document.
+ * @return all <code>IStructuredDocumentRegion</code>s in the document.
+ */
+ IStructuredDocumentRegion[] getStructuredDocumentRegions();
+
/**
* Note: this method was made public, and part of the interface, for
* easier testing. Clients normally never manipulate the reparser directly
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocumentRegionList.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocumentRegionList.java
index 9b03abc..0d7db56 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocumentRegionList.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/provisional/text/IStructuredDocumentRegionList.java
@@ -48,4 +48,5 @@
* @return the region at specified offset.
*/
IStructuredDocumentRegion item(int i);
+
}
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java
index 0210d01..8314683 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/BasicStructuredDocument.java
@@ -1702,6 +1702,57 @@
return result;
}
+
+
+ public IStructuredDocumentRegion[] getStructuredDocumentRegions() {
+ return getStructuredDocumentRegions(0, getLength());
+ }
+
+ /**
+ * In the case of 0 length, the region to the right is returned,
+ * except for at the end of the document, then the last region is returned.
+ *
+ * Otherwise all the regions "inbetween" the indicated range are returned,
+ * including the regions which overlap the region.
+ *
+ * eg.
+ * <p>
+ * <html>[<head></head>]</html> -> <head>,</head>
+ * <ht[ml><head></he]ad></html> -> <html>,<head>,</head>
+ * </p>
+ */
+ public IStructuredDocumentRegion[] getStructuredDocumentRegions(int start, int length) {
+
+ if(length < 0)
+ throw new IllegalArgumentException("can't have negative length");
+
+ // this will make the right edge of the range point into the selection
+ // eg. <html>[<head></head>]</html>
+ // will return <head>,</head> instead of <head>,</head>,</html>
+ if(length > 0) length--;
+
+ List results = new ArrayList();
+
+ // start thread safe block
+ try {
+ acquireLock();
+
+ IStructuredDocumentRegion currentRegion = getRegionAtCharacterOffset(start);
+ IStructuredDocumentRegion endRegion = getRegionAtCharacterOffset(start + length);
+ while(currentRegion != endRegion && currentRegion != null) {
+ results.add(currentRegion);
+ currentRegion = currentRegion.getNext();
+ }
+ // need to add that last end region
+ results.add(endRegion);
+ }
+ finally {
+ releaseLock();
+ }
+ // end thread safe block
+
+ return (IStructuredDocumentRegion[])results.toArray(new IStructuredDocumentRegion[results.size()]);
+ }
/**
* was made public for easier testing. Normally should never be used by
diff --git a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/MinimalDocument.java b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/MinimalDocument.java
index ed9a44f..1c023ff 100644
--- a/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/MinimalDocument.java
+++ b/bundles/org.eclipse.wst.sse.core/src/org/eclipse/wst/sse/core/internal/text/MinimalDocument.java
@@ -435,4 +435,12 @@
public void setLineDelimiter(String delimiter) {
}
+
+ public IStructuredDocumentRegion[] getStructuredDocumentRegions() {
+ throw new NotImplementedException("intentionally not implemented"); //$NON-NLS-1$
+ }
+
+ public IStructuredDocumentRegion[] getStructuredDocumentRegions(int start, int length) {
+ throw new NotImplementedException("intentionally not implemented"); //$NON-NLS-1$
+ }
}