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

Fri, 18 Jun 2010 15:12:04 -0700

author
jrose
date
Fri, 18 Jun 2010 15:12:04 -0700
changeset 573
005bec70ca27
parent 554
9d9f26857129
parent 571
f0e3ec1f9d9f
child 591
d1d7595fa824
permissions
-rw-r--r--

Merge

duke@1 1 /*
ohair@554 2 * Copyright (c) 2002, 2006, 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
duke@1 28 import com.sun.tools.javac.util.*;
duke@1 29 import com.sun.tools.javac.jvm.Target;
duke@1 30 import javax.lang.model.SourceVersion;
duke@1 31 import static javax.lang.model.SourceVersion.*;
duke@1 32 import java.util.*;
duke@1 33
duke@1 34 /** The source language version accepted.
duke@1 35 *
duke@1 36 * <p><b>This is NOT part of any API supported by Sun Microsystems. If
duke@1 37 * you write code that depends on this, you do so at your own risk.
duke@1 38 * This code and its internal interfaces are subject to change or
duke@1 39 * deletion without notice.</b>
duke@1 40 */
duke@1 41 public enum Source {
duke@1 42 /** 1.0 had no inner classes, and so could not pass the JCK. */
duke@1 43 // public static final Source JDK1_0 = new Source("1.0");
duke@1 44
duke@1 45 /** 1.1 did not have strictfp, and so could not pass the JCK. */
duke@1 46 // public static final Source JDK1_1 = new Source("1.1");
duke@1 47
duke@1 48 /** 1.2 introduced strictfp. */
duke@1 49 JDK1_2("1.2"),
duke@1 50
duke@1 51 /** 1.3 is the same language as 1.2. */
duke@1 52 JDK1_3("1.3"),
duke@1 53
duke@1 54 /** 1.4 introduced assert. */
duke@1 55 JDK1_4("1.4"),
duke@1 56
duke@1 57 /** 1.5 introduced generics, attributes, foreach, boxing, static import,
duke@1 58 * covariant return, enums, varargs, et al. */
duke@1 59 JDK1_5("1.5"),
duke@1 60
duke@1 61 /** 1.6 reports encoding problems as errors instead of warnings. */
duke@1 62 JDK1_6("1.6"),
duke@1 63
duke@1 64 /** 1.7 covers the to be determined language features that will be added in JDK 7. */
duke@1 65 JDK1_7("1.7");
duke@1 66
duke@1 67 private static final Context.Key<Source> sourceKey
duke@1 68 = new Context.Key<Source>();
duke@1 69
duke@1 70 public static Source instance(Context context) {
duke@1 71 Source instance = context.get(sourceKey);
duke@1 72 if (instance == null) {
duke@1 73 Options options = Options.instance(context);
duke@1 74 String sourceString = options.get("-source");
duke@1 75 if (sourceString != null) instance = lookup(sourceString);
duke@1 76 if (instance == null) instance = DEFAULT;
duke@1 77 context.put(sourceKey, instance);
duke@1 78 }
duke@1 79 return instance;
duke@1 80 }
duke@1 81
duke@1 82 public final String name;
duke@1 83
duke@1 84 private static Map<String,Source> tab = new HashMap<String,Source>();
duke@1 85 static {
duke@1 86 for (Source s : values()) {
duke@1 87 tab.put(s.name, s);
duke@1 88 }
duke@1 89 tab.put("5", JDK1_5); // Make 5 an alias for 1.5
duke@1 90 tab.put("6", JDK1_6); // Make 6 an alias for 1.6
duke@1 91 tab.put("7", JDK1_7); // Make 7 an alias for 1.7
duke@1 92 }
duke@1 93
duke@1 94 private Source(String name) {
duke@1 95 this.name = name;
duke@1 96 }
duke@1 97
jjg@286 98 public static final Source DEFAULT = JDK1_7;
duke@1 99
duke@1 100 public static Source lookup(String name) {
duke@1 101 return tab.get(name);
duke@1 102 }
duke@1 103
duke@1 104 public Target requiredTarget() {
duke@1 105 if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
duke@1 106 if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
duke@1 107 if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5;
duke@1 108 if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
duke@1 109 return Target.JDK1_1;
duke@1 110 }
duke@1 111
duke@1 112 /** Allow encoding errors, giving only warnings. */
duke@1 113 public boolean allowEncodingErrors() {
duke@1 114 return compareTo(JDK1_6) < 0;
duke@1 115 }
duke@1 116 public boolean allowAsserts() {
duke@1 117 return compareTo(JDK1_4) >= 0;
duke@1 118 }
duke@1 119 public boolean allowCovariantReturns() {
duke@1 120 return compareTo(JDK1_5) >= 0;
duke@1 121 }
duke@1 122 public boolean allowGenerics() {
duke@1 123 return compareTo(JDK1_5) >= 0;
duke@1 124 }
mcimadamore@537 125 public boolean allowDiamond() {
mcimadamore@537 126 return compareTo(JDK1_7) >= 0;
mcimadamore@537 127 }
mcimadamore@550 128 public boolean allowMulticatch() {
mcimadamore@550 129 return compareTo(JDK1_7) >= 0;
mcimadamore@550 130 }
duke@1 131 public boolean allowEnums() {
duke@1 132 return compareTo(JDK1_5) >= 0;
duke@1 133 }
duke@1 134 public boolean allowForeach() {
duke@1 135 return compareTo(JDK1_5) >= 0;
duke@1 136 }
duke@1 137 public boolean allowStaticImport() {
duke@1 138 return compareTo(JDK1_5) >= 0;
duke@1 139 }
duke@1 140 public boolean allowBoxing() {
duke@1 141 return compareTo(JDK1_5) >= 0;
duke@1 142 }
duke@1 143 public boolean allowVarargs() {
duke@1 144 return compareTo(JDK1_5) >= 0;
duke@1 145 }
duke@1 146 public boolean allowAnnotations() {
duke@1 147 return compareTo(JDK1_5) >= 0;
duke@1 148 }
duke@1 149 // hex floating-point literals supported?
duke@1 150 public boolean allowHexFloats() {
duke@1 151 return compareTo(JDK1_5) >= 0;
duke@1 152 }
duke@1 153 public boolean allowAnonOuterThis() {
duke@1 154 return compareTo(JDK1_5) >= 0;
duke@1 155 }
duke@1 156 public boolean addBridges() {
duke@1 157 return compareTo(JDK1_5) >= 0;
duke@1 158 }
duke@1 159 public boolean enforceMandatoryWarnings() {
duke@1 160 return compareTo(JDK1_5) >= 0;
duke@1 161 }
jjg@308 162 public boolean allowTypeAnnotations() {
jjg@308 163 return compareTo(JDK1_7) >= 0;
jjg@308 164 }
jjg@409 165 public boolean allowBinaryLiterals() {
jjg@409 166 return compareTo(JDK1_7) >= 0;
jjg@409 167 }
jjg@409 168 public boolean allowUnderscoresInLiterals() {
jjg@409 169 return compareTo(JDK1_7) >= 0;
jjg@409 170 }
darcy@443 171 public boolean allowStringsInSwitch() {
darcy@443 172 return compareTo(JDK1_7) >= 0;
darcy@443 173 }
jrose@571 174 // JSR 292: recognize @PolymorphicSignature on java/dyn names
jrose@571 175 public boolean allowPolymorphicSignature() {
jrose@571 176 return compareTo(JDK1_7) >= 0;
jrose@571 177 }
duke@1 178 public static SourceVersion toSourceVersion(Source source) {
duke@1 179 switch(source) {
duke@1 180 case JDK1_2:
duke@1 181 return RELEASE_2;
duke@1 182 case JDK1_3:
duke@1 183 return RELEASE_3;
duke@1 184 case JDK1_4:
duke@1 185 return RELEASE_4;
duke@1 186 case JDK1_5:
duke@1 187 return RELEASE_5;
duke@1 188 case JDK1_6:
duke@1 189 return RELEASE_6;
duke@1 190 case JDK1_7:
duke@1 191 return RELEASE_7;
duke@1 192 default:
duke@1 193 return null;
duke@1 194 }
duke@1 195 }
duke@1 196 }

mercurial