File: ExpressionsInterning.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 (55 lines) | stat: -rw-r--r-- 1,309 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
import org.checkerframework.checker.interning.qual.Interned;

public class ExpressionsInterning {

    class A {
        B b;
    }

    class B {
        C c;

        D d() {
            return new D();
        }

        Boolean bBoolean() {
            return true;
        }
    }

    class C {}

    class D {}

    public Boolean fieldThenMethod(A a) {
        Boolean temp = a.b.bBoolean();
        return temp;
    }

    class Foo {
        public @Interned Foo returnThis(@Interned Foo this, @Interned Foo other) {
            if (other == this) {
                return this;
            } else {
                return null;
            }
        }
    }

    // :: warning: (cast.unsafe.constructor.invocation)
    public @Interned Foo THEONE = new @Interned Foo();

    public boolean isItTheOne(Foo f) {
        return THEONE.equals(f);
    }

    // A warning when interned objects are compared via .equals helps me in
    // determining whether it is a good idea to convert a given class or
    // reference to @Interned -- I can see whether there are places that it
    // is compared with .equals, which I might need to examine.
    public boolean dontUseEqualsMethod(@Interned Foo f1, @Interned Foo f2) {
        // :: warning: (unnecessary.equals)
        return f1.equals(f2);
    }
}