/** * 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; }
/** * @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); }
public static String getContentType(IDocument document, int i) { IDocumentPartitionerExtension2 extension = (IDocumentPartitionerExtension2) document.getDocumentPartitioner(); return extension.getContentType(i, true); }