1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument;
26
27 import static net.sourceforge.plantumldependency.cli.constants.log.ErrorConstants.PROGRAMMING_LANGUAGE_NAME_NULL_ERROR;
28 import static net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument.ProgrammingLanguage.getProgrammingLanguageNamesSet;
29 import static net.sourceforge.plantumldependency.cli.main.option.programminglanguage.argument.ProgrammingLanguage.valueOfIgnoringCase;
30 import static net.sourceforge.plantumldependency.common.constants.CharacterConstants.DOT_CHAR;
31 import static net.sourceforge.plantumldependency.common.utils.string.StringUtils.isNotEmpty;
32 import net.sourceforge.plantumldependency.commoncli.exception.CommandLineException;
33 import net.sourceforge.plantumldependency.commoncli.option.argument.AbstractOptionArgument;
34
35
36
37
38
39
40
41
42
43
44 public class PlantUMLDependencyProgrammingLanguageOptionArgument extends AbstractOptionArgument < ProgrammingLanguage > {
45
46
47 private static final long serialVersionUID = -151684884591596960L;
48
49
50 private static final String MAIN_USAGE = "PROGRAMMING_LANGUAGE";
51
52
53 private static final String USAGE_DESCRIPTION = MAIN_USAGE
54 + " specifies the programming language contains in the source files to analyse. Possible values : "
55 + getProgrammingLanguageNamesSet() + DOT_CHAR;
56
57
58
59
60
61
62
63
64 public PlantUMLDependencyProgrammingLanguageOptionArgument(final boolean optionArgumentIsMandatory) {
65 super(optionArgumentIsMandatory, new StringBuilder(USAGE_DESCRIPTION));
66 }
67
68
69
70
71
72
73 @Override
74 protected String getMainUsageDescription() {
75 return MAIN_USAGE;
76 }
77
78
79
80
81
82
83 @Override
84 public ProgrammingLanguage parseArgument(final String argument) throws CommandLineException {
85 ProgrammingLanguage language = null;
86
87 if (isNotEmpty(argument)) {
88 try {
89 language = valueOfIgnoringCase(argument.toUpperCase());
90 } catch (final IllegalArgumentException e) {
91 throw new CommandLineException(e.getMessage(), e);
92 }
93 } else {
94 throw new CommandLineException(PROGRAMMING_LANGUAGE_NAME_NULL_ERROR);
95 }
96
97 return language;
98 }
99 }