author | dlsmith |
Wed, 14 Dec 2016 17:56:11 -0700 | |
changeset 42819 | 4ce83e629dc1 |
parent 36526 | 3b41f1c69604 |
child 43646 | 017aba6e9260 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
29293
1583c6dd6df7
8071453: Allow interface methods to be private
sadayapalam
parents:
27991
diff
changeset
|
2 |
* Copyright (c) 2002, 2015, 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 |
||
6721 | 28 |
import java.util.*; |
14258 | 29 |
|
6721 | 30 |
import javax.lang.model.SourceVersion; |
31 |
import static javax.lang.model.SourceVersion.*; |
|
32 |
||
14258 | 33 |
import com.sun.tools.javac.jvm.Target; |
10 | 34 |
import com.sun.tools.javac.util.*; |
11314 | 35 |
import static com.sun.tools.javac.main.Option.*; |
10 | 36 |
|
37 |
/** The source language version accepted. |
|
38 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
39 |
* <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
|
40 |
* If you write code that depends on this, you do so at your own risk. |
10 | 41 |
* This code and its internal interfaces are subject to change or |
42 |
* deletion without notice.</b> |
|
43 |
*/ |
|
44 |
public enum Source { |
|
45 |
/** 1.0 had no inner classes, and so could not pass the JCK. */ |
|
46 |
// public static final Source JDK1_0 = new Source("1.0"); |
|
47 |
||
48 |
/** 1.1 did not have strictfp, and so could not pass the JCK. */ |
|
49 |
// public static final Source JDK1_1 = new Source("1.1"); |
|
50 |
||
51 |
/** 1.2 introduced strictfp. */ |
|
52 |
JDK1_2("1.2"), |
|
53 |
||
54 |
/** 1.3 is the same language as 1.2. */ |
|
55 |
JDK1_3("1.3"), |
|
56 |
||
57 |
/** 1.4 introduced assert. */ |
|
58 |
JDK1_4("1.4"), |
|
59 |
||
60 |
/** 1.5 introduced generics, attributes, foreach, boxing, static import, |
|
61 |
* covariant return, enums, varargs, et al. */ |
|
62 |
JDK1_5("1.5"), |
|
63 |
||
64 |
/** 1.6 reports encoding problems as errors instead of warnings. */ |
|
65 |
JDK1_6("1.6"), |
|
66 |
||
10180 | 67 |
/** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */ |
68 |
JDK1_7("1.7"), |
|
69 |
||
22151 | 70 |
/** 1.8 lambda expressions and default methods. */ |
71 |
JDK1_8("1.8"), |
|
72 |
||
73 |
/** 1.9 covers the to be determined language features that will be added in JDK 9. */ |
|
74 |
JDK1_9("1.9"); |
|
10 | 75 |
|
22163 | 76 |
private static final Context.Key<Source> sourceKey = new Context.Key<>(); |
10 | 77 |
|
78 |
public static Source instance(Context context) { |
|
79 |
Source instance = context.get(sourceKey); |
|
80 |
if (instance == null) { |
|
81 |
Options options = Options.instance(context); |
|
6721 | 82 |
String sourceString = options.get(SOURCE); |
10 | 83 |
if (sourceString != null) instance = lookup(sourceString); |
84 |
if (instance == null) instance = DEFAULT; |
|
85 |
context.put(sourceKey, instance); |
|
86 |
} |
|
87 |
return instance; |
|
88 |
} |
|
89 |
||
90 |
public final String name; |
|
91 |
||
22151 | 92 |
private static final Map<String,Source> tab = new HashMap<>(); |
10 | 93 |
static { |
94 |
for (Source s : values()) { |
|
95 |
tab.put(s.name, s); |
|
96 |
} |
|
97 |
tab.put("5", JDK1_5); // Make 5 an alias for 1.5 |
|
98 |
tab.put("6", JDK1_6); // Make 6 an alias for 1.6 |
|
99 |
tab.put("7", JDK1_7); // Make 7 an alias for 1.7 |
|
10180 | 100 |
tab.put("8", JDK1_8); // Make 8 an alias for 1.8 |
22151 | 101 |
tab.put("9", JDK1_9); // Make 9 an alias for 1.9 |
10 | 102 |
} |
103 |
||
104 |
private Source(String name) { |
|
105 |
this.name = name; |
|
106 |
} |
|
107 |
||
25445
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25283
diff
changeset
|
108 |
public static final Source MIN = Source.JDK1_6; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25283
diff
changeset
|
109 |
|
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25283
diff
changeset
|
110 |
private static final Source MAX = values()[values().length - 1]; |
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25283
diff
changeset
|
111 |
|
603f0c93d5c9
8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents:
25283
diff
changeset
|
112 |
public static final Source DEFAULT = MAX; |
10 | 113 |
|
114 |
public static Source lookup(String name) { |
|
115 |
return tab.get(name); |
|
116 |
} |
|
117 |
||
118 |
public Target requiredTarget() { |
|
22151 | 119 |
if (this.compareTo(JDK1_9) >= 0) return Target.JDK1_9; |
10180 | 120 |
if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8; |
10 | 121 |
if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7; |
122 |
if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6; |
|
123 |
if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5; |
|
124 |
if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4; |
|
125 |
return Target.JDK1_1; |
|
126 |
} |
|
127 |
||
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
128 |
public boolean allowDiamond() { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
129 |
return compareTo(JDK1_7) >= 0; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
130 |
} |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
131 |
public boolean allowMulticatch() { |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
132 |
return compareTo(JDK1_7) >= 0; |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
133 |
} |
8849
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
134 |
public boolean allowImprovedRethrowAnalysis() { |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
135 |
return compareTo(JDK1_7) >= 0; |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
136 |
} |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
137 |
public boolean allowImprovedCatchAnalysis() { |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
138 |
return compareTo(JDK1_7) >= 0; |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
139 |
} |
36526 | 140 |
public boolean allowModules() { |
141 |
return compareTo(JDK1_9) >= 0; |
|
142 |
} |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
143 |
public boolean allowTryWithResources() { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
144 |
return compareTo(JDK1_7) >= 0; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
145 |
} |
27844
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
25874
diff
changeset
|
146 |
public boolean allowEffectivelyFinalVariablesInTryWithResources() { |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
25874
diff
changeset
|
147 |
return compareTo(JDK1_9) >= 0; |
8b5d79870a2f
7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents:
25874
diff
changeset
|
148 |
} |
3895 | 149 |
public boolean allowBinaryLiterals() { |
150 |
return compareTo(JDK1_7) >= 0; |
|
151 |
} |
|
152 |
public boolean allowUnderscoresInLiterals() { |
|
153 |
return compareTo(JDK1_7) >= 0; |
|
154 |
} |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6148
diff
changeset
|
155 |
public boolean allowStringsInSwitch() { |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
156 |
return compareTo(JDK1_7) >= 0; |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
157 |
} |
27854
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27844
diff
changeset
|
158 |
public boolean allowDeprecationOnImport() { |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27844
diff
changeset
|
159 |
return compareTo(JDK1_9) < 0; |
22b4bfc4e22f
8032211: Don't issue deprecation warnings on import statements
jlahoda
parents:
27844
diff
changeset
|
160 |
} |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7330
diff
changeset
|
161 |
public boolean allowSimplifiedVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7330
diff
changeset
|
162 |
return compareTo(JDK1_7) >= 0; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7330
diff
changeset
|
163 |
} |
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9087
diff
changeset
|
164 |
public boolean allowObjectToPrimitiveCast() { |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9087
diff
changeset
|
165 |
return compareTo(JDK1_7) >= 0; |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9087
diff
changeset
|
166 |
} |
24218
9102c46a15dc
8039026: Definitely unassigned field can be accessed
pgovereau
parents:
23800
diff
changeset
|
167 |
public boolean enforceThisDotInit() { |
9102c46a15dc
8039026: Definitely unassigned field can be accessed
pgovereau
parents:
23800
diff
changeset
|
168 |
return compareTo(JDK1_7) >= 0; |
9102c46a15dc
8039026: Definitely unassigned field can be accessed
pgovereau
parents:
23800
diff
changeset
|
169 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13689
diff
changeset
|
170 |
public boolean allowPoly() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13689
diff
changeset
|
171 |
return compareTo(JDK1_8) >= 0; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13689
diff
changeset
|
172 |
} |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10180
diff
changeset
|
173 |
public boolean allowLambda() { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10180
diff
changeset
|
174 |
return compareTo(JDK1_8) >= 0; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10180
diff
changeset
|
175 |
} |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
176 |
public boolean allowMethodReferences() { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
177 |
return compareTo(JDK1_8) >= 0; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
178 |
} |
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14258
diff
changeset
|
179 |
public boolean allowDefaultMethods() { |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14258
diff
changeset
|
180 |
return compareTo(JDK1_8) >= 0; |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14258
diff
changeset
|
181 |
} |
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
182 |
public boolean allowStaticInterfaceMethods() { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
183 |
return compareTo(JDK1_8) >= 0; |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
184 |
} |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14267
diff
changeset
|
185 |
public boolean allowStrictMethodClashCheck() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14267
diff
changeset
|
186 |
return compareTo(JDK1_8) >= 0; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14267
diff
changeset
|
187 |
} |
13439
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
11314
diff
changeset
|
188 |
public boolean allowEffectivelyFinalInInnerClasses() { |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
11314
diff
changeset
|
189 |
return compareTo(JDK1_8) >= 0; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
11314
diff
changeset
|
190 |
} |
15385 | 191 |
public boolean allowTypeAnnotations() { |
192 |
return compareTo(JDK1_8) >= 0; |
|
193 |
} |
|
23800
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
23105
diff
changeset
|
194 |
public boolean allowAnnotationsAfterTypeParams() { |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
23105
diff
changeset
|
195 |
return compareTo(JDK1_8) >= 0; |
f7ffcfe938f2
8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents:
23105
diff
changeset
|
196 |
} |
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13631
diff
changeset
|
197 |
public boolean allowRepeatedAnnotations() { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13631
diff
changeset
|
198 |
return compareTo(JDK1_8) >= 0; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13631
diff
changeset
|
199 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14443
diff
changeset
|
200 |
public boolean allowIntersectionTypesInCast() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14443
diff
changeset
|
201 |
return compareTo(JDK1_8) >= 0; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14443
diff
changeset
|
202 |
} |
15717 | 203 |
public boolean allowGraphInference() { |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
204 |
return compareTo(JDK1_8) >= 0; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
205 |
} |
24404
cf534ffbc9d8
8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents:
24218
diff
changeset
|
206 |
public boolean allowFunctionalInterfaceMostSpecific() { |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
207 |
return compareTo(JDK1_8) >= 0; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
208 |
} |
25008
969bfaae5bce
8036953: Fix timing of varargs access check, per JDK-8016205
vromero
parents:
24404
diff
changeset
|
209 |
public boolean allowPostApplicabilityVarargsAccessCheck() { |
969bfaae5bce
8036953: Fix timing of varargs access check, per JDK-8016205
vromero
parents:
24404
diff
changeset
|
210 |
return compareTo(JDK1_8) >= 0; |
969bfaae5bce
8036953: Fix timing of varargs access check, per JDK-8016205
vromero
parents:
24404
diff
changeset
|
211 |
} |
42819
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
36526
diff
changeset
|
212 |
public boolean mapCapturesToBounds() { |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
36526
diff
changeset
|
213 |
return compareTo(JDK1_8) < 0; |
4ce83e629dc1
8075793: Source incompatibility for inference using -source 7
dlsmith
parents:
36526
diff
changeset
|
214 |
} |
25283
082d51b7010b
7196160: Project Coin: allow @SafeVarargs on private methods
darcy
parents:
25008
diff
changeset
|
215 |
public boolean allowPrivateSafeVarargs() { |
082d51b7010b
7196160: Project Coin: allow @SafeVarargs on private methods
darcy
parents:
25008
diff
changeset
|
216 |
return compareTo(JDK1_9) >= 0; |
082d51b7010b
7196160: Project Coin: allow @SafeVarargs on private methods
darcy
parents:
25008
diff
changeset
|
217 |
} |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29293
diff
changeset
|
218 |
public boolean allowDiamondWithAnonymousClassCreation() { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29293
diff
changeset
|
219 |
return compareTo(JDK1_9) >= 0; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29293
diff
changeset
|
220 |
} |
27991
8f4b68523da3
8061549: Disallow _ as a one-character identifier
jlahoda
parents:
27854
diff
changeset
|
221 |
public boolean allowUnderscoreIdentifier() { |
8f4b68523da3
8061549: Disallow _ as a one-character identifier
jlahoda
parents:
27854
diff
changeset
|
222 |
return compareTo(JDK1_8) <= 0; |
8f4b68523da3
8061549: Disallow _ as a one-character identifier
jlahoda
parents:
27854
diff
changeset
|
223 |
} |
29293
1583c6dd6df7
8071453: Allow interface methods to be private
sadayapalam
parents:
27991
diff
changeset
|
224 |
public boolean allowPrivateInterfaceMethods() { return compareTo(JDK1_9) >= 0; } |
10 | 225 |
public static SourceVersion toSourceVersion(Source source) { |
226 |
switch(source) { |
|
227 |
case JDK1_2: |
|
228 |
return RELEASE_2; |
|
229 |
case JDK1_3: |
|
230 |
return RELEASE_3; |
|
231 |
case JDK1_4: |
|
232 |
return RELEASE_4; |
|
233 |
case JDK1_5: |
|
234 |
return RELEASE_5; |
|
235 |
case JDK1_6: |
|
236 |
return RELEASE_6; |
|
237 |
case JDK1_7: |
|
238 |
return RELEASE_7; |
|
10180 | 239 |
case JDK1_8: |
240 |
return RELEASE_8; |
|
22151 | 241 |
case JDK1_9: |
22170
62da5257a0a7
8031360: Update langtools code base to use RELEASE_9
darcy
parents:
22167
diff
changeset
|
242 |
return RELEASE_9; |
10 | 243 |
default: |
244 |
return null; |
|
245 |
} |
|
246 |
} |
|
247 |
} |