No references are resolved

Answered

Hello everyone,

I started last week developing my first Intellij plugin and need to resolve all method calls within one class as fully qualified. So I started using PSI and tried to get the references, but they are always returning null, while in in the IDE itself everything can be perfectly resolved. I'm using IntelliJ 2020.2.

This is my code I tried so far:

public class MyAction extends AnAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
PsiFile data = e.getData(LangDataKeys.PSI_FILE);
PsiReference reference = data.getReference();
data.accept(new Visitor());
}

public static class Visitor extends JavaRecursiveElementVisitor {
@Override
public void visitMethodCallExpression(PsiMethodCallExpression expression) {
super.visitMethodCallExpression(expression);
PsiReference reference = expression.getReference();
}
}
}

Both references are always null, I also tried using different ways of getting the files, and played around with GlobalSearchScopes because I thought I maybe missed including all necessary files. On the other hand, return types of method declarations can be perfectly resolved. 

Do you know what I am missing?

Thank you very much!

0
1 comment

Getting references directly out of the PsiFile will not work. Please follow our docs regarding the references:

A reference in a PSI tree is an object that represents a link from a usage of a certain element in the code to the corresponding declaration. Resolving a reference means locating the declaration to which a specific usage refers.

PSI References, References and Resolve in the IntelliJ SDK Docs.

0

Please sign in to leave a comment.