langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java
author dlsmith
Wed, 14 Dec 2016 17:56:11 -0700
changeset 42819 4ce83e629dc1
parent 36526 3b41f1c69604
child 43646 017aba6e9260
permissions -rw-r--r--
8075793: Source incompatibility for inference using -source 7 Summary: In pre-8 sources, avoid capture variables as inference bounds, consistent with old javac behavior Reviewed-by: vromero, mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
29293
1583c6dd6df7 8071453: Allow interface methods to be private
sadayapalam
parents: 27991
diff changeset
     2
 * Copyright (c) 2002, 2015, Oracle and/or its affiliates. All rights reserved.
10
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
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
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
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5492
diff changeset
    23
 * questions.
10
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
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    28
import java.util.*;
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    29
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    30
import javax.lang.model.SourceVersion;
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    31
import static javax.lang.model.SourceVersion.*;
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    32
14258
8d2148961366 8000663: clean up langtools imports
jjg
parents: 14057
diff changeset
    33
import com.sun.tools.javac.jvm.Target;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    34
import com.sun.tools.javac.util.*;
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11144
diff changeset
    35
import static com.sun.tools.javac.main.Option.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
06bc494ca11e Initial load
duke
parents:
diff changeset
    37
/** The source language version accepted.
06bc494ca11e Initial load
duke
parents:
diff changeset
    38
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    39
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    40
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    44
public enum Source {
06bc494ca11e Initial load
duke
parents:
diff changeset
    45
    /** 1.0 had no inner classes, and so could not pass the JCK. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
    // public static final Source JDK1_0 =              new Source("1.0");
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
    /** 1.1 did not have strictfp, and so could not pass the JCK. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
    // public static final Source JDK1_1 =              new Source("1.1");
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    /** 1.2 introduced strictfp. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
    JDK1_2("1.2"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    /** 1.3 is the same language as 1.2. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
    JDK1_3("1.3"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    /** 1.4 introduced assert. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
    JDK1_4("1.4"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    /** 1.5 introduced generics, attributes, foreach, boxing, static import,
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
     *  covariant return, enums, varargs, et al. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    JDK1_5("1.5"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
    /** 1.6 reports encoding problems as errors instead of warnings. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    JDK1_6("1.6"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
    67
    /** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
    68
    JDK1_7("1.7"),
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
    69
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    70
    /** 1.8 lambda expressions and default methods. */
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    71
    JDK1_8("1.8"),
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    72
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    73
    /** 1.9 covers the to be determined language features that will be added in JDK 9. */
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    74
    JDK1_9("1.9");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22151
diff changeset
    76
    private static final Context.Key<Source> sourceKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
