Help with different behavior between writable and readonly files

I have a bug in my IdentifierHighlighter plugin when browsing read-only files that come from the JDK src.zip. For example, if I do a Ctrl+N and bring up JTabbedPane.java source code, my plugin doesn't really work that well. After debugging, it is because ReferencesSearch.search() returns an empty collection. I copied the entire source file for JTabbedPane.java from the src.zip and pasted it into a writable java file that was part of my project. My plugin worked perfectly and ReferencesSearch.search() returned correct results.

Anybody know why I am getting different behavior with ReferencesSearch between a writable source file in my project and a readonly file from JDK src.zip?
Does ReferencesSearch need the file to be writable or something?

2 comments
Comment actions Permalink

I believe the problem is that the search doesn't work inside library sources rather than that it is related to read-only files.

The fix for this might be to use com.intellij.psi.search.searches.ReferencesSearch#search(PsiElement element, SearchScope searchScope) and specify something like "new LocalSearchScope(element.getContainingFile())" for the scope parameter.

Otherwise, when just using ReferencesSearch#search(PsiElement), you'll get GlobalSearchScope.projectScope(element.getProject()) as the search scope which doesn't include any libraries. The LocalSearchScope should could also be significantly faster, especially for public identifiers (fields, method).

HTH,
Sascha

0
Comment actions Permalink

Thanks a bunch. That was the answer. The plugin works great for files outside the current project.

0

Please sign in to leave a comment.