@@ -433,6 +433,78 @@ public void testOnlyIfAlreadyInScopeAndItIs() {
433
433
.doTest ();
434
434
}
435
435
436
+ @ Test
437
+ public void testArrayDeclaration () {
438
+ createRefactoringTestHelper ()
439
+ .addInputLines (
440
+ "in/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
441
+ "package com.google.errorprone.bugpatterns.nullness;" ,
442
+ "import javax.annotation.Nullable;" ,
443
+ "public class LiteralNullReturnTest {" ,
444
+ " public String[] getMessage(boolean b) {" ,
445
+ " return b ? null : new String[0];" ,
446
+ " }" ,
447
+ "}" )
448
+ .addOutputLines (
449
+ "out/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
450
+ "package com.google.errorprone.bugpatterns.nullness;" ,
451
+ "import javax.annotation.Nullable;" ,
452
+ "public class LiteralNullReturnTest {" ,
453
+ " @Nullable public String[] getMessage(boolean b) {" ,
454
+ " return b ? null : new String[0];" ,
455
+ " }" ,
456
+ "}" )
457
+ .doTest ();
458
+ }
459
+
460
+ @ Test
461
+ public void testArrayTypeUse () {
462
+ createRefactoringTestHelper ()
463
+ .addInputLines (
464
+ "in/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
465
+ "package com.google.errorprone.bugpatterns.nullness;" ,
466
+ "import org.checkerframework.checker.nullness.qual.Nullable;" ,
467
+ "public class LiteralNullReturnTest {" ,
468
+ " public String[] getMessage(boolean b) {" ,
469
+ " return b ? null : new String[0];" ,
470
+ " }" ,
471
+ "}" )
472
+ .addOutputLines (
473
+ "out/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
474
+ "package com.google.errorprone.bugpatterns.nullness;" ,
475
+ "import org.checkerframework.checker.nullness.qual.Nullable;" ,
476
+ "public class LiteralNullReturnTest {" ,
477
+ " public String @Nullable [] getMessage(boolean b) {" ,
478
+ " return b ? null : new String[0];" ,
479
+ " }" ,
480
+ "}" )
481
+ .doTest ();
482
+ }
483
+
484
+ @ Test
485
+ public void testArrayTypeUseTwoDimensional () {
486
+ createRefactoringTestHelper ()
487
+ .addInputLines (
488
+ "in/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
489
+ "package com.google.errorprone.bugpatterns.nullness;" ,
490
+ "import org.checkerframework.checker.nullness.qual.Nullable;" ,
491
+ "public class LiteralNullReturnTest {" ,
492
+ " public String[][] getMessage(boolean b, String[][] s) {" ,
493
+ " return b ? null : s;" ,
494
+ " }" ,
495
+ "}" )
496
+ .addOutputLines (
497
+ "out/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
498
+ "package com.google.errorprone.bugpatterns.nullness;" ,
499
+ "import org.checkerframework.checker.nullness.qual.Nullable;" ,
500
+ "public class LiteralNullReturnTest {" ,
501
+ " public String @Nullable [][] getMessage(boolean b, String[][] s) {" ,
502
+ " return b ? null : s;" ,
503
+ " }" ,
504
+ "}" )
505
+ .doTest ();
506
+ }
507
+
436
508
@ Test
437
509
public void testLimitation_staticFinalFieldInitializedLater () {
438
510
createCompilationTestHelper ()
@@ -553,20 +625,6 @@ public void testNegativeCases_onlyStatementIsNullReturn() {
553
625
.doTest ();
554
626
}
555
627
556
- @ Test
557
- public void testNegativeCases_array () {
558
- createCompilationTestHelper ()
559
- .addSourceLines (
560
- "com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
561
- "package com.google.errorprone.bugpatterns.nullness;" ,
562
- "public class LiteralNullReturnTest {" ,
563
- " public String[] getMessage(boolean b) {" ,
564
- " return b ? null : new String[0];" ,
565
- " }" ,
566
- "}" )
567
- .doTest ();
568
- }
569
-
570
628
@ Test
571
629
public void testNegativeCases_typeVariableUsage () {
572
630
createCompilationTestHelper ()
@@ -1463,78 +1521,6 @@ public void testAggressive_onlyStatementIsNullReturn() {
1463
1521
.doTest ();
1464
1522
}
1465
1523
1466
- @ Test
1467
- public void testAggressive_arrayDeclaration () {
1468
- createAggressiveRefactoringTestHelper ()
1469
- .addInputLines (
1470
- "in/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1471
- "package com.google.errorprone.bugpatterns.nullness;" ,
1472
- "import javax.annotation.Nullable;" ,
1473
- "public class LiteralNullReturnTest {" ,
1474
- " public String[] getMessage(boolean b) {" ,
1475
- " return b ? null : new String[0];" ,
1476
- " }" ,
1477
- "}" )
1478
- .addOutputLines (
1479
- "out/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1480
- "package com.google.errorprone.bugpatterns.nullness;" ,
1481
- "import javax.annotation.Nullable;" ,
1482
- "public class LiteralNullReturnTest {" ,
1483
- " @Nullable public String[] getMessage(boolean b) {" ,
1484
- " return b ? null : new String[0];" ,
1485
- " }" ,
1486
- "}" )
1487
- .doTest ();
1488
- }
1489
-
1490
- @ Test
1491
- public void testAggressive_arrayTypeUse () {
1492
- createAggressiveRefactoringTestHelper ()
1493
- .addInputLines (
1494
- "in/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1495
- "package com.google.errorprone.bugpatterns.nullness;" ,
1496
- "import org.checkerframework.checker.nullness.qual.Nullable;" ,
1497
- "public class LiteralNullReturnTest {" ,
1498
- " public String[] getMessage(boolean b) {" ,
1499
- " return b ? null : new String[0];" ,
1500
- " }" ,
1501
- "}" )
1502
- .addOutputLines (
1503
- "out/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1504
- "package com.google.errorprone.bugpatterns.nullness;" ,
1505
- "import org.checkerframework.checker.nullness.qual.Nullable;" ,
1506
- "public class LiteralNullReturnTest {" ,
1507
- " public String @Nullable [] getMessage(boolean b) {" ,
1508
- " return b ? null : new String[0];" ,
1509
- " }" ,
1510
- "}" )
1511
- .doTest ();
1512
- }
1513
-
1514
- @ Test
1515
- public void testAggressive_arrayTypeUseTwoDimensional () {
1516
- createAggressiveRefactoringTestHelper ()
1517
- .addInputLines (
1518
- "in/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1519
- "package com.google.errorprone.bugpatterns.nullness;" ,
1520
- "import org.checkerframework.checker.nullness.qual.Nullable;" ,
1521
- "public class LiteralNullReturnTest {" ,
1522
- " public String[][] getMessage(boolean b, String[][] s) {" ,
1523
- " return b ? null : s;" ,
1524
- " }" ,
1525
- "}" )
1526
- .addOutputLines (
1527
- "out/com/google/errorprone/bugpatterns/nullness/LiteralNullReturnTest.java" ,
1528
- "package com.google.errorprone.bugpatterns.nullness;" ,
1529
- "import org.checkerframework.checker.nullness.qual.Nullable;" ,
1530
- "public class LiteralNullReturnTest {" ,
1531
- " public String @Nullable [][] getMessage(boolean b, String[][] s) {" ,
1532
- " return b ? null : s;" ,
1533
- " }" ,
1534
- "}" )
1535
- .doTest ();
1536
- }
1537
-
1538
1524
@ Test
1539
1525
public void testAggressive_typeVariableUsage () {
1540
1526
createAggressiveCompilationTestHelper ()
@@ -1579,8 +1565,4 @@ private CompilationTestHelper createAggressiveCompilationTestHelper() {
1579
1565
private BugCheckerRefactoringTestHelper createRefactoringTestHelper () {
1580
1566
return BugCheckerRefactoringTestHelper .newInstance (ReturnMissingNullable .class , getClass ());
1581
1567
}
1582
-
1583
- private BugCheckerRefactoringTestHelper createAggressiveRefactoringTestHelper () {
1584
- return createRefactoringTestHelper ().setArgs ("-XepOpt:Nullness:Conservative=false" );
1585
- }
1586
1568
}
0 commit comments