Search references for Java classes in FitNesse

Hi,

I'm working on a plugin for FitNesse integration with IntelliJ.

I'm stuck at a point where I want to let Java classes and methods aware of that they're referenced from a FitNesse table.

A typical FitNesse descision table looks like this:

 | table name             |
 | have milk | need milk? |
 |  1        |  2         |


Where 'table name' resolves to the fixture name ("TableName"), 'have milk' resolves to method 'setHaveMilk(s)' on that class and 'need milk?' resolves to a query on method 'needMilk()'.

I assume the right way to reference the usages from the Java class is by creating a "referencesSearch" and a "methodReferencesSearch" extension point (am I correct?).

Secondly, I need to check on the names. FitNesse is using 'graceful naming', e.g. a class and method names can be written in lowercase, separated by spaces. The PSI element contain methods for translating a graceful name to a method name.

I am currently checking the FitNesse document files for (psi-)references, but it seems only a small part of the AST is actually created. This leads me to believe I have to use an index or stubs at some point. Am I correct? If so, which one is the preferred method?

The reference searcher code I created so far can be found at https://github.com/amolenaar/idea-fitnesse/blob/master/src/main/scala/fitnesse/idea/lang/reference/FixtureClassReferencesSearch.java.

How is this going to inteact with the find-usages functionality of IntelliJ?

Any advise would be appreciated :)

Regards,

Arjan

4 comments
Comment actions Permalink

It's correct that you need to plug in the <referencesSearch> extension point.

I'm not sure what you mean by "only a small part of the AST is actually created". IntelliJ IDEA builds the PSI for the entire file.

Implementing the references search usually does not require any additional index; it's based on the standard identifier index built by IntelliJ IDEA automatically. This index will be used if you call getOptimizer().searchWord() in your referencesSearch implementation.

The GitHub link is unfortinately 404 at the moment.

0
Comment actions Permalink

I found that only a small part of the AST was actually created.

Regarding the 404: That's my bad. I moved the file over the weekend and converted it to a scala file: https://github.com/amolenaar/idea-fitnesse/blob/master/src/main/scala/fitnesse/idea/fixtureclass/FixtureClassReferencesSearch.scala.

I modified the types I want to look for (FixtureClass, Decision table input and output fields) to be based on stubs, along with an index. This works for me. Default identifiers do not work since FitNesse uses "graceful naming": separate class or method parts by spaces, instead on a single camel-cased word. Or does the indentifier index

I wonder if I still need to give your "getOptimizer().searchWord()" suggestion a try.

Am I on the right track?

0
Comment actions Permalink

You actually have control over how exactly the contents of your files is split into identifiers and indexed. However, I think that the default behavior can be good enough. You simply split the file name given to you into camel-hump words, then search each word using the default ID index and combine the results.

0
Comment actions Permalink

"You simply split the file name given to you into camel-hump words,.. "

It's about the contents of the file. Then my lexer should make camel-case words of the file content, I assume? This will work for simple cases, but script tables are read in a different fashion. Fot instance:

| ensure | expect value | 123 | in output |

would result in a method name expectValueInOutput(arg). In this case "ensure" is a keyword (can also be omitted). By maintaining my own indexes (thanks to the psi-stubs) I can make sure the right things are looked for, also when names change.

0

Please sign in to leave a comment.