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

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 3938
93012e2a5d1d
parent 2702
9ca8d8713094
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset eb6ee6a5f2fe

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

mercurial