use of org.eclipse.jface.text.ITypedRegion in project tmdm-studio-se by Talend.
the class XMLDocumentPartitioner method computePartitioning.
public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
List<TypedRegion> list = new ArrayList<TypedRegion>();
try {
int endOffset = offset + length;
Position[] category = document.getPositions(positionCategory);
TypedPosition previous = null;
TypedPosition current = null;
Position gap = new Position(0);
int startIndex = getFirstIndexEndingAfterOffset(category, offset);
int endIndex = getFirstIndexStartingAfterOffset(category, endOffset);
for (int i = startIndex; i < endIndex; i++) {
current = (TypedPosition) category[i];
int gapOffset = previous == null ? 0 : previous.getOffset() + previous.getLength();
gap.setOffset(gapOffset);
gap.setLength(current.getOffset() - gapOffset);
if (includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length) || gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
int start = Math.max(offset, gapOffset);
int end = Math.min(endOffset, gap.getOffset() + gap.getLength());
// $NON-NLS-1$
list.add(new TypedRegion(start, end - start, "__dftl_partition_content_type"));
}
if (current.overlapsWith(offset, length)) {
int start = Math.max(offset, current.getOffset());
int end = Math.min(endOffset, current.getOffset() + current.getLength());
list.add(new TypedRegion(start, end - start, current.getType()));
}
previous = current;
}
if (previous != null) {
int gapOffset = previous.getOffset() + previous.getLength();
gap.setOffset(gapOffset);
gap.setLength(document.getLength() - gapOffset);
if (includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length) || gap.getLength() > 0 && gap.overlapsWith(offset, length)) {
int start = Math.max(offset, gapOffset);
int end = Math.min(endOffset, document.getLength());
// $NON-NLS-1$
list.add(new TypedRegion(start, end - start, "__dftl_partition_content_type"));
}
}
if (list.isEmpty()) {
// $NON-NLS-1$
list.add(new TypedRegion(offset, length, "__dftl_partition_content_type"));
}
} catch (BadPositionCategoryException _ex) {
}
TypedRegion[] result = new TypedRegion[list.size()];
list.toArray(result);
return result;
}
use of org.eclipse.jface.text.ITypedRegion in project liferay-ide by liferay.
the class RemoteJSPBreakpointProvider method getValidPosition.
private int getValidPosition(IDocument idoc, int editorLineNumber) {
int result = -1;
if (idoc != null) {
int startOffset = 0;
int endOffset = 0;
try {
IRegion line = idoc.getLineInformation(editorLineNumber - 1);
startOffset = line.getOffset();
endOffset = Math.max(line.getOffset(), line.getOffset() + line.getLength());
String lineText = idoc.get(startOffset, endOffset - startOffset).trim();
// scriptlet tag cannot have a breakpoint
if (// $NON-NLS-1$ //$NON-NLS-2$
lineText.equals("") || lineText.equals("{") || lineText.equals("}") || // $NON-NLS-1$ //$NON-NLS-2$
lineText.equals("<%")) {
result = -1;
} else {
// get all partitions for current line
ITypedRegion[] partitions = null;
partitions = idoc.computePartitioning(startOffset, endOffset - startOffset);
for (int i = 0; i < partitions.length; ++i) {
String type = partitions[i].getType();
// return that position
if (type == IJSPPartitions.JSP_CONTENT_JAVA || type == IJSPPartitions.JSP_DIRECTIVE || type == IJSPPartitions.JSP_DEFAULT_EL || type == IJSPPartitions.JSP_DEFAULT_EL2) {
result = partitions[i].getOffset();
}
}
}
} catch (BadLocationException e) {
result = -1;
}
}
return result;
}
use of org.eclipse.jface.text.ITypedRegion in project liferay-ide by liferay.
the class LiferayPropertiesContentAssistProcessor method _rewindOffsetToNearestNonDefaultPartition.
private int _rewindOffsetToNearestNonDefaultPartition(IDocumentPartitioner partitioner, final int initialOffset) {
int offset = initialOffset;
ITypedRegion partition = partitioner.getPartition(offset);
while ((offset > 0) && (partition != null) && IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())) {
offset--;
partition = partitioner.getPartition(offset);
}
if ((offset > 0) && (offset < initialOffset)) {
// move back up to next partition
offset++;
}
return offset;
}
use of org.eclipse.jface.text.ITypedRegion in project liferay-ide by liferay.
the class ItemSet method parse.
private void parse(ISourceViewer viewer, IResource resource) {
try {
this.directives = new ArrayList();
this.directiveRegions = new HashMap();
this.topLevelDirectives = new ArrayList();
Stack stackDirectives = new Stack();
List fullDirectives = new ArrayList();
for (Iterator i = regions.iterator(); i.hasNext(); ) {
ITypedRegion region = (ITypedRegion) i.next();
Item directive = ItemFactory.getItem(region, viewer, resource);
if (null != directive) {
directive.setItemSet(this);
if (directive instanceof MacroDirective) {
macroDefinitions.add(directive);
}
if (stackDirectives.size() == 0) {
topLevelDirectives.add(directive);
}
directiveRegions.put(new Integer(region.getOffset()), directive);
if (!directive.isEndItem())
directives.add(directive);
if (!directive.isStartItem()) {
Item directiveCheck = getFirstNestableItem(stackDirectives);
if (directive.isStartAndEndItem()) {
// not a true nestable but sub items will be nested
if (null != directiveCheck && directiveCheck.isStartAndEndItem()) {
if (directiveCheck.relatesToItem(directive)) {
directiveCheck.relateItem(directive);
directive.relateItem(directiveCheck);
}
stackDirectives.pop();
directiveCheck = getFirstNestableItem(stackDirectives);
}
directiveCheck = getFirstNestableItem(stackDirectives);
if (null != directiveCheck) {
directiveCheck.addSubDirective(directive);
directiveCheck.relateItem(directive);
directive.relateItem(directiveCheck);
}
stackDirectives.push(directive);
} else {
if (null != directiveCheck && directive.isEndItem() && directiveCheck.isStartAndEndItem()) {
if (directiveCheck.relatesToItem(directive)) {
directiveCheck.relateItem(directive);
directive.relateItem(directiveCheck);
}
stackDirectives.pop();
directiveCheck = getFirstNestableItem(stackDirectives);
}
if (null != directiveCheck && directiveCheck.relatesToItem(directive)) {
directiveCheck.relateItem(directive);
directive.relateItem(directiveCheck);
if (directive.isEndItem()) {
Item peek = (Item) stackDirectives.peek();
while (null != peek && peek.relatesToItem(directive)) {
if (peek.isStartItem()) {
stackDirectives.pop();
break;
} else {
stackDirectives.pop();
peek = (Item) ((stackDirectives.size() > 0) ? stackDirectives.peek() : null);
}
}
} else {
directiveCheck.addSubDirective(directive);
stackDirectives.push(directive);
}
} else if (!directive.isNestable() && !directive.isEndItem()) {
if (null != directiveCheck) {
directiveCheck.addSubDirective(directive);
}
} else if (directive.isNestable() && !directive.isEndItem()) {
if (null != directiveCheck) {
directiveCheck.addSubDirective(directive);
stackDirectives.push(directive);
}
} else {
// FIXME come up with a better way to handle this
return;
}
}
} else {
if (stackDirectives.size() > 0) {
((Item) stackDirectives.peek()).addSubDirective(directive);
}
if (directive.isNestable())
stackDirectives.push(directive);
}
}
}
} catch (Exception e) {
Plugin.log(e);
}
Collections.sort(macroDefinitions);
}
use of org.eclipse.jface.text.ITypedRegion in project liferay-ide by liferay.
the class NonRuleBasedDamagerRepairer method getDamageRegion.
/**
* @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
*/
public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged) {
if (!documentPartitioningChanged) {
try {
IRegion info = fDocument.getLineInformationOfOffset(event.getOffset());
int start = Math.max(partition.getOffset(), info.getOffset());
int end = event.getOffset() + (event.getText() == null ? event.getLength() : event.getText().length());
if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
// optimize the case of the same line
end = info.getOffset() + info.getLength();
} else
end = endOfLineOf(end);
end = Math.min(partition.getOffset() + partition.getLength(), end);
return new Region(start, end - start);
} catch (BadLocationException x) {
}
}
return partition;
}
Aggregations