Coverage Report - com.lexicalscope.jewel.cli.OptionAnnotationAdapter
 
Classes in this File Line Coverage Branch Coverage Complexity
OptionAnnotationAdapter
100%
19/19
100%
6/6
1.25
 
 1  
 package com.lexicalscope.jewel.cli;
 2  
 
 3  
 import static java.util.Arrays.asList;
 4  
 
 5  
 import java.util.ArrayList;
 6  
 import java.util.List;
 7  
 
 8  
 import com.lexicalscope.fluentreflection.FluentClass;
 9  
 import com.lexicalscope.fluentreflection.FluentMethod;
 10  
 
 11  
 /*
 12  
  * Copyright 2011 Tim Wood
 13  
  *
 14  
  * Licensed under the Apache License, Version 2.0 (the "License");
 15  
  * you may not use this file except in compliance with the License.
 16  
  * You may obtain a copy of the License at
 17  
  *
 18  
  * http://www.apache.org/licenses/LICENSE-2.0
 19  
  *
 20  
  * Unless required by applicable law or agreed to in writing, software
 21  
  * distributed under the License is distributed on an "AS IS" BASIS,
 22  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 23  
  * See the License for the specific language governing permissions and
 24  
  * limitations under the License.
 25  
  */
 26  
 
 27  
 class OptionAnnotationAdapter extends AbstractOptionAdapter {
 28  
     private final Option option;
 29  
 
 30  
     OptionAnnotationAdapter(
 31  
             final FluentClass<?> klass,
 32  
             final FluentMethod method) {
 33  514
         super(klass, method);
 34  514
         this.option = method.annotation(Option.class);
 35  514
     }
 36  
 
 37  
     @Override public String description() {
 38  246
         return option.description().trim();
 39  
     }
 40  
 
 41  
     @Override public String pattern() {
 42  324
         return option.pattern();
 43  
     }
 44  
 
 45  
     @Override public boolean defaultToNull() {
 46  2082
         return option.defaultToNull();
 47  
     }
 48  
 
 49  
     @Override public String[] defaultValue() {
 50  1034
         return option.defaultValue();
 51  
     }
 52  
 
 53  
     public List<String> shortName() {
 54  620
         final List<String> shortNames = new ArrayList<String>();
 55  1262
         for (final String element : option.shortName()) {
 56  642
             final String shortName = element.trim();
 57  642
             if (shortName.length() > 0) {
 58  132
                 shortNames.add(element.substring(0, 1));
 59  
             }
 60  
         }
 61  620
         return shortNames;
 62  
     }
 63  
 
 64  
     public List<String> longName() {
 65  1138
         return option.longName().length == 0
 66  
                 ? asList(method.property())
 67  
                 : asList(option.longName());
 68  
     }
 69  
 
 70  
     public boolean helpRequest() {
 71  232
         return option.helpRequest();
 72  
     }
 73  
 
 74  
     @Override public boolean isHidden() {
 75  92
         return option.hidden();
 76  
     }
 77  
 
 78  
     @Override public int minimum() {
 79  582
         return option.minimum();
 80  
     }
 81  
 
 82  
     @Override public int exactly() {
 83  1136
         return option.exactly();
 84  
     }
 85  
 
 86  
     @Override public int maximum() {
 87  1600
         return option.maximum();
 88  
     }
 89  
 }