src/share/classes/com/sun/tools/javac/code/Source.java

Thu, 06 Feb 2014 21:11:27 +0000

author
vromero
date
Thu, 06 Feb 2014 21:11:27 +0000
changeset 2261
79dc4b992c0a
parent 2260
fb870c70e774
child 2355
4f7d19235357
permissions
-rw-r--r--

8030855: Default methods should be visible under source previous to 8
Reviewed-by: jjg, dlsmith

duke@1 1 /*
vromero@2260 2 * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
duke@1 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@1 4 *
duke@1 5 * This code is free software; you can redistribute it and/or modify it
duke@1 6 * under the terms of the GNU General Public License version 2 only, as
ohair@554 7 * published by the Free Software Foundation. Oracle designates this
duke@1 8 * particular file as subject to the "Classpath" exception as provided
ohair@554 9 * by Oracle in the LICENSE file that accompanied this code.
duke@1 10 *
duke@1 11 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@1 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@1 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@1 14 * version 2 for more details (a copy is included in the LICENSE file that
duke@1 15 * accompanied this code).
duke@1 16 *
duke@1 17 * You should have received a copy of the GNU General Public License version
duke@1 18 * 2 along with this work; if not, write to the Free Software Foundation,
duke@1 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@1 20 *
ohair@554 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 22 * or visit www.oracle.com if you need additional information or have any
ohair@554 23 * questions.
duke@1 24 */
duke@1 25
duke@1 26 package com.sun.tools.javac.code;
duke@1 27
jjg@700 28 import java.util.*;
jjg@1357 29
jjg@700 30 import javax.lang.model.SourceVersion;
jjg@700 31 import static javax.lang.model.SourceVersion.*;
jjg@700 32
jjg@1357 33 import com.sun.tools.javac.jvm.Target;
duke@1 34 import com.sun.tools.javac.util.*;
jjg@1157 35 import static com.sun.tools.javac.main.Option.*;
duke@1 36
duke@1 37 /** The source language version accepted.
duke@1 38 *
jjg@581 39 * <p><b>This is NOT part of any supported API.
jjg@581 40 * If you write code that depends on this, you do so at your own risk.
duke@1 41 * This code and its internal interfaces are subject to change or
duke@1 42 * deletion without notice.</b>
duke@1 43 */
duke@1 44 public enum Source {
duke@1 45 /** 1.0 had no inner classes, and so could not pass the JCK. */
duke@1 46 // public static final Source JDK1_0 = new Source("1.0");
duke@1 47
duke@1 48 /** 1.1 did not have strictfp, and so could not pass the JCK. */
duke@1 49 // public static final Source JDK1_1 = new Source("1.1");
duke@1 50
duke@1 51 /** 1.2 introduced strictfp. */
duke@1 52 JDK1_2("1.2"),
duke@1 53
duke@1 54 /** 1.3 is the same language as 1.2. */
duke@1 55 JDK1_3("1.3"),
duke@1 56
duke@1 57 /** 1.4 introduced assert. */
duke@1 58 JDK1_4("1.4"),
duke@1 59
duke@1 60 /** 1.5 introduced generics, attributes, foreach, boxing, static import,
duke@1 61 * covariant return, enums, varargs, et al. */
duke@1 62 JDK1_5("1.5"),
duke@1 63
duke@1 64 /** 1.6 reports encoding problems as errors instead of warnings. */
duke@1 65 JDK1_6("1.6"),
duke@1 66
darcy@1042 67 /** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */
darcy@1042 68 JDK1_7("1.7"),
darcy@1042 69
darcy@1042 70 /** 1.8 covers the to be determined language features that will be added in JDK 8. */
darcy@1042 71 JDK1_8("1.8");
duke@1 72
duke@1 73 private static final Context.Key<Source> sourceKey
duke@1 74 = new Context.Key<Source>();
duke@1 75
duke@1 76 public static Source instance(Context context) {
duke@1 77 Source instance = context.get(sourceKey);
duke@1 78 if (instance == null) {
duke@1 79 Options options = Options.instance(context);
jjg@700 80 String sourceString = options.get(SOURCE);
duke@1 81 if (sourceString != null) instance = lookup(sourceString);
duke@1 82 if (instance == null) instance = DEFAULT;
duke@1 83 context.put(sourceKey, instance);
duke@1 84 }
duke@1 85 return instance;
duke@1 86 }
duke@1 87
duke@1 88 public final String name;
duke@1 89
vromero@1442 90 private static final Map<String,Source> tab = new HashMap<String,Source>();
duke@1 91 static {
duke@1 92 for (Source s : values()) {
duke@1 93 tab.put(s.name, s);
duke@1 94 }
duke@1 95 tab.put("5", JDK1_5); // Make 5 an alias for 1.5
duke@1 96 tab.put("6", JDK1_6); // Make 6 an alias for 1.6
duke@1 97 tab.put("7", JDK1_7); // Make 7 an alias for 1.7
darcy@1042 98 tab.put("8", JDK1_8); // Make 8 an alias for 1.8
duke@1 99 }
duke@1 100
duke@1 101 private Source(String name) {
duke@1 102 this.name = name;
duke@1 103 }
duke@1 104
darcy@1042 105 public static final Source DEFAULT = JDK1_8;
duke@1 106
duke@1 107 public static Source lookup(String name) {
duke@1 108 return tab.get(name);
duke@1 109 }
duke@1 110
duke@1 111 public Target requiredTarget() {
darcy@1042 112 if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8;
duke@1 113 if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
duke@1 114 if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
duke@1 115 if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5;
duke@1 116 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
duke@1 117 return Target.JDK1_1;
duke@1 118 }
duke@1 119
duke@1 120 /** Allow encoding errors, giving only warnings. */
duke@1 121 public boolean allowEncodingErrors() {
duke@1 122 return compareTo(JDK1_6) < 0;
duke@1 123 }
duke@1 124 public boolean allowAsserts() {
duke@1 125 return compareTo(JDK1_4) >= 0;
duke@1 126 }
duke@1 127 public boolean allowCovariantReturns() {
duke@1 128 return compareTo(JDK1_5) >= 0;
duke@1 129 }
duke@1 130 public boolean allowGenerics() {
duke@1 131 return compareTo(JDK1_5) >= 0;
duke@1 132 }
mcimadamore@537 133 public boolean allowDiamond() {
mcimadamore@537 134 return compareTo(JDK1_7) >= 0;
mcimadamore@537 135 }
mcimadamore@550 136 public boolean allowMulticatch() {
mcimadamore@550 137 return compareTo(JDK1_7) >= 0;
mcimadamore@550 138 }
mcimadamore@935 139 public boolean allowImprovedRethrowAnalysis() {
mcimadamore@935 140 return compareTo(JDK1_7) >= 0;
mcimadamore@935 141 }
mcimadamore@935 142 public boolean allowImprovedCatchAnalysis() {
mcimadamore@935 143 return compareTo(JDK1_7) >= 0;
mcimadamore@935 144 }
duke@1 145 public boolean allowEnums() {
duke@1 146 return compareTo(JDK1_5) >= 0;
duke@1 147 }
duke@1 148 public boolean allowForeach() {
duke@1 149 return compareTo(JDK1_5) >= 0;
duke@1 150 }
duke@1 151 public boolean allowStaticImport() {
duke@1 152 return compareTo(JDK1_5) >= 0;
duke@1 153 }
duke@1 154 public boolean allowBoxing() {
duke@1 155 return compareTo(JDK1_5) >= 0;
duke@1 156 }
duke@1 157 public boolean allowVarargs() {
duke@1 158 return compareTo(JDK1_5) >= 0;
duke@1 159 }
duke@1 160 public boolean allowAnnotations() {
duke@1 161 return compareTo(JDK1_5) >= 0;
duke@1 162 }
duke@1 163 // hex floating-point literals supported?
duke@1 164 public boolean allowHexFloats() {
duke@1 165 return compareTo(JDK1_5) >= 0;
duke@1 166 }
duke@1 167 public boolean allowAnonOuterThis() {
duke@1 168 return compareTo(JDK1_5) >= 0;
duke@1 169 }
duke@1 170 public boolean addBridges() {
duke@1 171 return compareTo(JDK1_5) >= 0;
duke@1 172 }
duke@1 173 public boolean enforceMandatoryWarnings() {
duke@1 174 return compareTo(JDK1_5) >= 0;
duke@1 175 }
darcy@609 176 public boolean allowTryWithResources() {
darcy@609 177 return compareTo(JDK1_7) >= 0;
darcy@609 178 }
jjg@409 179 public boolean allowBinaryLiterals() {
jjg@409 180 return compareTo(JDK1_7) >= 0;
jjg@409 181 }
jjg@409 182 public boolean allowUnderscoresInLiterals() {
jjg@409 183 return compareTo(JDK1_7) >= 0;
jjg@409 184 }
mcimadamore@674 185 public boolean allowStringsInSwitch() {
jrose@571 186 return compareTo(JDK1_7) >= 0;
jrose@571 187 }
mcimadamore@795 188 public boolean allowSimplifiedVarargs() {
mcimadamore@795 189 return compareTo(JDK1_7) >= 0;
mcimadamore@795 190 }
jjg@984 191 public boolean allowObjectToPrimitiveCast() {
jjg@984 192 return compareTo(JDK1_7) >= 0;
jjg@984 193 }
mcimadamore@1347 194 public boolean allowPoly() {
mcimadamore@1347 195 return compareTo(JDK1_8) >= 0;
mcimadamore@1347 196 }
mcimadamore@1144 197 public boolean allowLambda() {
mcimadamore@1144 198 return compareTo(JDK1_8) >= 0;
mcimadamore@1144 199 }
mcimadamore@1145 200 public boolean allowMethodReferences() {
mcimadamore@1145 201 return compareTo(JDK1_8) >= 0;
mcimadamore@1145 202 }
mcimadamore@1366 203 public boolean allowDefaultMethods() {
mcimadamore@1366 204 return compareTo(JDK1_8) >= 0;
mcimadamore@1366 205 }
mcimadamore@1513 206 public boolean allowStaticInterfaceMethods() {
mcimadamore@1513 207 return compareTo(JDK1_8) >= 0;
mcimadamore@1513 208 }
mcimadamore@1393 209 public boolean allowStrictMethodClashCheck() {
mcimadamore@1393 210 return compareTo(JDK1_8) >= 0;
mcimadamore@1393 211 }
mcimadamore@1297 212 public boolean allowEffectivelyFinalInInnerClasses() {
mcimadamore@1297 213 return compareTo(JDK1_8) >= 0;
mcimadamore@1297 214 }
jjg@1521 215 public boolean allowTypeAnnotations() {
jjg@1521 216 return compareTo(JDK1_8) >= 0;
jjg@1521 217 }
jfranck@1313 218 public boolean allowRepeatedAnnotations() {
jfranck@1313 219 return compareTo(JDK1_8) >= 0;
jfranck@1313 220 }
mcimadamore@1436 221 public boolean allowIntersectionTypesInCast() {
mcimadamore@1436 222 return compareTo(JDK1_8) >= 0;
mcimadamore@1436 223 }
mcimadamore@1562 224 public boolean allowGraphInference() {
mcimadamore@1510 225 return compareTo(JDK1_8) >= 0;
mcimadamore@1510 226 }
mcimadamore@1510 227 public boolean allowStructuralMostSpecific() {
mcimadamore@1510 228 return compareTo(JDK1_8) >= 0;
mcimadamore@1510 229 }
duke@1 230 public static SourceVersion toSourceVersion(Source source) {
duke@1 231 switch(source) {
duke@1 232 case JDK1_2:
duke@1 233 return RELEASE_2;
duke@1 234 case JDK1_3:
duke@1 235 return RELEASE_3;
duke@1 236 case JDK1_4:
duke@1 237 return RELEASE_4;
duke@1 238 case JDK1_5:
duke@1 239 return RELEASE_5;
duke@1 240 case JDK1_6:
duke@1 241 return RELEASE_6;
duke@1 242 case JDK1_7:
duke@1 243 return RELEASE_7;
darcy@1042 244 case JDK1_8:
darcy@1042 245 return RELEASE_8;
duke@1 246 default:
duke@1 247 return null;
duke@1 248 }
duke@1 249 }
duke@1 250 }

mercurial