java [unused declaration] - switch on functional ref nodes

GitOrigin-RevId: b79fa6d91931bcc2c47f6f363f4a099736000d44
This commit is contained in:
Ilyas Selimov
2022-02-09 12:40:24 +00:00
committed by intellij-monorepo-bot
parent b2bbb963d6
commit 4572835609
15 changed files with 334 additions and 117 deletions
@@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems>
<problem>
<file>Lambda_UnusedMethod.java</file>
<line>12</line>
<description>Method is never used.</description>
</problem>
<problem>
<file>MethodRef_UnusedMethod.java</file>
<line>12</line>
<description>Method is never used.</description>
</problem>
<problem>
<file>Lambda_UnusedMethodInHierarchy.java</file>
<line>12</line>
@@ -1,10 +1,14 @@
public class Test {
public static void main(String[] args) {
final Memento m = () -> isPlaying;
final Memento m = () -> isPlaying();
System.out.println(m);
}
private static boolean isPlaying() {
return false;
}
public static interface Memento {
boolean isPlaying();
}
}
}
@@ -2,8 +2,105 @@
<problems>
<problem>
<file>A.java</file>
<line>3</line>
<line>5</line>
<description>Variable &lt;code&gt;i&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>7</line>
<description>Variable &lt;code&gt;k&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>10</line>
<description>Variable &lt;code&gt;unusedStr1&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>13</line>
<description>Variable &lt;code&gt;unusedStr3&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>18</line>
<description>Variable &lt;code&gt;unusedStr5&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>21</line>
<description>Variable &lt;code&gt;unusedStr7&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>26</line>
<description>Variable &lt;code&gt;unusedStr8&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>27</line>
<description>Variable &lt;code&gt;unusedStr9&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>34</line>
<description>Variable &lt;code&gt;unusedStr10&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>A.java</file>
<line>35</line>
<description>Variable &lt;code&gt;unusedStr11&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>Lambda.java</file>
<line>6</line>
<description>Field has no usages.</description>
</problem>
<problem>
<file>Lambda.java</file>
<line>7</line>
<description>Variable &lt;code&gt;i1&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>Lambda.java</file>
<line>12</line>
<description>Variable &lt;code&gt;i3&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>Lambda.java</file>
<line>24</line>
<description>Variable &lt;code&gt;i1&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>Lambda.java</file>
<line>29</line>
<description>Variable &lt;code&gt;i3&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>AnonymousClass.java</file>
<line>6</line>
<description>Field has no usages.</description>
</problem>
<problem>
<file>AnonymousClass.java</file>
<line>10</line>
<description>Variable &lt;code&gt;i1&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>AnonymousClass.java</file>
<line>21</line>
<description>Variable &lt;code&gt;i3&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>AnonymousClass.java</file>
<line>39</line>
<description>Variable &lt;code&gt;i1&lt;/code&gt; is never used</description>
</problem>
<problem>
<file>AnonymousClass.java</file>
<line>50</line>
<description>Variable &lt;code&gt;i3&lt;/code&gt; is never used</description>
</problem>
</problems>
@@ -1,7 +1,51 @@
import java.util.*;
class A {
public static void main(String[] args) {
int i = 0;
@SuppressWarnings("unused") int j = 0;
int k;
initializeCons(value -> {
String unusedStr1 = "s";
@SuppressWarnings("unused") String unusedStr2 = "s";
{
String unusedStr3;
}
String unusedStr4 = "str";
initializeCons(innerValue1 -> {
{
String unusedStr5 = unusedStr4;
}
String unusedStr6 = "s";
String unusedStr7;
initializeSup(() -> unusedStr6);
class Local {
void test() {
String unusedStr8;
String unusedStr9 = "Str";
}
}
new Local().test();
Local o = new Local() {
void test() {
String unusedStr10;
String unusedStr11 = "Str";
}
}
System.out.println(o);
});
});
}
private static void initializeCons(Consumer<String> consumer) {
consumer.accept("String to test");
}
private static void initializeSup(Supplier<String> supplier) {
supplier.get();
}
}
@@ -0,0 +1,67 @@
interface Unused {
boolean test();
}
class Test {
Unused lambda1 = new Unused() {
@java.lang.Override
public boolean test() {
int i1 = 1;
Unused lambda2 = new Unused() {
@java.lang.Override
public boolean test() {
int i2 = 1;
Unused lambda3 = new Unused() {
@java.lang.Override
public boolean test() {
System.out.println(i2);
int i3 = 1;
return true;
}
}
System.out.println(lambda3);
return false;
}
};
System.out.println(lambda2);
return false;
}
};
public static void main(String[] args) {
bar(new Unused() {
@java.lang.Override
public boolean test() {
int i1 = 1;
Unused lambda2 = new Unused() {
@java.lang.Override
public boolean test() {
int i2 = 1;
Unused lambda3 = new Unused() {
@java.lang.Override
public boolean test() {
System.out.println(i2);
int i3 = 1;
return true;
}
}
System.out.println(lambda3);
return false;
}
};
System.out.println(lambda2);
return false;
}
});
}
static void bar(Unused unused) {
unused.test();
}
}
@@ -0,0 +1,43 @@
interface Unused {
boolean test();
}
class Test {
Unused lambda1 = () -> {
int i1 = 1;
Unused lambda2 = () -> {
int i2 = 1;
Unused lambda3 = () -> {
System.out.println(i2);
int i3 = 1;
return true;
}
System.out.println(lambda3);
return false;
};
System.out.println(lambda2);
return false;
};
public static void main(String[] args) {
bar(() -> {
int i1 = 1;
Unused lambda2 = () -> {
int i2 = 1;
Unused lambda3 = () -> {
System.out.println(i2);
int i3 = 1;
return true;
}
System.out.println(lambda3);
return false;
};
System.out.println(lambda2);
return false;
});
}
static void bar(Unused unused) {
unused.test();
}
}