src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java
author jlahoda
Wed, 27 Nov 2019 09:00:01 +0100
changeset 59285 7799a51dbe30
parent 59068 dc45ed0ab083
permissions -rw-r--r--
8231826: Implement javac changes for pattern matching for instanceof Reviewed-by: mcimadamore Contributed-by: brian.goetz@oracle.com, gavin.bierman@oracle.com, maurizio.cimadamore@oracle.com, srikanth.adayapalam@oracle.com, vicente.romero@oracle.com, jan.lahoda@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
55318
040e1c6dab96 8225532: Update source enums to describe 12 and 13 language features
darcy
parents: 55263
diff changeset
     2
 * Copyright (c) 2002, 2019, 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;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    34
import com.sun.tools.javac.resources.CompilerProperties.Errors;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    35
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    36
import com.sun.tools.javac.util.*;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    37
import com.sun.tools.javac.util.JCDiagnostic.Error;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    38
import com.sun.tools.javac.util.JCDiagnostic.Fragment;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    39
11314
b612aaca08d0 7120736: refactor javac option handling
jjg
parents: 11144
diff changeset
    40
import static com.sun.tools.javac.main.Option.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    41
06bc494ca11e Initial load
duke
parents:
diff changeset
    42
/** The source language version accepted.
06bc494ca11e Initial load
duke
parents:
diff changeset
    43
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    44
 *  <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
    45
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    46
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    47
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    48
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    49
public enum Source {
06bc494ca11e Initial load
duke
parents:
diff changeset
    50
    /** 1.0 had no inner classes, and so could not pass the JCK. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    51
    // public static final Source JDK1_0 =              new Source("1.0");
06bc494ca11e Initial load
duke
parents:
diff changeset
    52
06bc494ca11e Initial load
duke
parents:
diff changeset
    53
    /** 1.1 did not have strictfp, and so could not pass the JCK. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    54
    // public static final Source JDK1_1 =              new Source("1.1");
06bc494ca11e Initial load
duke
parents:
diff changeset
    55
06bc494ca11e Initial load
duke
parents:
diff changeset
    56
    /** 1.2 introduced strictfp. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    57
    JDK1_2("1.2"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    58
06bc494ca11e Initial load
duke
parents:
diff changeset
    59
    /** 1.3 is the same language as 1.2. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    60
    JDK1_3("1.3"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    61
06bc494ca11e Initial load
duke
parents:
diff changeset
    62
    /** 1.4 introduced assert. */
06bc494ca11e Initial load
duke
parents:
diff changeset
    63
    JDK1_4("1.4"),
06bc494ca11e Initial load
duke
parents:
diff changeset
    64
06bc494ca11e Initial load
duke
parents:
diff changeset
    65
    /** 1.5 introduced generics, attributes, foreach, boxing, static import,
06bc494ca11e Initial load
duke
parents:
diff changeset
    66
     *  covariant return, enums, varargs, et al. */
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    67
    JDK5("5"),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    68
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
    /** 1.6 reports encoding problems as errors instead of warnings. */
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    70
    JDK6("6"),
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
    72
    /** 1.7 introduced try-with-resources, multi-catch, string switch, etc. */
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    73
    JDK7("7"),
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
    74
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    75
    /** 1.8 lambda expressions and default methods. */
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    76
    JDK8("8"),
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
    77
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42819
diff changeset
    78
    /** 1.9 modularity. */
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    79
    JDK9("9"),
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42819
diff changeset
    80
48343
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48054
diff changeset
    81
    /** 1.10 local-variable type inference (var). */
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48054
diff changeset
    82
    JDK10("10"),
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48054
diff changeset
    83
50892
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50539
diff changeset
    84
    /** 1.11 local-variable syntax for lambda parameters */
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50539
diff changeset
    85
    JDK11("11"),
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50539
diff changeset
    86
59068
dc45ed0ab083 8233096: Update javax.lang.model for switch expressions
darcy
parents: 55382
diff changeset
    87
    /** 12, no language features; switch expression in preview */
53023
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 52016
diff changeset
    88
    JDK12("12"),
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 52016
diff changeset
    89
55318
040e1c6dab96 8225532: Update source enums to describe 12 and 13 language features
darcy
parents: 55263
diff changeset
    90
    /**
040e1c6dab96 8225532: Update source enums to describe 12 and 13 language features
darcy
parents: 55263
diff changeset
    91
     * 13, no language features; text blocks and revised switch
040e1c6dab96 8225532: Update source enums to describe 12 and 13 language features
darcy
parents: 55263
diff changeset
    92
     * expressions in preview
040e1c6dab96 8225532: Update source enums to describe 12 and 13 language features
darcy
parents: 55263
diff changeset
    93
     */
