Suppress unused-local-variable warnings in test inputs

Test code can do many things we'd consider bad style in real
application code, including defining local variables that are never
subsequently used.
This commit is contained in:
Ben Liblit 2017-05-12 18:09:00 +02:00 committed by Manu Sridharan
parent dee2412ab5
commit 24fb1f6d10
39 changed files with 50 additions and 5 deletions

View File

@ -20,6 +20,7 @@ public class Array1 {
ary[i]= i;
}
@SuppressWarnings("unused")
int sum = 0;
for(int j= 0; j < ary.length; j++) {

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
*****************************************************************************/
public class ArrayLiteral1 {
@SuppressWarnings("unused")
public static void main(String[] args) {
ArrayLiteral1 al1= new ArrayLiteral1();
int[] a= new int[] { 0, 1, 2, 3, 5 };

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
*****************************************************************************/
public class ArrayLiteral2 {
@SuppressWarnings("unused")
public static void main(String[] args) {
ArrayLiteral2 al2= new ArrayLiteral2();
int[] x= {};

View File

@ -14,6 +14,7 @@ public class Casts {
(new Casts()).test(args);
}
@SuppressWarnings("unused")
private void test(String[] args) {
long l1 = Long.parseLong(args[0]);
int i1 = Integer.parseInt(args[1]);

View File

@ -11,6 +11,7 @@
public class DefaultConstructors {
public static void main(String args[]) {
@SuppressWarnings("unused")
E e = new E();
// System.out.println(e.x);
// System.out.println(e.y);

View File

@ -11,6 +11,7 @@
public class Exception1 {
public static void main(String[] args) {
@SuppressWarnings("unused")
Exception1 e1= new Exception1();
try {
FooEx1 f = new FooEx1();

View File

@ -16,6 +16,7 @@ import java.io.IOException;
public final class Exception2 {
public static void main(String[] args) {
@SuppressWarnings("unused")
Exception2 e2= new Exception2();
FileInputStream fis = null;
FileOutputStream fos = null;

View File

@ -10,6 +10,7 @@
*****************************************************************************/
public class Finally1 {
public static void main(String[] args) throws BadLanguageExceptionF1 {
@SuppressWarnings("unused")
Finally1 f1= new Finally1();
try {
FooF1 f = new FooF1();

View File

@ -10,6 +10,7 @@
*****************************************************************************/
public class Inheritance1 {
public static void main(String[] args) {
@SuppressWarnings("unused")
Inheritance1 ih1= new Inheritance1();
Base b1 = new Base();
Base b2 = new Derived();
@ -22,6 +23,7 @@ public class Inheritance1 {
}
class Base {
public void foo() {
@SuppressWarnings("unused")
int i= 0;
}
public String bar(int x) {

View File

@ -10,6 +10,7 @@
*****************************************************************************/
public class InheritedField {
public static void main(String[] args) {
@SuppressWarnings("unused")
InheritedField if1= new InheritedField();
B b = new B();

View File

@ -22,6 +22,7 @@ public class InnerClass {
}
public void method() {
@SuppressWarnings("unused")
WhatsIt w= new WhatsIt();
}

View File

@ -52,6 +52,7 @@ public class InnerClassA {
AB ab = new AB();
AB.ABSubA absuba = ab.new ABSubA();
absuba.aba_x = 7;
@SuppressWarnings("unused")
AB.ABA.ABAA abaa2 = ab.new ABA().new ABAA(); // just used to add ABA instance key in ABAA.getABA_X()
AB.ABA aba = ab.new ABA();

View File

@ -47,6 +47,7 @@ public class InnerClassLexicalReads {
* 4 invokevirtual < Source, Ljava/io/PrintStream, println(I)V > v7,v8 @4 exception:v10[18:2] -> [18:38]
*/
public static void main(String args[]) {
@SuppressWarnings("unused")
InnerClassLexicalReads ignored = new InnerClassLexicalReads(); // call this just to make <init> reachable (test checks for unreachable methods)
int foo = 5;
int haha = foo * foo;

View File

@ -10,8 +10,10 @@
*****************************************************************************/
public class InterfaceTest1 {
public static void main(String[] args) {
@SuppressWarnings("unused")
InterfaceTest1 it= new InterfaceTest1();
IFoo foo = new FooIT1('a');
@SuppressWarnings("unused")
char ch2 = foo.getValue();
}
}

View File

@ -11,6 +11,7 @@
public class NullArrayInit {
String[] x = {null};
@SuppressWarnings("unused")
public static void main(String[] args) {
new NullArrayInit();
Object a[] = new Object[] {null,null};

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
*****************************************************************************/
public class QualifiedStatic {
@SuppressWarnings("unused")
public static void main(String[] args) {
QualifiedStatic qs= new QualifiedStatic();
FooQ fq= new FooQ();

View File

@ -10,6 +10,7 @@
*****************************************************************************/
public class Scoping1 {
public static void main(String[] args) {
@SuppressWarnings("unused")
Scoping1 s1= new Scoping1();
{
int x= 5;

View File

@ -10,6 +10,7 @@
*****************************************************************************/
public class Scoping2 {
public static void main(String[] args) {
@SuppressWarnings("unused")
Scoping2 s2 = new Scoping2();
{
final int x = 5;

View File

@ -19,6 +19,7 @@ public class Simple1 {
this(0);
}
public static void doStuff(int N) {
@SuppressWarnings("unused")
int prod = 1;
for(int j=0; j < N; j++)
prod *= j;

View File

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
*****************************************************************************/
public class StaticNesting {
@SuppressWarnings("unused")
public static void main(String[] args) {
StaticNesting sn= new StaticNesting();
WhatsIt w= new WhatsIt();

View File

@ -18,6 +18,7 @@ public class TwoClasses {
this(0);
}
public static void doStuff(int N) {
@SuppressWarnings("unused")
int prod= 1;
TwoClasses tc= new TwoClasses();
tc.instanceMethod1();
@ -35,6 +36,7 @@ public class TwoClasses {
instanceMethod2();
}
public void instanceMethod2() {
@SuppressWarnings("unused")
Bar b= Bar.create('a');
}
}

View File

@ -10,6 +10,7 @@
*****************************************************************************/
public class WhileTest1 {
public static void main(String[] args) {
@SuppressWarnings("unused")
WhileTest1 wt1= new WhileTest1();
int x= 235834;
boolean stop= false;

View File

@ -87,6 +87,7 @@ public class InnerClassAA {
AB ab = new AB();
AB.ABSubA absuba = ab.new ABSubA();
absuba.aba_x = 7;
@SuppressWarnings("unused")
AB.ABA.ABAA abaa2 = ab.new ABA().new ABAA(); // just used to add ABA instance key in ABAA.getABA_X()
AB.ABA aba = ab.new ABA();

View File

@ -42,6 +42,7 @@ public class ArraysAndSuch {
public static void main(String args[]) {
ArraysAndSuch.main();
}
@SuppressWarnings("unused")
public static void main() {
Object o1 = null;
Object[] os1 = new Object[] { null, o1, null };

View File

@ -101,6 +101,7 @@ public class ConstructorsAndInitializers extends Super {
class T{
}
@SuppressWarnings("unused")
T t = new T();
}
}

View File

@ -40,6 +40,7 @@ package foo.bar.hello.world;
public class CopyOfLoopsAndLabels {
static int X=5;
public static void main(String args[]) {
@SuppressWarnings("unused")
int k=X;
for (; ; k++)
break;

View File

@ -87,6 +87,7 @@ public class InnerClasses extends Temp {
se2.setSEVar();
System.out.println(sub2.hello()); //1001
@SuppressWarnings("unused")
int foo = 12;
foo++;
--foo;

View File

@ -40,6 +40,7 @@ package foo.bar.hello.world;
public class MiniaturList2 {
public static void main(String[] args) {
@SuppressWarnings("unused")
int a;
for ( ;; ) {
break;

View File

@ -113,11 +113,13 @@ public class CustomGenericsAndFields {
/////////////////////////////
@SuppressWarnings("unused")
String thrownaway = cg2.bar("a","b");
cg2.setFoo("real one");
MyGeneric<String,ConcreteGeneric2<String>> mygeneric = new MyGeneric<String,ConcreteGeneric2<String>>("useless",cg2);
String x = mygeneric.doFoo();
System.out.println(x);
@SuppressWarnings("unused")
String y = cg2.x;
System.out.println(mygeneric.getB().y);
System.out.println(mygeneric.b.y); // TODO: fields are going to be a pain... watch out for Lvalues in context?

View File

@ -47,6 +47,7 @@ public class ExplicitBoxingTest {
int a = 6;
a = a + a;
System.out.println(a);
@SuppressWarnings("unused")
Integer useless1 = new Integer(5+6);
Integer aa = new Integer(a+a);
int aaa = aa.intValue();
@ -55,6 +56,7 @@ public class ExplicitBoxingTest {
int b = 6;
b = b + b;
System.out.println(b);
@SuppressWarnings("unused")
Integer useless2 = 5+6;
Integer bb = b+b;
int bbb = bb;

View File

@ -52,6 +52,7 @@ public class GenericArrays {
List<Integer> li = new ArrayList<Integer>();
li.add(new Integer(3));
oa[1] = li; // correct
@SuppressWarnings("unused")
String s = (String) lsa[1].get(0); // run time error, but cast is explicit
}

View File

@ -13,6 +13,7 @@ package javaonepointfive;
public class TypeInferencePrimAndStringOp {
public static void main(String[] args) {
int a = 2;
@SuppressWarnings("unused")
String result = "a" + a;
}
}

View File

@ -11,6 +11,7 @@
package p;
public class NonPrimaryTopLevel {
@SuppressWarnings("unused")
public static void main(String[] args) {
NonPrimaryTopLevel nptl= new NonPrimaryTopLevel();
Foo f = new Foo();

View File

@ -67,11 +67,11 @@ public abstract class JavaIRTests extends IRTests {
@Test public void testSimple1() throws IllegalArgumentException, CancelException, IOException {
List<? extends IRAssertion> assertions = Arrays.asList(
new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "prod", 24),
new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "j", 23),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "s", 32),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "i", 28),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "sum", 29),
new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "prod", 25),
new SourceMapAssertion("Source#Simple1#doStuff#(I)V", "j", 24),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "s", 33),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "i", 29),
new SourceMapAssertion("Source#Simple1#main#([Ljava/lang/String;)V", "sum", 30),
EdgeAssertions.make("Source#Simple1#main#([Ljava/lang/String;)V", "Source#Simple1#doStuff#(I)V"),
EdgeAssertions.make("Source#Simple1#instanceMethod1#()V", "Source#Simple1#instanceMethod2#()V"));

View File

@ -44,6 +44,7 @@ public class CPATest1 {
return x;
}
@SuppressWarnings("unused")
public static void main(String[] args) {
F f = new F(3.4);
I i = new I(7);

View File

@ -44,6 +44,7 @@ public class CPATest2 {
return x;
}
@SuppressWarnings("unused")
public static void main(String[] args) {
F f = new F(3.4);
I i = new I(7);

View File

@ -14,6 +14,7 @@ public class TestStaticInitOrder {
private static class A {
@SuppressWarnings("unused")
static int f;
static {
@ -26,6 +27,7 @@ public class TestStaticInitOrder {
}
private static class B {
@SuppressWarnings("unused")
static int b;
static {
@ -39,6 +41,7 @@ public class TestStaticInitOrder {
private static class C extends B {
@SuppressWarnings("unused")
static int c = 5;
public static void dostuff() {

View File

@ -399,6 +399,7 @@ public class CallGraphTest extends WalaTestCase {
}
// perform a little icfg exercise
@SuppressWarnings("unused")
int count = 0;
for (Iterator<BasicBlockInContext<ISSABasicBlock>> it = icfg.iterator(); it.hasNext();) {
BasicBlockInContext<ISSABasicBlock> bb = it.next();

View File

@ -48,6 +48,7 @@ public class LambdaTest extends WalaTestCase {
"Lbug144/A");
AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints);
@SuppressWarnings("unused")
CallGraph cg = CallGraphTestUtil.buildZeroCFA(options, new AnalysisCacheImpl(), cha, scope, false);
}