Coverage Report - com.lexicalscope.jewel.cli.ParsedOptionSpecificationImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ParsedOptionSpecificationImpl
100%
21/21
100%
12/12
1.333
 
 1  
 /*
 2  
  * Copyright 2009 Tim Wood
 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 http://www.apache.org/licenses/LICENSE-2.0
 7  
  *
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package com.lexicalscope.jewel.cli;
 15  
 
 16  
 import com.lexicalscope.jewel.cli.specification.ParsedOptionSpecification;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 class ParsedOptionSpecificationImpl extends AbstractOptionSpecification implements ParsedOptionSpecification {
 22  
     private final OptionAnnotationAdapter optionAnnotation;
 23  
 
 24  
     ParsedOptionSpecificationImpl(final OptionAnnotationAdapter annotation) {
 25  514
         super(annotation);
 26  512
         optionAnnotation = annotation;
 27  512
         for (final String longName : annotation.longName()) {
 28  522
             if (longName.trim().isEmpty())
 29  
             {
 30  2
                 throw new InvalidOptionSpecificationException(String.format(
 31  
                         "option %s long name cannot be blank",
 32  
                         getMethod()));
 33  
             }
 34  520
         }
 35  510
     }
 36  
 
 37  
     @Override public List<String> getLongName() {
 38  626
         return optionAnnotation.longName();
 39  
     }
 40  
 
 41  
     @Override public List<String> getShortNames() {
 42  620
         return optionAnnotation.shortName();
 43  
     }
 44  
 
 45  
     @Override public List<String> getNames() {
 46  430
         final List<String> result = new ArrayList<String>(getShortNames());
 47  430
         result.addAll(getLongName());
 48  430
         return result;
 49  
     }
 50  
 
 51  
     @Override public boolean hasShortName() {
 52  4
         return !getShortNames().isEmpty();
 53  
     }
 54  
 
 55  
     @Override public boolean isHelpOption() {
 56  232
         return optionAnnotation.helpRequest();
 57  
     }
 58  
 
 59  
     @Override public String getPattern() {
 60  324
         return annotation.pattern();
 61  
     }
 62  
 
 63  
     @Override public boolean hasValue() {
 64  470
         return !isBoolean();
 65  
     }
 66  
 
 67  
     @Override public final boolean isBoolean() {
 68  1448
         return getType().isAssignableFrom(Boolean.class) || getType().isAssignableFrom(boolean.class);
 69  
     }
 70  
 
 71  
     @Override public String toString() {
 72  72
         return new ParsedOptionSummary(this).toString();
 73  
     }
 74  
 
 75  
     @Override public boolean allowedValue(final String value) {
 76  182
         return value.matches(getPattern());
 77  
     }
 78  
 
 79  
     @Override public void reportMissingTo(final ValidationErrorBuilder validationErrorBuilder) {
 80  14
        validationErrorBuilder.missingOption(this);
 81  14
     }
 82  
 }