Search in sources :

Example 66 with BadPositionCategoryException

use of org.eclipse.jface.text.BadPositionCategoryException in project erlide_eclipse by erlang.

the class ErlangBracketInserter method left.

/*
     * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.
     * jface.text.link.LinkedModeModel, int)
     */
@Override
@SuppressWarnings("synthetic-access")
public void left(final LinkedModeModel environment, final int flags) {
    final BracketLevel level = fBracketLevelStack.pop();
    if (flags != ILinkedModeListener.EXTERNAL_MODIFICATION) {
        return;
    }
    // remove brackets
    final IDocument document = sourceViewer.getDocument();
    if (document instanceof IDocumentExtension) {
        final IDocumentExtension extension = (IDocumentExtension) document;
        extension.registerPostNotificationReplace(null, (d, owner) -> {
            if ((level.fFirstPosition.isDeleted || level.fFirstPosition.length == 0) && !level.fSecondPosition.isDeleted && level.fSecondPosition.offset == level.fFirstPosition.offset) {
                try {
                    document.replace(level.fSecondPosition.offset, level.fSecondPosition.length, // $NON-NLS-1$
                    "");
                } catch (final BadLocationException e1) {
                    ErlLogger.error(e1);
                }
            }
            if (fBracketLevelStack.isEmpty()) {
                document.removePositionUpdater(fUpdater);
                try {
                    document.removePositionCategory(CATEGORY);
                } catch (final BadPositionCategoryException e2) {
                    ErlLogger.error(e2);
                }
            }
        });
    }
}
Also used : IDocumentExtension(org.eclipse.jface.text.IDocumentExtension) BadPositionCategoryException(org.eclipse.jface.text.BadPositionCategoryException) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)66 Position (org.eclipse.jface.text.Position)46 BadLocationException (org.eclipse.jface.text.BadLocationException)38 TypedPosition (org.eclipse.jface.text.TypedPosition)27 IDocument (org.eclipse.jface.text.IDocument)21 ArrayList (java.util.ArrayList)14 ITypedRegion (org.eclipse.jface.text.ITypedRegion)14 TypedRegion (org.eclipse.jface.text.TypedRegion)12 IRegion (org.eclipse.jface.text.IRegion)8 List (java.util.List)6 Point (org.eclipse.swt.graphics.Point)5 IToken (org.eclipse.jface.text.rules.IToken)4 DefaultPositionUpdater (org.eclipse.jface.text.DefaultPositionUpdater)3 IPositionUpdater (org.eclipse.jface.text.IPositionUpdater)3 Region (org.eclipse.jface.text.Region)3 Iterator (java.util.Iterator)2 IBlockTextSelection (org.eclipse.jface.text.IBlockTextSelection)2 NoChangeEvent (org.eclipse.wst.sse.core.internal.provisional.events.NoChangeEvent)2 HighlightedPosition (org.eclipse.wst.sse.ui.internal.style.SemanticHighlightingManager.HighlightedPosition)2 XMLNode (com.amalto.workbench.widgets.xmlviewer.model.XMLNode)1