Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorteicher2004-04-14 14:19:36 +0000
committerteicher2004-04-14 14:19:36 +0000
commitf76337eb2bc5da86cf9a5fee0d62a4c4421068a4 (patch)
tree3bd58985770e5124479ac6640a1d5833c890525c
parenta8433877fb4d67c7d51fbb29d95fbe733ca8d08e (diff)
downloadeclipse.platform.text-f76337eb2bc5da86cf9a5fee0d62a4c4421068a4.tar.gz
eclipse.platform.text-f76337eb2bc5da86cf9a5fee0d62a4c4421068a4.tar.xz
eclipse.platform.text-f76337eb2bc5da86cf9a5fee0d62a4c4421068a4.zip
support for open/zero-length partitions
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java8
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java4
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java6
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java4
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java2
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java115
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java115
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java60
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java6
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java81
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java84
-rw-r--r--org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java33
15 files changed, 367 insertions, 157 deletions
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java
index cad15b446..b81af39c0 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java
@@ -1366,7 +1366,7 @@ public class ContentAssistant2 implements IContentAssistant, IContentAssistantEx
*/
private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) {
try {
- String type= TextUtilities.getContentType(viewer.getDocument(), getDocumentPartitioning(), offset);
+ String type= TextUtilities.getContentType(viewer.getDocument(), getDocumentPartitioning(), offset, true);
return getContentAssistProcessor(type);
} catch (BadLocationException x) {
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
index 0bddd5a98..8a064d698 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
@@ -1766,7 +1766,7 @@ public class TextViewer extends Viewer implements
return null;
try {
- TextHoverKey key= new TextHoverKey(TextUtilities.getContentType(document, getDocumentPartitioning(), offset), stateMask);
+ TextHoverKey key= new TextHoverKey(TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true), stateMask);
Object textHover= fTextHovers.get(key);
if (textHover == null) {
// Use default text hover
@@ -2775,7 +2775,7 @@ public class TextViewer extends Viewer implements
/**
* Returns the width of the text when being drawn into this viewer's widget.
*
- * @param the string to measure
+ * @param text the string to measure
* @return the width of the presentation of the given string
* @deprecated use <code>getWidthInPixels(int, int)</code> instead
*/
@@ -3151,7 +3151,7 @@ public class TextViewer extends Viewer implements
*/
protected Object selectContentTypePlugin(int offset, Map plugins) {
try {
- return selectContentTypePlugin(TextUtilities.getContentType(getDocument(), getDocumentPartitioning(), offset), plugins);
+ return selectContentTypePlugin(TextUtilities.getContentType(getDocument(), getDocumentPartitioning(), offset, true), plugins);
} catch (BadLocationException x) {
if (TRACE_ERRORS)
System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$
@@ -3639,7 +3639,7 @@ public class TextViewer extends Viewer implements
Point selection= getSelectedRange();
IRegion block= getTextBlockFromSelection(selection);
- ITypedRegion[] regions= TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength());
+ ITypedRegion[] regions= TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength(), false);
int lineCount= 0;
int[] lines= new int[regions.length * 2]; // [startline, endline, startline, endline, ...]
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
index ce34c877b..1178f40fd 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
@@ -1374,7 +1374,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt
try {
IDocument document= viewer.getDocument();
- String type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset);
+ String type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true);
return getContentAssistProcessor(type);
@@ -1398,7 +1398,7 @@ public class ContentAssistant implements IContentAssistant, IContentAssistantExt
IDocument document= contentAssistSubject.getDocument();
String type;
if (document != null)
- type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset);
+ type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true);
else
type= IDocument.DEFAULT_CONTENT_TYPE;
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java
index d04bea9be..3ca684ba1 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java
@@ -451,7 +451,7 @@ public class ContentFormatter implements IContentFormatter, IContentFormatterExt
*/
private TypedPosition[] getPartitioning(IRegion region) throws BadLocationException {
- ITypedRegion[] regions= TextUtilities.computePartitioning(fDocument, fPartitioning, region.getOffset(), region.getLength());
+ ITypedRegion[] regions= TextUtilities.computePartitioning(fDocument, fPartitioning, region.getOffset(), region.getLength(), false);
TypedPosition[] positions= new TypedPosition[regions.length];
for (int i= 0; i < regions.length; i++) {
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java
index 4eec06a28..b871ee629 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java
@@ -239,15 +239,15 @@ public class MultiPassContentFormatter implements IContentFormatter, IContentFor
Map partitioners= new HashMap(0);
try {
- final ITypedRegion[] partitions= TextUtilities.computePartitioning(document, fPartitioning, offset, length);
+ final ITypedRegion[] partitions= TextUtilities.computePartitioning(document, fPartitioning, offset, length, false);
if (!fType.equals(partitions[0].getType()))
- partitions[0]= TextUtilities.getPartition(document, fPartitioning, partitions[0].getOffset());
+ partitions[0]= TextUtilities.getPartition(document, fPartitioning, partitions[0].getOffset(), false);
if (partitions.length > 1) {
if (!fType.equals(partitions[partitions.length - 1].getType()))
- partitions[partitions.length - 1]= TextUtilities.getPartition(document, fPartitioning, partitions[partitions.length - 1].getOffset());
+ partitions[partitions.length - 1]= TextUtilities.getPartition(document, fPartitioning, partitions[partitions.length - 1].getOffset(), false);
}
String type= null;
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java
index 37d05768c..35f6cc827 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java
@@ -320,7 +320,7 @@ public class InformationPresenter extends AbstractInformationControlManager impl
IInformationProvider provider= null;
try {
- String contentType= TextUtilities.getContentType(fTextViewer.getDocument(), getDocumentPartitioning(), offset);
+ String contentType= TextUtilities.getContentType(fTextViewer.getDocument(), getDocumentPartitioning(), offset, true);
provider= getInformationProvider(contentType);
} catch (BadLocationException x) {
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java
index b9d9150ee..a75c60408 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java
@@ -434,7 +434,7 @@ public class PresentationReconciler implements IPresentationReconciler, IPresent
TextPresentation presentation= new TextPresentation(damage, 1000);
- ITypedRegion[] partitioning= TextUtilities.computePartitioning(document, getDocumentPartitioning(), damage.getOffset(), damage.getLength());
+ ITypedRegion[] partitioning= TextUtilities.computePartitioning(document, getDocumentPartitioning(), damage.getOffset(), damage.getLength(), false);
for (int i= 0; i < partitioning.length; i++) {
ITypedRegion r= partitioning[i];
IPresentationRepairer repairer= getRepairer(r.getType());
@@ -573,6 +573,6 @@ public class PresentationReconciler implements IPresentationReconciler, IPresent
* @since 3.0
*/
private ITypedRegion getPartition(IDocument document, int offset) throws BadLocationException {
- return TextUtilities.getPartition(document, getDocumentPartitioning(), offset);
+ return TextUtilities.getPartition(document, getDocumentPartitioning(), offset, false);
}
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java
index 16932770b..29ec6a722 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java
@@ -210,7 +210,7 @@ public class Reconciler extends AbstractReconciler implements IReconcilerExtensi
private ITypedRegion[] computePartitioning(int offset, int length) {
ITypedRegion[] regions= null;
try {
- regions= TextUtilities.computePartitioning(getDocument(), getDocumentPartitioning(), offset, length);
+ regions= TextUtilities.computePartitioning(getDocument(), getDocumentPartitioning(), offset, length, false);
} catch (BadLocationException x) {
regions= new TypedRegion[0];
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java
index 03335e4d4..43076de60 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java
@@ -447,7 +447,79 @@ public class DefaultPartitioner implements IDocumentPartitioner, IDocumentPartit
* @see IDocumentPartitioner#computePartitioning(int, int)
*/
public ITypedRegion[] computePartitioning(int offset, int length) {
+ return computePartitioning(offset, length, false);
+ }
+
+ /*
+ * @see IDocumentPartitioner#getLegalContentTypes()
+ */
+ public String[] getLegalContentTypes() {
+ return fLegalContentTypes;
+ }
+
+ /**
+ * Returns whether the given type is one of the legal content types.
+ *
+ * @param contentType the content type to check
+ * @return <code>true</code> if the content type is a legal content type
+ */
+ protected boolean isSupportedContentType(String contentType) {
+ if (contentType != null) {
+ for (int i= 0; i < fLegalContentTypes.length; i++) {
+ if (fLegalContentTypes[i].equals(contentType))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns a content type encoded in the given token. If the token's
+ * data is not <code>null</code> and a string it is assumed that
+ * it is the encoded content type.
+ *
+ * @param token the token whose content type is to be determined
+ * @return the token's content type
+ */
+ protected String getTokenContentType(IToken token) {
+ Object data= token.getData();
+ if (data instanceof String)
+ return (String) data;
+ return null;
+ }
+
+ /* zero-length partition support */
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthContentType(int)
+ */
+ public String getContentType(int offset, boolean preferOpenPartitions) {
+ return getPartition(offset, preferOpenPartitions).getType();
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthPartition(int)
+ */
+ public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
+ ITypedRegion region= getPartition(offset);
+ if (preferOpenPartitions) {
+ if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
+ if (offset > 0) {
+ region= getPartition(offset - 1);
+ if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE))
+ return region;
+ }
+ return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
+ }
+ }
+ return region;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#computeZeroLengthPartitioning(int, int)
+ */
+ public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
List list= new ArrayList();
try {
@@ -466,7 +538,7 @@ public class DefaultPartitioner implements IDocumentPartitioner, IDocumentPartit
gapOffset= (previous != null) ? previous.getOffset() + previous.getLength() : 0;
gap= new Position(gapOffset, current.getOffset() - gapOffset);
- if (gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
+ if ((includeZeroLengthPartitions || gap.getLength() > 0) && gap.overlapsWith(offset, length)) {
start= Math.max(offset, gapOffset);
end= Math.min(endOffset, gap.getOffset() + gap.getLength());
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
@@ -484,7 +556,7 @@ public class DefaultPartitioner implements IDocumentPartitioner, IDocumentPartit
if (previous != null) {
gapOffset= previous.getOffset() + previous.getLength();
gap= new Position(gapOffset, fDocument.getLength() - gapOffset);
- if (gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
+ if ((includeZeroLengthPartitions || gap.getLength() > 0) && ((includeZeroLengthPartitions && offset + length == gapOffset && gap.length == 0) || gap.overlapsWith(offset, length))) {
start= Math.max(offset, gapOffset);
end= Math.min(endOffset, fDocument.getLength());
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
@@ -501,43 +573,4 @@ public class DefaultPartitioner implements IDocumentPartitioner, IDocumentPartit
list.toArray(result);
return result;
}
-
- /*
- * @see IDocumentPartitioner#getLegalContentTypes()
- */
- public String[] getLegalContentTypes() {
- return fLegalContentTypes;
- }
-
- /**
- * Returns whether the given type is one of the legal content types.
- *
- * @param contentType the content type to check
- * @return <code>true</code> if the content type is a legal content type
- */
- protected boolean isSupportedContentType(String contentType) {
- if (contentType != null) {
- for (int i= 0; i < fLegalContentTypes.length; i++) {
- if (fLegalContentTypes[i].equals(contentType))
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Returns a content type encoded in the given token. If the token's
- * data is not <code>null</code> and a string it is assumed that
- * it is the encoded content type.
- *
- * @param token the token whose content type is to be determined
- * @return the token's content type
- */
- protected String getTokenContentType(IToken token) {
- Object data= token.getData();
- if (data instanceof String)
- return (String) data;
- return null;
- }
}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java
index 707a67f95..1b096b974 100644
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java
+++ b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java
@@ -455,7 +455,79 @@ public class RuleBasedPartitioner implements IDocumentPartitioner, IDocumentPart
* @see IDocumentPartitioner#computePartitioning
*/
public ITypedRegion[] computePartitioning(int offset, int length) {
+ return computePartitioning(offset, length, false);
+ }
+
+ /*
+ * @see IDocumentPartitioner#getLegalContentTypes
+ */
+ public String[] getLegalContentTypes() {
+ return fLegalContentTypes;
+ }
+
+ /**
+ * Returns whether the given type is one of the legal content types.
+ *
+ * @param contentType the content type to check
+ * @return <code>true</code> if the content type is a legal content type
+ */
+ protected boolean isSupportedContentType(String contentType) {
+ if (contentType != null) {
+ for (int i= 0; i < fLegalContentTypes.length; i++) {
+ if (fLegalContentTypes[i].equals(contentType))
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns a content type encoded in the given token. If the token's
+ * data is not <code>null</code> and a string it is assumed that
+ * it is the encoded content type.
+ *
+ * @param token the token whose content type is to be determined
+ * @return the token's content type
+ */
+ protected String getTokenContentType(IToken token) {
+ Object data= token.getData();
+ if (data instanceof String)
+ return (String) data;
+ return null;
+ }
+
+ /* zero-length partition support */
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthContentType(int)
+ */
+ public String getContentType(int offset, boolean preferOpenPartitions) {
+ return getPartition(offset, preferOpenPartitions).getType();
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthPartition(int)
+ */
+ public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
+ ITypedRegion region= getPartition(offset);
+ if (preferOpenPartitions) {
+ if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
+ if (offset > 0) {
+ region= getPartition(offset - 1);
+ if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE))
+ return region;
+ }
+ return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
+ }
+ }
+ return region;
+ }
+
+ /*
+ * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#computeZeroLengthPartitioning(int, int)
+ */
+ public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
List list= new ArrayList();
try {
@@ -474,7 +546,7 @@ public class RuleBasedPartitioner implements IDocumentPartitioner, IDocumentPart
gapOffset= (previous != null) ? previous.getOffset() + previous.getLength() : 0;
gap= new Position(gapOffset, current.getOffset() - gapOffset);
- if (gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
+ if ((includeZeroLengthPartitions || gap.getLength() > 0) && gap.overlapsWith(offset, length)) {
start= Math.max(offset, gapOffset);
end= Math.min(endOffset, gap.getOffset() + gap.getLength());
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
@@ -492,7 +564,7 @@ public class RuleBasedPartitioner implements IDocumentPartitioner, IDocumentPart
if (previous != null) {
gapOffset= previous.getOffset() + previous.getLength();
gap= new Position(gapOffset, fDocument.getLength() - gapOffset);
- if (gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
+ if ((includeZeroLengthPartitions || gap.getLength() > 0) && ((includeZeroLengthPartitions && offset + length == gapOffset && gap.length == 0) || gap.overlapsWith(offset, length))) {
start= Math.max(offset, gapOffset);
end= Math.min(endOffset, fDocument.getLength());
list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
@@ -509,43 +581,4 @@ public class RuleBasedPartitioner implements IDocumentPartitioner, IDocumentPart
list.toArray(result);
return result;
}
-
- /*
- * @see IDocumentPartitioner#getLegalContentTypes
- */
- public String[] getLegalContentTypes() {
- return fLegalContentTypes;
- }
-
- /**
- * Returns whether the given type is one of the legal content types.
- *
- * @param contentType the content type to check
- * @return <code>true</code> if the content type is a legal content type
- */
- protected boolean isSupportedContentType(String contentType) {
- if (contentType != null) {
- for (int i= 0; i < fLegalContentTypes.length; i++) {
- if (fLegalContentTypes[i].equals(contentType))
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Returns a content type encoded in the given token. If the token's
- * data is not <code>null</code> and a string it is assumed that
- * it is the encoded content type.
- *
- * @param token the token whose content type is to be determined
- * @return the token's content type
- */
- protected String getTokenContentType(IToken token) {
- Object data= token.getData();
- if (data instanceof String)
- return (String) data;
- return null;
- }
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
index 1e426e73f..93080c6d7 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/AbstractDocument.java
@@ -715,7 +715,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
public String getContentType(int offset) throws BadLocationException {
String contentType= null;
try {
- contentType= getContentType(DEFAULT_PARTITIONING, offset);
+ contentType= getContentType(DEFAULT_PARTITIONING, offset, false);
Assert.isNotNull(contentType);
} catch (BadPartitioningException e) {
Assert.isTrue(false);
@@ -820,7 +820,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
public ITypedRegion getPartition(int offset) throws BadLocationException {
ITypedRegion partition= null;
try {
- partition= getPartition(DEFAULT_PARTITIONING, offset);
+ partition= getPartition(DEFAULT_PARTITIONING, offset, false);
Assert.isNotNull(partition);
} catch (BadPartitioningException e) {
Assert.isTrue(false);
@@ -834,7 +834,7 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
public ITypedRegion[] computePartitioning(int offset, int length) throws BadLocationException {
ITypedRegion[] partitioning= null;
try {
- partitioning= computePartitioning(DEFAULT_PARTITIONING, offset, length);
+ partitioning= computePartitioning(DEFAULT_PARTITIONING, offset, length, false);
Assert.isNotNull(partitioning);
} catch (BadPartitioningException e) {
Assert.isTrue(false);
@@ -1177,35 +1177,43 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
}
/*
- * @see org.eclipse.jface.text.IDocumentExtension3#computePartitioning(java.lang.String, int, int)
- * @since 3.0
+ * @see org.eclipse.jface.text.IDocumentExtension3#computeZeroLengthPartitioning(java.lang.String, int, int)
*/
- public ITypedRegion[] computePartitioning(String partitioning, int offset, int length) throws BadLocationException, BadPartitioningException {
+ public ITypedRegion[] computePartitioning(String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException, BadPartitioningException {
if ((0 > offset) || (0 > length) || (offset + length > getLength()))
throw new BadLocationException();
+
IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning);
- if (partitioner != null)
+
+ if (partitioner instanceof IDocumentPartitionerExtension2)
+ return ((IDocumentPartitionerExtension2) partitioner).computePartitioning(offset, length, includeZeroLengthPartitions);
+ else if (partitioner != null)
return partitioner.computePartitioning(offset, length);
- if (DEFAULT_PARTITIONING.equals(partitioning))
+ else if (DEFAULT_PARTITIONING.equals(partitioning))
return new TypedRegion[] { new TypedRegion(offset, length, DEFAULT_CONTENT_TYPE) };
- throw new BadPartitioningException();
+ else
+ throw new BadPartitioningException();
}
-
+
/*
- * @see org.eclipse.jface.text.IDocumentExtension3#getContentType(java.lang.String, int)
- * @since 3.0
+ * @see org.eclipse.jface.text.IDocumentExtension3#getZeroLengthContentType(java.lang.String, int)
*/
- public String getContentType(String partitioning, int offset) throws BadLocationException, BadPartitioningException {
+ public String getContentType(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException {
if ((0 > offset) || (offset > getLength()))
throw new BadLocationException();
+
IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning);
- if (partitioner != null)
+
+ if (partitioner instanceof IDocumentPartitionerExtension2)
+ return ((IDocumentPartitionerExtension2) partitioner).getContentType(offset, preferOpenPartitions);
+ else if (partitioner != null)
return partitioner.getContentType(offset);
- if (DEFAULT_PARTITIONING.equals(partitioning))
+ else if (DEFAULT_PARTITIONING.equals(partitioning))
return DEFAULT_CONTENT_TYPE;
- throw new BadPartitioningException();
+ else
+ throw new BadPartitioningException();
}
-
+
/*
* @see org.eclipse.jface.text.IDocumentExtension3#getDocumentPartitioner(java.lang.String)
* @since 3.0
@@ -1228,20 +1236,24 @@ public abstract class AbstractDocument implements IDocument, IDocumentExtension,
}
/*
- * @see org.eclipse.jface.text.IDocumentExtension3#getPartition(java.lang.String, int)
- * @since 3.0
+ * @see org.eclipse.jface.text.IDocumentExtension3#getZeroLengthPartition(java.lang.String, int)
*/
- public ITypedRegion getPartition(String partitioning, int offset) throws BadLocationException, BadPartitioningException {
+ public ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException {
if ((0 > offset) || (offset > getLength()))
throw new BadLocationException();
+
IDocumentPartitioner partitioner= getDocumentPartitioner(partitioning);
- if (partitioner != null)
+
+ if (partitioner instanceof IDocumentPartitionerExtension2)
+ return ((IDocumentPartitionerExtension2) partitioner).getPartition(offset, preferOpenPartitions);
+ else if (partitioner != null)
return partitioner.getPartition(offset);
- if (DEFAULT_PARTITIONING.equals(partitioning))
+ else if (DEFAULT_PARTITIONING.equals(partitioning))
return new TypedRegion(0, getLength(), DEFAULT_CONTENT_TYPE);
- throw new BadPartitioningException();
+ else
+ throw new BadPartitioningException();
}
-
+
/*
* @see org.eclipse.jface.text.IDocumentExtension3#getPartitionings()
* @since 3.0
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java b/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java
index be8199096..70451d8df 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/ChildDocumentManager.java
@@ -211,7 +211,7 @@ public final class ChildDocumentManager implements IDocumentListener, ISlaveDocu
try {
offset += fChildDocument.getParentDocumentRange().getOffset();
if (fParentDocument3 != null)
- return fParentDocument3.getPartition(fPartitioning, offset);
+ return fParentDocument3.getPartition(fPartitioning, offset, false);
return fParentDocument.getPartition(offset);
} catch (BadLocationException x) {
} catch (BadPartitioningException x) {
@@ -227,7 +227,7 @@ public final class ChildDocumentManager implements IDocumentListener, ISlaveDocu
try {
offset += fChildDocument.getParentDocumentRange().getOffset();
if (fParentDocument3 != null)
- return fParentDocument3.computePartitioning(fPartitioning, offset, length);
+ return fParentDocument3.computePartitioning(fPartitioning, offset, length, false);
return fParentDocument.computePartitioning(offset, length);
} catch (BadLocationException x) {
} catch (BadPartitioningException x) {
@@ -243,7 +243,7 @@ public final class ChildDocumentManager implements IDocumentListener, ISlaveDocu
try {
offset += fChildDocument.getParentDocumentRange().getOffset();
if (fParentDocument3 != null)
- return fParentDocument3.getContentType(fPartitioning, offset);
+ return fParentDocument3.getContentType(fPartitioning, offset, false);
return fParentDocument.getContentType(offset);
} catch (BadLocationException x) {
} catch (BadPartitioningException x) {
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java
index fbea0a812..88581b838 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentExtension3.java
@@ -11,8 +11,10 @@ Contributors:
package org.eclipse.jface.text;
/**
- * Extension interface for <code>IDocument</code>. Adds the concept of multiple partitionings.
+ * Extension interface for <code>IDocument</code>. Adds the concept of
+ * multiple partitionings the concept of open and delimited paritions.
*
+ * @see org.eclipse.jface.text.IDocumentPartitionerExtension2
* @since 3.0
*/
public interface IDocumentExtension3 {
@@ -42,41 +44,86 @@ public interface IDocumentExtension3 {
*/
String[] getLegalContentTypes(String partitioning) throws BadPartitioningException;
+
/**
- * Returns the type of the document partition containing the given offset for the
- * given partitioning. This is a convenience method for
- * <code>getPartition(partitioning, offset).getType()</code>.
- *
+ * Returns the type of the document partition containing the given offset
+ * for the given partitioning. This is a convenience method for
+ * <code>getPartition(partitioning, offset, boolean).getType()</code>.
+ * <p>
+ * If <code>preferOpenPartitions</code> is <code>true</code>,
+ * precedence is given to an open partition ending at <code>offset</code>
+ * over a delimited partition starting at <code>offset</code>. If it is
+ * <code>false</code>, precedence is given to the partition that does not
+ * end at <code>offset</code>.
+ * </p>
+ * This is only supported if the connected <code>IDocumentPartitioner</code>
+ * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
+ * Otherwise, <code>preferOpenPartitions</code> is ignored.
+ * </p>
+ *
* @param partitioning the partitioning
* @param offset the document offset
+ * @param preferOpenPartitions <code>true</code> if precedence should be
+ * given to a open partition ending at <code>offset</code> over a
+ * closed partition starting at <code>offset</code>
* @return the partition type
* @exception BadLocationException if offset is invalid in this document
- * @exception BadPartitioningException if partitioning is invalid for this document
+ * @exception BadPartitioningException if partitioning is invalid for this
+ * document
*/
- String getContentType(String partitioning, int offset) throws BadLocationException, BadPartitioningException;
+ String getContentType(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException;
/**
- * Returns the document partition of the given partitioning in which the given offset is located.
- *
- * @param partitioning the document partitioning
+ * Returns the document partition of the given partitioning in which the
+ * given offset is located.
+ * <p>
+ * If <code>preferOpenPartitions</code> is <code>true</code>,
+ * precedence is given to an open partition ending at <code>offset</code>
+ * over a delimited partition starting at <code>offset</code>. If it is
+ * <code>false</code>, precedence is given to the partition that does not
+ * end at <code>offset</code>.
+ * </p>
+ * This is only supported if the connected <code>IDocumentPartitioner</code>
+ * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
+ * Otherwise, <code>preferOpenPartitions</code> is ignored.
+ * </p>
+ *
+ * @param partitioning the partitioning
* @param offset the document offset
+ * @param preferOpenPartitions <code>true</code> if precedence should be
+ * given to a open partition ending at <code>offset</code> over a
+ * closed partition starting at <code>offset</code>
* @return a specification of the partition
* @exception BadLocationException if offset is invalid in this document
- * @exception BadPartitioningException if partitioning is invalid for this document
+ * @exception BadPartitioningException if partitioning is invalid for this
+ * document
*/
- ITypedRegion getPartition(String partitioning, int offset) throws BadLocationException, BadPartitioningException;
+ ITypedRegion getPartition(String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException, BadPartitioningException;
/**
- * Computes the partitioning of the given document range based on the given partitioning.
- *
- * @param partitioning the document's partitioning
+ * Computes the partitioning of the given document range based on the given
+ * partitioning type.
+ * <p>
+ * If <code>includeZeroLengthPartitions</code> is <code>true</code>, a
+ * zero-length partition of an open partition type (usually the default
+ * partition) is included between two closed partitions. If it is
+ * <code>false</code>, no zero-length partitions are included.
+ * </p>
+ * This is only supported if the connected <code>IDocumentPartitioner</code>
+ * supports it, i.e. implements <code>IDocumentPartitionerExtension2</code>.
+ * Otherwise, <code>includeZeroLengthPartitions</code> is ignored.
+ * </p>
+ *
+ * @param partitioning the document's partitioning type
* @param offset the document offset at which the range starts
* @param length the length of the document range
+ * @param includeZeroLengthPartitions <code>true</code> if zero-length
+ * partitions should be returned as part of the computed partitioning
* @return a specification of the range's partitioning
* @exception BadLocationException if the range is invalid in this document
*/
- ITypedRegion[] computePartitioning(String partitioning, int offset, int length) throws BadLocationException, BadPartitioningException;
-
+ ITypedRegion[] computePartitioning(String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException, BadPartitioningException;
+
/**
* Sets this document's partitioner. The caller of this method is responsible for
* disconnecting the document's old partitioner from the document and to
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java
index bc4a25a63..31831b9b7 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/IDocumentPartitionerExtension2.java
@@ -13,13 +13,26 @@ package org.eclipse.jface.text;
/**
- * Extension interface for <code>IDocumentPartitioner</code>. Extends the original
- * concept of a document partitioner to answer the position categories that are used
- * to manage the partitioning information.
+ * Extension interface for <code>IDocumentPartitioner</code>. Extends the
+ * original concept of a document partitioner to answer the position categories
+ * that are used to manage the partitioning information.
+ * <p>
+ * This extension introduces the concept of open and closed (or delimited)
+ * partitions. A delimited partition has a textual token delimiting its start
+ * and end, while an open partition can fill any space between two delimited
+ * partitions.
+ * </p>
+ * <p>
+ * An open partition of zero length can occur between two delimited partitions,
+ * thus having the same offset as the following delimited partition. The
+ * document start and end are considered to be delimiters of open partitions,
+ * i.e. there may be a zero-length partition between the document start and a
+ * closed partition starting at offset 0.
+ * </p>
*
* @since 3.0
-
-*/
+ *
+ */
public interface IDocumentPartitionerExtension2 {
/**
@@ -30,4 +43,65 @@ public interface IDocumentPartitionerExtension2 {
* @return the position categories used to manage partitioning information
*/
String[] getManagingPositionCategories();
+
+ /* zero-length partition support */
+
+ /**
+ * Returns the content type of the partition containing the given offset in
+ * the connected document. There must be a document connected to this
+ * partitioner.
+ * <p>
+ * If <code>preferOpenPartitions</code> is <code>true</code>,
+ * precedence is given to an open partition ending at <code>offset</code>
+ * over a delimited partition starting at <code>offset</code>. If it is
+ * <code>false</code>, the method behaves like
+ * {@link IDocumentPartitioner#getContentType(int)}, i.e. precedence is
+ * always given to the partition that does not end at <code>offset</code>.
+ * </p>
+ *
+ * @param offset the offset in the connected document
+ * @param preferOpenPartitions <code>true</code> if precedence should be
+ * given to a open partition ending at <code>offset</code> over a
+ * closed partition starting at <code>offset</code>
+ * @return the content type of the offset's partition
+ */
+ String getContentType(int offset, boolean preferOpenPartitions);
+
+ /**
+ * Returns the partition containing the given offset of the connected
+ * document. There must be a document connected to this partitioner.
+ * <p>
+ * If <code>preferOpenPartitions</code> is <code>true</code>,
+ * precedence is given to an open partition ending at <code>offset</code>
+ * over a delimited partition starting at <code>offset</code>. If it is
+ * <code>false</code>, the method behaves like
+ * {@link IDocumentPartitioner#getPartition(int)}, i.e. precedence is always
+ * given to the partition that does not end at <code>offset</code>.
+ * </p>
+ *
+ * @param offset the offset for which to determine the partition
+ * @param preferOpenPartitions <code>true</code> if precedence should be
+ * given to a open partition ending at <code>offset</code> over a
+ * closed partition starting at <code>offset</code>
+ * @return the partition containing the offset
+ */
+ ITypedRegion getPartition(int offset, boolean preferOpenPartitions);
+
+ /**
+ * Returns the partitioning of the given range of the connected document.
+ * There must be a document connected to this partitioner.
+ * <p>
+ * If <code>includeZeroLengthPartitions</code> is <code>true</code>, a
+ * zero-length partition of an open partition type (usually the default
+ * partition) is included between two closed partitions. If it is
+ * <code>false</code>, no zero-length partitions are included.
+ * </p>
+ *
+ * @param offset the offset of the range of interest
+ * @param length the length of the range of interest
+ * @param includeZeroLengthPartitions <code>true</code> if zero-length
+ * partitions should be returned as part of the computed partitioning
+ * @return the partitioning of the range
+ */
+ ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions);
}
diff --git a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
index 42bed0f81..3b20673c1 100644
--- a/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
+++ b/org.eclipse.text/src/org/eclipse/jface/text/TextUtilities.java
@@ -353,15 +353,18 @@ public class TextUtilities {
* @param document the document
* @param partitioning the partitioning to be used
* @param offset the offset
+ * @param preferOpenPartitions <code>true</code> if precedence should be
+ * given to a open partition ending at <code>offset</code> over a
+ * closed partition starting at <code>offset</code>
* @return the content type at the given offset of the document
* @throws BadLocationException if offset is invalid in the document
* @since 3.0
*/
- public static String getContentType(IDocument document, String partitioning, int offset) throws BadLocationException {
+ public static String getContentType(IDocument document, String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException {
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3= (IDocumentExtension3) document;
try {
- return extension3.getContentType(partitioning, offset);
+ return extension3.getContentType(partitioning, offset, preferOpenPartitions);
} catch (BadPartitioningException x) {
return IDocument.DEFAULT_CONTENT_TYPE;
}
@@ -372,19 +375,23 @@ public class TextUtilities {
/**
* Returns the partition of the given offset of the given document.
- *
+ *
* @param document the document
* @param partitioning the partitioning to be used
* @param offset the offset
- * @return the content type at the given offset of this viewer's input document
+ * @param preferOpenPartitions <code>true</code> if precedence should be
+ * given to a open partition ending at <code>offset</code> over a
+ * closed partition starting at <code>offset</code>
+ * @return the content type at the given offset of this viewer's input
+ * document
* @throws BadLocationException if offset is invalid in the given document
* @since 3.0
*/
- public static ITypedRegion getPartition(IDocument document, String partitioning, int offset) throws BadLocationException {
+ public static ITypedRegion getPartition(IDocument document, String partitioning, int offset, boolean preferOpenPartitions) throws BadLocationException {
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3= (IDocumentExtension3) document;
try {
- return extension3.getPartition(partitioning, offset);
+ return extension3.getPartition(partitioning, offset, preferOpenPartitions);
} catch (BadPartitioningException x) {
return new TypedRegion(0, document.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
}
@@ -394,21 +401,25 @@ public class TextUtilities {
}
/**
- * Computes and returns the partitioning for the given region of the given document for the given partitioning name.
+ * Computes and returns the partitioning for the given region of the given
+ * document for the given partitioning name.
*
* @param document the document
* @param partitioning the partitioning name
* @param offset the region offset
* @param length the region length
- * @return the partitioning for the given region of the given document for the given partitioning name
- * @throws BadLocationException if the given region is invalid for the given document
+ * @param includeZeroLengthPartitions whether to include zero-length partitions
+ * @return the partitioning for the given region of the given document for
+ * the given partitioning name
+ * @throws BadLocationException if the given region is invalid for the given
+ * document
* @since 3.0
*/
- public static ITypedRegion[] computePartitioning(IDocument document, String partitioning, int offset, int length) throws BadLocationException {
+ public static ITypedRegion[] computePartitioning(IDocument document, String partitioning, int offset, int length, boolean includeZeroLengthPartitions) throws BadLocationException {
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3= (IDocumentExtension3) document;
try {
- return extension3.computePartitioning(partitioning, offset, length);
+ return extension3.computePartitioning(partitioning, offset, length, includeZeroLengthPartitions);
} catch (BadPartitioningException x) {
return new ITypedRegion[0];
}

Back to the top