author | mcimadamore |
Wed, 13 Feb 2013 17:04:21 +0000 | |
changeset 15720 | e61b2f7a5148 |
parent 15717 | ab55670d2e62 |
child 22151 | cb8daa93eeb1 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
15385 | 2 |
* Copyright (c) 2002, 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 |
||
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 |
||
70 |
/** 1.8 covers the to be determined language features that will be added in JDK 8. */ |
|
71 |
JDK1_8("1.8"); |
|
10 | 72 |
|
73 |
private static final Context.Key<Source> sourceKey |
|
74 |
= new Context.Key<Source>(); |
|
75 |
||
76 |
public static Source instance(Context context) { |
|
77 |
Source instance = context.get(sourceKey); |
|
78 |
if (instance == null) { |
|
79 |
Options options = Options.instance(context); |
|
6721 | 80 |
String sourceString = options.get(SOURCE); |
10 | 81 |
if (sourceString != null) instance = lookup(sourceString); |
82 |
if (instance == null) instance = DEFAULT; |
|
83 |
context.put(sourceKey, instance); |
|
84 |
} |
|
85 |
return instance; |
|
86 |
} |
|
87 |
||
88 |
public final String name; |
|
89 |
||
14801
d66cab4ef397
8003967: detect and remove all mutable implicit static enum fields in langtools
vromero
parents:
14725
diff
changeset
|
90 |
private static final Map<String,Source> tab = new HashMap<String,Source>(); |
10 | 91 |
static { |
92 |
for (Source s : values()) { |
|
93 |
tab.put(s.name, s); |
|
94 |
} |
|
95 |
tab.put("5", JDK1_5); // Make 5 an alias for 1.5 |
|
96 |
tab.put("6", JDK1_6); // Make 6 an alias for 1.6 |
|
97 |
tab.put("7", JDK1_7); // Make 7 an alias for 1.7 |
|
10180 | 98 |
tab.put("8", JDK1_8); // Make 8 an alias for 1.8 |
10 | 99 |
} |
100 |
||
101 |
private Source(String name) { |
|
102 |
this.name = name; |
|
103 |
} |
|
104 |
||
10180 | 105 |
public static final Source DEFAULT = JDK1_8; |
10 | 106 |
|
107 |
public static Source lookup(String name) { |
|
108 |
return tab.get(name); |
|
109 |
} |
|
110 |
||
111 |
public Target requiredTarget() { |
|
10180 | 112 |
if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8; |
10 | 113 |
if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7; |
114 |
if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6; |
|
115 |
if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5; |
|
116 |
if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4; |
|
117 |
return Target.JDK1_1; |
|
118 |
} |
|
119 |
||
120 |
/** Allow encoding errors, giving only warnings. */ |
|
121 |
public boolean allowEncodingErrors() { |
|
122 |
return compareTo(JDK1_6) < 0; |
|
123 |
} |
|
124 |
public boolean allowAsserts() { |
|
125 |
return compareTo(JDK1_4) >= 0; |
|
126 |
} |
|
127 |
public boolean allowCovariantReturns() { |
|
128 |
return compareTo(JDK1_5) >= 0; |
|
129 |
} |
|
130 |
public boolean allowGenerics() { |
|
131 |
return compareTo(JDK1_5) >= 0; |
|
132 |
} |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
133 |
public boolean allowDiamond() { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
134 |
return compareTo(JDK1_7) >= 0; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
135 |
} |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
136 |
public boolean allowMulticatch() { |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
137 |
return compareTo(JDK1_7) >= 0; |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
138 |
} |
8849
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
139 |
public boolean allowImprovedRethrowAnalysis() { |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
140 |
return compareTo(JDK1_7) >= 0; |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
141 |
} |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
142 |
public boolean allowImprovedCatchAnalysis() { |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
143 |
return compareTo(JDK1_7) >= 0; |
4189ac38ddc9
6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents:
7681
diff
changeset
|
144 |
} |
10 | 145 |
public boolean allowEnums() { |
146 |
return compareTo(JDK1_5) >= 0; |
|
147 |
} |
|
148 |
public boolean allowForeach() { |
|
149 |
return compareTo(JDK1_5) >= 0; |
|
150 |
} |
|
151 |
public boolean allowStaticImport() { |
|
152 |
return compareTo(JDK1_5) >= 0; |
|
153 |
} |
|
154 |
public boolean allowBoxing() { |
|
155 |
return compareTo(JDK1_5) >= 0; |
|
156 |
} |
|
157 |
public boolean allowVarargs() { |
|
158 |
return compareTo(JDK1_5) >= 0; |
|
159 |
} |
|
160 |
public boolean allowAnnotations() { |
|
161 |
return compareTo(JDK1_5) >= 0; |
|
162 |
} |
|
163 |
// hex floating-point literals supported? |
|
164 |
public boolean allowHexFloats() { |
|
165 |
return compareTo(JDK1_5) >= 0; |
|
166 |
} |
|
167 |
public boolean allowAnonOuterThis() { |
|
168 |
return compareTo(JDK1_5) >= 0; |
|
169 |
} |
|
170 |
public boolean addBridges() { |
|
171 |
return compareTo(JDK1_5) >= 0; |
|
172 |
} |
|
173 |
public boolean enforceMandatoryWarnings() { |
|
174 |
return compareTo(JDK1_5) >= 0; |
|
175 |
} |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
176 |
public boolean allowTryWithResources() { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
177 |
return compareTo(JDK1_7) >= 0; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
178 |
} |
3895 | 179 |
public boolean allowBinaryLiterals() { |
180 |
return compareTo(JDK1_7) >= 0; |
|
181 |
} |
|
182 |
public boolean allowUnderscoresInLiterals() { |
|
183 |
return compareTo(JDK1_7) >= 0; |
|
184 |
} |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6148
diff
changeset
|
185 |
public boolean allowStringsInSwitch() { |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
186 |
return compareTo(JDK1_7) >= 0; |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
187 |
} |
7643
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7330
diff
changeset
|
188 |
public boolean allowSimplifiedVarargs() { |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7330
diff
changeset
|
189 |
return compareTo(JDK1_7) >= 0; |
a067a0cda531
6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents:
7330
diff
changeset
|
190 |
} |
9595
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9087
diff
changeset
|
191 |
public boolean allowObjectToPrimitiveCast() { |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9087
diff
changeset
|
192 |
return compareTo(JDK1_7) >= 0; |
a7dea6cbd5f7
7038363: cast from object to primitive should be for source >= 1.7
jjg
parents:
9087
diff
changeset
|
193 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13689
diff
changeset
|
194 |
public boolean allowPoly() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13689
diff
changeset
|
195 |
return compareTo(JDK1_8) >= 0; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
13689
diff
changeset
|
196 |
} |
11143
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10180
diff
changeset
|
197 |
public boolean allowLambda() { |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10180
diff
changeset
|
198 |
return compareTo(JDK1_8) >= 0; |
9dbe313bfb74
7115050: Add parser support for lambda expressions
mcimadamore
parents:
10180
diff
changeset
|
199 |
} |
11144
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
200 |
public boolean allowMethodReferences() { |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
201 |
return compareTo(JDK1_8) >= 0; |
8a4ae514eedf
7115052: Add parser support for method references
mcimadamore
parents:
11143
diff
changeset
|
202 |
} |
14267
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14258
diff
changeset
|
203 |
public boolean allowDefaultMethods() { |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14258
diff
changeset
|
204 |
return compareTo(JDK1_8) >= 0; |
6321fbe0cf50
7192245: Add parser support for default methods
mcimadamore
parents:
14258
diff
changeset
|
205 |
} |
15377
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
206 |
public boolean allowStaticInterfaceMethods() { |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
207 |
return compareTo(JDK1_8) >= 0; |
515846bb6637
8005166: Add support for static interface methods
mcimadamore
parents:
15374
diff
changeset
|
208 |
} |
14443
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14267
diff
changeset
|
209 |
public boolean allowStrictMethodClashCheck() { |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14267
diff
changeset
|
210 |
return compareTo(JDK1_8) >= 0; |
91c05eb19277
7192246: Add type-checking support for default methods
mcimadamore
parents:
14267
diff
changeset
|
211 |
} |
13439
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
11314
diff
changeset
|
212 |
public boolean allowEffectivelyFinalInInnerClasses() { |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
11314
diff
changeset
|
213 |
return compareTo(JDK1_8) >= 0; |
3025d6ac1401
7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents:
11314
diff
changeset
|
214 |
} |
15385 | 215 |
public boolean allowTypeAnnotations() { |
216 |
return compareTo(JDK1_8) >= 0; |
|
217 |
} |
|
13689
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13631
diff
changeset
|
218 |
public boolean allowRepeatedAnnotations() { |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13631
diff
changeset
|
219 |
return compareTo(JDK1_8) >= 0; |
4d519199a6aa
7151010: Add compiler support for repeating annotations
jfranck
parents:
13631
diff
changeset
|
220 |
} |
14725
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14443
diff
changeset
|
221 |
public boolean allowIntersectionTypesInCast() { |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14443
diff
changeset
|
222 |
return compareTo(JDK1_8) >= 0; |
65836e833f59
8002099: Add support for intersection types in cast expression
mcimadamore
parents:
14443
diff
changeset
|
223 |
} |
15717 | 224 |
public boolean allowGraphInference() { |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
225 |
return compareTo(JDK1_8) >= 0; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
226 |
} |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
227 |
public boolean allowStructuralMostSpecific() { |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
228 |
return compareTo(JDK1_8) >= 0; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
14801
diff
changeset
|
229 |
} |
10 | 230 |
public static SourceVersion toSourceVersion(Source source) { |
231 |
switch(source) { |
|
232 |
case JDK1_2: |
|
233 |
return RELEASE_2; |
|
234 |
case JDK1_3: |
|
235 |
return RELEASE_3; |
|
236 |
case JDK1_4: |
|
237 |
return RELEASE_4; |
|
238 |
case JDK1_5: |
|
239 |
return RELEASE_5; |
|
240 |
case JDK1_6: |
|
241 |
return RELEASE_6; |
|
242 |
case JDK1_7: |
|
243 |
return RELEASE_7; |
|
10180 | 244 |
case JDK1_8: |
245 |
return RELEASE_8; |
|
10 | 246 |
default: |
247 |
return null; |
|
248 |
} |
|
249 |
} |
|
250 |
} |