0

I am devloping a plug-in for eclipse that present metrics of Xtext-project.

I should present at in two levels : Xtext file and the all project.

in order to get details about the file I am using the following code in order to extract the Xtext file :

IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart activeEditor = page.getActiveEditor();
if (activeEditor instanceof XtextEditor) {
    XtextEditor xtextEditor = (XtextEditor) activeEditor;
    xtextEditor.getDocument().readOnly((XtextResource resource) -> {    
     ResourceHandler.resource = resource;
      });

and It works good on the current open Xtext file.

Now I want to get all the Xtext files in current eclipse project.

I tried the following code,but it doesnt seem to work :

IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
for (IWorkbenchWindow window : windows) {
  IWorkbenchPage[] pages = window.getPages();
  for (IWorkbenchPage page : pages) {
    IEditorPart activeEditor = page.getActiveEditor();
    if (activeEditor instanceof XtextEditor) {
      XtextEditor xtextEditor = (XtextEditor) activeEditor;
      xtextEditor.getDocument().readOnly((XtextResource resource) -> {
        resourceList.add(resource);

the best solution for me is getting a list of XtextResource.

thanks.

Matan
  • 109
  • 2
  • 13
  • i dont see where you work with a project at all. do ypu mean the project of the current open editor? can you be a bit more specific what you want to do with the files/resources whatever? – Christian Dietrich May 22 '17 at 19:11
  • 1
    There are only editors for things that the user is actually editing. If you want to look at all the files in a project you will need to use the `IFile` APIs. XText presumably has something to get an `XTextResource` from an `IFile`. – greg-449 May 22 '17 at 20:21
  • @ChristianDietrich : my input is in the first case Xtext file.and in the second case project in eclipse with Xtext files.and I need to analyze metrics(for example : max,min,avg of number_of_lines and other metrics).so I need kind of iterator to get all Xtext resource in eclipse project of Xtext. – Matan May 23 '17 at 04:38
  • Yes but what is your starting point ? A project ? A editor ? If it's just metrics it is about files in general and not xtext files .... – Christian Dietrich May 23 '17 at 04:39
  • @ChristianDietrich : it is not just about files but about a specification over Xtext called Spectra and I need to analyze propertities unique to it. so in case of active page in editor it works good,but I need to get also project-level, which is avg/median/max/min of all what I did for single XtextResource - just for the project in eclipse. – Matan May 23 '17 at 04:44
  • Use eclipse mechanism to traverse the project. Use iresourcesetprovider to obtain a resourceset . Ask the resourceset to load the resources you are interested in ... – Christian Dietrich May 23 '17 at 04:46
  • @greg-449 : Do you know any way to get an XtextResource from an IFile? – Matan May 23 '17 at 10:36
  • I don't know anything about XText – greg-449 May 23 '17 at 10:38

0 Answers0