Search in sources :

Example 61 with BadLocationException

use of org.eclipse.jface.text.BadLocationException in project ow by vtst.

the class AbstractCompletionProposal method apply.

@Override
public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
    String replacementString = getReplacementString(trigger);
    try {
        IDocument document = viewer.getDocument();
        int replacementOffset = context.getInvocationOffset() - context.getPrefixLength();
        document.replace(replacementOffset, context.getPrefixLength() + offset - context.getInvocationOffset(), replacementString);
        regionToSelect = new Point(context.getInvocationOffset() + replacementString.length() - context.getPrefixLength(), 0);
        setUpLinkedMode(document, replacementOffset, getFragments());
    } catch (BadLocationException e) {
        assert false;
    }
}
Also used : StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) IDocument(org.eclipse.jface.text.IDocument) Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 62 with BadLocationException

use of org.eclipse.jface.text.BadLocationException in project ow by vtst.

the class AbstractCompletionProposal method validate.

/* (non-Javadoc)
   * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
   */
@Override
public boolean validate(IDocument document, int offset, DocumentEvent event) {
    // Update matchLength if there is an event which affect the known match.
    int invocationOffset = context.getInvocationOffset();
    if (event != null && event.getOffset() < invocationOffset + matchLength + (nextCharDoesNotMatch ? 1 : 0) && event.getOffset() + event.getLength() >= invocationOffset) {
        nextCharDoesNotMatch = false;
        matchLength = Math.min(matchLength, Math.max(0, event.getOffset() - invocationOffset));
    }
    // Test whether some additional characters match
    if (!nextCharDoesNotMatch) {
        int prefixLength = context.getPrefixLength();
        try {
            while (matchLength < offset - invocationOffset) {
                if (prefixLength + matchLength < completionString.length() && Character.toLowerCase(document.getChar(invocationOffset + matchLength)) == completionStringLowerCase.charAt(prefixLength + matchLength)) {
                    ++matchLength;
                } else {
                    break;
                }
            }
        } catch (BadLocationException e) {
            assert false;
        }
    }
    return (matchLength >= offset - invocationOffset);
}
Also used : Point(org.eclipse.swt.graphics.Point) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 63 with BadLocationException

use of org.eclipse.jface.text.BadLocationException in project ow by vtst.

the class ClosureContentAssistIncovationContext method computePrefixAndPathOffsets.

// **************************************************************************
// Prefix and path
/**
   * Compute the prefix already present in the document at the invocation offset.
   */
private void computePrefixAndPathOffsets() {
    IDocument document = context.getDocument();
    invocationOffset = context.getInvocationOffset();
    try {
        prefixOffset = invocationOffset;
        while (prefixOffset > 0 && isCharForPrefix(document.getChar(prefixOffset - 1))) --prefixOffset;
        pathOffset = prefixOffset;
        while (pathOffset > 0 && isCharForPath(document.getChar(pathOffset - 1))) --pathOffset;
    } catch (BadLocationException e) {
        assert false;
    }
}
Also used : IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 64 with BadLocationException

use of org.eclipse.jface.text.BadLocationException in project cubrid-manager by CUBRID.

the class NonRuleBasedDamagerRepairer method endOfLineOf.

/**
	 * Returns the end offset of the line that contains the specified offset or
	 * if the offset is inside a line delimiter, the end offset of the next
	 * line.
	 * 
	 * @param offset the offset whose line end offset must be computed
	 * @return the line end offset for the given offset
	 * @exception BadLocationException if offset is invalid in the current
	 *            document
	 */
protected int endOfLineOf(int offset) throws BadLocationException {
    IRegion info = fDocument.getLineInformationOfOffset(offset);
    if (offset <= info.getOffset() + info.getLength()) {
        return info.getOffset() + info.getLength();
    }
    int line = fDocument.getLineOfOffset(offset);
    try {
        info = fDocument.getLineInformation(line + 1);
        return info.getOffset() + info.getLength();
    } catch (BadLocationException x) {
        return fDocument.getLength();
    }
}
Also used : IRegion(org.eclipse.jface.text.IRegion) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 65 with BadLocationException

use of org.eclipse.jface.text.BadLocationException in project eclipse.platform.text by eclipse.

the class FileBufferCreation method test4_IFILE.

/*
	 * Tests that two different files linked to the same target file result
	 * in two different, independent file buffers.
	 */
@Test
public void test4_IFILE() throws Exception {
    IPath path1 = createLinkedFile("file1", "testResources/LinkedFileTarget");
    assertNotNull(path1);
    IPath path2 = createLinkedFile("file2", "testResources/LinkedFileTarget");
    assertNotNull(path2);
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    manager.connect(path1, LocationKind.IFILE, null);
    ITextFileBuffer buffer1 = manager.getTextFileBuffer(path1, LocationKind.IFILE);
    assertNotNull(buffer1);
    manager.connect(path2, LocationKind.IFILE, null);
    ITextFileBuffer buffer2 = manager.getTextFileBuffer(path2, LocationKind.IFILE);
    assertNotNull(buffer2);
    IDocument document1 = buffer1.getDocument();
    assertNotNull(document1);
    assertSame(buffer1, manager.getTextFileBuffer(document1));
    IDocument document2 = buffer2.getDocument();
    assertNotNull(document2);
    assertSame(buffer2, manager.getTextFileBuffer(document2));
    assertEquals(document1.get(), document2.get());
    assertEquals(CONTENT2, document1.get());
    try {
        document1.replace(0, document1.getLength(), CONTENT1);
    } catch (BadLocationException x) {
        Assert.assertFalse(false);
    }
    assertFalse(document1.get().equals(document2.get()));
    manager.disconnect(path1, LocationKind.IFILE, null);
    assertNull(manager.getTextFileBuffer(path1, LocationKind.IFILE));
    assertNotNull(manager.getTextFileBuffer(path2, LocationKind.IFILE));
    manager.disconnect(path2, LocationKind.IFILE, null);
    assertNull(manager.getTextFileBuffer(path2, LocationKind.IFILE));
}
Also used : IPath(org.eclipse.core.runtime.IPath) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException) Test(org.junit.Test)

Aggregations

BadLocationException (org.eclipse.jface.text.BadLocationException)455 IDocument (org.eclipse.jface.text.IDocument)196 IRegion (org.eclipse.jface.text.IRegion)161 Test (org.junit.Test)102 Position (org.eclipse.jface.text.Position)101 Region (org.eclipse.jface.text.Region)68 Point (org.eclipse.swt.graphics.Point)61 Document (org.eclipse.jface.text.Document)47 CoreException (org.eclipse.core.runtime.CoreException)34 ArrayList (java.util.ArrayList)27 ITypedRegion (org.eclipse.jface.text.ITypedRegion)27 BadPositionCategoryException (org.eclipse.jface.text.BadPositionCategoryException)22 DocumentEvent (org.eclipse.jface.text.DocumentEvent)21 ITextSelection (org.eclipse.jface.text.ITextSelection)21 StyledText (org.eclipse.swt.custom.StyledText)18 StyledString (org.eclipse.jface.viewers.StyledString)17 IStatus (org.eclipse.core.runtime.IStatus)16 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)15 FindReplaceDocumentAdapter (org.eclipse.jface.text.FindReplaceDocumentAdapter)15 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)15