ReferenceSearch doesn't exist in Android Studio?
Hi, I'm completely new in this, I'm trying to create a custom lint, to check if an object is properly released:
execution = TaskOrchestrator.enqueueTask(
Task(TaskOrchestrator.Priority.HIGH) {
Log.d("TEST", "Test")
}
)
execution?.release()
I want to check if execution?.release() is called. In order to do that, I checked the calls to the method enqueueTask with getApplicableMethodNames() and then I got the left operand of the UBinaryExpression:
USimpleNameReferenceExpression referenceExpression = (USimpleNameReferenceExpression) resolve.getLeftOperand();
PsiElement element = UastUtils.tryResolve(referenceExpression);
The only thing I need to do now is check all the references to this PsiElement in the current scope and check if one of them is a release call. I thought ReferenceSearch would be exactly what I need, I was planning to do something like this:
references = ReferencesSearch.search(element, new LocalSearchScope(element)).findAll();
Then iterate over all the references and if none of them is release call, report it.
The problem is that I can't find ReferenceSearch anywhere, I tried to manually
import com.intellij.psi.search.searches.ReferenceSearch
But it seems like this class doesn't exist, only these 3 classes exist under the searches package:
import com.intellij.psi.search.searches.ExtensibleQueryFactory
import com.intellij.psi.search.searches.DeepestSuperMethodsSearch
import com.intellij.psi.search.searches.SuperMethodsSearch
Do you know how can I find the references to PsiElement in android studio? any help would be really helpful since I spent a lot of hours trying to figure out what's going on.
Thank you!
请先登录再写评论。
Hi Daniel,
the `ReferenceSearch` should be there. It looks like the IDEA SDK is broken, could you try to recreate it from scratch?
Anna
Hi Anna,
Thanks for your fast reply, so if you download the latest stable version of Android Studio: https://developer.android.com/studio/index.html?hl=en and then try to compile the google example about lint: https://github.com/googlesamples/android-custom-lint-rules you will see that ReferenceSearch is not available in the SampleCodeDetector of the android-studio-3 project.
I changed the gradle project to use:
Instead of the -beta5 they were using in the example. But even doing that it doesn't work. Is there anything else I have to do in order to be able to use ReferenceSearch?. I'm using Ubuntu 16.04LTS
Dani.
Hi Daniel,
did you try on google's forum? It looks like more a gradle dependency problem rather than one in IDEA Community sources. Probably they intentionally forbid searching in lint rules as this may cause performance problems if used on too broad scope or similar.
Anna
Thank you Anna, I'll check it with them