Java Code Examples for org.eclipse.xtext.ui.editor.model.IXtextDocument#getLength()

The following examples show how to use org.eclipse.xtext.ui.editor.model.IXtextDocument#getLength() . 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: Bug369087Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test 
public void testPositionTypesDontChange() throws Exception {
	String model = 
			"grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.xbase.Xbase\n" +
			"\n" +
			"generate myDsl \"http://www.xtext.org/example/mydsl/MyDsl\"\n" +
			"\n" +
			"Model:\n" +
			"    'package' name=ID '{'\n" +
			"'}';";
	XtextEditor editor = openEditor(model);
	IXtextDocument xtextDocument = editor.getDocument();
	String category = getContentTypeCategory(xtextDocument).toString();
	Position[] positions = xtextDocument.getPositions(category);
	for(int i=1; i<xtextDocument.getLength(); ++i) {
		if(!Character.isLetter(xtextDocument.getChar(i-1)) || !Character.isLetter(xtextDocument.getChar(i))) {
			editor.getInternalSourceViewer().setSelectedRange(i, 0);
			editor.getInternalSourceViewer().getTextWidget().setFocus();
			pressKey(editor, ' ');
			reconcile(xtextDocument);
			assertSamePositionTypes(positions, xtextDocument.getPositions(category));
			pressKey(editor, SWT.BS);
		}
	}
}
 
Example 2
Source File: XbaseDispatchingEObjectTextHover.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
	IXtextDocument xtextDocument = xtextDocumentUtil.getXtextDocument(textViewer);
	if(xtextDocument == null || offset<0 || xtextDocument.getLength() < offset) 
		return null;
	@SuppressWarnings("restriction")
	IRegion word = org.eclipse.jdt.internal.ui.text.JavaWordFinder.findWord(xtextDocument, offset);
	if (word!= null)
		return word;
	//TODO return null for non-operators.
	return new Region(offset, 0);
}
 
Example 3
Source File: AbstractFoldingTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected String insertFoldingRegionMarkers(IXtextDocument document) {
	if (document.getLength() == 0) { // The document is empty
		return null;
	}

	try {
		String lineSeparator = document.getLineDelimiter(0);
		if (lineSeparator == null) { // The document contains a single line
			lineSeparator = document.getLegalLineDelimiters()[0];
		}
		return insertFoldingRegionMarkers(document, lineSeparator);
	} catch (BadLocationException e) {
		throw new RuntimeException(e);
	}
}