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

The following examples show how to use org.eclipse.jface.text.IDocument#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: HighlightingPresenter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 2
Source File: XtextReconciler.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void assistSessionStarted(ContentAssistEvent event) {
	IDocument document = textViewer.getDocument();
	document.addPositionCategory(XTEXT_TEMPLATE_POS_CATEGORY);
	document.addPositionUpdater(templatePositionUpdater);
	sessionStarted = true;
}
 
Example 3
Source File: TexDocumentModel.java    From texlipse with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 4
Source File: SemanticHighlightingPresenter.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 5
Source File: AbstractJavaCompletionProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Source File: MarkRing.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: SemanticHighlightingReconciler.java    From eclipse.jdt.ls with Eclipse Public License 2.0 4 votes vote down vote up
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;
		}
	}
}
 
Example 8
Source File: DocumentScopeManager.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
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;
}