summaryrefslogtreecommitdiff
path: root/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlighting/FinalFieldInit.java
blob: ec01fd7af13750a3a47b08269c7534d952442232 (plain)
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// final Fields initialization
import java.io.*;
import java.net.*;
import java.awt.event.*;

public class a  {
  /**
   * javadoc should not be highlighted
   */ 
  <error descr="Variable 'javaDoced' might not have been initialized">final int javaDoced</error>;

  <error descr="Variable 'sfi1' might not have been initialized">static final int sfi1</error>;
  <error descr="Variable 'sfi2' might not have been initialized">static final int sfi2</error>;
  <error descr="Variable 'fi1' might not have been initialized">final int fi1</error>;
  <error descr="Variable 'fi2' might not have been initialized">final int fi2</error>;

  class inner {
    <error descr="Variable 'fii' might not have been initialized">final int fii</error>;
  }
  final int fi3;
  final int fi4;


  static final int csfi1 = 0;
  static final int csfi2 = csfi1 + 13 / 5;
  static final int csfi3; 
  static {
   if (csfi1 < 13) {
     csfi3 = csfi2 + (csfi1 == 4 ? 5 : csfi2/13);
   }
   else {
     csfi3 = 0;
     sfi2 = 2;
   }
  }


  final int cifi1 = 1;
  final int cifi2 = ff();
  final int cifi3;

  int ff() { 
    int i = cifi1 + cifi2 + cifi3 + fi3 + fi4;
    return i; 
  }

  {
   switch (cifi1) {
    case 2: cifi3 = 2; break;
    case 1: cifi3 = 20; break;
    case 0: cifi3 = 21; break;
    default: cifi3 = 22; break;
   }
  }

  final int cifi4;
  a() {
    cifi4 = 4;
    int i = <error descr="Variable 'fi3' might not have been initialized">fi3</error>;
    fi3 = 3;
    a ainst = null;
    fi4 = ainst.fi4;
  }
  a(int i) {
    this.cifi4 = i;
    fi2 = 3;
    fi3 = 3;
    a ainst = null;
    fi4 = ainst.fi4;
  }
  a(String s) {
    this(0);
    int i = fi3;

  }
}

class Test {
  // access from within inner class OK
    final boolean FB;
    {
      class s {
        boolean b = FB;
      }
      FB = true;

    }
    private final String text;
    public Test() {
      new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          doSomething(text);////
        }
      };
      text = "Hello world";
    }

    private void doSomething(String value) {
    }
}

// multiple initalizers
class c1 {
 private final String x;
 {
   x = "Hello";
 }

 private final String y;
 {
   y = x; 
 }
 void f() {
   String s = x+y;
 }
}

class c2 {
    static { 
    }
    private static final int limit;
    static {
        limit = 5;
    }
    final String s;
    int k = <error descr="Variable 's' might not have been initialized">s</error>.length();
    final String c;
    int k2 = <error descr="Variable 'c' might not have been initialized">c</error>.length();
    {
        s = "";
    }

    public c2() {
        c = "";
    }
    // its ok
    int k3 = c.length();

    c2(int i) {
      this();
    }
}

class UninitializedFinal2 {
    <error descr="Variable 's' might not have been initialized">private final String s</error>;

    UninitializedFinal2(){
        try {
        }
        finally {
        }
    }
}
class UninitedFinalFied {

	<error descr="Variable 'string' might not have been initialized">private final String string</error>;

	public UninitedFinalFied() throws IOException {
		init();
	}

	private void init() throws IOException {}
}
class AssertFinalFied {
	private final String string;

	public AssertFinalFied(boolean b) throws Exception {
	     assert b;
	     string = null;
	}
}

class a20Exotic {
    int n=k=0;
    final int k;
    final int k2;
    int n2 = k==0 ? (k2=9) : (k2=0);
}

public class cX {
    final int i;
    cX() {
        this(1);
        int k = i;
    }
    cX(int d) {
        i = d;
    }
}

// http://www.intellij.net/tracker/idea/viewSCR?publicId=20097
class Lemma {
    public Lemma() {
        name.hashCode();
    }
    private final String name;
    {   name = "Andy";
    }
}

class correct {
    void f() {
        final Object o;
        o = new Object();
        new Object() {
          { o.toString(); }
        }; 
    }
}

public class X {
    final int i;
    X() {
        try {
            i = 0;
        }
        finally {

        }
    }
}
class Y {
  private final int mayBeFinal;

  Y() {
    (mayBeFinal) = 1;
  }
}