Local inspection invoked in file A, and error registered in file B. Is this possible?
Hi,
My plugin has a local inspection tool that can find some issues related to code in other files, and may register the issue on PsiElement in other files. However, I got the following error when I test it:
Reported element PsiArrayInitializerMemberValue:{Destination.UNKNOWN} is not from the file 'PsiJavaFile:SeparateLocationListener.java' the inspection 'LocationAPIInspection' (class org.intellij.privacyhelper.codeInspection.inspections.LocationAPIInspection) was invoked for. Message: 'PRIVACY: The field is unknown'.
Element' containing file: PsiJavaFile:SeparateLocationListener.java
Inspection invoked for file: PsiJavaFile:LocationTestActivity.java
com.intellij.openapi.diagnostic.Logger$EmptyThrowable
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:134)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.createHighlightsForDescriptor(LocalInspectionsPass.java:490)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.access$800(LocalInspectionsPass.java:77)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass$2.process(LocalInspectionsPass.java:392)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass$2.process(LocalInspectionsPass.java:369)
at com.intellij.util.containers.TransferToEDTQueue.processNext(TransferToEDTQueue.java:99)
at com.intellij.util.containers.TransferToEDTQueue.access$300(TransferToEDTQueue.java:37)
at com.intellij.util.containers.TransferToEDTQueue$1.run(TransferToEDTQueue.java:58)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:827)
at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:655)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:365)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
com.intellij.openapi.diagnostic.Logger$EmptyThrowable
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:134)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.createHighlightsForDescriptor(LocalInspectionsPass.java:490)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.addHighlightsFromResults(LocalInspectionsPass.java:464)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.inspect(LocalInspectionsPass.java:232)
at com.intellij.codeInsight.daemon.impl.LocalInspectionsPass.collectInformationWithProgress(LocalInspectionsPass.java:132)
at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:83)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:70)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$null$1(PassExecutorService.java:438)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1156)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$doRun$2(PassExecutorService.java:431)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:556)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:501)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:66)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.doRun(PassExecutorService.java:430)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.lambda$run$0(PassExecutorService.java:406)
at com.intellij.openapi.application.impl.ReadMostlyRWLock.executeByImpatientReader(ReadMostlyRWLock.java:142)
at com.intellij.openapi.application.impl.ApplicationImpl.executeByImpatientReader(ApplicationImpl.java:242)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:404)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask$1.exec(JobLauncherImpl.java:165)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
It seems that this is because when the inspection is invoked for file "LocationTestActivity.java", it tries to register a new issue on an element in another file "SeparateLocationListener.java. I wonder whether there is a way to avoid this error?
请先登录再写评论。
Hi,
local inspections can highlight only subchildren of element they get in the visitor/checkMember. That's done to ensure that highlighting will be invalidated when user changes code around element. So you need to turn your logic so it will work starting from the element to highlight
Anna
I see. Thanks!