org.eclipse.jface.text.DefaultPositionUpdater Java Examples

The following examples show how to use org.eclipse.jface.text.DefaultPositionUpdater. 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: BlockCommentAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a new edition on the document of this factory.
 *
 * @param offset the offset of the edition at the point when is created.
 * @param length the length of the edition (not updated via the position update mechanism)
 * @param text the text to be replaced on the document
 * @return an <code>Edit</code> reflecting the edition on the document
 */
public Edit createEdit(int offset, int length, String text) throws BadLocationException {

	if (!fDocument.containsPositionCategory(fCategory)) {
		fDocument.addPositionCategory(fCategory);
		fUpdater= new DefaultPositionUpdater(fCategory);
		fDocument.addPositionUpdater(fUpdater);
	}

	Position position= new Position(offset);
	try {
		fDocument.addPosition(fCategory, position);
	} catch (BadPositionCategoryException e) {
		Assert.isTrue(false);
	}
	return new Edit(fDocument, length, text, position);
}
 
Example #2
Source File: CommentFormatterUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns a document with the given content and the given positions
 * registered with the {@link DefaultPositionUpdater}.
 *
 * @param content the content
 * @param positions the positions
 * @return the document
 * @throws IllegalArgumentException
 */
private static Document createDocument(String content, Position[] positions) throws IllegalArgumentException {
	Document doc= new Document(content);
	try {
		if (positions != null) {
			final String POS_CATEGORY= "myCategory"; //$NON-NLS-1$

			doc.addPositionCategory(POS_CATEGORY);
			doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {
				protected boolean notDeleted() {
					if (this.fOffset < this.fPosition.offset && (this.fPosition.offset + this.fPosition.length < this.fOffset + this.fLength)) {
						this.fPosition.offset= this.fOffset + this.fLength; // deleted positions: set to end of remove
						return false;
					}
					return true;
				}
			});
			for (int i= 0; i < positions.length; i++) {
				try {
					doc.addPosition(POS_CATEGORY, positions[i]);
				} catch (BadLocationException e) {
					throw new IllegalArgumentException("Position outside of string. offset: " + positions[i].offset + ", length: " + positions[i].length + ", string size: " + content.length());   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
				}
			}
		}
	} catch (BadPositionCategoryException cannotHappen) {
		// can not happen: category is correctly set up
	}
	return doc;
}
 
Example #3
Source File: ASTRewriteFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static Document createDocument(String string, Position[] positions) throws IllegalArgumentException {
	Document doc= new Document(string);
	try {
		if (positions != null) {
			final String POS_CATEGORY= "myCategory"; //$NON-NLS-1$

			doc.addPositionCategory(POS_CATEGORY);
			doc.addPositionUpdater(new DefaultPositionUpdater(POS_CATEGORY) {
				protected boolean notDeleted() {
					int start= this.fOffset;
					int end= start + this.fLength;
					if (start < this.fPosition.offset && (this.fPosition.offset + this.fPosition.length < end)) {
						this.fPosition.offset= end; // deleted positions: set to end of remove
						return false;
					}
					return true;
				}
			});
			for (int i= 0; i < positions.length; i++) {
				try {
					doc.addPosition(POS_CATEGORY, positions[i]);
				} catch (BadLocationException e) {
					throw new IllegalArgumentException("Position outside of string. offset: " + positions[i].offset + ", length: " + positions[i].length + ", string size: " + string.length());   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
				}
			}
		}
	} catch (BadPositionCategoryException cannotHappen) {
		// can not happen: category is correctly set up
	}
	return doc;
}
 
Example #4
Source File: DocumentPartitioner.java    From xtext-eclipse with Eclipse Public License 2.0 3 votes vote down vote up
/**
 * Creates a new partitioner that uses the given scanner and may return partitions of the given legal content types.
 * 
 * @param scanner
 *            the scanner this partitioner is supposed to use
 * @param legalContentTypes
 *            the legal content types of this partitioner
 * @since 2.2
 */
public DocumentPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
	fScanner = scanner;
	fLegalContentTypes = TextUtilities.copy(legalContentTypes);
	fPositionCategory = CONTENT_TYPES_CATEGORY + hashCode();
	fPositionUpdater = new DefaultPositionUpdater(fPositionCategory);
}
 
Example #5
Source File: TLAFastPartitioner.java    From tlaplus with MIT License 3 votes vote down vote up
/**
 * Creates a new partitioner that uses the given scanner and may return
 * partitions of the given legal content types.
 *
 * @param scanner the scanner this partitioner is supposed to use
 * @param legalContentTypes the legal content types of this partitioner
 */
public TLAFastPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
    fScanner= (TLAPartitionScanner) scanner;
    fLegalContentTypes= TextUtilities.copy(legalContentTypes);
    fPositionCategory= CONTENT_TYPES_CATEGORY + hashCode();
    fPositionUpdater= new DefaultPositionUpdater(fPositionCategory);
}
 
Example #6
Source File: FastPartitioner.java    From Pydev with Eclipse Public License 1.0 3 votes vote down vote up
/**
 * Creates a new partitioner that uses the given scanner and may return
 * partitions of the given legal content types.
 *
 * @param scanner the scanner this partitioner is supposed to use
 * @param legalContentTypes the legal content types of this partitioner
 */
public FastPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
    fScanner = scanner;
    fLegalContentTypes = TextUtilities.copy(legalContentTypes);
    fPositionCategory = CONTENT_TYPES_CATEGORY + hashCode();
    fPositionUpdater = new DefaultPositionUpdater(fPositionCategory);
}