org.eclipse.jface.text.IDocumentPartitionerExtension2 Java Examples

The following examples show how to use org.eclipse.jface.text.IDocumentPartitionerExtension2. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PartitionCodeReader.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Note: this just gets the positions in the document. To cover for holes, use
 * StringUtils.sortAndMergePositions with the result of this call.
 */
public static Position[] getDocumentTypedPositions(IDocument document, String defaultContentType) {
    if (ALL_CONTENT_TYPES_AVAILABLE.equals(defaultContentType)) {
        //Consider the whole document
        return new Position[] { new TypedPosition(0, document.getLength(), defaultContentType) };
    }
    Position[] positions;
    try {
        IDocumentPartitionerExtension2 partitioner = (IDocumentPartitionerExtension2) document
                .getDocumentPartitioner();
        String[] managingPositionCategories = partitioner.getManagingPositionCategories();
        Assert.isTrue(managingPositionCategories.length == 1);
        positions = document.getPositions(managingPositionCategories[0]);
        if (positions == null) {
            positions = new Position[] { new TypedPosition(0, document.getLength(), defaultContentType) };
        }
    } catch (Exception e) {
        Log.log("Unable to get positions for: " + defaultContentType, e); //Shouldn't happen, but if it does, consider the whole doc.
        positions = new Position[] { new TypedPosition(0, document.getLength(), defaultContentType) };
    }
    return positions;
}
 
Example #2
Source File: ParsingUtils.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param document the document we want to get info on
 * @param i the document offset we're interested in
 * @return the content type at that position (according to IPythonPartitions)
 *
 * Uses the default if the partitioner is not set in the document (for testing purposes)
 */
public static String getContentType(IDocument document, int i) {
    IDocumentExtension3 docExtension = (IDocumentExtension3) document;
    IDocumentPartitionerExtension2 partitioner = (IDocumentPartitionerExtension2) docExtension
            .getDocumentPartitioner(IPythonPartitions.PYTHON_PARTITION_TYPE);

    if (partitioner != null) {
        return partitioner.getContentType(i, true);
    }
    return getContentType(document.get(), i);
}
 
Example #3
Source File: BaseParsingUtils.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public static String getContentType(IDocument document, int i) {
    IDocumentPartitionerExtension2 extension = (IDocumentPartitionerExtension2) document.getDocumentPartitioner();
    return extension.getContentType(i, true);
}