use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class StructuredPresentationReconciler method getDamageEndOffset.
/**
* Returns the end offset of the damage. If a partition has been split by
* the given document event also the second half of the original
* partition must be considered. This is achieved by using the remembered
* partition range.
*
* @param e the event describing the change
* @return the damage end offset (excluding)
* @exception BadLocationException if method accesses invalid offset
*/
int getDamageEndOffset(DocumentEvent e) throws BadLocationException {
IDocument d = e.getDocument();
int length = 0;
if (e.getText() != null) {
length = e.getText().length();
if (length > 0)
--length;
}
ITypedRegion partition = getPartition(d, e.getOffset() + length);
int endOffset = partition.getOffset() + partition.getLength();
if (endOffset == e.getOffset())
return -1;
int end = fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength();
if (endOffset < end && end < d.getLength())
partition = getPartition(d, end);
// if there is not damager for the partition then use the endOffset of the partition
IPresentationDamager damager = getDamager(partition.getType());
if (damager != null) {
IRegion r = damager.getDamageRegion(partition, e, fDocumentPartitioningChanged);
endOffset = r.getOffset() + r.getLength();
}
return endOffset;
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class DebugInfoHoverProcessor method getHoverInfo.
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.text.ITextHover#getHoverInfo(org.eclipse.jface.text.ITextViewer,
* org.eclipse.jface.text.IRegion)
*/
public String getHoverInfo(ITextViewer viewer, IRegion hoverRegion) {
String displayText = null;
if ((hoverRegion == null) || (viewer == null) || (viewer.getDocument() == null)) {
displayText = null;
} else {
int offset = hoverRegion.getOffset();
ITypedRegion region;
try {
region = viewer.getDocument().getPartition(offset);
if (region != null) {
displayText = region.getType();
} else {
// $NON-NLS-1$
displayText = "Null Region was returned?!";
}
} catch (BadLocationException e) {
// $NON-NLS-1$
displayText = "BadLocationException Occurred!?";
}
}
return displayText;
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class FastPartitionerTest method assertComputePartitioning_InterleavingPartitions.
private void assertComputePartitioning_InterleavingPartitions(int startOffset, int endOffset, int[] offsets, String startType) {
ITypedRegion[] regions = fPartitioner.computePartitioning(startOffset, endOffset - startOffset);
String type = startType;
int previousOffset = startOffset;
int j = 0;
for (int i = 0; i <= offsets.length; i++) {
int currentOffset = (i == offsets.length) ? endOffset : offsets[i];
if (currentOffset - previousOffset != 0) {
// don't do empty partitions
ITypedRegion region = regions[j++];
assertTypedRegion(region, previousOffset, currentOffset, type);
}
// advance
if (type == DEFAULT)
type = COMMENT;
else
type = DEFAULT;
previousOffset = currentOffset;
}
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class FastPartitionerTest method assertEqualPartition.
private void assertEqualPartition(int offset, int end, String type) {
int from = offset;
int to = end - 1;
for (int i = from; i <= to; i++) {
ITypedRegion region = fPartitioner.getPartition(i);
assertTypedRegion(region, offset, end, type);
}
}
use of org.eclipse.jface.text.ITypedRegion in project webtools.sourceediting by eclipse.
the class JavascriptValidationStrategy method computePartitioning.
protected ITypedRegion[] computePartitioning(int drOffset, int drLength) {
ITypedRegion[] tr = new ITypedRegion[0];
IDocument doc = getDocument();
if (doc != null) {
int docLength = doc.getLength();
if (drOffset > docLength) {
drOffset = docLength;
drLength = 0;
} else if (drOffset + drLength > docLength) {
drLength = docLength - drOffset;
}
try {
// dirty region may span multiple partitions
tr = TextUtilities.computePartitioning(doc, getDocumentPartitioning(), drOffset, drLength, true);
} catch (BadLocationException e) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String info = "dr: [" + drOffset + ":" + drLength + "] doc: [" + docLength + "] ";
IStatus status = new Status(IStatus.ERROR, JavaScriptUI.ID_PLUGIN, IStatus.OK, info, e);
JavaScriptPlugin.getDefault().getLog().log(status);
tr = new ITypedRegion[0];
}
}
return tr;
}
Aggregations