warn about unused parameter if method is used locally as method reference as it could be transformed to equivalent lambda (IDEA-157988)

This commit is contained in:
Anna Kozlova
2016-06-29 18:45:13 +03:00
parent eb937bc8d7
commit 1193a54876
8 changed files with 7 additions and 33 deletions

View File

@@ -406,12 +406,6 @@ class PostHighlightingVisitor {
@NotNull PsiIdentifier identifier,
@NotNull ProgressIndicator progress) {
if (!myRefCountHolder.isReferenced(parameter) && !UnusedSymbolUtil.isImplicitUsage(myProject, parameter, progress)) {
//parameter is defined by functional interface
final PsiElement declarationScope = parameter.getDeclarationScope();
if (declarationScope instanceof PsiMethod &&
myRefCountHolder.isReferencedByMethodReference((PsiMethod)declarationScope, myLanguageLevel)) {
return null;
}
String message = JavaErrorMessages.message("parameter.is.not.used", identifier.getText());
return UnusedSymbolUtil.createUnusedSymbolInfo(identifier, message, myDeadCodeInfoType);
}

View File

@@ -222,26 +222,6 @@ class RefCountHolder {
return usedStatus == Boolean.TRUE;
}
boolean isReferencedByMethodReference(@NotNull PsiMethod method, @NotNull LanguageLevel languageLevel) {
if (!languageLevel.isAtLeast(LanguageLevel.JDK_1_8)) return false;
Collection<PsiReference> array;
synchronized (myLocalRefsMap) {
array = myLocalRefsMap.get(method);
}
if (!array.isEmpty()) {
for (PsiReference reference : array) {
final PsiElement element = reference.getElement();
if (element instanceof PsiMethodReferenceExpression) {
return true;
}
}
}
return false;
}
private static boolean isParameterUsedRecursively(@NotNull PsiElement element, @NotNull Collection<PsiReference> array) {
if (!(element instanceof PsiParameter)) return false;
PsiParameter parameter = (PsiParameter)element;

View File

@@ -14,7 +14,7 @@ class Test {
class Test2 {
static void m(Integer i) { }
static void m(Integer <warning descr="Parameter 'i' is never used">i</warning>) { }
interface I1 {
void m(int x);

View File

@@ -77,7 +77,7 @@ abstract class AbstractCollection<E> implements Collection<E> {
public boolean add(E e) {
return true;
}
public boolean addAll(Collection<? extends E> c) {
public boolean addAll(Collection<? extends E> <warning descr="Parameter 'c' is never used">c</warning>) {
boolean modified = false;
return modified;
}

View File

@@ -6,11 +6,11 @@ class Test {
Test m(List<Integer> l1, List<Integer> l2);
}
static Test meth(List<Integer>... lli) {
static Test meth(List<Integer>... <warning descr="Parameter 'lli' is never used">lli</warning>) {
return null;
}
Test(List<Integer>... lli) {}
Test(List<Integer>... <warning descr="Parameter 'lli' is never used">lli</warning>) {}
{
I <warning descr="Variable 'i1' is never used">i1</warning> = <warning descr="Unchecked generics array creation for varargs parameter">Test::meth</warning>;

View File

@@ -1,7 +1,7 @@
import java.util.stream.Stream;
class A {
private void test5(Integer i, String... strings) {}
private void test5(Integer <warning descr="Parameter 'i' is never used">i</warning>, String... <warning descr="Parameter 'strings' is never used">strings</warning>) {}
private void <warning descr="Private method 'test5(java.lang.Integer, java.lang.Integer, java.lang.String...)' is never used">test5</warning>(Integer i, Integer b, String... strings) {
System.out.println(i);
System.out.println(b);

View File

@@ -12,7 +12,7 @@ class MyTest<T> {
public static class Builder<E> {
public Builder<E> add(E element) {
public Builder<E> add(E <warning descr="Parameter 'element' is never used">element</warning>) {
return this;
}

View File

@@ -8,6 +8,6 @@ class Main {
}
public static boolean checkForJdk(String <warning descr="Parameter 'homePath' is never used">homePath</warning>) {return false;}
public static boolean checkForJdk(File homePath) {return false;}
public static boolean checkForJdk(File <warning descr="Parameter 'homePath' is never used">homePath</warning>) {return false;}
}