Search in sources :

Example 41 with ITypedRegion

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;
}
Also used : TypedPosition(org.eclipse.jface.text.TypedPosition) Position(org.eclipse.jface.text.Position) TypedPosition(org.eclipse.jface.text.TypedPosition) ArrayList(java.util.ArrayList) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) ITypedRegion(org.eclipse.jface.text.ITypedRegion) TypedRegion(org.eclipse.jface.text.TypedRegion)

Example 42 with ITypedRegion

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;
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion) IBreakpoint(org.eclipse.debug.core.model.IBreakpoint) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 43 with ITypedRegion

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;
}
Also used : ITypedRegion(org.eclipse.jface.text.ITypedRegion)

Example 44 with ITypedRegion

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);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ITypedRegion(org.eclipse.jface.text.ITypedRegion) ArrayList(java.util.ArrayList) List(java.util.List) BadLocationException(org.eclipse.jface.text.BadLocationException) Stack(java.util.Stack)

Example 45 with ITypedRegion

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;
}
Also used : Region(org.eclipse.jface.text.Region) ITypedRegion(org.eclipse.jface.text.ITypedRegion) IRegion(org.eclipse.jface.text.IRegion) IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

ITypedRegion (org.eclipse.jface.text.ITypedRegion)129 BadLocationException (org.eclipse.jface.text.BadLocationException)59 IRegion (org.eclipse.jface.text.IRegion)42 IDocument (org.eclipse.jface.text.IDocument)21 Region (org.eclipse.jface.text.Region)19 ArrayList (java.util.ArrayList)17 TypedRegion (org.eclipse.jface.text.TypedRegion)16 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)14 Position (org.eclipse.jface.text.Position)14 TypedPosition (org.eclipse.jface.text.TypedPosition)13 List (java.util.List)11 StyleRange (org.eclipse.swt.custom.StyleRange)7 Test (org.junit.Test)7 Iterator (java.util.Iterator)6 IStructuredModel (org.eclipse.wst.sse.core.internal.provisional.IStructuredModel)6 ITextSelection (org.eclipse.jface.text.ITextSelection)5 BadPartitioningException (org.eclipse.jface.text.BadPartitioningException)4 Document (org.eclipse.jface.text.Document)4 IDocumentExtension3 (org.eclipse.jface.text.IDocumentExtension3)4 IDocumentPartitioner (org.eclipse.jface.text.IDocumentPartitioner)4