类org.eclipse.jface.text.BadPositionCategoryException源码实例Demo

下面列出了怎么用org.eclipse.jface.text.BadPositionCategoryException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: xtext-eclipse   文件: DocumentPartitioner.java
/**
 * Returns the partitioners positions.
 * 
 * @return the partitioners positions
 * @throws BadPositionCategoryException
 *             if getting the positions from the document fails
 * @since 2.2
 */
protected synchronized final Position[] getPositions() throws BadPositionCategoryException {
	if (fCachedPositions == null) {
		fCachedPositions = fDocument.getPositions(fPositionCategory);
	} else if (CHECK_CACHE_CONSISTENCY) {
		Position[] positions = fDocument.getPositions(fPositionCategory);
		int len = Math.min(positions.length, fCachedPositions.length);
		for (int i = 0; i < len; i++) {
			if (!positions[i].equals(fCachedPositions[i]))
				System.err
						.println("FastPartitioner.getPositions(): cached position is not up to date: from document: " + toString(positions[i]) + " in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ //$NON-NLS-2$
		}
		for (int i = len; i < positions.length; i++)
			System.err
					.println("FastPartitioner.getPositions(): new position in document: " + toString(positions[i])); //$NON-NLS-1$
		for (int i = len; i < fCachedPositions.length; i++)
			System.err
					.println("FastPartitioner.getPositions(): stale position in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$
	}
	return fCachedPositions;
}
 
源代码2 项目: eclipse.jdt.ls   文件: DocumentLifeCycleHandler.java
@Override
public ICompilationUnit handleOpen(DidOpenTextDocumentParams params) {
	ICompilationUnit unit = super.handleOpen(params);

	if (unit == null || unit.getResource() == null || unit.getResource().isDerived()) {
		return unit;
	}

	try {
		installSemanticHighlightings(unit);
	} catch (JavaModelException | BadPositionCategoryException e) {
		JavaLanguageServerPlugin.logException("Error while opening document. URI: " + params.getTextDocument().getUri(), e);
	}

	return unit;
}
 
源代码3 项目: tlaplus   文件: TLAFastPartitioner.java
/**
 * Returns the partitioner's positions.   Apparently, this is an array of TypedPosition objects
 * that partitions the document, ordered from start to end.  These TypedPosition objects mark
 * all the non-TLA+ portions of the document--that is, comments, strings, and PlusCal tokens.
 *
 * @return the partitioner's positions
 * @throws BadPositionCategoryException if getting the positions from the
 *         document fails
 */
protected final Position[] getPositions() throws BadPositionCategoryException {
    if (fCachedPositions == null) {
        fCachedPositions= fDocument.getPositions(fPositionCategory);
    } else if (CHECK_CACHE_CONSISTENCY) {
        Position[] positions= fDocument.getPositions(fPositionCategory);
        int len= Math.min(positions.length, fCachedPositions.length);
        for (int i= 0; i < len; i++) {
            if (!positions[i].equals(fCachedPositions[i]))
                System.err.println("FastPartitioner.getPositions(): cached position is not up to date: from document: " + toString(positions[i]) + " in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$ //$NON-NLS-2$
        }
        for (int i= len; i < positions.length; i++)
            System.err.println("FastPartitioner.getPositions(): new position in document: " + toString(positions[i])); //$NON-NLS-1$
        for (int i= len; i < fCachedPositions.length; i++)
            System.err.println("FastPartitioner.getPositions(): stale position in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$
    }
    return fCachedPositions;
}
 
/**
 * 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);
}
 
源代码5 项目: e4macs   文件: EmacsPlusUtils.java
/**
 * Get all positions of the given position category
 * In sexp's these positions are typically skipped
 * 
 * @param doc
 * @param pos_names
 * @return the positions to exclude
 */
public static List<Position> getExclusions(IDocument doc, String[] pos_names) {
	List<Position> excludePositions = new LinkedList<Position>();
	String cat = getTypeCategory(doc);
	if (cat != null) {
		try {
			Position[] xpos = doc.getPositions(cat);
			for (int j = 0; j < xpos.length; j++) {
				if (xpos[j] instanceof TypedPosition) {

					for (int jj = 0; jj < pos_names.length; jj++) {
						if (((TypedPosition) xpos[j]).getType().contains(pos_names[jj])) {
							excludePositions.add(xpos[j]);
						}
					}
				}
			}
		} catch (BadPositionCategoryException e) {}
	}
	return excludePositions;
}
 
源代码6 项目: e4macs   文件: TecoRegister.java
public void partClosed(IWorkbenchPartReference partRef) {
	
	if (partRef instanceof IEditorReference) {
		IEditorPart epart = ((IEditorReference) partRef).getEditor(false);
		ITextEditor editor = (location != null ? location.getEditor() : null);
		if (editor == EmacsPlusUtils.getTextEditor(epart, false)) {
			RegisterLocation loc = location;
			// we're out of here
			removeListener(this);
			IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
			// remove position category, if still present
			if (document.containsPositionCategory(MarkRing.MARK_CATEGORY)) {
				try {
					document.removePositionUpdater(MarkRing.updater);
					document.removePositionCategory(MarkRing.MARK_CATEGORY);
				} catch (BadPositionCategoryException e) {
				}
			}
			// convert to path
			loc.setPath(convertToPath(editor));
		}
	}
}
 
源代码7 项目: Pydev   文件: FastPartitioner.java
/**
 * Returns the partitioners positions.
 *
 * @return the partitioners positions
 * @throws BadPositionCategoryException if getting the positions from the
 *         document fails
 */
protected final Position[] getPositions() throws BadPositionCategoryException {
    if (fCachedPositions == null) {
        fCachedPositions = fDocument.getPositions(fPositionCategory);
    } else if (CHECK_CACHE_CONSISTENCY) {
        Position[] positions = fDocument.getPositions(fPositionCategory);
        int len = Math.min(positions.length, fCachedPositions.length);
        for (int i = 0; i < len; i++) {
            if (!positions[i].equals(fCachedPositions[i])) {
                System.err.println(
                        "FastPartitioner.getPositions(): cached position is not up to date: from document: " //$NON-NLS-1$
                                + toString(positions[i]) + " in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$
            }
        }
        for (int i = len; i < positions.length; i++) {
            System.err
                    .println("FastPartitioner.getPositions(): new position in document: " + toString(positions[i])); //$NON-NLS-1$
        }
        for (int i = len; i < fCachedPositions.length; i++) {
            System.err.println(
                    "FastPartitioner.getPositions(): stale position in cache: " + toString(fCachedPositions[i])); //$NON-NLS-1$
        }
    }
    return fCachedPositions;
}
 
源代码8 项目: Pydev   文件: PartitionCodeReader.java
public void configureForwardReaderKeepingPositions(int offset, int end) throws IOException,
        BadPositionCategoryException {
    if (!fSupportKeepPositions) {
        throw new AssertionError("configureForwardReader must be called with supportKeepPositions=true.");
    }
    fOffset = offset;
    fStartForwardOffset = offset;
    fForward = true;
    fEnd = Math.min(fDocument.getLength(), end);
    fcurrentPositionI = 0;
    if (fPositions.length > 0) {
        fCurrentPosition = fPositions[0];
    } else {
        fCurrentPosition = null;
    }
}
 
源代码9 项目: Pydev   文件: PartitionCodeReader.java
public void configureForwardReader(IDocument document, int offset, int end, boolean supportKeepPositions)
        throws IOException,
        BadPositionCategoryException {
    fSupportKeepPositions = supportKeepPositions;
    fDocument = document;
    fOffset = offset;
    fStartForwardOffset = offset;
    fForward = true;
    fEnd = Math.min(fDocument.getLength(), end);
    fcurrentPositionI = 0;
    fPositions = createPositions(document);
    if (fPositions.length > 0) {
        fCurrentPosition = fPositions[0];
    } else {
        fCurrentPosition = null;
    }
}
 
源代码10 项目: Pydev   文件: PartitionCodeReader.java
private Position[] createPositions(IDocument document) throws BadPositionCategoryException {
    Position[] positions = getDocumentTypedPositions(document, contentType);
    List<TypedPosition> typedPositions = PartitionMerger.sortAndMergePositions(positions, document.getLength());
    int size = typedPositions.size();
    List<Position> list = new ArrayList<Position>(size);
    for (int i = 0; i < size; i++) {
        Position position = typedPositions.get(i);
        if (isPositionValid(position, contentType)) {
            list.add(position);
        }
    }

    if (!fForward) {
        Collections.reverse(list);
    }
    Position[] ret = list.toArray(new Position[list.size()]);
    return ret;
}
 
源代码11 项目: Pydev   文件: DocCopy.java
public DocCopy(IDocument document) {
    this.contents = document.get();
    this.document = document;
    categoryToPos = new HashMap<>();
    String[] positionCategories = document.getPositionCategories();
    for (String string : positionCategories) {
        try {
            categoryToPos.put(string, document.getPositions(string));
        } catch (BadPositionCategoryException e) {
            Log.log(e);
        }
    }

    IDocumentExtension4 doc4 = (IDocumentExtension4) document;
    modificationStamp = doc4.getModificationStamp();
}
 
源代码12 项目: Pydev   文件: PyOpenLastConsoleHyperlink.java
@SuppressWarnings("restriction")
private void processIOConsole(IOConsole ioConsole) {
    IDocument document = ioConsole.getDocument();
    try {
        Position[] positions = document.getPositions(ConsoleHyperlinkPosition.HYPER_LINK_CATEGORY);
        Arrays.sort(positions, new Comparator<Position>() {

            @Override
            public int compare(Position o1, Position o2) {
                return Integer.compare(o1.getOffset(), o2.getOffset());
            }
        });
        if (positions.length > 0) {
            Position p = positions[positions.length - 1];
            if (p instanceof ConsoleHyperlinkPosition) {
                ConsoleHyperlinkPosition consoleHyperlinkPosition = (ConsoleHyperlinkPosition) p;
                IHyperlink hyperLink = consoleHyperlinkPosition.getHyperLink();
                hyperLink.linkActivated();
            }
        }
    } catch (BadPositionCategoryException e) {
        Log.log(e);
    }
}
 
源代码13 项目: xtext-eclipse   文件: XtextDocument.java
@Override
public Position[] getPositions(String category, int offset, int length, boolean canStartBefore, boolean canEndAfter)
		throws BadPositionCategoryException {
	positionsReadLock.lock();
	try {
		return super.getPositions(category, offset, length, canStartBefore, canEndAfter);
	} finally {
		positionsReadLock.unlock();
	}
}
 
源代码14 项目: xtext-eclipse   文件: XtextDocument.java
@Override
public Position[] getPositions(String category) throws BadPositionCategoryException {
	positionsReadLock.lock();
	try {
		return super.getPositions(category);
	} finally {
		positionsReadLock.unlock();
	}
}
 
源代码15 项目: xtext-eclipse   文件: XtextDocument.java
@Override
public void addPosition(String category, Position position) throws BadLocationException,
		BadPositionCategoryException {
	positionsWriteLock.lock();
	try {
		super.addPosition(category, position);
	} finally {
		positionsWriteLock.unlock();
	}
}
 
源代码16 项目: xtext-eclipse   文件: XtextDocument.java
@Override
public void removePosition(String category, Position position) throws BadPositionCategoryException {
	positionsWriteLock.lock();
	try {
		super.removePosition(category, position);
	} finally {
		positionsWriteLock.unlock();
	}
}
 
源代码17 项目: xtext-eclipse   文件: DocumentPartitioner.java
/**
 * {@inheritDoc}
 * <p>
 * May be extended by subclasses.
 * </p>
 * 
 * @since 2.2
 */
@Override
public synchronized void disconnect() {

	Assert.isTrue(fDocument.containsPositionCategory(fPositionCategory));

	try {
		fDocument.removePositionCategory(fPositionCategory);
	} catch (BadPositionCategoryException x) {
		// can not happen because of Assert
	}
}
 
源代码18 项目: xtext-eclipse   文件: DocumentPartitioner.java
/**
 * Flushes the active rewrite session.
 * 
 * @since 2.2
 */
protected synchronized final void flushRewriteSession() {
	fActiveRewriteSession = null;

	// remove all position belonging to the partitioner position category
	try {
		fDocument.removePositionCategory(fPositionCategory);
	} catch (BadPositionCategoryException x) {
	}
	fDocument.addPositionCategory(fPositionCategory);

	fIsInitialized = false;
}
 
源代码19 项目: xtext-eclipse   文件: HighlightingPresenter.java
/**
 * Stop managing the given document.
 * 
 * @param document
 *            The document
 */
private void releaseDocument(IDocument document) {
	if (document != null) {
		document.removeDocumentListener(this);
		document.removePositionUpdater(fPositionUpdater);
		try {
			document.removePositionCategory(getPositionCategory());
		} catch (BadPositionCategoryException e) {
			// Should not happen
			log.debug(e.getMessage(), e);
		}
	}
}
 
源代码20 项目: xtext-eclipse   文件: XtextReconciler.java
@Override
public void assistSessionEnded(ContentAssistEvent event) {
	sessionStarted = false;
	IDocument document = textViewer.getDocument();
	document.removePositionUpdater(templatePositionUpdater);
	try {
		document.removePositionCategory(XTEXT_TEMPLATE_POS_CATEGORY);
	} catch (BadPositionCategoryException e) {
		log.debug(e.getMessage(), e);
	}
	resume();
}
 
源代码21 项目: texlipse   文件: TexDocumentModel.java
/**
 * 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;
}
 
public List<Position> install(ICompilationUnit unit) throws JavaModelException, BadPositionCategoryException {
	if (enabled.get()) {
		List<HighlightedPositionCore> positions = calculateHighlightedPositions(unit, false);
		String uri = JDTUtils.getFileURI(unit.getResource());
		this.cache.put(uri, positions);
		if (!positions.isEmpty()) {
			IDocument document = JsonRpcHelpers.toDocument(unit.getBuffer());
			List<SemanticHighlightingInformation> infos = toInfos(document, positions);
			VersionedTextDocumentIdentifier textDocument = new VersionedTextDocumentIdentifier(uri, 1);
			notifyClient(textDocument, infos);
		}
		return ImmutableList.copyOf(positions);
	}
	return emptyList();
}
 
public List<HighlightedPositionCore> calculateHighlightedPositions(ICompilationUnit unit, boolean cache) throws JavaModelException, BadPositionCategoryException {
	if (enabled.get()) {
		IDocument document = JsonRpcHelpers.toDocument(unit.getBuffer());
		ASTNode ast = getASTNode(unit);
		List<HighlightedPositionCore> positions = calculateHighlightedPositions(document, ast);
		if (cache) {
			String uri = JDTUtils.getFileURI(unit.getResource());
			this.cache.put(uri, positions);
		}
		return ImmutableList.copyOf(positions);
	}
	return emptyList();
}
 
public void update(VersionedTextDocumentIdentifier textDocument, List<HighlightedPositionDiffContext> diffContexts) throws BadLocationException, BadPositionCategoryException, JavaModelException {
	if (enabled.get() && !diffContexts.isEmpty()) {
		List<SemanticHighlightingInformation> deltaInfos = newArrayList();
		for (HighlightedPositionDiffContext context : diffContexts) {
			deltaInfos.addAll(diffCalculator.getDiffInfos(context));
		}
		if (!deltaInfos.isEmpty()) {
			notifyClient(textDocument, deltaInfos);
		}
	}
}
 
源代码25 项目: tlaplus   文件: TLAFastPartitioner.java
/**
 * {@inheritDoc}
 * <p>
 * May be extended by subclasses.
 * </p>
 */
public void disconnect() {

    Assert.isTrue(fDocument.containsPositionCategory(fPositionCategory));

    try {
        fDocument.removePositionCategory(fPositionCategory);
    } catch (BadPositionCategoryException x) {
        // can not happen because of Assert
    }
}
 
源代码26 项目: tlaplus   文件: TLAFastPartitioner.java
/**
 * Flushes the active rewrite session.
 */
protected final void flushRewriteSession() {
    fActiveRewriteSession= null;

    // remove all position belonging to the partitioner position category
    try {
        fDocument.removePositionCategory(fPositionCategory);
    } catch (BadPositionCategoryException x) {
    }
    fDocument.addPositionCategory(fPositionCategory);

    fIsInitialized= false;
}
 
源代码27 项目: tlaplus   文件: TLAFastPartitioner.java
/**
 * For printing out debugging information
 *   (TypedPosition)
 * @param msg
 */
public void debugPrint(String msg) {
    System.out.println("Debug print " + msg);
    System.out.println("Start comment offset: " + pcalStartCommentOffset
            + ";  Start: (" + pcalStartOffset + ", " + pcalStartLength + 
            ");  End comment: (" + pcalEndCommentOffset + ", "
            + pcalEndCommentLength + ")") ;
    Position[] positions = null;
    try {
        positions = fDocument.getPositions(fPositionCategory);
    } catch (BadPositionCategoryException e1) {
        System.out.println("Can't get positions") ;
        e1.printStackTrace();
        return ;
    }
    for (int i = 0; i < positions.length; i++) {
       try {
          TypedPosition position = (TypedPosition) positions[i] ;
          System.out.println("Position " + i + ": (" + position.getOffset()
                  + ", " + position.getLength() + ")  type: "
                  + position.getType() + (position.isDeleted?" DELETED":""));
          System.out.println("  `" + 
                  fDocument.get(position.getOffset(), position.getLength()) + "'") ;
    
       } catch (Exception e) {
            System.out.println("Item " + i + " Exception: " + e.getMessage()) ;
         }
    }
    IRegion result = createRegion();
    if (result == null) {
        System.out.println("Returned null");
    } else {
        System.out.println("Returned (" + result.getOffset() + ", " 
            + result.getLength() + ")") ;
    }
}
 
private void ensurePositionCategoryRemoved(IDocument document) {
	if (document.containsPositionCategory(getCategory())) {
		try {
			document.removePositionCategory(getCategory());
		} catch (BadPositionCategoryException e) {
			// ignore
		}
		document.removePositionUpdater(fUpdater);
	}
}
 
源代码29 项目: APICloud-Studio   文件: SnippetTemplateProposal.java
private void ensurePositionCategoryRemoved(IDocument document)
{
	if (document.containsPositionCategory(getCategory()))
	{
		try
		{
			document.removePositionCategory(getCategory());
		}
		catch (BadPositionCategoryException e)
		{
			// ignore
		}
		document.removePositionUpdater(fUpdater);
	}
}
 
/**
 * Restores any decorated regions and updates the buffer's variable offsets.
 *
 * @return the buffer.
 * @throws MalformedTreeException
 * @throws BadLocationException
 */
public TemplateBuffer updateBuffer() throws MalformedTreeException, BadLocationException {
	checkState();
	TemplateVariable[] variables= fBuffer.getVariables();
	try {
		removeRangeMarkers(fPositions, fDocument, variables);
	} catch (BadPositionCategoryException x) {
		Assert.isTrue(false);
	}
	fBuffer.setContent(fDocument.get(), variables);
	fDocument= null;

	return fBuffer;
}
 
 类所在包
 类方法
 同包方法