File: DefaultsSignedness.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (202 lines) | stat: -rw-r--r-- 4,843 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
import org.checkerframework.checker.signedness.qual.*;

public class DefaultsSignedness {

    public void ConstantTest() {

        // Test bytes with literal values
        @SignednessGlb byte conByte;
        @SignednessBottom byte botByte;

        byte testByte = 0;

        conByte = testByte;

        // :: error: (assignment.type.incompatible)
        botByte = testByte;

        // Test shorts with literal values
        @SignednessGlb short conShort;
        @SignednessBottom short botShort;

        short testShort = 128;

        conShort = testShort;

        // :: error: (assignment.type.incompatible)
        botShort = testShort;

        // Test ints with literal values
        @SignednessGlb int conInt;
        @SignednessBottom int botInt;

        int testInt = 32768;

        conInt = testInt;

        // :: error: (assignment.type.incompatible)
        botInt = testInt;

        // Test longs with literal values
        @SignednessGlb long conLong;
        @SignednessBottom long botLong;

        long testLong = 2147483648L;

        conLong = testLong;

        // :: error: (assignment.type.incompatible)
        botLong = testLong;

        // Test chars with literal values
        @SignednessGlb char conChar;
        @SignednessBottom char botChar;

        char testChar = 'a';

        conChar = testChar;

        // :: error: (assignment.type.incompatible)
        botChar = testChar;
    }

    public void SignedTest(
            byte testByte,
            short testShort,
            int testInt,
            long testLong,
            float testFloat,
            double testDouble,
            char testChar,
            boolean testBool,
            Byte testBoxedByte,
            Short testBoxedShort,
            Integer testBoxedInteger,
            Long testBoxedLong) {

        // Test bytes
        @Signed byte sinByte;
        @SignednessGlb byte conByte;

        sinByte = testByte;

        // :: error: (assignment.type.incompatible)
        conByte = testByte;

        // Test shorts
        @Signed short sinShort;
        @SignednessGlb short conShort;

        sinShort = testShort;

        // :: error: (assignment.type.incompatible)
        conShort = testShort;

        // Test ints
        @Signed int sinInt;
        @SignednessGlb int conInt;

        sinInt = testInt;

        // :: error: (assignment.type.incompatible)
        conInt = testInt;

        // Test longs
        @Signed long sinLong;
        @SignednessGlb long conLong;

        sinLong = testLong;

        // :: error: (assignment.type.incompatible)
        conLong = testLong;

        // Test floats
        @Signed float sinFloat;
        @SignednessGlb float conFloat;

        sinFloat = testFloat;

        // :: error: (assignment.type.incompatible)
        conFloat = testFloat;

        // Test doubles
        @Signed double sinDouble;
        @SignednessGlb double conDouble;

        sinDouble = testDouble;

        // :: error: (assignment.type.incompatible)
        conDouble = testDouble;

        // Test chars
        @Signed char sinChar;
        @SignednessGlb char conChar;

        sinChar = testChar;

        // :: error: (assignment.type.incompatible)
        conChar = testChar;

        /*
        // Test boxed bytes
        @Signed Byte sinBoxedByte;
        @SignednessGlb Byte conBoxedByte;

        sinBoxedByte = testBoxedByte;

        //// :: error: (assignment.type.incompatible)
        conBoxedByte = testBoxedByte;

        // Test boxed shorts
        @Signed Short sinBoxedShort;
        @SignednessGlb Short conBoxedShort;

        sinBoxedShort = testBoxedShort;

        //// :: error: (assignment.type.incompatible)
        conBoxedShort = testBoxedShort;

        // Test boxed Integers
        @Signed Integer sinBoxedInteger;
        @SignednessGlb Integer conBoxedInteger;

        sinBoxedInteger = testBoxedInteger;

        //// :: error: (assignment.type.incompatible)
        conBoxedInteger = testBoxedInteger;

        // Test boxed Longs
        @Signed Long sinBoxedLong;
        @SignednessGlb Long conBoxedLong;

        sinBoxedLong = testBoxedLong;

        //// :: error: (assignment.type.incompatible)
        conBoxedLong = testBoxedLong;
        */
    }

    public void SignednessBottom() {

        @SignednessBottom Object botObj;

        Object testObj = null;

        botObj = testObj;
    }

    public void UnknownSignedness(Object testObj, @Unsigned int unsigned, @Signed int signed) {

        @UnknownSignedness Object unkObj;
        @Signed Object sinObj;

        unkObj = testObj;

        // :: error: (assignment.type.incompatible)
        sinObj = testObj;
    }

    public void booleanProblem(@Unsigned int unsigned, @Signed int signed) {
        boolean testBool = unsigned == 1 || signed > 1;
    }
}