< prev index next >

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

Print this page




  77 
  78     /** 1.9 modularity. */
  79     JDK9("9"),
  80 
  81     /** 1.10 local-variable type inference (var). */
  82     JDK10("10"),
  83 
  84     /** 1.11 local-variable syntax for lambda parameters */
  85     JDK11("11"),
  86 
  87     /** 12, no language features; switch expression in preview */
  88     JDK12("12"),
  89 
  90     /**
  91      * 13, no language features; text blocks and revised switch
  92      * expressions in preview
  93      */
  94     JDK13("13"),
  95 
  96     /**
  97      * 14, switch expressions

  98      */
  99     JDK14("14");





 100 
 101     private static final Context.Key<Source> sourceKey = new Context.Key<>();
 102 
 103     public static Source instance(Context context) {
 104         Source instance = context.get(sourceKey);
 105         if (instance == null) {
 106             Options options = Options.instance(context);
 107             String sourceString = options.get(SOURCE);
 108             if (sourceString != null) instance = lookup(sourceString);
 109             if (instance == null) instance = DEFAULT;
 110             context.put(sourceKey, instance);
 111         }
 112         return instance;
 113     }
 114 
 115     public final String name;
 116 
 117     private static final Map<String,Source> tab = new HashMap<>();
 118     static {
 119         for (Source s : values()) {


 130 
 131     private Source(String name) {
 132         this.name = name;
 133     }
 134 
 135     public static final Source MIN = Source.JDK7;
 136 
 137     private static final Source MAX = values()[values().length - 1];
 138 
 139     public static final Source DEFAULT = MAX;
 140 
 141     public static Source lookup(String name) {
 142         return tab.get(name);
 143     }
 144 
 145     public boolean isSupported() {
 146         return this.compareTo(MIN) >= 0;
 147     }
 148 
 149     public Target requiredTarget() {

 150         if (this.compareTo(JDK14) >= 0) return Target.JDK1_14;
 151         if (this.compareTo(JDK13) >= 0) return Target.JDK1_13;
 152         if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
 153         if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
 154         if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
 155         if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
 156         if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
 157         if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
 158         if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
 159         if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
 160         if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
 161         return Target.JDK1_1;
 162     }
 163 
 164     /**
 165      * Models a feature of the Java programming language. Each feature can be associated with a
 166      * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
 167      * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
 168      */
 169     public enum Feature {


 181         STRICT_METHOD_CLASH_CHECK(JDK8),
 182         EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
 183         TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
 184         ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
 185         REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
 186         INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
 187         GRAPH_INFERENCE(JDK8),
 188         FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
 189         POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
 190         MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
 191         PRIVATE_SAFE_VARARGS(JDK9),
 192         DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
 193         UNDERSCORE_IDENTIFIER(MIN, JDK8),
 194         PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
 195         LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
 196         VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
 197         IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
 198         SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
 199         SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
 200         SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
 201         TEXT_BLOCKS(JDK14, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
 202         PATTERN_MATCHING_IN_INSTANCEOF(JDK14, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
 203         REIFIABLE_TYPES_INSTANCEOF(JDK14, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
 204         RECORDS(JDK14, Fragments.FeatureRecords, DiagKind.PLURAL),
 205         ;
 206 
 207         enum DiagKind {
 208             NORMAL,
 209             PLURAL;
 210         }
 211 
 212         private final Source minLevel;
 213         private final Source maxLevel;
 214         private final Fragment optFragment;
 215         private final DiagKind optKind;
 216 
 217         Feature(Source minLevel) {
 218             this(minLevel, null, null);
 219         }
 220 
 221         Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
 222             this(minLevel, MAX, optFragment, optKind);
 223         }
 224 


 274         case JDK5:
 275             return RELEASE_5;
 276         case JDK6:
 277             return RELEASE_6;
 278         case JDK7:
 279             return RELEASE_7;
 280         case JDK8:
 281             return RELEASE_8;
 282         case JDK9:
 283             return RELEASE_9;
 284         case JDK10:
 285             return RELEASE_10;
 286         case JDK11:
 287             return RELEASE_11;
 288         case JDK12:
 289             return RELEASE_12;
 290         case JDK13:
 291             return RELEASE_13;
 292         case JDK14:
 293             return RELEASE_14;


 294         default:
 295             return null;
 296         }
 297     }
 298 }


  77 
  78     /** 1.9 modularity. */
  79     JDK9("9"),
  80 
  81     /** 1.10 local-variable type inference (var). */
  82     JDK10("10"),
  83 
  84     /** 1.11 local-variable syntax for lambda parameters */
  85     JDK11("11"),
  86 
  87     /** 12, no language features; switch expression in preview */
  88     JDK12("12"),
  89 
  90     /**
  91      * 13, no language features; text blocks and revised switch
  92      * expressions in preview
  93      */
  94     JDK13("13"),
  95 
  96     /**
  97      * 14, switch expressions; pattern matching, records, and revised
  98      * text blocks in preview
  99      */
 100     JDK14("14"),
 101 
 102     /**
 103       * 15, tbd
 104       */
 105     JDK15("15");
 106 
 107     private static final Context.Key<Source> sourceKey = new Context.Key<>();
 108 
 109     public static Source instance(Context context) {
 110         Source instance = context.get(sourceKey);
 111         if (instance == null) {
 112             Options options = Options.instance(context);
 113             String sourceString = options.get(SOURCE);
 114             if (sourceString != null) instance = lookup(sourceString);
 115             if (instance == null) instance = DEFAULT;
 116             context.put(sourceKey, instance);
 117         }
 118         return instance;
 119     }
 120 
 121     public final String name;
 122 
 123     private static final Map<String,Source> tab = new HashMap<>();
 124     static {
 125         for (Source s : values()) {


 136 
 137     private Source(String name) {
 138         this.name = name;
 139     }
 140 
 141     public static final Source MIN = Source.JDK7;
 142 
 143     private static final Source MAX = values()[values().length - 1];
 144 
 145     public static final Source DEFAULT = MAX;
 146 
 147     public static Source lookup(String name) {
 148         return tab.get(name);
 149     }
 150 
 151     public boolean isSupported() {
 152         return this.compareTo(MIN) >= 0;
 153     }
 154 
 155     public Target requiredTarget() {
 156         if (this.compareTo(JDK15) >= 0) return Target.JDK1_15;
 157         if (this.compareTo(JDK14) >= 0) return Target.JDK1_14;
 158         if (this.compareTo(JDK13) >= 0) return Target.JDK1_13;
 159         if (this.compareTo(JDK12) >= 0) return Target.JDK1_12;
 160         if (this.compareTo(JDK11) >= 0) return Target.JDK1_11;
 161         if (this.compareTo(JDK10) >= 0) return Target.JDK1_10;
 162         if (this.compareTo(JDK9) >= 0) return Target.JDK1_9;
 163         if (this.compareTo(JDK8) >= 0) return Target.JDK1_8;
 164         if (this.compareTo(JDK7) >= 0) return Target.JDK1_7;
 165         if (this.compareTo(JDK6) >= 0) return Target.JDK1_6;
 166         if (this.compareTo(JDK5) >= 0) return Target.JDK1_5;
 167         if (this.compareTo(JDK1_4) >= 0) return Target.JDK1_4;
 168         return Target.JDK1_1;
 169     }
 170 
 171     /**
 172      * Models a feature of the Java programming language. Each feature can be associated with a
 173      * minimum source level, a maximum source level and a diagnostic fragment describing the feature,
 174      * which is used to generate error messages of the kind {@code feature XYZ not supported in source N}.
 175      */
 176     public enum Feature {


 188         STRICT_METHOD_CLASH_CHECK(JDK8),
 189         EFFECTIVELY_FINAL_IN_INNER_CLASSES(JDK8),
 190         TYPE_ANNOTATIONS(JDK8, Fragments.FeatureTypeAnnotations, DiagKind.PLURAL),
 191         ANNOTATIONS_AFTER_TYPE_PARAMS(JDK8, Fragments.FeatureAnnotationsAfterTypeParams, DiagKind.PLURAL),
 192         REPEATED_ANNOTATIONS(JDK8, Fragments.FeatureRepeatableAnnotations, DiagKind.PLURAL),
 193         INTERSECTION_TYPES_IN_CAST(JDK8, Fragments.FeatureIntersectionTypesInCast, DiagKind.PLURAL),
 194         GRAPH_INFERENCE(JDK8),
 195         FUNCTIONAL_INTERFACE_MOST_SPECIFIC(JDK8),
 196         POST_APPLICABILITY_VARARGS_ACCESS_CHECK(JDK8),
 197         MAP_CAPTURES_TO_BOUNDS(MIN, JDK7),
 198         PRIVATE_SAFE_VARARGS(JDK9),
 199         DIAMOND_WITH_ANONYMOUS_CLASS_CREATION(JDK9, Fragments.FeatureDiamondAndAnonClass, DiagKind.NORMAL),
 200         UNDERSCORE_IDENTIFIER(MIN, JDK8),
 201         PRIVATE_INTERFACE_METHODS(JDK9, Fragments.FeaturePrivateIntfMethods, DiagKind.PLURAL),
 202         LOCAL_VARIABLE_TYPE_INFERENCE(JDK10),
 203         VAR_SYNTAX_IMPLICIT_LAMBDAS(JDK11, Fragments.FeatureVarSyntaxInImplicitLambda, DiagKind.PLURAL),
 204         IMPORT_ON_DEMAND_OBSERVABLE_PACKAGES(JDK1_2, JDK8),
 205         SWITCH_MULTIPLE_CASE_LABELS(JDK14, Fragments.FeatureMultipleCaseLabels, DiagKind.PLURAL),
 206         SWITCH_RULE(JDK14, Fragments.FeatureSwitchRules, DiagKind.PLURAL),
 207         SWITCH_EXPRESSION(JDK14, Fragments.FeatureSwitchExpressions, DiagKind.PLURAL),
 208         TEXT_BLOCKS(JDK15, Fragments.FeatureTextBlocks, DiagKind.PLURAL),
 209         PATTERN_MATCHING_IN_INSTANCEOF(JDK15, Fragments.FeaturePatternMatchingInstanceof, DiagKind.NORMAL),
 210         REIFIABLE_TYPES_INSTANCEOF(JDK15, Fragments.FeatureReifiableTypesInstanceof, DiagKind.PLURAL),
 211         RECORDS(JDK15, Fragments.FeatureRecords, DiagKind.PLURAL),
 212         ;
 213 
 214         enum DiagKind {
 215             NORMAL,
 216             PLURAL;
 217         }
 218 
 219         private final Source minLevel;
 220         private final Source maxLevel;
 221         private final Fragment optFragment;
 222         private final DiagKind optKind;
 223 
 224         Feature(Source minLevel) {
 225             this(minLevel, null, null);
 226         }
 227 
 228         Feature(Source minLevel, Fragment optFragment, DiagKind optKind) {
 229             this(minLevel, MAX, optFragment, optKind);
 230         }
 231 


 281         case JDK5:
 282             return RELEASE_5;
 283         case JDK6:
 284             return RELEASE_6;
 285         case JDK7:
 286             return RELEASE_7;
 287         case JDK8:
 288             return RELEASE_8;
 289         case JDK9:
 290             return RELEASE_9;
 291         case JDK10:
 292             return RELEASE_10;
 293         case JDK11:
 294             return RELEASE_11;
 295         case JDK12:
 296             return RELEASE_12;
 297         case JDK13:
 298             return RELEASE_13;
 299         case JDK14:
 300             return RELEASE_14;
 301         case JDK15:
 302             return RELEASE_15;
 303         default:
 304             return null;
 305         }
 306     }
 307 }
< prev index next >