55382
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
    94
    JDK13("13"),
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
    95
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
    96
    /**
59068
dc45ed0ab083 8233096: Update javax.lang.model for switch expressions
darcy
parents: 55382
diff changeset
    97
     * 14, switch expressions
55382
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
    98
     */
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
    99
    JDK14("14");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22151
diff changeset
   101
    private static final Context.Key<Source> sourceKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
    public static Source instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        Source instance = context.get(sourceKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
        if (instance == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
            Options options = Options.instance(context);
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
   107
            String sourceString = options.get(SOURCE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
            if (sourceString != null) instance = lookup(sourceString);
06bc494ca11e Initial load
duke
parents:
diff changeset
   109
            if (instance == null) instance = DEFAULT;
06bc494ca11e Initial load
duke
parents:
diff changeset
   110
            context.put(sourceKey, instance);
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    public final String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
   117
    private static final Map<String,Source> tab = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   118
    static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   119
        for (Source s : values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   120
            tab.put(s.name, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   121
        }
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   122
        tab.put("1.5", JDK5); // Make 5 an alias for 1.5
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   123
        tab.put("1.6", JDK6); // Make 6 an alias for 1.6
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   124
        tab.put("1.7", JDK7); // Make 7 an alias for 1.7
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   125
        tab.put("1.8", JDK8); // Make 8 an alias for 1.8
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   126
        tab.put("1.9", JDK9); // Make 9 an alias for 1.9
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   127
        tab.put("1.10", JDK10); // Make 10 an alias for 1.10
48343
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48054
diff changeset
   128
        // Decline to make 1.11 an alias for 11.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   129
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   130
06bc494ca11e Initial load
duke
parents:
diff changeset
   131
    private Source(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   132
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   133
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
51047
860a3648c494 8028563: Remove javac support for 6/1.6 source and target values
darcy
parents: 51040
diff changeset
   135
    public static final Source MIN = Source.JDK7;
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   136
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   137
    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
   138
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   139
    public static final Source DEFAULT = MAX;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
06bc494ca11e Initial load
duke
parents:
diff changeset
   141
    public static Source lookup(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   142
        return tab.get(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   143
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   144
51040
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   145
    public boolean isSupported() {
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   146
        return this.compareTo(MIN) >= 0;
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   147
    }
e0bce2635ec5 8207055: Make javac -help output for -source and -target more informative
darcy
parents: 50892
diff changeset
   148
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   149
    public Target requiredTarget() {
55382
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
   150
        if (this.compareTo(JDK14) >= 0) return Target.JDK1_14;
53023
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 52016
diff changeset
   151
        if (this.compareTo(JDK13) >= 0) return Target.JDK1_13;
50892
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50539
diff changeset
   152
        if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
48343
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48054
diff changeset
   153
        if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   154
        if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   155
        if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   156
        if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   157
        if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   158
        if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   159
        if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   160
        if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   161
        return Target.JDK1_1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   162
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   163
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   164
    /**
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   165
     * Models a feature of the Java programming language. Each feature can be associated with a
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   166
     * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   167
     * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   168
     */
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   169
    public enum Feature {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   170
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   171
        DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   172
        MODULES(JDK9, Fragments.FeatureModules, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   173
        EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES(JDK9, Fragments.FeatureVarInTryWithResources, DiagKind.PLURAL),
48776
107413b070b9 8194764: javac incorrectly flags deprecated for removal imports
jlahoda
parents: 48054
diff changeset
   174
        DEPRECATION_ON_IMPORT(MIN, JDK8),
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   175
        POLY(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   176
        LAMBDA(JDK8, Fragments.FeatureLambda, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   177
        METHOD_REFERENCES(JDK8, Fragments.FeatureMethodReferences, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   178
        DEFAULT_METHODS(JDK8, Fragments.FeatureDefaultMethods, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   179
        STATIC_INTERFACE_METHODS(JDK8, Fragments.FeatureStaticIntfMethods, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   180
        STATIC_INTERFACE_METHODS_INVOKE(JDK8, Fragments.FeatureStaticIntfMethodInvoke, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   181
        STRICT_METHOD_CLASH_CHECK(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   182
        EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   183
        TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   184
        ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   185
        REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   186
        INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   187
        GRAPH_INFERENCE(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   188
        FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   189
        POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   190
        MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   191
        PRIVATE_SAFE_VARARGS(JDK9),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   192
        DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   193
        UNDERSCORE_IDENTIFIER(MIN, JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   194
        PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
50539
7bf4f1b5e438 8193302: Javac AssertionError: typeSig ERROR on usage of @Generated
jlahoda
parents: 49580
diff changeset
   195
        LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
52016
9ea22a0f9540 8211148: var in implicit lambdas shouldn't be accepted for source < 11
vromero
parents: 51713
diff changeset
   196
        VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
51563
de411d537aae 8206986: Compiler support for Switch Expressions (Preview)
jlahoda
parents: 51047
diff changeset
   197
        IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
55382
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
   198
        SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
   199
        SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
   200
        SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
59285
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents: 59068
diff changeset
   201
        TEXT_BLOCKS(JDK14, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents: 59068
diff changeset
   202
        PATTERN_MATCHING_IN_INSTANCEOF(JDK14, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents: 59068
diff changeset
   203
        REIFIABLE_TYPES_INSTANCEOF(JDK14, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
7799a51dbe30 8231826: Implement javac changes for pattern matching for instanceof
jlahoda
parents: 59068
diff changeset
   204
        ;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   205
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   206
        enum DiagKind {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   207
            NORMAL,
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   208
            PLURAL;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   209
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   210
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   211
        private final Source minLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   212
        private final Source maxLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   213
        private final Fragment optFragment;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   214
        private final DiagKind optKind;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   215
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   216
        Feature(Source minLevel) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   217
            this(minLevel, null, null);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   218
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   219
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   220
        Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   221
            this(minLevel, MAX, optFragment, optKind);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   222
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   223
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   224
        Feature(Source minLevel, Source maxLevel) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   225
            this(minLevel, maxLevel, null, null);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   226
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   227
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   228
        Feature(Source minLevel, Source maxLevel, Fragment optFragment, DiagKind optKind) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   229
            this.minLevel = minLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   230
            this.maxLevel = maxLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   231
            this.optFragment = optFragment;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   232
            this.optKind = optKind;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   233
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   234
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   235
        public boolean allowedInSource(Source source) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   236
            return source.compareTo(minLevel) >= 0 &&
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   237
                    source.compareTo(maxLevel) <= 0;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   238
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   239
49580
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   240
        public boolean isPlural() {
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   241
            Assert.checkNonNull(optKind);
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   242
            return optKind == DiagKind.PLURAL;
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   243
        }
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   244
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   245
        public Fragment nameFragment() {
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   246
            Assert.checkNonNull(optFragment);
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   247
            return optFragment;
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   248
        }
62b908c9f0e6 8199194: Add javac support for preview features
mcimadamore
parents: 48780
diff changeset
   249
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   250
        public Fragment fragment(String sourceName) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   251
            Assert.checkNonNull(optFragment);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   252
            return optKind == DiagKind.NORMAL ?
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   253
                    Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   254
                    Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   255
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   256
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   257
        public Error error(String sourceName) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   258
            Assert.checkNonNull(optFragment);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   259
            return optKind == DiagKind.NORMAL ?
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   260
                    Errors.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   261
                    Errors.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   262
        }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 10180
diff changeset
   263
    }
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   264
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   265
    public static SourceVersion toSourceVersion(Source source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   266
        switch(source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   267
        case JDK1_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   268
            return RELEASE_2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   269
        case JDK1_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   270
            return RELEASE_3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   271
        case JDK1_4:
06bc494ca11e Initial load
duke
parents:
diff changeset
   272
            return RELEASE_4;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   273
        case JDK5:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   274
            return RELEASE_5;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   275
        case JDK6:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   276
            return RELEASE_6;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   277
        case JDK7:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   278
            return RELEASE_7;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   279
        case JDK8:
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
   280
            return RELEASE_8;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   281
        case JDK9:
22170
62da5257a0a7 8031360: Update langtools code base to use RELEASE_9
darcy
parents: 22167
diff changeset
   282
            return RELEASE_9;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   283
        case JDK10:
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42819
diff changeset
   284
            return RELEASE_10;
48343
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48054
diff changeset
   285
        case JDK11:
d4329843abf4 8173382: Add -source 11 and -target 11 to javac
darcy
parents: 48054
diff changeset
   286
            return RELEASE_11;
50892
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50539
diff changeset
   287
        case JDK12:
a5557f24b4d4 8205615: Start of release updates for JDK 12
darcy
parents: 50539
diff changeset
   288
            return RELEASE_12;
53023
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 52016
diff changeset
   289
        case JDK13:
6879069d9d94 8205626: Start of release updates for JDK 13
darcy
parents: 52016
diff changeset
   290
            return RELEASE_13;
55382
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
   291
        case JDK14:
30b1b7b4dd86 8214546: Start of release updates for JDK 14
darcy
parents: 55318
diff changeset
   292
            return RELEASE_14;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   293
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   294
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   295
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   296
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   297
}