[java] - unused declaration rework for functional expressions

GitOrigin-RevId: e2f2188edf79fddd902c038bdfdea072eed01bfe
This commit is contained in:
Ilyas Selimov
2021-10-11 05:51:42 +00:00
committed by intellij-monorepo-bot
parent edae7f4aa0
commit 6b74c12eab
62 changed files with 1342 additions and 430 deletions
@@ -1,4 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<problems/>
<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>
<description>Method is never used as a member of this interface, but only as a member of the implementation class(es). The project will stay compilable if the method is removed from the interface.</description>
</problem>
<problem>
<file>MethodRef_UnusedMethodInHierarchy.java</file>
<line>14</line>
<description>Method is never used as a member of this interface, but only as a member of the implementation class(es). The project will stay compilable if the method is removed from the interface.</description>
</problem>
</problems>
@@ -0,0 +1,14 @@
public class Test {
public static void main(String[] args) {
final Memento m = () -> isPlaying();
System.out.println(m);
}
private static boolean isPlaying() {
return false;
}
public static interface Memento {
boolean isPlaying();
}
}
@@ -0,0 +1,17 @@
class Clazz {
void doSmth(Child child) {
child.execute();
}
public static void main(String[] args) {
new Clazz().doSmth(() -> {});
}
}
interface Parent {
void execute();
}
interface Child extends Parent {
void execute();
}
@@ -0,0 +1,14 @@
public class Test {
public static void main(String[] args) {
final Memento m = () -> isPlaying();
System.out.println(m.isPlaying());
}
private static boolean isPlaying() {
return false;
}
public static interface Memento {
boolean isPlaying();
}
}
@@ -1,9 +1,13 @@
public class Test {
public static void main(String[] args) {
final Memento m = () -> isPlaying;
final Memento m = Test::isPlaying;
System.out.println(m);
}
private static boolean isPlaying() {
return false;
}
public static interface Memento {
boolean isPlaying();
}
@@ -0,0 +1,19 @@
class Clazz {
void doSmth(Child child) {
child.execute();
}
public static void main(String[] args) {
new Clazz().doSmth(Clazz::execute);
}
private static void execute() {}
}
interface Parent {
void execute();
}
interface Child extends Parent {
void execute();
}
@@ -0,0 +1,14 @@
public class Test {
public static void main(String[] args) {
final Memento m = Test::isPlaying;
System.out.println(m.isPlaying());
}
private static boolean isPlaying() {
return false;
}
public static interface Memento {
boolean isPlaying();
}
}
@@ -50,5 +50,57 @@
<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>
@@ -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();
}
}