com.beust.jcommander.ParametersDelegate Java Examples
The following examples show how to use
com.beust.jcommander.ParametersDelegate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeowaveOperationGrpcGenerator.java From geowave with Apache License 2.0 | 6 votes |
public String processOperation(final Class<?> operation, final ProcessOperationResult pr) throws IOException { final Field[] fields = operation.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { if (fields[i].isAnnotationPresent(Parameter.class)) { final String type = GeoWaveGrpcOperationParser.getGrpcType(fields[i].getType()); pr.message += "\n\t" + type; if (type.equalsIgnoreCase("repeated")) { final ParameterizedType parameterizedType = (ParameterizedType) fields[i].getGenericType(); final Type actualType = parameterizedType.getActualTypeArguments()[0]; pr.message += " " + GeoWaveGrpcOperationParser.getGrpcType(actualType.getClass()); } pr.message += " " + fields[i].getName() + " = " + pr.currFieldPosition + ";"; pr.currFieldPosition++; } if (fields[i].isAnnotationPresent(ParametersDelegate.class)) { processOperation(fields[i].getType(), pr); } } return ""; }
Example #2
Source File: ReadmeUtils.java From rdf2x with Apache License 2.0 | 4 votes |
private static void printConfig(Class configClass) throws IllegalAccessException, InstantiationException { Field[] fields = configClass.getDeclaredFields(); System.out.println(); System.out.println("### " + configClass.getSimpleName()); System.out.println(); Object defaultConfig = configClass.newInstance(); System.out.println("|Name|Default|Description|"); System.out.println("|---|---|---|"); try { for (Field field : fields) { field.setAccessible(true); StringBuilder sb = new StringBuilder(); sb.append("|"); Parameter param = field.getDeclaredAnnotation(Parameter.class); if (param != null) { String names = Stream.of(param.names()) .collect(Collectors.joining(", ")); // name sb.append(names).append("|"); // default sb.append(param.required() ? "**required**" : field.get(defaultConfig) + " ").append("|"); // description sb.append(param.description()).append("|"); System.out.println(sb.toString()); } ParametersDelegate delegate = field.getDeclaredAnnotation(ParametersDelegate.class); if (delegate != null) { printConfig(field.getType()); } } } catch (IllegalAccessException e) { e.printStackTrace(); } }