Java Code Examples for org.eclipse.jface.text.Document#addPositionCategory()

The following examples show how to use org.eclipse.jface.text.Document#addPositionCategory() . 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: JavaFormatter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new tracker.
 * 
 * @param buffer the buffer to track
 * @throws MalformedTreeException
 * @throws BadLocationException
 */
public VariableTracker(TemplateBuffer buffer) throws MalformedTreeException, BadLocationException {
	Assert.isLegal(buffer != null);
	fBuffer= buffer;
	fDocument= new Document(fBuffer.getString());
	installJavaStuff(fDocument);
	fDocument.addPositionCategory(CATEGORY);
	fDocument.addPositionUpdater(new ExclusivePositionUpdater(CATEGORY));
	fPositions= createRangeMarkers(fBuffer.getVariables(), fDocument);
}
 
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: PartitionCodeReaderTest.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public String setupDocument(Document document) {
    IPartitionTokenScanner scanner = new RuleBasedPartitionScanner();
    FastPartitioner partitioner = new FastPartitioner(scanner, new String[] { IDocument.DEFAULT_CONTENT_TYPE });
    String[] managingPositionCategories = partitioner.getManagingPositionCategories();
    String category = managingPositionCategories[0];
    document.setDocumentPartitioner(partitioner);
    document.addPositionCategory(category);
    return category;
}
 
Example 5
Source File: JavaFormatter.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a new tracker.
 * 
 * @param buffer the buffer to track
 * @throws MalformedTreeException
 * @throws BadLocationException
 */
public VariableTracker(TemplateBuffer buffer) throws MalformedTreeException, BadLocationException {
	Assert.isLegal(buffer != null);
	fBuffer= buffer;
	fDocument= new Document(fBuffer.getString());
	installJavaStuff(fDocument);
	fDocument.addPositionCategory(CATEGORY);
	fDocument.addPositionUpdater(new ExclusivePositionUpdater(CATEGORY));
	fPositions= createRangeMarkers(fBuffer.getVariables(), fDocument);
}