mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
more strict control over which unresolved references to report as groovy dynamic usages:
take into account closure arguments don't report property access as a method usage don't return usages with a qualifier of a known type
This commit is contained in:
+28
-11
@@ -21,12 +21,17 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.search.*;
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch;
|
||||
import com.intellij.psi.util.PropertyUtil;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrCommandArgumentList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrMethodCall;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil;
|
||||
@@ -46,9 +51,8 @@ public class MethodLateBoundReferencesSearcher extends QueryExecutorBase<PsiRefe
|
||||
@Override
|
||||
public void processQuery(@NotNull MethodReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
|
||||
final PsiMethod method = queryParameters.getMethod();
|
||||
SearchScope searchScope = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope()).intersectWith(getUseScope(method));
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
String className = aClass == null ? null : aClass.getName();
|
||||
SearchScope searchScope = GroovyScopeUtil.restrictScopeToGroovyFiles(queryParameters.getEffectiveSearchScope()).intersectWith(
|
||||
getUseScope(method));
|
||||
orderSearching(searchScope, method.getName(), method, queryParameters.getOptimizer(), method.getParameterList().getParametersCount());
|
||||
|
||||
final String propName = PropertyUtil.getPropertyName(method);
|
||||
@@ -85,16 +89,29 @@ public class MethodLateBoundReferencesSearcher extends QueryExecutorBase<PsiRefe
|
||||
}
|
||||
|
||||
final GrReferenceExpression ref = (GrReferenceExpression)element;
|
||||
if (!name.equals(ref.getReferenceName()) || PsiUtil.isLValue(ref) || ref.resolve() != null) {
|
||||
if (!name.equals(ref.getReferenceName()) || PsiUtil.isLValue(ref)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
PsiElement parent = ref.getParent();
|
||||
if (parent instanceof GrMethodCall) {
|
||||
if (!argumentsMatch((GrMethodCall)parent, paramCount)) {
|
||||
return true;
|
||||
}
|
||||
} else if (ResolveUtil.isKeyOfMap(ref)) {
|
||||
if (parent instanceof GrCommandArgumentList) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
if (paramCount >= 0 && !ref.hasMemberPointer() &&
|
||||
(!(parent instanceof GrMethodCall) || !argumentsMatch((GrMethodCall)parent, paramCount))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
GrExpression qualifier = ref.getQualifierExpression();
|
||||
if (qualifier == null || qualifier.getType() != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ref.resolve() != null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ResolveUtil.isKeyOfMap(ref)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -104,7 +121,7 @@ public class MethodLateBoundReferencesSearcher extends QueryExecutorBase<PsiRefe
|
||||
}
|
||||
|
||||
private static boolean argumentsMatch(GrMethodCall call, int paramCount) {
|
||||
int argCount = call.getExpressionArguments().length;
|
||||
int argCount = call.getExpressionArguments().length + call.getClosureArguments().length;
|
||||
if (PsiImplUtil.hasNamedArguments(call.getArgumentList())) {
|
||||
argCount++;
|
||||
}
|
||||
|
||||
@@ -151,6 +151,10 @@ public class FindUsagesTest extends LightGroovyTestCase {
|
||||
doTestImpl("DynamicUsages.groovy", 2);
|
||||
}
|
||||
|
||||
public void testDynamicCallExpressionUsages() {
|
||||
doTestImpl("DynamicCallExpressionUsages.groovy", 2);
|
||||
}
|
||||
|
||||
public void testAnnotatedMemberSearch() throws Throwable {
|
||||
|
||||
final PsiReference ref = myFixture.getReferenceAtCaretPosition("A.groovy");
|
||||
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
class Bar {
|
||||
boolean fo<caret>o(a) { }
|
||||
}
|
||||
|
||||
def boo(Map args, p) {
|
||||
p.foo 2
|
||||
p.foo { println "hello" }
|
||||
}
|
||||
|
||||
@@ -6,6 +6,12 @@ def boo(Map args, p) {
|
||||
println p.focused
|
||||
println p.isFocused()
|
||||
|
||||
println args.focused //not a usage
|
||||
// not usage candidates
|
||||
println focused
|
||||
println isFocused()
|
||||
println "a".focused
|
||||
println "a".isFocused()
|
||||
|
||||
println args.focused
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user