org.eclipse.xtext.resource.DefaultLocationInFileProvider Java Examples

The following examples show how to use org.eclipse.xtext.resource.DefaultLocationInFileProvider. 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: DefaultFoldingRegionProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test public void testShouldProcessContent() throws Exception {
	IFile iFile = createFile("foo/bar.foldingtestlanguage", 
			"element foo \n" +
			"element bar \n" +
			"end \n" +
			"end");
	IXtextDocument document = openFileAndReturnDocument(iFile);
	DefaultFoldingRegionProvider reg = new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider()) {
		@Override
		protected boolean shouldProcessContent(EObject object) {
			if (object instanceof Element) {
				return !"foo".equals(((Element) object).getName());
			}
			return super.shouldProcessContent(object);
		}
	};
	Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
	assertEquals(1, regions.size());
	assertEquals(0, regions.iterator().next().getOffset());
}
 
Example #2
Source File: DefaultFoldingRegionProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Test public void testIsHandled() throws Exception {
	IFile iFile = createFile("foo/bar.foldingtestlanguage", 
			"element foo \n" +
			"element bar \n" +
			"end \n" +
			"end");
	IXtextDocument document = openFileAndReturnDocument(iFile);
	DefaultFoldingRegionProvider reg = new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider()) {
		@Override
		protected boolean isHandled(EObject object) {
			if (object instanceof Element) {
				return !"foo".equals(((Element) object).getName());
			}
			return super.isHandled(object);
		}
	};
	Collection<FoldedPosition> regions = reg.getFoldingRegions(document);
	assertEquals(1, regions.size());
	assertEquals("element foo \n".length(), regions.iterator().next().getOffset());
}
 
Example #3
Source File: CFGraph.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Constructor
 */
public CFGraph() {
	locFileProvider = new DefaultLocationInFileProvider();
	editor = EditorUtils.getActiveXtextEditor();
	styledText = editor.getInternalSourceViewer().getTextWidget();
	layoutDone = false;
}
 
Example #4
Source File: OutlineTreeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void setUp() throws Exception {
	super.setUp();
	final Injector injector = TestsActivator.getInstance().getInjector("org.eclipse.xtext.ui.tests.editor.outline.OutlineTestLanguage");
	with(new ISetup() {
		@Override
		public Injector createInjectorAndDoEMFRegistration() {
			return injector;
		}
	});
	treeProvider = new DefaultOutlineTreeProvider(new DefaultEObjectLabelProvider(),
			new DefaultLocationInFileProvider());
}
 
Example #5
Source File: OutlineTreeProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testNoNames() throws Exception {
	final DefaultOutlineTreeProvider noNamesTreeProvider = new DefaultOutlineTreeProvider(new DefaultEObjectLabelProvider(),
			new DefaultLocationInFileProvider()) {
		@Override
		protected Object _text(Object modelElement) {
			return null;
		}
	};
	final String modelAsText = "element1 { element11 {}} element2 {}";
	IXtextDocument document = createXtextDocument(modelAsText);
	final IOutlineNode rootNode = noNamesTreeProvider.createRoot(document);
	document.readOnly(new IUnitOfWork.Void<XtextResource>() {
		@Override
		public void process(XtextResource state) throws Exception {
			noNamesTreeProvider.createChildren(rootNode, state.getContents().get(0));
			
			assertEquals(1, rootNode.getChildren().size());
			IOutlineNode modelNode = rootNode.getChildren().get(0);
			assertEquals(state.getURI().trimFileExtension().lastSegment(), modelNode.getText());
			assertTrue(modelNode.hasChildren());
			
			assertEquals(1, modelNode.getChildren().size());
			IOutlineNode element1 = modelNode.getChildren().get(0);
			assertEquals("<unnamed>", element1.getText().toString());
			assertEquals(new TextRegion(0, 8), element1.getSignificantTextRegion());
			assertEquals(new TextRegion(0, 24), element1.getFullTextRegion());
			assertEquals(modelNode, element1.getParent());
			// node does not know that its children will be skipped
			assertTrue(element1.hasChildren());
			assertTrue(element1.getChildren().isEmpty());
		}
	});
}
 
Example #6
Source File: EditorOverlay.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Constructor
 */
public EditorOverlay() {
	locFileProvider = new DefaultLocationInFileProvider();
}
 
Example #7
Source File: DefaultFoldingRegionProviderTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
protected DefaultFoldingRegionProvider createFoldingRegionProvider() {
	return new DefaultFoldingRegionProvider(new DefaultLocationInFileProvider());
}
 
Example #8
Source File: DefaultRuntimeModule.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public Class<? extends ILocationInFileProvider> bindILocationInFileProvider() {
	return DefaultLocationInFileProvider.class;
}