author | mcimadamore |
Tue, 07 Sep 2010 17:32:27 +0100 | |
changeset 6592 | dc56420a69bc |
parent 6148 | 3a8158299c51 |
child 6721 | d92073844278 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
5520 | 2 |
* Copyright (c) 2002, 2006, 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 |
||
28 |
import com.sun.tools.javac.util.*; |
|
29 |
import com.sun.tools.javac.jvm.Target; |
|
30 |
import javax.lang.model.SourceVersion; |
|
31 |
import static javax.lang.model.SourceVersion.*; |
|
32 |
import java.util.*; |
|
33 |
||
34 |
/** The source language version accepted. |
|
35 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5520
diff
changeset
|
36 |
* <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
|
37 |
* If you write code that depends on this, you do so at your own risk. |
10 | 38 |
* This code and its internal interfaces are subject to change or |
39 |
* deletion without notice.</b> |
|
40 |
*/ |
|
41 |
public enum Source { |
|
42 |
/** 1.0 had no inner classes, and so could not pass the JCK. */ |
|
43 |
// public static final Source JDK1_0 = new Source("1.0"); |
|
44 |
||
45 |
/** 1.1 did not have strictfp, and so could not pass the JCK. */ |
|
46 |
// public static final Source JDK1_1 = new Source("1.1"); |
|
47 |
||
48 |
/** 1.2 introduced strictfp. */ |
|
49 |
JDK1_2("1.2"), |
|
50 |
||
51 |
/** 1.3 is the same language as 1.2. */ |
|
52 |
JDK1_3("1.3"), |
|
53 |
||
54 |
/** 1.4 introduced assert. */ |
|
55 |
JDK1_4("1.4"), |
|
56 |
||
57 |
/** 1.5 introduced generics, attributes, foreach, boxing, static import, |
|
58 |
* covariant return, enums, varargs, et al. */ |
|
59 |
JDK1_5("1.5"), |
|
60 |
||
61 |
/** 1.6 reports encoding problems as errors instead of warnings. */ |
|
62 |
JDK1_6("1.6"), |
|
63 |
||
64 |
/** 1.7 covers the to be determined language features that will be added in JDK 7. */ |
|
65 |
JDK1_7("1.7"); |
|
66 |
||
67 |
private static final Context.Key<Source> sourceKey |
|
68 |
= new Context.Key<Source>(); |
|
69 |
||
70 |
public static Source instance(Context context) { |
|
71 |
Source instance = context.get(sourceKey); |
|
72 |
if (instance == null) { |
|
73 |
Options options = Options.instance(context); |
|
74 |
String sourceString = options.get("-source"); |
|
75 |
if (sourceString != null) instance = lookup(sourceString); |
|
76 |
if (instance == null) instance = DEFAULT; |
|
77 |
context.put(sourceKey, instance); |
|
78 |
} |
|
79 |
return instance; |
|
80 |
} |
|
81 |
||
82 |
public final String name; |
|
83 |
||
84 |
private static Map<String,Source> tab = new HashMap<String,Source>(); |
|
85 |
static { |
|
86 |
for (Source s : values()) { |
|
87 |
tab.put(s.name, s); |
|
88 |
} |
|
89 |
tab.put("5", JDK1_5); // Make 5 an alias for 1.5 |
|
90 |
tab.put("6", JDK1_6); // Make 6 an alias for 1.6 |
|
91 |
tab.put("7", JDK1_7); // Make 7 an alias for 1.7 |
|
92 |
} |
|
93 |
||
94 |
private Source(String name) { |
|
95 |
this.name = name; |
|
96 |
} |
|
97 |
||
2982 | 98 |
public static final Source DEFAULT = JDK1_7; |
10 | 99 |
|
100 |
public static Source lookup(String name) { |
|
101 |
return tab.get(name); |
|
102 |
} |
|
103 |
||
104 |
public Target requiredTarget() { |
|
105 |
if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7; |
|
106 |
if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6; |
|
107 |
if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5; |
|
108 |
if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4; |
|
109 |
return Target.JDK1_1; |
|
110 |
} |
|
111 |
||
112 |
/** Allow encoding errors, giving only warnings. */ |
|
113 |
public boolean allowEncodingErrors() { |
|
114 |
return compareTo(JDK1_6) < 0; |
|
115 |
} |
|
116 |
public boolean allowAsserts() { |
|
117 |
return compareTo(JDK1_4) >= 0; |
|
118 |
} |
|
119 |
public boolean allowCovariantReturns() { |
|
120 |
return compareTo(JDK1_5) >= 0; |
|
121 |
} |
|
122 |
public boolean allowGenerics() { |
|
123 |
return compareTo(JDK1_5) >= 0; |
|
124 |
} |
|
5321
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
125 |
public boolean allowDiamond() { |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
126 |
return compareTo(JDK1_7) >= 0; |
c8efe769cb3b
6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents:
5320
diff
changeset
|
127 |
} |
5492
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
128 |
public boolean allowMulticatch() { |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
129 |
return compareTo(JDK1_7) >= 0; |
515e4b33b335
6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents:
5321
diff
changeset
|
130 |
} |
10 | 131 |
public boolean allowEnums() { |
132 |
return compareTo(JDK1_5) >= 0; |
|
133 |
} |
|
134 |
public boolean allowForeach() { |
|
135 |
return compareTo(JDK1_5) >= 0; |
|
136 |
} |
|
137 |
public boolean allowStaticImport() { |
|
138 |
return compareTo(JDK1_5) >= 0; |
|
139 |
} |
|
140 |
public boolean allowBoxing() { |
|
141 |
return compareTo(JDK1_5) >= 0; |
|
142 |
} |
|
143 |
public boolean allowVarargs() { |
|
144 |
return compareTo(JDK1_5) >= 0; |
|
145 |
} |
|
146 |
public boolean allowAnnotations() { |
|
147 |
return compareTo(JDK1_5) >= 0; |
|
148 |
} |
|
149 |
// hex floating-point literals supported? |
|
150 |
public boolean allowHexFloats() { |
|
151 |
return compareTo(JDK1_5) >= 0; |
|
152 |
} |
|
153 |
public boolean allowAnonOuterThis() { |
|
154 |
return compareTo(JDK1_5) >= 0; |
|
155 |
} |
|
156 |
public boolean addBridges() { |
|
157 |
return compareTo(JDK1_5) >= 0; |
|
158 |
} |
|
159 |
public boolean enforceMandatoryWarnings() { |
|
160 |
return compareTo(JDK1_5) >= 0; |
|
161 |
} |
|
6148
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
162 |
public boolean allowTryWithResources() { |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
163 |
return compareTo(JDK1_7) >= 0; |
3a8158299c51
6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents:
5857
diff
changeset
|
164 |
} |
3149 | 165 |
public boolean allowTypeAnnotations() { |
166 |
return compareTo(JDK1_7) >= 0; |
|
167 |
} |
|
3895 | 168 |
public boolean allowBinaryLiterals() { |
169 |
return compareTo(JDK1_7) >= 0; |
|
170 |
} |
|
171 |
public boolean allowUnderscoresInLiterals() { |
|
172 |
return compareTo(JDK1_7) >= 0; |
|
173 |
} |
|
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6148
diff
changeset
|
174 |
public boolean allowExoticIdentifiers() { |
4417
fc5cc811d2dd
6906748: Project Coin: Minor strings in switch cleanup
darcy
parents:
4142
diff
changeset
|
175 |
return compareTo(JDK1_7) >= 0; |
fc5cc811d2dd
6906748: Project Coin: Minor strings in switch cleanup
darcy
parents:
4142
diff
changeset
|
176 |
} |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6148
diff
changeset
|
177 |
public boolean allowStringsInSwitch() { |
5736
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
178 |
return compareTo(JDK1_7) >= 0; |
ee0850472ca1
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
5321
diff
changeset
|
179 |
} |
10 | 180 |
public static SourceVersion toSourceVersion(Source source) { |
181 |
switch(source) { |
|
182 |
case JDK1_2: |
|
183 |
return RELEASE_2; |
|
184 |
case JDK1_3: |
|
185 |
return RELEASE_3; |
|
186 |
case JDK1_4: |
|
187 |
return RELEASE_4; |
|
188 |
case JDK1_5: |
|
189 |
return RELEASE_5; |
|
190 |
case JDK1_6: |
|
191 |
return RELEASE_6; |
|
192 |
case JDK1_7: |
|
193 |
return RELEASE_7; |
|
194 |
default: |
|
195 |
return null; |
|
196 |
} |
|
197 |
} |
|
198 |
} |