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

Wed, 06 Apr 2011 20:33:44 -0700

author
ohair
date
Wed, 06 Apr 2011 20:33:44 -0700
changeset 962
0ff2bbd38f10
parent 935
5b29f2a85085
child 984
4c5f13798b8d
permissions
-rw-r--r--

7033660: Update copyright year to 2011 on any files changed in 2011
Reviewed-by: dholmes

duke@1 1 /*
ohair@962 2 * Copyright (c) 2002, 2011, 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@700 29 import javax.lang.model.SourceVersion;
jjg@700 30 import static javax.lang.model.SourceVersion.*;
jjg@700 31
duke@1 32 import com.sun.tools.javac.util.*;
duke@1 33 import com.sun.tools.javac.jvm.Target;
jjg@700 34
jjg@700 35 import static com.sun.tools.javac.main.OptionName.*;
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
duke@1 67 /** 1.7 covers the to be determined language features that will be added in JDK 7. */
duke@1 68 JDK1_7("1.7");
duke@1 69
duke@1 70 private static final Context.Key<Source> sourceKey
duke@1 71 = new Context.Key<Source>();
duke@1 72
duke@1 73 public static Source instance(Context context) {
duke@1 74 Source instance = context.get(sourceKey);
duke@1 75 if (instance == null) {
duke@1 76 Options options = Options.instance(context);
jjg@700 77 String sourceString = options.get(SOURCE);
duke@1 78 if (sourceString != null) instance = lookup(sourceString);
duke@1 79 if (instance == null) instance = DEFAULT;
duke@1 80 context.put(sourceKey, instance);
duke@1 81 }
duke@1 82 return instance;
duke@1 83 }
duke@1 84
duke@1 85 public final String name;
duke@1 86
duke@1 87 private static Map<String,Source> tab = new HashMap<String,Source>();
duke@1 88 static {
duke@1 89 for (Source s : values()) {
duke@1 90 tab.put(s.name, s);
duke@1 91 }
duke@1 92 tab.put("5", JDK1_5); // Make 5 an alias for 1.5
duke@1 93 tab.put("6", JDK1_6); // Make 6 an alias for 1.6
duke@1 94 tab.put("7", JDK1_7); // Make 7 an alias for 1.7
duke@1 95 }
duke@1 96
duke@1 97 private Source(String name) {
duke@1 98 this.name = name;
duke@1 99 }
duke@1 100
jjg@286 101 public static final Source DEFAULT = JDK1_7;
duke@1 102
duke@1 103 public static Source lookup(String name) {
duke@1 104 return tab.get(name);
duke@1 105 }
duke@1 106
duke@1 107 public Target requiredTarget() {
duke@1 108 if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
duke@1 109 if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
duke@1 110 if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5;
duke@1 111 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
duke@1 112 return Target.JDK1_1;
duke@1 113 }
duke@1 114
duke@1 115 /** Allow encoding errors, giving only warnings. */
duke@1 116 public boolean allowEncodingErrors() {
duke@1 117 return compareTo(JDK1_6) < 0;
duke@1 118 }
duke@1 119 public boolean allowAsserts() {
duke@1 120 return compareTo(JDK1_4) >= 0;
duke@1 121 }
duke@1 122 public boolean allowCovariantReturns() {
duke@1 123 return compareTo(JDK1_5) >= 0;
duke@1 124 }
duke@1 125 public boolean allowGenerics() {
duke@1 126 return compareTo(JDK1_5) >= 0;
duke@1 127 }
mcimadamore@537 128 public boolean allowDiamond() {
mcimadamore@537 129 return compareTo(JDK1_7) >= 0;
mcimadamore@537 130 }
mcimadamore@550 131 public boolean allowMulticatch() {
mcimadamore@550 132 return compareTo(JDK1_7) >= 0;
mcimadamore@550 133 }
mcimadamore@935 134 public boolean allowImprovedRethrowAnalysis() {
mcimadamore@935 135 return compareTo(JDK1_7) >= 0;
mcimadamore@935 136 }
mcimadamore@935 137 public boolean allowImprovedCatchAnalysis() {
mcimadamore@935 138 return compareTo(JDK1_7) >= 0;
mcimadamore@935 139 }
duke@1 140 public boolean allowEnums() {
duke@1 141 return compareTo(JDK1_5) >= 0;
duke@1 142 }
duke@1 143 public boolean allowForeach() {
duke@1 144 return compareTo(JDK1_5) >= 0;
duke@1 145 }
duke@1 146 public boolean allowStaticImport() {
duke@1 147 return compareTo(JDK1_5) >= 0;
duke@1 148 }
duke@1 149 public boolean allowBoxing() {
duke@1 150 return compareTo(JDK1_5) >= 0;
duke@1 151 }
duke@1 152 public boolean allowVarargs() {
duke@1 153 return compareTo(JDK1_5) >= 0;
duke@1 154 }
duke@1 155 public boolean allowAnnotations() {
duke@1 156 return compareTo(JDK1_5) >= 0;
duke@1 157 }
duke@1 158 // hex floating-point literals supported?
duke@1 159 public boolean allowHexFloats() {
duke@1 160 return compareTo(JDK1_5) >= 0;
duke@1 161 }
duke@1 162 public boolean allowAnonOuterThis() {
duke@1 163 return compareTo(JDK1_5) >= 0;
duke@1 164 }
duke@1 165 public boolean addBridges() {
duke@1 166 return compareTo(JDK1_5) >= 0;
duke@1 167 }
duke@1 168 public boolean enforceMandatoryWarnings() {
duke@1 169 return compareTo(JDK1_5) >= 0;
duke@1 170 }
darcy@609 171 public boolean allowTryWithResources() {
darcy@609 172 return compareTo(JDK1_7) >= 0;
darcy@609 173 }
jjg@308 174 public boolean allowTypeAnnotations() {
jjg@308 175 return compareTo(JDK1_7) >= 0;
jjg@308 176 }
jjg@409 177 public boolean allowBinaryLiterals() {
jjg@409 178 return compareTo(JDK1_7) >= 0;
jjg@409 179 }
jjg@409 180 public boolean allowUnderscoresInLiterals() {
jjg@409 181 return compareTo(JDK1_7) >= 0;
jjg@409 182 }
mcimadamore@674 183 public boolean allowStringsInSwitch() {
jrose@571 184 return compareTo(JDK1_7) >= 0;
jrose@571 185 }
mcimadamore@795 186 public boolean allowSimplifiedVarargs() {
mcimadamore@795 187 return compareTo(JDK1_7) >= 0;
mcimadamore@795 188 }
duke@1 189 public static SourceVersion toSourceVersion(Source source) {
duke@1 190 switch(source) {
duke@1 191 case JDK1_2:
duke@1 192 return RELEASE_2;
duke@1 193 case JDK1_3:
duke@1 194 return RELEASE_3;
duke@1 195 case JDK1_4:
duke@1 196 return RELEASE_4;
duke@1 197 case JDK1_5:
duke@1 198 return RELEASE_5;
duke@1 199 case JDK1_6:
duke@1 200 return RELEASE_6;
duke@1 201 case JDK1_7:
duke@1 202 return RELEASE_7;
duke@1 203 default:
duke@1 204 return null;
duke@1 205 }
duke@1 206 }
duke@1 207 }

mercurial