下面列出了org.eclipse.jface.text.IDocument#addPositionCategory ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Start managing the given document.
*
* @param document
* The document
*/
private void manageDocument(IDocument document) {
if (document != null) {
document.addPositionCategory(getPositionCategory());
document.addPositionUpdater(fPositionUpdater);
document.addDocumentListener(this);
}
}
@Override
public void assistSessionStarted(ContentAssistEvent event) {
IDocument document = textViewer.getDocument();
document.addPositionCategory(XTEXT_TEMPLATE_POS_CATEGORY);
document.addPositionUpdater(templatePositionUpdater);
sessionStarted = true;
}
/**
* Traverses the OutlineNode tree and adds a Position for each
* node to Document.
*
* Also adds the nodes to type lists of the OutlineInput and
* calculates the tree depth.
*
* Old Positions are removed before adding new ones.
*
* @param rootNodes
* @param monitor monitor for the job calling this method
*/
private void updateDocumentPositions(List<OutlineNode> rootNodes, IProgressMonitor monitor) {
TexOutlineInput newOutlineInput = new TexOutlineInput(rootNodes);
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
// remove previous positions
try {
document.removePositionCategory("__outline");
} catch (BadPositionCategoryException bpce) {
// do nothing, the category will be added again next, it does not exists the first time
}
document.addPositionCategory("__outline");
pollCancel(monitor);
// add new positions for nodes and their children
int maxDepth = 0;
for (Iterator<OutlineNode> iter = rootNodes.iterator(); iter.hasNext(); ) {
OutlineNode node = iter.next();
int localDepth = addNodePosition(node, document, 0, newOutlineInput);
if (localDepth > maxDepth) {
maxDepth = localDepth;
}
pollCancel(monitor);
}
pollCancel(monitor);
// set the new outline input
newOutlineInput.setTreeDepth(maxDepth);
this.outlineInput = newOutlineInput;
}
/**
* Start managing the given document.
*
* @param document The document
*/
private void manageDocument(IDocument document) {
if (document != null) {
document.addPositionCategory(getPositionCategory());
document.addPositionUpdater(fPositionUpdater);
document.addDocumentListener(this);
}
}
/**
* Called before document changes occur. It must be followed by a call to postReplace().
*
* @param document the document on which to track the reference position.
* @param offset the offset
* @throws BadLocationException if the offset describes an invalid range in this document
*
*/
public void preReplace(IDocument document, int offset) throws BadLocationException {
fPosition.setOffset(offset);
try {
document.addPositionCategory(CATEGORY);
document.addPositionUpdater(fPositionUpdater);
document.addPosition(CATEGORY, fPosition);
} catch (BadPositionCategoryException e) {
// should not happen
JavaPlugin.log(e);
}
}
/**
* Add the previous mark to the Mark Ring
*
* @param editor - the current editor
* @param document - the editor's document for position updating
* @param localMark - the previous mark location to save
* @param globalMark - the new mark location; a potential global candidate
*/
public static void addMark(ITextEditor editor, IDocument document, int localMark, int globalMark) {
MarkList local = localMarks.get(document);
if (local == null) {
local = new MarkList(RingBuffer.getDefaultSize());
localMarks.put(document, local);
document.addPositionCategory(MARK_CATEGORY);
document.addPositionUpdater(updater);
}
local.addMark(document, localMark);
// check to see if we should save globally
globalMarks.addMark(editor,document,globalMark,true);
}
public List<HighlightedPositionCore> reconciled(IDocument document, ASTNode ast, boolean forced, IProgressMonitor progressMonitor) throws BadPositionCategoryException {
// ensure at most one thread can be reconciling at any time
synchronized (fReconcileLock) {
if (fIsReconciling) {
return emptyList();
} else {
fIsReconciling= true;
}
}
fJobPresenter= fPresenter;
fJobSemanticHighlightings= fSemanticHighlightings;
fJobHighlightings= fHighlightings;
try {
if (ast == null) {
return emptyList();
}
ASTNode[] subtrees= getAffectedSubtrees(ast);
if (subtrees.length == 0) {
return emptyList();
}
startReconcilingPositions();
if (!fJobPresenter.isCanceled()) {
fJobDeprecatedMemberHighlighting= null;
for (int i= 0, n= fJobSemanticHighlightings.length; i < n; i++) {
SemanticHighlightingCore semanticHighlighting= fJobSemanticHighlightings[i];
if (semanticHighlighting instanceof DeprecatedMemberHighlighting) {
fJobDeprecatedMemberHighlighting = fJobHighlightings.get(i);
break;
}
}
reconcilePositions(subtrees);
}
// We need to manually install the position category
if (!document.containsPositionCategory(fPresenter.getPositionCategory())) {
document.addPositionCategory(fPresenter.getPositionCategory());
}
updatePresentation(document, fAddedPositions, fRemovedPositions);
stopReconcilingPositions();
Position[] positions = document.getPositions(fPresenter.getPositionCategory());
for (Position position : positions) {
Preconditions.checkState(position instanceof HighlightedPositionCore);
}
return FluentIterable.from(Arrays.asList(positions)).filter(HighlightedPositionCore.class).toList();
} finally {
fJobPresenter= null;
fJobSemanticHighlightings= null;
fJobHighlightings= null;
fJobDeprecatedMemberHighlighting= null;
synchronized (fReconcileLock) {
fIsReconciling= false;
}
}
}
private String getTokenScopeFragments(ITextViewer viewer, IDocument document, int offset)
{
if (!(viewer instanceof ISourceViewer))
{
return null;
}
try
{
// Force adding the category in case it doesn't exist yet...
document.addPositionCategory(ICommonConstants.SCOPE_CATEGORY);
Position[] scopes = document.getPositions(ICommonConstants.SCOPE_CATEGORY);
int index = document.computeIndexInCategory(ICommonConstants.SCOPE_CATEGORY, offset);
if (scopes == null || scopes.length == 0)
{
return null;
}
if (index >= scopes.length)
{
index = scopes.length - 1;
}
Position scope = scopes[index];
if (scope == null)
{
return null;
}
if (!scope.includes(offset))
{
if (index > 0)
{
scope = scopes[--index];
if (scope == null || !scope.includes(offset))
{
return null;
}
}
else
{
return null;
}
}
if (scope instanceof TypedPosition)
{
TypedPosition pos = (TypedPosition) scope;
return pos.getType();
}
}
catch (Exception e)
{
IdeLog.logError(CommonEditorPlugin.getDefault(), e);
}
return null;
}