Search code examples
rascal

Incrementing offset of Location and clicking on location


I got a problem on clicking locations. The thing I do is creating a AST from a method with the function:

getMethodASTEclipse(method, model=projectModel);

where method is just an instance of

methods(projectModel);

When I visit that tree and want to get if statements for example I can call

case i: \if(_, _, _):println(i@src);

The source will be printed and I can click on it, eclipse will go to the right class with the right if statement. The form is like this:

|project://MyProject/src/MyClass.java|(2836,143,<104,1>,<109,2>)

But when I get the AST from file with the method:

createAstFromFile(class, true);

and giving a class instaed of a method or even a file I can also visit it and get the same if statement and print it but the form of it is different and I can't click on it. Why not ?

The form of it looks like this:

|java+class:///MyClass/src/MyClass|(17938,1105,<544,4>,<570,5>)

What I also notice is that the offsets are incrementing heavily after each location is printed.

How can I make it clickable to the right location? I think it has to do something with the offset and the form of the location. I tried to use the method:

resolveJava(loc l); 

from the Registry class but that didn't work either and tried to look up at declarations for the |loc definition but that wasn't there either.

Thanks in advance.


Solution

  • The reason the locations aren't clickable is because they cannot be resolved. The problem is that createAstFromFile(_,_) was only intended to be used with locations that have either project or file schemes.

    For now, you can get the physical location from the declarations annotation in the model and use that to create the AST.

    We'll look into making it so that it is possible to use locations with other schemes as well.