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.util.List; 24 25 /** 26 * Applied to an {@link OptionsBase} subclass to indicate that all of its options fields have types 27 * chosen from {@link #coreTypes}. Any subclasses of the class to which it's applied must also 28 * satisfy the same property. 29 * 30 * <p>Options classes with this annotation are serializable and deeply immutable, except that the 31 * fields of the options class can be reassigned (although this is bad practice). 32 * 33 * <p>Note that {@link Option#allowMultiple} is not allowed for options in classes with this 34 * annotation, since their type is {@link List}. 35 */ 36 @Target({ElementType.TYPE}) 37 @Retention(RetentionPolicy.RUNTIME) 38 @Inherited 39 public @interface UsesOnlyCoreTypes { 40 41 /** 42 * These are the core options field types. They all have default converters, are deeply immutable, 43 * and are serializable. 44 * 45 * Lists are not considered core types, so {@link Option#allowMultiple} options are not permitted. 46 */ 47 public static final ImmutableList<Class<?>> CORE_TYPES = ImmutableList.of( 48 // 1:1 correspondence with Converters.DEFAULT_CONVERTERS. 49 String.class, 50 int.class, 51 long.class, 52 double.class, 53 boolean.class, 54 TriState.class, 55 Void.class 56 ); 57 } 58