unused declarations: don't search for usages under ReadLock(IDEA-175710)

when jvm-like langs are processed, refs should be already in graph, otherwise they will be caught by post processing task
This commit is contained in:
Anna.Kozlova
2017-07-13 18:24:00 +02:00
parent c853af26f3
commit a8a2fcb2e1
6 changed files with 23 additions and 10 deletions
@@ -43,7 +43,6 @@ import com.intellij.psi.search.DelegatingGlobalSearchScope;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.PsiNonJavaFileReferenceProcessor;
import com.intellij.psi.search.PsiSearchHelper;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiMethodUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.HashMap;
@@ -333,16 +332,13 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
}
};
if (helper.processUsagesInNonJavaFiles(qualifiedName, processor, globalSearchScope)) {
final PsiReference reference = ReferencesSearch.search(psiClass, globalSearchScope).findFirst();
if (reference != null) {
helper.processUsagesInNonJavaFiles(qualifiedName, processor, globalSearchScope);
//references from java-like are already in graph or
//they would be checked during GlobalJavaInspectionContextImpl.performPostRunActivities
for (RefElement element : refElement.getInReferences()) {
if (!(element instanceof RefJavaElement)) {
getEntryPointsManager(globalContext).addEntryPoint(refElement, false);
for (PsiMethod method : psiClass.getMethods()) {
final RefElement refMethod = refManager.getReference(method);
if (refMethod != null) {
getEntryPointsManager(globalContext).addEntryPoint(refMethod, false);
}
}
}
}
}
@@ -125,6 +125,7 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
if (!((RefElementImpl)refElement).hasSuspiciousCallers() || ((RefJavaElementImpl)refElement).isSuspiciousRecursive()) return 1;
for (RefElement element : refElement.getInReferences()) {
if (refElement instanceof RefFile) return 1;
if (((UnusedDeclarationInspectionBase)myTool).isEntryPoint(element)) return 1;
}
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
</problems>
@@ -0,0 +1,5 @@
class MyGroovyUsage {
static void "to use java"() {
new Util().foo()
}
}
@@ -0,0 +1,3 @@
class Util {
void foo() { }
}
@@ -198,4 +198,8 @@ public class UnusedDeclarationTest extends AbstractUnusedDeclarationTest {
public void testReferenceFromReflection() {
doTest();
}
public void testReferenceFromGroovy() {
doTest();
}
}