Navigation
Synopsis A Resource datatype and related functions on Eclipse resources.
Types
data Resource = root(set[Resource] projects) 
              | project(loc id, set[Resource] contents)
              | folder(loc id, set[Resource] contents)
              | file(loc id);
Usage import util::Resources;
Description The Resource library provides direct access to Eclipse projects and the resources they contain. A Resource is the Rascal representation of an Eclipse project, or a folder or a file in an Eclipse project. In combination with the IO library module, users of the Resources library gain access to the contents of any file that is in an Eclipse project.

Resource is a recursive data-type, where recursion indicates containment, i.e., a folder contains many other resources, a project also contains other resources. The root of an Eclipse workspace also contains other resources, in particular projects.

Each Resource, but the root, has an id field that explains the exact location of the resource.

The schema project that is supported by source locations (see Location) gives direct access to Eclipse projects.

The Resource library provides the following:
  • dependencies: Compute the (transitive) dependencies of a project.
  • getProject: Retrieve the hierarchical representation of a single named project.
  • projects: Retrieve the set of project locations of the current Eclipse workspace.
  • references: The set of projects that are referenced by a project.
  • Resource:
  • root: Retrieve a full hierarchical representation of all resources in the Eclipse workspace.
Examples A location that points to a project in the Eclipse workspace named "myProject":
|project://myProject| 
A location that points to a file named HelloWorld.java in the src folder of the example-project project in the workspace:
|project://example-project/src/HelloWorld.java| 
A location that points to a part of the previous file, namely the first 10 characters on the first line:
|project://example-project/src/HelloWorld.java|(0,10,1,0,1,10) 
Assuming that the project |project://example-project| exists in the current workspace, we can get the following:
rascal>import util::Resources;
ok
rascal>getProject(|project://example-project|);
Resource: project(
  |project://example-project|,
  {
    folder(
      |project://example-project/bin|,
      {
        file(|project://example-project/bin/IFruit.class|),
        file(|project://example-project/bin/Apple.class|),
        file(|project://example-project/bin/HelloWorld.class|),
        file(|project://example-project/bin/Fruit.class|)
      }),
    file(|project://example-project/.project|),
    file(|project://example-project/.classpath|),
    folder(
      |project://example-project/src|,
      {
        file(|project://example-project/src/IFruit.java|),
        file(|project://example-project/src/Apple.java|),
        file(|project://example-project/src/HelloWorld.java|),
        file(|project://example-project/src/Fruit.java|)
      })
  })
rascal>import util::Resources;
ok
rascal>getProject(|project://example-project-which-does-not-exist|);
|rascal://util::Resources|(1557,102,<49,0>,<50,45>): "Project does is not open: example-project-which-does-not-exist"
	at *** somewhere ***(|rascal://util::Resources|(1557,102,<49,0>,<50,45>))
	at getProject(|stdin:///|(11,48,<1,11>,<1,59>))


Pitfalls This library is only available for the Eclipse version of Rascal.
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.