From 9b5383d79cb759b40f74a072c0e34debd253db83 Mon Sep 17 00:00:00 2001 From: George Fraser Date: Sat, 5 Jan 2019 13:19:15 -0800 Subject: Don't warn unused params --- src/main/java/org/javacs/WarnUnused.java | 2 +- src/test/java/org/javacs/WarningsTest.java | 1 + src/test/test-project/workspace/src/org/javacs/warn/Unused.java | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/org/javacs/WarnUnused.java b/src/main/java/org/javacs/WarnUnused.java index 451a524..22f97e0 100644 --- a/src/main/java/org/javacs/WarnUnused.java +++ b/src/main/java/org/javacs/WarnUnused.java @@ -28,7 +28,7 @@ class WarnUnused extends TreePathScanner { boolean isLocal(VariableTree t) { var parent = getCurrentPath().getParentPath().getLeaf(); - return !(parent instanceof ClassTree); + return !(parent instanceof ClassTree) && !(parent instanceof MethodTree); } boolean isPrivate(MethodTree t) { diff --git a/src/test/java/org/javacs/WarningsTest.java b/src/test/java/org/javacs/WarningsTest.java index 692e985..7619f25 100644 --- a/src/test/java/org/javacs/WarningsTest.java +++ b/src/test/java/org/javacs/WarningsTest.java @@ -32,5 +32,6 @@ public class WarningsTest { public void unusedLocal() { server.reportErrors(List.of(FindResource.uri("org/javacs/warn/Unused.java"))); assertThat(errors, hasItem("unused(5)")); + assertThat(errors, not(hasItem("unused(4)"))); } } diff --git a/src/test/test-project/workspace/src/org/javacs/warn/Unused.java b/src/test/test-project/workspace/src/org/javacs/warn/Unused.java index 9b4f11c..f03012d 100644 --- a/src/test/test-project/workspace/src/org/javacs/warn/Unused.java +++ b/src/test/test-project/workspace/src/org/javacs/warn/Unused.java @@ -1,7 +1,7 @@ package org.javacs.warn; class Unused { - void test() { + void test(int unusedParam) { int unusedLocal = 1; } } \ No newline at end of file -- cgit v1.2.3