langtools/src/share/classes/com/sun/tools/javac/code/Source.java
author jrose
Sat, 01 May 2010 15:05:39 -0700
changeset 5736 ee0850472ca1
parent 5321 c8efe769cb3b
child 5738 c24b113fe4ac
permissions -rw-r--r--
6939134: JSR 292 adjustments to method handle invocation Summary: split MethodHandle.invoke into invokeExact and invokeGeneric Reviewed-by: twisti
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
06bc494ca11e Initial load
duke
parents:
diff changeset
     2
 * Copyright 2002-2006 Sun Microsystems, Inc.  All Rights Reserved.
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06bc494ca11e Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
06bc494ca11e Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
06bc494ca11e Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
06bc494ca11e Initial load
duke
parents:
diff changeset
    23
 * have any questions.
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.code;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
06bc494ca11e Initial load
duke
parents:
diff changeset
    28
import com.sun.tools.javac.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    29
import com.sun.tools.javac.jvm.Target;
06bc494ca11e Initial load
duke
parents:
diff changeset
    30
import javax.lang.model.SourceVersion;
06bc494ca11e Initial load
duke
parents:
diff changeset
    31
import static javax.lang.model.SourceVersion.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import java.util.*;
06bc494ca11e Initial load
duke
parents:
diff changeset
    33
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
/** The source language version accepted.
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
 *  <p><b>This is NOT part of any API supported by Sun Microsystems.  If
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
 *  you write code that depends on this, you do so at your own risk.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    39
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    40
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
public enum Source {
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
    /** 1.0 had no inner classes, and so could not pass the JCK. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
    // public static final Source JDK1_0 =              new Source("1.0");
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    /** 1.1 did not have strictfp, and so could not pass the JCK. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    // public static final Source JDK1_1 =              new Source("1.1");
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /** 1.2 introduced strictfp. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    JDK1_2("1.2"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    /** 1.3 is the same language as 1.2. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    JDK1_3("1.3"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /** 1.4 introduced assert. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    JDK1_4("1.4"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /** 1.5 introduced generics, attributes, foreach, boxing, static import,
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
     *  covariant return, enums, varargs, et al. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    JDK1_5("1.5"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
    /** 1.6 reports encoding problems as errors instead of warnings. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    JDK1_6("1.6"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    /** 1.7 covers the to be determined language features that will be added in JDK 7. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    JDK1_7("1.7");
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
06bc494ca11e Initial load
duke
parents:
diff changeset
    67
    private static final Context.Key<Source> sourceKey
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
        = new Context.Key<Source>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
    public static Source instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
        Source instance = context.get(sourceKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    72
        if (instance == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    73
            Options options = Options.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
            String sourceString = options.get("-source");
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
            if (sourceString != null) instance = lookup(sourceString);
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
            if (instance == null) instance = DEFAULT;
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
            context.put(sourceKey, instance);
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    public final String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
    private static Map<String,Source> tab = new HashMap<String,Source>();
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
    static {
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        for (Source s : values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
            tab.put(s.name, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
        tab.put("5", JDK1_5); // Make 5 an alias for 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
        tab.put("6", JDK1_6); // Make 6 an alias for 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
        tab.put("7", JDK1_7); // Make 7 an alias for 1.7
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
    private Source(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
2982
090c71af18f6 6827026: Change javac source and target default to 7
jjg
parents: 10
diff changeset
    98
    public static final Source DEFAULT = JDK1_7;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    public static Source lookup(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        return tab.get(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    public Target requiredTarget() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
        if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
        if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
        return Target.JDK1_1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
    /** Allow encoding errors, giving only warnings. */
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    public boolean allowEncodingErrors() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        return compareTo(JDK1_6) < 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    public boolean allowAsserts() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
        return compareTo(JDK1_4) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
    public boolean allowCovariantReturns() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
    public boolean allowGenerics() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   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
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   128
    public boolean allowEnums() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    public boolean allowForeach() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
    public boolean allowStaticImport() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
    public boolean allowBoxing() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   138
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   139
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
    public boolean allowVarargs() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    public boolean allowAnnotations() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   145
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   146
    // hex floating-point literals supported?
06bc494ca11e Initial load
duke
parents:
diff changeset
   147
    public boolean allowHexFloats() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   148
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   150
    public boolean allowAnonOuterThis() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   151
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   152
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   153
    public boolean addBridges() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   154
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   155
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   156
    public boolean enforceMandatoryWarnings() {
06bc494ca11e Initial load
duke
parents:
diff changeset
   157
        return compareTo(JDK1_5) >= 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   158
    }
3149
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2982
diff changeset
   159
    public boolean allowTypeAnnotations() {
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2982
diff changeset
   160
        return compareTo(JDK1_7) >= 0;
0cd06d598d6f 6843077: JSR 308: Annotations on types
jjg
parents: 2982
diff changeset
   161
    }
3895
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   162
    public boolean allowBinaryLiterals() {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   163
        return compareTo(JDK1_7) >= 0;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   164
    }
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   165
    public boolean allowUnderscoresInLiterals() {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   166
        return compareTo(JDK1_7) >= 0;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   167
    }
4417
fc5cc811d2dd 6906748: Project Coin: Minor strings in switch cleanup
darcy
parents: 4142
diff changeset
   168
    public boolean allowStringsInSwitch() {
fc5cc811d2dd 6906748: Project Coin: Minor strings in switch cleanup
darcy
parents: 4142
diff changeset
   169
        return compareTo(JDK1_7) >= 0;
fc5cc811d2dd 6906748: Project Coin: Minor strings in switch cleanup
darcy
parents: 4142
diff changeset
   170
    }
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   171
    // JSR 292: recognize @PolymorphicSignature on java/dyn names
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   172
    public boolean allowPolymorphicSignature() {
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   173
        return compareTo(JDK1_7) >= 0;
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   174
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   175
    public static SourceVersion toSourceVersion(Source source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   176
        switch(source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   177
        case JDK1_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   178
            return RELEASE_2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   179
        case JDK1_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   180
            return RELEASE_3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        case JDK1_4:
06bc494ca11e Initial load
duke
parents:
diff changeset
   182
            return RELEASE_4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   183
        case JDK1_5:
06bc494ca11e Initial load
duke
parents:
diff changeset
   184
            return RELEASE_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   185
        case JDK1_6:
06bc494ca11e Initial load
duke
parents:
diff changeset
   186
            return RELEASE_6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   187
        case JDK1_7:
06bc494ca11e Initial load
duke
parents:
diff changeset
   188
            return RELEASE_7;
06bc494ca11e Initial load
duke
parents:
diff changeset
   189
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   190
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   191
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   192
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   193
}