本文整理匯總了Java中com.beust.jcommander.Parameters類的典型用法代碼示例。如果您正苦於以下問題:Java Parameters類的具體用法?Java Parameters怎麽用?Java Parameters使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Parameters類屬於com.beust.jcommander包,在下文中一共展示了Parameters類的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCommandNames
import com.beust.jcommander.Parameters; //導入依賴的package包/類
private static <T extends Command> List<String> getCommandNames(Class<T> tClass) {
Parameters paramAnn = tClass.getAnnotation(Parameters.class);
if (paramAnn.commandNames().length == 0) {
String simpleName = tClass.getClass().getSimpleName();
simpleName = Character.toLowerCase(simpleName.charAt(0)) +
simpleName.substring(1, simpleName.length());
return Collections.singletonList(simpleName);
}
return Arrays.asList(paramAnn.commandNames());
}
示例2: getDescription
import com.beust.jcommander.Parameters; //導入依賴的package包/類
@NotNull
@Override
public String getDescription() {
return Optional.ofNullable(this.getClass().getAnnotation(Parameters.class))
.map(Parameters::commandDescription)
.orElse("");
}
示例3: appendPullRequestComment
import com.beust.jcommander.Parameters; //導入依賴的package包/類
protected void appendPullRequestComment(StringBuilder builder) {
builder.append(COMMAND_COMMENT_INDENT);
Parameters annotation = getClass().getAnnotation(Parameters.class);
if (annotation != null) {
String[] commandNames = annotation.commandNames();
if (commandNames != null && commandNames.length > 0) {
builder.append(commandNames[0]);
}
}
appendPullRequestCommentArguments(builder);
builder.append("\n");
}
示例4: getCommandDescription
import com.beust.jcommander.Parameters; //導入依賴的package包/類
public static String getCommandDescription( JCommander jc) {
Parameters parameters = jc.getObjects().get(0).getClass().getAnnotation(Parameters.class);
if (parameters == null) {
return null;
}
return parameters.commandDescription();
}
示例5: test_commandMap_allCommandsHaveDescriptions
import com.beust.jcommander.Parameters; //導入依賴的package包/類
@Test
public void test_commandMap_allCommandsHaveDescriptions() throws Exception {
for (Map.Entry<String, ? extends Class<? extends Command>> commandEntry :
RegistryTool.COMMAND_MAP.entrySet()) {
Parameters parameters = commandEntry.getValue().getAnnotation(Parameters.class);
assertThat(parameters).isNotNull();
assertThat(parameters.commandDescription()).isNotEmpty();
}
}
示例6: getCommandClasses
import com.beust.jcommander.Parameters; //導入依賴的package包/類
/**
* Returns a list of all annotated command classes.
*
* @return a list of all command classes or an empty {@link List}, if none present
*/
public List<Class<?>> getCommandClasses() {
List<Class<?>> commandClasses = new LinkedList<Class<?>>();
for (Class<?> innerClass : SongbirdDatabaseToolsCli.class.getDeclaredClasses()) {
if (innerClass.isAnnotationPresent(Parameters.class)) {
commandClasses.add(innerClass);
}
}
return commandClasses;
}
示例7: createCommands
import com.beust.jcommander.Parameters; //導入依賴的package包/類
/**
* Creates the command instances and adds them to {@link #commander}.
*
* @return a map mapping command string to command instance (command string in <b>lower case letters</b>)
*/
private Map<String, Object> createCommands() {
Map<String, Object> commandString2Instance = new HashMap<String, Object>();
for (Class<?> innerClass : getCommandClasses()) {
if (innerClass.isAnnotationPresent(Parameters.class) && Object.class.isAssignableFrom(innerClass)) {
Object command = null;
try {
/*
* Create an instance of the inner class relating to this instance of the outer class
*/
command =
innerClass.getDeclaredConstructor(new Class[] { this.getClass() }).newInstance(
new Object[] { this });
} catch (Exception e) { // NOSONAR: Method call preserves exception!
printErrorThrowException(e);
}
String commandStr = innerClass.getSimpleName();
String commandStrLower = commandStr.toLowerCase();
String commandStrUpper = commandStr.toUpperCase();
commandString2Instance.put(commandStrLower, command);
// Add command, define lower and upper version as aliases
commander.addCommand(commandStr, command, commandStrLower, commandStrUpper);
}
}
return commandString2Instance;
}
示例8: getDescription
import com.beust.jcommander.Parameters; //導入依賴的package包/類
private static <T extends Command> String getDescription(Class<T> tClass) {
return Optional.ofNullable(tClass.getAnnotation(Parameters.class))
.map(Parameters::commandDescription)
.orElse("");
}
示例9: process
import com.beust.jcommander.Parameters; //導入依賴的package包/類
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
Map<String, TypeMirror> types = new HashMap<>();
TypeMirror expectedInterfaceType =
processingEnv.getElementUtils().getTypeElement(Command.class.getCanonicalName())
.asType();
PackageElement pkg = null;
for (TypeElement a : annotations) {
for (Element element : roundEnv.getElementsAnnotatedWith(a)) {
Parameters parameters =
Objects.requireNonNull(element.getAnnotation(Parameters.class));
TypeMirror typeMirror = element.asType();
if (pkg == null) {
pkg = processingEnv.getElementUtils().getPackageOf(element);
}
if (!processingEnv.getTypeUtils().isAssignable(typeMirror, expectedInterfaceType)) {
processingEnv.getMessager()
.printMessage(Diagnostic.Kind.ERROR,
String.format("Class %s does not implement %s",
element.getSimpleName(),
Command.class.getCanonicalName()));
}
for (String commandName : extractCommandNames(element.getSimpleName(),
parameters.commandNames())) {
types.put(commandName, typeMirror);
}
}
}
if (!types.isEmpty()) {
try {
writeFile(types, pkg);
}
catch (IOException e) {
processingEnv.getMessager()
.printMessage(Diagnostic.Kind.ERROR,
"Unable to process jeesh annotations: " +
e.getMessage());
}
}
return false;
}
示例10: getParameters
import com.beust.jcommander.Parameters; //導入依賴的package包/類
/**
* Gets the {@link Parameters} annotation from the command.
*
* @return the {@link Parameters} annotation
*/
Parameters getParameters() {
Parameters parameters = this.getClass().getAnnotation(Parameters.class);
Preconditions.checkNotNull(parameters, "There must be @Parameters on the Command class: " + this.getClass());
return parameters;
}
示例11: parseParameters
import com.beust.jcommander.Parameters; //導入依賴的package包/類
private JsonObject parseParameters() {
// get the high level attributes from the annotation for the operation
// (name and description)
final JsonObject op_json = new JsonObject();
final String opId = operation.getId();
op_json.addProperty(
"operationId",
opId);
final Parameters command_annotation = this.operation.getClass().getAnnotation(
Parameters.class);
op_json.addProperty(
"description",
command_annotation.commandDescription());
// iterate over the parameters for this operation and add them to the
// json object
final JsonArray fields_obj = new JsonArray();
final List<RestField<?>> fields = RestFieldFactory.createRestFields(operation.getClass());
for (final RestField<?> field : fields) {
final JsonObject[] field_obj_array = processField(
field.getName(),
field.getType(),
field.getDescription(),
field.isRequired());
if (field_obj_array != null) {
for (final JsonObject field_obj : field_obj_array) {
fields_obj.add(field_obj);
}
}
}
op_json.add(
"parameters",
fields_obj);
// build up the response codes for this operation
final JsonObject resp_json = new JsonObject();
JsonObject codes_json = new JsonObject();
codes_json.addProperty(
"description",
"success");
resp_json.add(
"200",
codes_json);
codes_json = new JsonObject();
codes_json.addProperty(
"description",
"route not found");
resp_json.add(
"404",
codes_json);
codes_json = new JsonObject();
codes_json.addProperty(
"description",
"invalid or null parameter");
resp_json.add(
"500",
codes_json);
op_json.add(
"responses",
resp_json);
return op_json;
}
示例12: getDescription
import com.beust.jcommander.Parameters; //導入依賴的package包/類
public String getDescription() {
Parameters params = supplier.get().getClass().getAnnotation(Parameters.class);
return params == null ? "(No description)" : params.commandDescription();
}
示例13: CliTool
import com.beust.jcommander.Parameters; //導入依賴的package包/類
public CliTool() {
if (!getClass().isAnnotationPresent(Parameters.class)) {
throw new RuntimeException();
}
}
示例14: getNames
import com.beust.jcommander.Parameters; //導入依賴的package包/類
/**
* Gets the names of this command (should be long name first followed by
* short name).
*
* @return list of command names
*/
public List<String> getNames() {
Parameters parameters = getParameters();
String[] commandNames = parameters.commandNames();
return Arrays.asList(commandNames);
}