本文整理汇总了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);
}