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;
}
}
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);
}
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;
}
}
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();
}
}
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));
}
Aggregations