source: java2python/core/src/test/java/testcode/NonnullCode.java

Last change on this file was 816, checked in by wouter, 6 months ago

#289 fix @NonNull annotation handling in <? extends ..>

File size: 1.8 KB
Line 
1package testcode;
2
3import java.util.Arrays;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Map;
7
8import org.eclipse.jdt.annotation.NonNull;
9
10/**
11 * Check if translation with @NonNull works .
12 *
13 */
14public class NonnullCode {
15
16 private @NonNull String string;
17
18 // #278 map should not have "Optional" in it
19 private @NonNull Map<@NonNull String, @NonNull Integer> nonnullmap = new HashMap<>();
20
21 /**
22 * Check constructor nonnull works ok
23 */
24 public NonnullCode(@NonNull String v) {
25 this.string = v;
26 }
27
28 private String get() {
29 return string;
30 }
31
32 public static @NonNull String f0(@NonNull String x) {
33 return x;
34 }
35
36 public static @NonNull Integer f1() {
37 return 1;
38 }
39
40 public static @NonNull String f2() {
41 Integer x = null;
42 return "2ok";
43 }
44
45 public static @NonNull String f3() {
46 // @formatter:off
47 @NonNull Integer y = 1;
48 // @formatter:on
49 return "3ok";
50 }
51
52 public static Integer f4() {
53 return 4;
54 }
55
56 public static @NonNull String f5(Integer x) {
57 return "5ok";
58 }
59
60 public static String f6() {
61 // isinstance is special, it contains class name without ".class"
62 if (((Object) 1f) instanceof Float)
63 return "6ok";
64 return "6ko";
65 }
66
67 public static @NonNull String f7() {
68 @NonNull
69 String res = "";
70 for (final @NonNull String zz : Arrays.asList("7", "ok")) {
71 res = res + zz;
72 }
73 return res;
74 }
75
76 public static @NonNull String f8() {
77 @NonNull
78 List<@NonNull ? extends Number> list8;
79 return "8ok";
80
81 }
82
83 static public void main(String[] args) {
84 System.out.println(new NonnullCode("Cok").get());
85 System.out.println(f0("0ok"));
86 System.out.println(f1());
87 System.out.println(f2());
88 System.out.println(f3());
89 System.out.println(f4());
90 System.out.println(f5(null));
91 System.out.println(f6());
92 System.out.println(f7());
93 System.out.println(f8());
94 }
95
96}
Note: See TracBrowser for help on using the repository browser.