Home | History | Annotate | Download | only in options
      1 // Copyright 2017 The Bazel Authors. All rights reserved.
      2 //
      3 // Licensed under the Apache License, Version 2.0 (the "License");
      4 // you may not use this file except in compliance with the License.
      5 // You may obtain a copy of the License at
      6 //
      7 //    http://www.apache.org/licenses/LICENSE-2.0
      8 //
      9 // Unless required by applicable law or agreed to in writing, software
     10 // distributed under the License is distributed on an "AS IS" BASIS,
     11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 // See the License for the specific language governing permissions and
     13 // limitations under the License.
     14 
     15 package com.google.devtools.common.options;
     16 
     17 import com.google.common.collect.ImmutableList;
     18 import java.lang.annotation.ElementType;
     19 import java.lang.annotation.Inherited;
     20 import java.lang.annotation.Retention;
     21 import java.lang.annotation.RetentionPolicy;
     22 import java.lang.annotation.Target;
     23 import java.time.Duration;
     24 import java.util.List;
     25 
     26 /**
     27  * Applied to an {@link OptionsBase} subclass to indicate that all of its options fields have types
     28  * chosen from {@link #coreTypes}. Any subclasses of the class to which it's applied must also
     29  * satisfy the same property.
     30  *
     31  * <p>Options classes with this annotation are serializable and deeply immutable, except that the
     32  * fields of the options class can be reassigned (although this is bad practice).
     33  *
     34  * <p>Note that {@link Option#allowMultiple} is not allowed for options in classes with this
     35  * annotation, since their type is {@link List}.
     36  */
     37 @Target({ElementType.TYPE})
     38 @Retention(RetentionPolicy.RUNTIME)
     39 @Inherited
     40 public @interface UsesOnlyCoreTypes {
     41 
     42   /**
     43    * These are the core options field types. They all have default converters, are deeply immutable,
     44    * and are serializable.
     45    *
     46    * Lists are not considered core types, so {@link Option#allowMultiple} options are not permitted.
     47    */
     48   public static final ImmutableList<Class<?>> CORE_TYPES = ImmutableList.of(
     49       // 1:1 correspondence with Converters.DEFAULT_CONVERTERS.
     50       String.class,
     51       int.class,
     52       long.class,
     53       double.class,
     54       boolean.class,
     55       TriState.class,
     56       Void.class,
     57       Duration.class
     58   );
     59 }
     60