0

The function

set[loc] visibleFiles(loc l)

from from util::FileSystem allows you to get the files from a directory.

However it does not work if the location is an Eclipse project. Suppose we apply

visibleFiles(|project://HelloWorld/|);

then we get the Java exception

java.lang.IllegalArgumentException: Path must include project and resource name: /HelloWorld(internal error)    at $shell$(|main://$shell$|)
java.lang.IllegalArgumentException: Path must include project and resource name: /HelloWorld
    at org.eclipse.core.runtime.Assert.isLegal(Assert.java:63)
    at org.eclipse.core.internal.resources.Workspace.newResource(Workspace.java:2131)

So, how to get the files in an Eclipse project?

For completeness I give the sample project with only one Java file:

public class HelloWorld
{
   public static void main(String[] args) {
     System.out.println("Hello World!");
  }
}

2 Answers2

0

For the project scheme I think rascal wants to know the path in which it should start. Try |project://HelloWorld/src/|.

In the end the visibleFiles function is a wrapper for the .ls field of source locations (in combination with other source location functions).

Davy Landman
  • 15,109
  • 6
  • 49
  • 73
0

Adding "/src" doesn't really help.

visibleFiles(|project://HelloWorld/src/|);

results in

set[loc]: {|project://HelloWorld/src/|}

This is actually what we can expect, since

 isDirectory(|project://HelloWorld/src/|);

reduceer to "false", and we have

@doc{
Synopsis: lists all files recursively ignored files and directories starting    with a dot.
}
set[loc] visibleFiles(loc l) {
  if (/^\./ := l.file) 
    return {};
  else if (isDirectory(l)) 
    return {*visibleFiles(f) | f <- l.ls};
  else 
    return {l};
}

So, it boils down to applying "ls";

|project://HelloWorld/|.ls

gives the error I reported earlier, whereas

|project://HelloWorld/src/|.ls

gives the message

IO("You can only access ls on an existing location.")
  • could you make a github issue with the full stack trace? this should work. (also please report which version of rascal you are running) – Davy Landman Jun 03 '15 at 15:07
  • 1
    Potentially silly question, but is HelloWorld a new project without any files yet? Using `ls` on the `src` folder works for me, but if you've just created the project the src directory shows up in the project explorer but doesn't really exist (on disk) until you add a file to it. – Mark Hills Jun 03 '15 at 15:55