src/jdk.compiler/share/classes/com/sun/tools/javac/code/Source.java
author jlahoda
Wed, 07 Feb 2018 16:49:24 +0100
changeset 48776 107413b070b9
parent 48054 702043a4cdeb
child 48780 eb5572d58bb1
permissions -rw-r--r--
8194764: javac incorrectly flags deprecated for removal imports Summary: Fixing source range for the Source.Feature.DEPRECATE_ON_IMPORT Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
48776
107413b070b9 8194764: javac incorrectly flags deprecated for removal imports
jlahoda
parents: 48054
diff changeset
     2
 * Copyright (c) 2002, 2018, 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
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42819
diff changeset
    81
    /** 1.10 covers the to be determined language features that will be added in JDK 10. */
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
    82
    JDK10("10");
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 22151
diff changeset
    84
    private static final Context.Key<Source> sourceKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    85
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
    public static Source instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    87
        Source instance = context.get(sourceKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
    88
        if (instance == null) {
06bc494ca11e Initial load
duke
parents:
diff changeset
    89
            Options options = Options.instance(context);
6721
d92073844278 6988436: Cleanup javac option handling
jjg
parents: 6592
diff changeset
    90
            String sourceString = options.get(SOURCE);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    91
            if (sourceString != null) instance = lookup(sourceString);
06bc494ca11e Initial load
duke
parents:
diff changeset
    92
            if (instance == null) instance = DEFAULT;
06bc494ca11e Initial load
duke
parents:
diff changeset
    93
            context.put(sourceKey, instance);
06bc494ca11e Initial load
duke
parents:
diff changeset
    94
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
    95
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
    96
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
    97
06bc494ca11e Initial load
duke
parents:
diff changeset
    98
    public final String name;
06bc494ca11e Initial load
duke
parents:
diff changeset
    99
22151
cb8daa93eeb1 8028545: Add -source 9 and -target 9 to javac
darcy
parents: 15717
diff changeset
   100
    private static final Map<String,Source> tab = new HashMap<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
    static {
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        for (Source s : values()) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            tab.put(s.name, s);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        }
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   105
        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
   106
        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
   107
        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
   108
        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
   109
        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
   110
        tab.put("1.10", JDK10); // Make 10 an alias for 1.10
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   111
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
    private Source(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   114
        this.name = name;
06bc494ca11e Initial load
duke
parents:
diff changeset
   115
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   116
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   117
    public static final Source MIN = Source.JDK6;
25445
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   118
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   119
    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
   120
603f0c93d5c9 8011044: Remove support for 1.5 and earlier source and target options
ntoda
parents: 25283
diff changeset
   121
    public static final Source DEFAULT = MAX;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   122
06bc494ca11e Initial load
duke
parents:
diff changeset
   123
    public static Source lookup(String name) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
        return tab.get(name);
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   126
06bc494ca11e Initial load
duke
parents:
diff changeset
   127
    public Target requiredTarget() {
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   128
        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
   129
        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
   130
        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
   131
        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
   132
        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
   133
        if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
        return Target.JDK1_1;
06bc494ca11e Initial load
duke
parents:
diff changeset
   136
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   137
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   138
    /**
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   139
     * 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
   140
     * 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
   141
     * 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
   142
     */
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   143
    public enum Feature {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   144
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   145
        DIAMOND(JDK7, Fragments.FeatureDiamond, DiagKind.NORMAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   146
        MULTICATCH(JDK7, Fragments.FeatureMulticatch, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   147
        IMPROVED_RETHROW_ANALYSIS(JDK7),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   148
        IMPROVED_CATCH_ANALYSIS(JDK7),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   149
        MODULES(JDK9, Fragments.FeatureModules, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   150
        TRY_WITH_RESOURCES(JDK7, Fragments.FeatureTryWithResources, DiagKind.NORMAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   151
        EFFECTIVELY_FINAL_VARIABLES_IN_TRY_WITH_RESOURCES(JDK9, Fragments.FeatureVarInTryWithResources, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   152
        BINARY_LITERALS(JDK7, Fragments.FeatureBinaryLit, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   153
        UNDERSCORES_IN_LITERALS(JDK7, Fragments.FeatureUnderscoreLit, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   154
        STRINGS_IN_SWITCH(JDK7, Fragments.FeatureStringSwitch, DiagKind.PLURAL),
48776
107413b070b9 8194764: javac incorrectly flags deprecated for removal imports
jlahoda
parents: 48054
diff changeset
   155
        DEPRECATION_ON_IMPORT(MIN, JDK8),
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   156
        SIMPLIFIED_VARARGS(JDK7),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   157
        OBJECT_TO_PRIMITIVE_CAST(JDK7),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   158
        ENFORCE_THIS_DOT_INIT(JDK7),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   159
        POLY(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   160
        LAMBDA(JDK8, Fragments.FeatureLambda, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   161
        METHOD_REFERENCES(JDK8, Fragments.FeatureMethodReferences, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   162
        DEFAULT_METHODS(JDK8, Fragments.FeatureDefaultMethods, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   163
        STATIC_INTERFACE_METHODS(JDK8, Fragments.FeatureStaticIntfMethods, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   164
        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
   165
        STRICT_METHOD_CLASH_CHECK(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   166
        EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   167
        TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   168
        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
   169
        REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   170
        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
   171
        GRAPH_INFERENCE(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   172
        FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   173
        POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   174
        MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   175
        PRIVATE_SAFE_VARARGS(JDK9),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   176
        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
   177
        UNDERSCORE_IDENTIFIER(MIN, JDK8),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   178
        PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   179
        LOCAL_VARIABLE_TYPE_INFERENCE(JDK10);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   180
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   181
        enum DiagKind {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   182
            NORMAL,
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   183
            PLURAL;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   184
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   185
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   186
        private final Source minLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   187
        private final Source maxLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   188
        private final Fragment optFragment;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   189
        private final DiagKind optKind;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   190
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   191
        Feature(Source minLevel) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   192
            this(minLevel, null, null);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   193
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   194
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   195
        Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   196
            this(minLevel, MAX, optFragment, optKind);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   197
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   198
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   199
        Feature(Source minLevel, Source maxLevel) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   200
            this(minLevel, maxLevel, null, null);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   201
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   202
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   203
        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
   204
            this.minLevel = minLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   205
            this.maxLevel = maxLevel;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   206
            this.optFragment = optFragment;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   207
            this.optKind = optKind;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   208
        }
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
        public boolean allowedInSource(Source source) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   211
            return source.compareTo(minLevel) >= 0 &&
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   212
                    source.compareTo(maxLevel) <= 0;
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   213
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   214
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   215
        public Fragment fragment(String sourceName) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   216
            Assert.checkNonNull(optFragment);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   217
            return optKind == DiagKind.NORMAL ?
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   218
                    Fragments.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   219
                    Fragments.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   220
        }
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   221
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   222
        public Error error(String sourceName) {
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   223
            Assert.checkNonNull(optFragment);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   224
            return optKind == DiagKind.NORMAL ?
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   225
                    Errors.FeatureNotSupportedInSource(optFragment, sourceName, minLevel.name) :
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   226
                    Errors.FeatureNotSupportedInSourcePlural(optFragment, sourceName, minLevel.name);
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   227
        }
11143
9dbe313bfb74 7115050: Add parser support for lambda expressions
mcimadamore
parents: 10180
diff changeset
   228
    }
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   229
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
    public static SourceVersion toSourceVersion(Source source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   231
        switch(source) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   232
        case JDK1_2:
06bc494ca11e Initial load
duke
parents:
diff changeset
   233
            return RELEASE_2;
06bc494ca11e Initial load
duke
parents:
diff changeset
   234
        case JDK1_3:
06bc494ca11e Initial load
duke
parents:
diff changeset
   235
            return RELEASE_3;
06bc494ca11e Initial load
duke
parents:
diff changeset
   236
        case JDK1_4:
06bc494ca11e Initial load
duke
parents:
diff changeset
   237
            return RELEASE_4;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   238
        case JDK5:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   239
            return RELEASE_5;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   240
        case JDK6:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   241
            return RELEASE_6;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   242
        case JDK7:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   243
            return RELEASE_7;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   244
        case JDK8:
10180
b293c1f36ac4 7025784: Add SourceVersion.RELEASE_8
darcy
parents: 9595
diff changeset
   245
            return RELEASE_8;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   246
        case JDK9:
22170
62da5257a0a7 8031360: Update langtools code base to use RELEASE_9
darcy
parents: 22167
diff changeset
   247
            return RELEASE_9;
48054
702043a4cdeb 8189749: Devise strategy for making source level checks more uniform
mcimadamore
parents: 47268
diff changeset
   248
        case JDK10:
43646
017aba6e9260 8028544: Add SourceVersion.RELEASE_10
darcy
parents: 42819
diff changeset
   249
            return RELEASE_10;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   250
        default:
06bc494ca11e Initial load
duke
parents:
diff changeset
   251
            return null;
06bc494ca11e Initial load
duke
parents:
diff changeset
   252
        }
06bc494ca11e Initial load
duke
parents:
diff changeset
   253
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   254
}