HelpBlock getHelp() { HelpBlock root = new HelpBlock(); commands.keySet().stream().sorted().map(commands::get).forEach(method -> root .addChild(getHelp(method.getDeclaredAnnotation(CliCommand.class), null, null))); return root; }
public CommandRequest(final GfshParseResult parseResult, final Map<String, String> env, final List<File> fileList) { assert parseResult != null : "The Gfsh ParseResult cannot be null!"; assert env != null : "The reference to the Gfsh CLI environment cannot be null!"; this.env = env; this.fileList = fileList; this.parseResult = parseResult; CliMetaData metaData = parseResult.getMethod().getDeclaredAnnotation(CliMetaData.class); this.downloadFile = (metaData != null && metaData.isFileDownloadOverHttp()); }
/** * get help string for a specific command, or a brief description of all the commands if buffer is * null or empty */ public String getHelp(String buffer, int terminalWidth) { if (StringUtils.isBlank(buffer)) { return getHelp().toString(terminalWidth); } Method method = commands.get(buffer); if (method == null) { return "no help exists for this command."; } HelpBlock helpBlock = getHelp(method.getDeclaredAnnotation(CliCommand.class), method.getParameterAnnotations(), method.getParameterTypes()); return helpBlock.toString(terminalWidth); }
public ConfigDescriptor getConfigDescriptor(Object configurationProxy) { Class<?> inter = configurationProxy.getClass().getInterfaces()[0]; ConfigGroup group = inter.getAnnotation(ConfigGroup.class); if (group == null) { throw new IllegalArgumentException("Not a config group"); } final List<ConfigItemDescriptor> items = Arrays.stream(inter.getMethods()) .filter(m -> m.getParameterCount() == 0) .map(m -> new ConfigItemDescriptor( m.getDeclaredAnnotation(ConfigItem.class), m.getReturnType(), m.getDeclaredAnnotation(Range.class), m.getDeclaredAnnotation(Alpha.class) )) .sorted((a, b) -> ComparisonChain.start() .compare(a.getItem().position(), b.getItem().position()) .compare(a.getItem().name(), b.getItem().name()) .result()) .collect(Collectors.toList()); return new ConfigDescriptor(group, items); }
public void addCommand(CliCommand command, Method commandMethod) { // put all the command synonyms in the command map Arrays.stream(command.value()).forEach(cmd -> commands.put(cmd, commandMethod)); // resolve the hint message for each method CliMetaData cliMetaData = commandMethod.getDeclaredAnnotation(CliMetaData.class); if (cliMetaData == null) return; String[] related = cliMetaData.relatedTopic(); // for hint message, we only need to show the first synonym String commandString = command.value()[0]; if (related == null) { return; } Arrays.stream(related).forEach(topic -> { Topic foundTopic = topics.get(topic); if (foundTopic == null) { throw new IllegalArgumentException("No such topic found in the initial map: " + topic); } foundTopic.addRelatedCommand(commandString, command.help()); }); }
AsyncMethodDef asyncMethod = method.getDeclaredAnnotation(AsyncMethodDef.class); if (null != asyncMethod) {
public void setMethod(Method m, int mn, int mx) { _method = m; _minArgs = mn; _maxArgs = mx; _isDeprecated = m.getDeclaredAnnotation(Deprecated.class) != null; }
private static boolean isUDF(Method m) { return m.getDeclaredAnnotation(UDF.class) != null; } }
/** **/ public static Path getPath(final Method method) { return getPath(method.getDeclaredAnnotation(Path.class)); }
private Transactional.TxType getTransactionType(Method m) { Transactional transactional = m.getDeclaredAnnotation(Transactional.class); return transactional != null ? transactional.value() : null; }
public Map<String, List<Method>> getBuiltinMethods() { List<Method> methods = Arrays.asList(getClass().getMethods()); return methods .stream() .filter(BeamBuiltinFunctionProvider::isUDF) .collect( Collectors.groupingBy(method -> method.getDeclaredAnnotation(UDF.class).funcName())); }
private boolean methodFilter(final Method method, final String tag) { try { final SunriseRoute annotationsByTypeOption = method.getDeclaredAnnotation(SunriseRoute.class); return Optional.ofNullable(annotationsByTypeOption).map(annotationsByType -> Arrays.stream(annotationsByType.value()) .anyMatch(value -> tag.equals(value))).orElse(false); } catch (final Exception e) { throw new CompletionException("failed in methodFilter", e); } } }
@Override protected String getParams() { rules_params.putIfAbsent(getClass(), new ConcurrentHashMap<>());//使用并发安全的map,避免系统启动后突然同一个规则被高并发访问出现并发问题 Map<String, String> methodName_paramsString = rules_params.get(getClass()); String params = methodName_paramsString.get(next); if (params == null) { Params paramsAnnotation = getMethod().getDeclaredAnnotation(Params.class); LOG.info(String.format("[RuleController] %s 的 params = %s", next, paramsAnnotation == null ? "" : paramsAnnotation.value())); methodName_paramsString.put(next, paramsAnnotation == null ? "" : paramsAnnotation.value()); } return methodName_paramsString.get(next); }
@Override public void configure(ResourceInfo resourceInfo, FeatureContext ctx) { if (!isRegistered) { Method method = resourceInfo.getResourceMethod(); Annotation transactional = method.getDeclaredAnnotation(LRA.class); if (transactional != null || method.getDeclaringClass().getDeclaredAnnotation(LRA.class) != null) { ctx.register(ServerLRAFilter.class); isRegistered = true; } } } }
@Override protected String getParams() { rules_params.putIfAbsent(getClass(), new ConcurrentHashMap<>());//使用并发安全的map,避免系统启动后突然同一个规则被高并发访问出现并发问题 Map<String, String> methodName_paramsString = rules_params.get(getClass()); String params = methodName_paramsString.get(next); if (params == null) { Params paramsAnnotation = getMethod().getDeclaredAnnotation(Params.class); LOG.info(String.format("[RuleController] %s 的 params = %s", next, paramsAnnotation == null ? "" : paramsAnnotation.value())); methodName_paramsString.put(next, paramsAnnotation == null ? "" : paramsAnnotation.value()); } return methodName_paramsString.get(next); }
@Override protected String getReturnParams() { rules_returnParams.putIfAbsent(getClass(), new ConcurrentHashMap<>()); Map<String, String> methodName_returnParams = rules_returnParams.get(getClass()); String returnParams = methodName_returnParams.get(next); if (returnParams == null) { ReturnParams returnParamsAnnotation = getMethod().getDeclaredAnnotation(ReturnParams.class); LOG.info(String.format("[RuleController] %s 的 returnParams = %s", next, returnParamsAnnotation == null ? "" : returnParamsAnnotation.value())); methodName_returnParams.put(next, returnParamsAnnotation == null ? "" : returnParamsAnnotation.value()); } return methodName_returnParams.get(next); }
/** * Get event bus address. * * @param event * @return */ protected String address(final Event event) { final Method method = event.getAction(); final Annotation annotation = method.getDeclaredAnnotation(Address.class); return Ut.invoke(annotation, "value"); }
private long getTimeOut(Method method) { Annotation timeLimit = method.getDeclaredAnnotation(TimeLimit.class); if (timeLimit == null) { timeLimit = method.getDeclaringClass().getDeclaredAnnotation(TimeLimit.class); } if (timeLimit == null) { return NarayanaLRAClient.DEFAULT_TIMEOUT_MILLIS; } TimeLimit tl = (TimeLimit) timeLimit; return tl.unit().toMillis(tl.limit()); }
public AgentFactory buildFactory(Method method) { AgentBuilderStatic agentBuilder = method.getDeclaredAnnotation(AgentBuilderStatic.class); String name = agentBuilder.value(); HashMap<Integer, Parameter> parameters = new HashMap<>(); for (Parameter p : method.getAnnotationsByType(Parameter.class)) { if (!parameters.containsKey(p.id())) { parameters.put(p.id(), p); } } Function<String, ?>[] convertersInst = getConverters(method.getDeclaringClass(), method.getParameterTypes(), parameters); return new MethodFactory(method.getDeclaringClass(), method, convertersInst, name); }
private Permissions getRequiredPermission() { Permissions permission = resourceInfo.getResourceMethod().getDeclaredAnnotation(Permissions.class); if (permission == null) { return resourceInfo.getResourceClass().getDeclaredAnnotation(Permissions.class); } return permission; } }