author | mcimadamore |
Thu, 15 Jan 2015 13:58:11 +0000 | |
changeset 28456 | b87fdde1404d |
parent 27844 | 8b5d79870a2f |
child 29774 | 9d438163db79 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
14801
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.code; |
|
27 |
||
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
28 |
import java.util.EnumSet; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
29 |
import java.util.Set; |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1264
diff
changeset
|
30 |
import java.util.Locale; |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
31 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
32 |
import com.sun.source.tree.MemberReferenceTree; |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
33 |
import com.sun.tools.javac.api.Formattable; |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1264
diff
changeset
|
34 |
import com.sun.tools.javac.api.Messages; |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
35 |
|
14258 | 36 |
import static com.sun.tools.javac.code.Flags.*; |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
37 |
import static com.sun.tools.javac.code.TypeTag.CLASS; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
38 |
import static com.sun.tools.javac.code.TypeTag.PACKAGE; |
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
39 |
import static com.sun.tools.javac.code.TypeTag.TYPEVAR; |
10 | 40 |
|
41 |
/** Internal symbol kinds, which distinguish between elements of |
|
42 |
* different subclasses of Symbol. Symbol kinds are organized so they can be |
|
43 |
* or'ed to sets. |
|
44 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
45 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
46 |
* If you write code that depends on this, you do so at your own risk. |
10 | 47 |
* This code and its internal interfaces are subject to change or |
48 |
* deletion without notice.</b> |
|
49 |
*/ |
|
50 |
public class Kinds { |
|
51 |
||
52 |
private Kinds() {} // uninstantiable |
|
53 |
||
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
54 |
/** |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
55 |
* Kind of symbols. |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
56 |
* |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
57 |
* IMPORTANT: This is an ordered type. The ordering of |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
58 |
* declarations in this enum matters. Be careful when changing |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
59 |
* it. |
10 | 60 |
*/ |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
61 |
public enum Kind { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
62 |
NIL(Category.BASIC, KindSelector.NIL), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
63 |
PCK(Category.BASIC, KindName.PACKAGE, KindSelector.PCK), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
64 |
TYP(Category.BASIC, KindName.CLASS, KindSelector.TYP), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
65 |
VAR(Category.BASIC, KindName.VAR, KindSelector.VAR), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
66 |
MTH(Category.BASIC, KindName.METHOD, KindSelector.MTH), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
67 |
POLY(Category.BASIC, KindSelector.POLY), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
68 |
ERR(Category.ERROR, KindSelector.ERR), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
69 |
AMBIGUOUS(Category.OVERLOAD), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
70 |
HIDDEN(Category.OVERLOAD), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
71 |
STATICERR(Category.OVERLOAD), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
72 |
MISSING_ENCL(Category.OVERLOAD), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
73 |
ABSENT_VAR(Category.OVERLOAD, KindName.VAR), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
74 |
WRONG_MTHS(Category.OVERLOAD, KindName.METHOD), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
75 |
WRONG_MTH(Category.OVERLOAD, KindName.METHOD), |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
76 |
ABSENT_MTH(Category.OVERLOAD, KindName.METHOD), |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
27844
diff
changeset
|
77 |
ABSENT_TYP(Category.OVERLOAD, KindName.CLASS); |
10 | 78 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
79 |
// There are essentially two "levels" to the Kind datatype. |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
80 |
// The first is a totally-ordered set of categories of |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
81 |
// solutions. Within each category, we have more |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
82 |
// possibilities. |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
83 |
private enum Category { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
84 |
BASIC, ERROR, OVERLOAD; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
85 |
} |
10 | 86 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
87 |
private final KindName kindName; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
88 |
private final KindName absentKind; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
89 |
private final KindSelector selector; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
90 |
private final Category category; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
91 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
92 |
private Kind(Category category) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
93 |
this(category, null, null, null); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
94 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
95 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
96 |
private Kind(Category category, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
97 |
KindSelector selector) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
98 |
this(category, null, null, selector); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
99 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
100 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
101 |
private Kind(Category category, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
102 |
KindName absentKind) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
103 |
this(category, null, absentKind, null); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
104 |
} |
10 | 105 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
106 |
private Kind(Category category, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
107 |
KindName kindName, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
108 |
KindSelector selector) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
109 |
this(category, kindName, null, selector); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
110 |
} |
10 | 111 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
112 |
private Kind(Category category, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
113 |
KindName kindName, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
114 |
KindName absentKind, |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
115 |
KindSelector selector) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
116 |
this.category = category; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
117 |
this.kindName = kindName; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
118 |
this.absentKind = absentKind; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
119 |
this.selector = selector; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
120 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
121 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
122 |
public KindSelector toSelector() { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
123 |
return selector; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
124 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
125 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
126 |
public boolean matches(KindSelector kindSelectors) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
127 |
return selector.contains(kindSelectors); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
128 |
} |
10 | 129 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
130 |
public boolean isOverloadError() { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
131 |
return category == Category.OVERLOAD; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
132 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
133 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
134 |
public boolean isValid() { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
135 |
return category == Category.BASIC; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
136 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
137 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
138 |
public boolean betterThan(Kind other) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
139 |
return ordinal() < other.ordinal(); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
140 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
141 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
142 |
public KindName kindName() { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
143 |
if (kindName == null) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
144 |
throw new AssertionError("Unexpected kind: " + this); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
145 |
} else { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
146 |
return kindName; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
147 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
148 |
} |
18643
fdd7572e0c18
8016613: javac should avoid source 8 only analysis when compiling for source 7
vromero
parents:
14801
diff
changeset
|
149 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
150 |
public KindName absentKind() { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
151 |
if (absentKind == null) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
152 |
throw new AssertionError("Unexpected kind: " + this); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
153 |
} else { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
154 |
return absentKind; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
155 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
156 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
157 |
} |
10 | 158 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
159 |
public static class KindSelector { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
160 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
161 |
//basic selectors |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
162 |
public static final KindSelector NIL = new KindSelector(0); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
163 |
public static final KindSelector PCK = new KindSelector(0x01); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
164 |
public static final KindSelector TYP = new KindSelector(0x02); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
165 |
public static final KindSelector VAR = new KindSelector(0x04); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
166 |
public static final KindSelector VAL = new KindSelector(0x0c); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
167 |
public static final KindSelector MTH = new KindSelector(0x10); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
168 |
public static final KindSelector ERR = new KindSelector(0x3f); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
169 |
public static final KindSelector POLY = new KindSelector(0x20); |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
27224
diff
changeset
|
170 |
public static final KindSelector ASG = new KindSelector(0x44); |
10 | 171 |
|
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
172 |
//common derived selectors |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
173 |
public static final KindSelector TYP_PCK = of(TYP, PCK); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
174 |
public static final KindSelector VAL_MTH = of(VAL, MTH); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
175 |
public static final KindSelector VAL_POLY = of(VAL, POLY); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
176 |
public static final KindSelector VAL_TYP = of(VAL, TYP); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
177 |
public static final KindSelector VAL_TYP_PCK = of(VAL, TYP, PCK); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
178 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
179 |
private final byte data; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
180 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
181 |
private KindSelector(int data) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
182 |
this.data = (byte) data; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
183 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
184 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
185 |
public static KindSelector of(KindSelector... kindSelectors) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
186 |
byte newData = 0; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
187 |
for (KindSelector kindSel : kindSelectors) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
188 |
newData |= kindSel.data; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
189 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
190 |
return new KindSelector(newData); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
191 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
192 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
193 |
public boolean subset(KindSelector other) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
194 |
return (data & ~other.data) == 0; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
195 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
196 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
197 |
public boolean contains(KindSelector other) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
198 |
return (data & other.data) != 0; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
199 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
200 |
|
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
201 |
/** A set of KindName(s) representing a set of symbol's kinds. */ |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
202 |
public Set<KindName> kindNames() { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
203 |
EnumSet<KindName> kinds = EnumSet.noneOf(KindName.class); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
204 |
if ((data & VAL.data) != 0) { |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
205 |
if ((data & VAL.data) == VAR.data) kinds.add(KindName.VAR); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
206 |
else kinds.add(KindName.VAL); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
207 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
208 |
if ((data & MTH.data) != 0) kinds.add(KindName.METHOD); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
209 |
if ((data & TYP.data) != 0) kinds.add(KindName.CLASS); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
210 |
if ((data & PCK.data) != 0) kinds.add(KindName.PACKAGE); |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
211 |
return kinds; |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
212 |
} |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
25874
diff
changeset
|
213 |
} |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
214 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
215 |
public enum KindName implements Formattable { |
6031
50004868a787
6964768: need test program to validate javac resource bundles
jjg
parents:
5847
diff
changeset
|
216 |
ANNOTATION("kindname.annotation"), |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
217 |
CONSTRUCTOR("kindname.constructor"), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
218 |
INTERFACE("kindname.interface"), |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
219 |
ENUM("kindname.enum"), |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
220 |
STATIC("kindname.static"), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
221 |
TYPEVAR("kindname.type.variable"), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
222 |
BOUND("kindname.type.variable.bound"), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
223 |
VAR("kindname.variable"), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
224 |
VAL("kindname.value"), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
225 |
METHOD("kindname.method"), |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
226 |
CLASS("kindname.class"), |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
8620
diff
changeset
|
227 |
STATIC_INIT("kindname.static.init"), |
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
8620
diff
changeset
|
228 |
INSTANCE_INIT("kindname.instance.init"), |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
229 |
PACKAGE("kindname.package"); |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
230 |
|
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14359
diff
changeset
|
231 |
private final String name; |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
232 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
233 |
KindName(String name) { |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
234 |
this.name = name; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
235 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
236 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
237 |
public String toString() { |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
238 |
return name; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
239 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
240 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
241 |
public String getKind() { |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
242 |
return "Kindname"; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
243 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
244 |
|
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1264
diff
changeset
|
245 |
public String toString(Locale locale, Messages messages) { |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
246 |
String s = toString(); |
1471
57506cdfb7b4
6406133: JCDiagnostic.getMessage ignores locale argument
mcimadamore
parents:
1264
diff
changeset
|
247 |
return messages.getLocalizedString(locale, "compiler.misc." + s); |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
248 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
249 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
250 |
|
14062
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
251 |
public static KindName kindName(MemberReferenceTree.ReferenceMode mode) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
252 |
switch (mode) { |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
253 |
case INVOKE: return KindName.METHOD; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
254 |
case NEW: return KindName.CONSTRUCTOR; |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
255 |
default : throw new AssertionError("Unexpected mode: "+ mode); |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
256 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
257 |
} |
b7439971a094
7177386: Add attribution support for method references
mcimadamore
parents:
10626
diff
changeset
|
258 |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
259 |
/** A KindName representing a given symbol |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
260 |
*/ |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
261 |
public static KindName kindName(Symbol sym) { |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
262 |
switch (sym.getKind()) { |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
263 |
case PACKAGE: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
264 |
return KindName.PACKAGE; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
265 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
266 |
case ENUM: |
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
267 |
return KindName.ENUM; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
268 |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
269 |
case ANNOTATION_TYPE: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
270 |
case CLASS: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
271 |
return KindName.CLASS; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
272 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
273 |
case INTERFACE: |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
274 |
return KindName.INTERFACE; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
275 |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
276 |
case TYPE_PARAMETER: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
277 |
return KindName.TYPEVAR; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
278 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
279 |
case ENUM_CONSTANT: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
280 |
case FIELD: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
281 |
case PARAMETER: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
282 |
case LOCAL_VARIABLE: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
283 |
case EXCEPTION_PARAMETER: |
8620 | 284 |
case RESOURCE_VARIABLE: |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
285 |
return KindName.VAR; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
286 |
|
3143
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
287 |
case CONSTRUCTOR: |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
288 |
return KindName.CONSTRUCTOR; |
0413d5b5b7fd
6822637: ResolveError hierarchy needs to be refactored
mcimadamore
parents:
1471
diff
changeset
|
289 |
|
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
290 |
case METHOD: |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
8620
diff
changeset
|
291 |
return KindName.METHOD; |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
292 |
case STATIC_INIT: |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
8620
diff
changeset
|
293 |
return KindName.STATIC_INIT; |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
294 |
case INSTANCE_INIT: |
10626
83f0c2860f5b
7086595: Error message bug: name of initializer is 'null'
mcimadamore
parents:
8620
diff
changeset
|
295 |
return KindName.INSTANCE_INIT; |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
296 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
297 |
default: |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
298 |
throw new AssertionError("Unexpected kind: "+sym.getKind()); |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
299 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
300 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
301 |
|
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
302 |
/** A KindName representing the kind of a given class/interface type. |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
303 |
*/ |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
304 |
public static KindName typeKindName(Type t) { |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
305 |
if (t.hasTag(TYPEVAR) || |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
306 |
t.hasTag(CLASS) && (t.tsym.flags() & COMPOUND) != 0) |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
307 |
return KindName.BOUND; |
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
308 |
else if (t.hasTag(PACKAGE)) |
939
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
309 |
return KindName.PACKAGE; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
310 |
else if ((t.tsym.flags_field & ANNOTATION) != 0) |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
311 |
return KindName.ANNOTATION; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
312 |
else if ((t.tsym.flags_field & INTERFACE) != 0) |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
313 |
return KindName.INTERFACE; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
314 |
else |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
315 |
return KindName.CLASS; |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
316 |
} |
38e24969c7e9
6717241: some diagnostic argument is prematurely converted into a String object
mcimadamore
parents:
10
diff
changeset
|
317 |
|
10 | 318 |
} |