use of org.eclipse.jface.text.TypedPosition in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method initialize.
protected void initialize() {
partitionScanner.setRange(document, 0, document.getLength());
try {
for (IToken token = partitionScanner.nextToken(); !token.isEOF(); token = partitionScanner.nextToken()) {
String contentType = getTokenContentType(token);
if (isSupportedContentType(contentType)) {
TypedPosition p = createPosition(partitionScanner.getTokenOffset(), partitionScanner.getTokenLength(), contentType);
addPosition(document, positionCategory, p);
}
}
} catch (BadLocationException _ex) {
} catch (BadPositionCategoryException _ex) {
}
}
use of org.eclipse.jface.text.TypedPosition in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method getPartition.
public ITypedRegion getPartition(int offset) {
try {
Position[] category = document.getPositions(positionCategory);
if (category == null || category.length == 0) {
// $NON-NLS-1$
return new TypedRegion(0, document.getLength(), "__dftl_partition_content_type");
}
int index = document.computeIndexInCategory(positionCategory, offset);
if (index < category.length) {
TypedPosition next = (TypedPosition) category[index];
if (offset == next.offset) {
return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
}
if (index == 0) {
// $NON-NLS-1$
return new TypedRegion(0, next.offset, "__dftl_partition_content_type");
}
TypedPosition previous = (TypedPosition) category[index - 1];
if (previous.includes(offset)) {
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
}
int endOffset = previous.getOffset() + previous.getLength();
// $NON-NLS-1$
return new TypedRegion(endOffset, next.getOffset() - endOffset, "__dftl_partition_content_type");
}
TypedPosition previous = (TypedPosition) category[category.length - 1];
if (previous.includes(offset)) {
return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
}
int endOffset = previous.getOffset() + previous.getLength();
// $NON-NLS-1$
return new TypedRegion(endOffset, document.getLength() - endOffset, "__dftl_partition_content_type");
} catch (BadPositionCategoryException _ex) {
} catch (BadLocationException _ex) {
}
// $NON-NLS-1$
return new TypedRegion(0, document.getLength(), "__dftl_partition_content_type");
}
use of org.eclipse.jface.text.TypedPosition in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method documentChanged2.
public IRegion documentChanged2(DocumentEvent e) {
try {
IDocument d = e.getDocument();
Position[] category = d.getPositions(positionCategory);
IRegion line = d.getLineInformationOfOffset(e.getOffset());
int reparseStart = line.getOffset();
int partitionStart = -1;
String contentType = null;
int first = d.computeIndexInCategory(positionCategory, reparseStart);
if (first > 0) {
TypedPosition partition = (TypedPosition) category[first - 1];
if (partition.includes(reparseStart)) {
partitionStart = partition.getOffset();
contentType = partition.getType();
if (e.getOffset() == partition.getOffset() + partition.getLength()) {
reparseStart = partitionStart;
}
first--;
} else if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) {
partitionStart = partition.getOffset();
contentType = partition.getType();
reparseStart = partitionStart;
first--;
} else {
partitionStart = partition.getOffset() + partition.getLength();
// $NON-NLS-1$
contentType = "__dftl_partition_content_type";
}
}
positionUpdater.update(e);
for (int i = first; i < category.length; i++) {
Position p = category[i];
if (!p.isDeleted) {
continue;
}
rememberDeletedOffset(e.getOffset());
break;
}
category = d.getPositions(positionCategory);
partitionScanner.setPartialRange(d, reparseStart, d.getLength() - reparseStart, contentType, partitionStart);
int lastScannedPosition = reparseStart;
for (IToken token = partitionScanner.nextToken(); !token.isEOF(); ) {
contentType = getTokenContentType(token);
if (!isSupportedContentType(contentType)) {
token = partitionScanner.nextToken();
} else {
int start = partitionScanner.getTokenOffset();
int length = partitionScanner.getTokenLength();
lastScannedPosition = (start + length) - 1;
for (; first < category.length; first++) {
TypedPosition p = (TypedPosition) category[first];
if (lastScannedPosition < p.offset + p.length && (!p.overlapsWith(start, length) || d.containsPosition(positionCategory, start, length) && contentType.equals(p.getType()))) {
break;
}
rememberRegion(p.offset, p.length);
d.removePosition(positionCategory, p);
}
if (d.containsPosition(positionCategory, start, length)) {
if (lastScannedPosition > e.getOffset()) {
return createRegion();
}
first++;
} else {
try {
TypedPosition p = createPosition(start, length, contentType);
addPosition(d, positionCategory, p);
rememberRegion(start, length);
} catch (BadPositionCategoryException _ex) {
} catch (BadLocationException _ex) {
}
}
token = partitionScanner.nextToken();
}
}
if (lastScannedPosition != reparseStart)
lastScannedPosition++;
for (first = d.computeIndexInCategory(positionCategory, lastScannedPosition); first < category.length; ) {
TypedPosition p = (TypedPosition) category[first++];
d.removePosition(positionCategory, p);
rememberRegion(p.offset, p.length);
}
} catch (BadPositionCategoryException _ex) {
} catch (BadLocationException _ex) {
}
return createRegion();
}
Aggregations