• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.loganalysis.util.config;
18 
19 import java.lang.annotation.ElementType;
20 import java.lang.annotation.Retention;
21 import java.lang.annotation.RetentionPolicy;
22 import java.lang.annotation.Target;
23 import java.util.Collection;
24 import java.util.Map;
25 
26 /**
27  * Annotates a field as representing a {@link IConfiguration} option.
28  */
29 //TODO: Use libTF once this is copied over.
30 @Retention(RetentionPolicy.RUNTIME)
31 @Target(ElementType.FIELD)
32 public @interface Option {
33 
34     static final char NO_SHORT_NAME = '0';
35 
36     public enum Importance {
37         /** the option should never be treated as important */
38         NEVER,
39         /** the option should be treated as important only if it has no value */
40         IF_UNSET,
41         /** the option should always be treated as important */
42         ALWAYS;
43     }
44 
45     /**
46      * The mandatory unique name for this option.
47      * <p/>
48      * This will map to a command line argument prefixed with two '-' characters.
49      * For example, an {@link Option} with name 'help' would be specified with '--help' on the
50      * command line.
51      * <p/>
52      * Names may not contain a colon eg ':'.
53      */
name()54     String name();
55 
56     /**
57      * Optional abbreviated name for option.
58      * This will map to a command line argument prefixed with a single '-'.
59      * e.g. "-h" where h = shortName.
60      *
61      * '0' is reserved to mean the option has no shortName.
62      **/
shortName()63     char shortName() default NO_SHORT_NAME;
64 
65     /**
66      * User friendly description of the option.
67      */
description()68     String description() default "";
69 
70     /**
71      * The importance of the option.
72      * <p/>
73      * An option deemed 'important' will be displayed in the abbreviated help output. Help for an
74      * unimportant option will only be displayed in the full help text.
75      */
importance()76     Importance importance() default Importance.NEVER;
77 
78     /**
79      * Whether the option is mandatory or optional.
80      * <p />
81      * The configuration framework will throw a {@code ConfigurationException} if either of the
82      * following is true of a mandatory field after options have been parsed from all sources:
83      * <ul>
84      *   <li>The field is {@code null}.</li>
85      *   <li>The field is an empty {@link java.util.Collection}.</li>
86      * </ul>
87      */
mandatory()88      boolean mandatory() default false;
89 
90     /**
91      * Controls the behavior when an option is specified multiple times.  Note that this rule is
92      * ignored completely for options that are {@link Collection}s or {@link Map}s.
93      */
updateRule()94     OptionUpdateRule updateRule() default OptionUpdateRule.LAST;
95 }
96