06bc494ca11e Initial load
duke
parents:
diff changeset
    78
    public static Source instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
        Source instance = context.get(sourceKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    80
        if (instance == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    81
            Options options = Options.instance(context);
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    82
            String sourceString = options.get(SOURCE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
            if (sourceString != null) instance = lookup(sourceString);
06bc494ca11e Initial load
duke
parents:
diff changeset
    84
            if (instance == null) instance = DEFAULT;
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
            context.put(sourceKey, instance);
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
06bc494ca11e Initial load
duke
parents:
diff changeset
    90
    public final String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    92
    private static final Map<String,Source> tab = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
    static {
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        for (Source s : values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
            tab.put(s.name, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
        tab.put("5", JDK1_5); // Make 5 an alias for 1.5
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
        tab.put("6", JDK1_6); // Make 6 an alias for 1.6
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
        tab.put("7", JDK1_7); // Make 7 an alias for 1.7
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
   100
        tab.put("8", JDK1_8); // Make 8 an alias for 1.8
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
   101
        tab.put("9", JDK1_9); // Make 9 an alias for 1.9
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
    private Source(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   108
    public static final Source MIN = Source.JDK1_6;
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   109
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   110
    private static final Source MAX = values()[values().length - 1];
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   111
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   112
    public static final Source DEFAULT = MAX;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
    public static Source lookup(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
        return tab.get(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   117
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    public Target requiredTarget() {
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
   119
        if (this.compareTo(JDK1_9) >= 0) return Target.JDK1_9;
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
   120
        if (this.compareTo(JDK1_8) >= 0) return Target.JDK1_8;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        if (this.compareTo(JDK1_7) >= 0) return Target.JDK1_7;
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
        if (this.compareTo(JDK1_6) >= 0) return Target.JDK1_6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
        if (this.compareTo(JDK1_5) >= 0) return Target.JDK1_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
        return Target.JDK1_1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
5321
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   128
    public boolean allowDiamond() {
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   129
        return compareTo(JDK1_7) >= 0;
c8efe769cb3b 6939620: Switch to 'complex' diamond inference scheme
mcimadamore
parents: 5320
diff changeset
   130
    }
5492
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   131
    public boolean allowMulticatch() {
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   132
        return compareTo(JDK1_7) >= 0;
515e4b33b335 6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
mcimadamore
parents: 5321
diff changeset
   133
    }
8849
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 7681
diff changeset
   134
    public boolean allowImprovedRethrowAnalysis() {
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 7681
diff changeset
   135
        return compareTo(JDK1_7) >= 0;
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 7681
diff changeset
   136
    }
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 7681
diff changeset
   137
    public boolean allowImprovedCatchAnalysis() {
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 7681
diff changeset
   138
        return compareTo(JDK1_7) >= 0;
4189ac38ddc9 6558548: The compiler needs to be aligned with clarified specification of throws
mcimadamore
parents: 7681
diff changeset
   139
    }
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 29776
diff changeset
   140
    public boolean allowModules() {
3b41f1c69604 8142968: Module System implementation
alanb
parents: 29776
diff changeset
   141
        return compareTo(JDK1_9) >= 0;
3b41f1c69604 8142968: Module System implementation
alanb
parents: 29776
diff changeset
   142
    }
6148
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   143
    public boolean allowTryWithResources() {
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   144
        return compareTo(JDK1_7) >= 0;
3a8158299c51 6911256: Project Coin: Support Automatic Resource Management (ARM) blocks in the compiler
darcy
parents: 5857
diff changeset
   145
    }
27844
8b5d79870a2f 7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents: 25874
diff changeset
   146
    public boolean allowEffectivelyFinalVariablesInTryWithResources() {
8b5d79870a2f 7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents: 25874
diff changeset
   147
        return compareTo(JDK1_9) >= 0;
8b5d79870a2f 7196163: Project Coin: Allow effectively final variables to be used as resources in try-with-resources
jlahoda
parents: 25874
diff changeset
   148
    }
3895
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   149
    public boolean allowBinaryLiterals() {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   150
        return compareTo(JDK1_7) >= 0;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   151
    }
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   152
    public boolean allowUnderscoresInLiterals() {
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   153
        return compareTo(JDK1_7) >= 0;
3b3c2a1e5e8a 6860965: Project Coin: binary literals
jjg
parents: 3765
diff changeset
   154
    }
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6148
diff changeset
   155
    public boolean allowStringsInSwitch() {
5736
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   156
        return compareTo(JDK1_7) >= 0;
ee0850472ca1 6939134: JSR 292 adjustments to method handle invocation
jrose
parents: 5321
diff changeset
   157
    }
27854
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27844
diff changeset
   158
    public boolean allowDeprecationOnImport() {
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27844
diff changeset
   159
        return compareTo(JDK1_9) < 0;
22b4bfc4e22f 8032211: Don't issue deprecation warnings on import statements
jlahoda
parents: 27844
diff changeset
   160
    }
7643
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7330
diff changeset
   161
    public boolean allowSimplifiedVarargs() {
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7330
diff changeset
   162
        return compareTo(JDK1_7) >= 0;
a067a0cda531 6993978: Project Coin: Compiler support of annotation to reduce varargs warnings
mcimadamore
parents: 7330
diff changeset
   163
    }
9595
a7dea6cbd5f7 7038363: cast from object to primitive should be for source >= 1.7
jjg
parents: 9087
diff changeset
   164
    public boolean allowObjectToPrimitiveCast() {
a7dea6cbd5f7 7038363: cast from object to primitive should be for source >= 1.7
jjg
parents: 9087
diff changeset
   165
        return compareTo(JDK1_7) >= 0;
a7dea6cbd5f7 7038363: cast from object to primitive should be for source >= 1.7
jjg
parents: 9087
diff changeset
   166
    }
24218
9102c46a15dc 8039026: Definitely unassigned field can be accessed
pgovereau
parents: 23800
diff changeset
   167
    public boolean enforceThisDotInit() {
9102c46a15dc 8039026: Definitely unassigned field can be accessed
pgovereau
parents: 23800
diff changeset
   168
        return compareTo(JDK1_7) >= 0;
9102c46a15dc 8039026: Definitely unassigned field can be accessed
pgovereau
parents: 23800
diff changeset
   169
    }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13689
diff changeset
   170
    public boolean allowPoly() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13689
diff changeset
   171
        return compareTo(JDK1_8) >= 0;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 13689
diff changeset
   172
    }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 10180
diff changeset
   173
    public boolean allowLambda() {
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 10180
diff changeset
   174
        return compareTo(JDK1_8) >= 0;
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 10180
diff changeset
   175
    }
11144
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   176
    public boolean allowMethodReferences() {
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   177
        return compareTo(JDK1_8) >= 0;
8a4ae514eedf 7115052: Add parser support for method references
mcimadamore
parents: 11143
diff changeset
   178
    }
14267
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14258
diff changeset
   179
    public boolean allowDefaultMethods() {
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14258
diff changeset
   180
        return compareTo(JDK1_8) >= 0;
6321fbe0cf50 7192245: Add parser support for default methods
mcimadamore
parents: 14258
diff changeset
   181
    }
15377
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15374
diff changeset
   182
    public boolean allowStaticInterfaceMethods() {
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15374
diff changeset
   183
        return compareTo(JDK1_8) >= 0;
515846bb6637 8005166: Add support for static interface methods
mcimadamore
parents: 15374
diff changeset
   184
    }
14443
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14267
diff changeset
   185
    public boolean allowStrictMethodClashCheck() {
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14267
diff changeset
   186
        return compareTo(JDK1_8) >= 0;
91c05eb19277 7192246: Add type-checking support for default methods
mcimadamore
parents: 14267
diff changeset
   187
    }
13439
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 11314
diff changeset
   188
    public boolean allowEffectivelyFinalInInnerClasses() {
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 11314
diff changeset
   189
        return compareTo(JDK1_8) >= 0;
3025d6ac1401 7175538: Integrate efectively final check with DA/DU analysis
mcimadamore
parents: 11314
diff changeset
   190
    }
15385
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
   191
    public boolean allowTypeAnnotations() {
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
   192
        return compareTo(JDK1_8) >= 0;
ee1eebe7e210 8006775: JSR 308: Compiler changes in JDK8
jjg
parents: 15377
diff changeset
   193
    }
23800
f7ffcfe938f2 8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents: 23105
diff changeset
   194
    public boolean allowAnnotationsAfterTypeParams() {
f7ffcfe938f2 8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents: 23105
diff changeset
   195
        return compareTo(JDK1_8) >= 0;
f7ffcfe938f2 8035890: jdk8 javac -source 7 compiles test case it should not
jlahoda
parents: 23105
diff changeset
   196
    }
13689
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13631
diff changeset
   197
    public boolean allowRepeatedAnnotations() {
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13631
diff changeset
   198
        return compareTo(JDK1_8) >= 0;
4d519199a6aa 7151010: Add compiler support for repeating annotations
jfranck
parents: 13631
diff changeset
   199
    }
14725
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14443
diff changeset
   200
    public boolean allowIntersectionTypesInCast() {
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14443
diff changeset
   201
        return compareTo(JDK1_8) >= 0;
65836e833f59 8002099: Add support for intersection types in cast expression
mcimadamore
parents: 14443
diff changeset
   202
    }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15385
diff changeset
   203
    public boolean allowGraphInference() {
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 14801
diff changeset
   204
        return compareTo(JDK1_8) >= 0;
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 14801
diff changeset
   205
    }
24404
cf534ffbc9d8 8034223: Most-specific should not have any special treatment for boxed vs. unboxed types
dlsmith
parents: 24218
diff changeset
   206
    public boolean allowFunctionalInterfaceMostSpecific() {
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 14801
diff changeset
   207
        return compareTo(JDK1_8) >= 0;
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 14801
diff changeset
   208
    }
25008
969bfaae5bce 8036953: Fix timing of varargs access check, per JDK-8016205
vromero
parents: 24404
diff changeset
   209
    public boolean allowPostApplicabilityVarargsAccessCheck() {
969bfaae5bce 8036953: Fix timing of varargs access check, per JDK-8016205
vromero
parents: 24404
diff changeset
   210
        return compareTo(JDK1_8) >= 0;
969bfaae5bce 8036953: Fix timing of varargs access check, per JDK-8016205
vromero
parents: 24404
diff changeset
   211
    }
42819
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 36526
diff changeset
   212
    public boolean mapCapturesToBounds() {
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 36526
diff changeset
   213
        return compareTo(JDK1_8) < 0;
4ce83e629dc1 8075793: Source incompatibility for inference using -source 7
dlsmith
parents: 36526
diff changeset
   214
    }
25283
082d51b7010b 7196160: Project Coin: allow @SafeVarargs on private methods
darcy
parents: 25008
diff changeset
   215
    public boolean allowPrivateSafeVarargs() {
082d51b7010b 7196160: Project Coin: allow @SafeVarargs on private methods
darcy
parents: 25008
diff changeset
   216
        return compareTo(JDK1_9) >= 0;
082d51b7010b 7196160: Project Coin: allow @SafeVarargs on private methods
darcy
parents: 25008
diff changeset
   217
    }
29776
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 29293
diff changeset
   218
    public boolean allowDiamondWithAnonymousClassCreation() {
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 29293
diff changeset
   219
        return compareTo(JDK1_9) >= 0;
984a79b71cfe 8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents: 29293
diff changeset
   220
    }
27991
8f4b68523da3 8061549: Disallow _ as a one-character identifier
jlahoda
parents: 27854
diff changeset
   221
    public boolean allowUnderscoreIdentifier() {
8f4b68523da3 8061549: Disallow _ as a one-character identifier
jlahoda
parents: 27854
diff changeset
   222
        return compareTo(JDK1_8) <= 0;
8f4b68523da3 8061549: Disallow _ as a one-character identifier
jlahoda
parents: 27854
diff changeset
   223
    }
29293
1583c6dd6df7 8071453: Allow interface methods to be private
sadayapalam
parents: 27991
diff changeset
   224
    public boolean allowPrivateInterfaceMethods() { return compareTo(JDK1_9) >= 0; }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   225
    public static SourceVersion toSourceVersion(Source source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   226
        switch(source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   227
        case JDK1_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   228
            return RELEASE_2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   229
        case JDK1_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
            return RELEASE_3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        case JDK1_4:
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
            return RELEASE_4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
        case JDK1_5:
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
            return RELEASE_5;
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
        case JDK1_6:
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
            return RELEASE_6;
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
        case JDK1_7:
06bc494ca11e Initial load
duke
parents:
diff changeset
   238
            return RELEASE_7;
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
   239
        case JDK1_8:
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
   240
            return RELEASE_8;
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
   241
        case JDK1_9:
22170
62da5257a0a7 8031360: Update langtools code base to use RELEASE_9
darcy
parents: 22167
diff changeset
   242
            return RELEASE_9;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   244
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   245
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   246
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   247
}