mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
unused parameter: do not highlight if method is used locally by method reference (IDEA-123265)
This commit is contained in:
@@ -507,6 +507,12 @@ public class PostHighlightingPass extends ProgressableTextEditorHighlightingPass
|
||||
@NotNull PsiIdentifier identifier,
|
||||
@NotNull ProgressIndicator progress) {
|
||||
if (!myRefCountHolder.isReferenced(parameter) && !isImplicitUsage(myProject, parameter, progress)) {
|
||||
//parameter is defined by functional interface
|
||||
final PsiElement declarationScope = parameter.getDeclarationScope();
|
||||
if (declarationScope instanceof PsiMethod &&
|
||||
myRefCountHolder.isReferencedByMethodReference((PsiMethod)declarationScope)) {
|
||||
return null;
|
||||
}
|
||||
String message = JavaErrorMessages.message("parameter.is.not.used", identifier.getText());
|
||||
return createUnusedSymbolInfo(identifier, message, HighlightInfoType.UNUSED_SYMBOL);
|
||||
}
|
||||
|
||||
@@ -203,6 +203,26 @@ public class RefCountHolder {
|
||||
return usedStatus == Boolean.TRUE;
|
||||
}
|
||||
|
||||
public boolean isReferencedByMethodReference(@NotNull PsiMethod method) {
|
||||
if (!PsiUtil.isLanguageLevel8OrHigher(method)) return false;
|
||||
|
||||
List<PsiReference> array;
|
||||
synchronized (myLocalRefsMap) {
|
||||
array = myLocalRefsMap.getKeysByValue(method);
|
||||
}
|
||||
|
||||
if (array != null && !array.isEmpty()) {
|
||||
for (PsiReference reference : array) {
|
||||
final PsiElement element = reference.getElement();
|
||||
if (element != null && element instanceof PsiMethodReferenceExpression) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean isParameterUsedRecursively(@NotNull PsiElement element, @NotNull List<PsiReference> array) {
|
||||
if (!(element instanceof PsiParameter)) return false;
|
||||
PsiParameter parameter = (PsiParameter)element;
|
||||
|
||||
@@ -77,7 +77,7 @@ abstract class AbstractCollection<E> implements Collection<E> {
|
||||
public boolean add(E e) {
|
||||
return true;
|
||||
}
|
||||
public boolean addAll(Collection<? extends E> <warning descr="Parameter 'c' is never used">c</warning>) {
|
||||
public boolean addAll(Collection<? extends E> c) {
|
||||
boolean modified = false;
|
||||
return modified;
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@ class Test {
|
||||
Test m(List<Integer> l1, List<Integer> l2);
|
||||
}
|
||||
|
||||
static Test meth(List<Integer>... <warning descr="Parameter 'lli' is never used">lli</warning>) {
|
||||
static Test meth(List<Integer>... lli) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Test(List<Integer>... <warning descr="Parameter 'lli' is never used">lli</warning>) {}
|
||||
Test(List<Integer>... lli) {}
|
||||
|
||||
{
|
||||
I <warning descr="Variable 'i1' is never used">i1</warning> = <warning descr="Unchecked generics array creation for varargs parameter">Test::meth</warning>;
|
||||
|
||||
Reference in New Issue
Block a user