检查“方法调用"的最佳方法是什么?使用checkstyle匹配格式? [英] What is the best way to check "method call" match format using checkstyle?

查看:23
本文介绍了检查“方法调用"的最佳方法是什么?使用checkstyle匹配格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组属于单个类的方法,该类至少应包含 2 个参数.第一个应该是文字"字符串类型(例如 instance.do("literal_string", obj) - 应该在方法调用行本身中正确指定).作为 next 第一个参数也应该匹配给定的正则表达式模式.第二个参数可以有任何值(对象).

I have a group of methods that belong a single class that should contain at-least 2 parameters. The first one should be of type "literal" string (e.g. instance.do("literal_string", obj) - should be specified just right in the method call line itself). As next first parameter should also match a given regex pattern. The second argument can have any value (Object).

另外,第一个参数在整个项目中应该是唯一的(这部分并不是真的那么重要).

Additionally first parameter should be unique across whole project (this part is not really that important to consider).

是否有可能对我上面列出的条件进行检查?(也许使用 checkstyle?或者自定义 Java 注释?)

Are there any possibilities to implement a check for conditions I've listed above? (Perhaps with checkstyle? Or custom Java annotations?)

更新.此类检查最好在开发时间执行(例如,在 Eclipse 中提示黄色灯泡).

推荐答案

你的意思是这样的:

if(nameOfStringVar.matches("regex")){
    throw new java.lang.Error("First arg did not match the regex");
}
Objects.requireNonNull(nameOfSecondVariable);

?

这篇关于检查“方法调用"的最佳方法是什么?使用checkstyle匹配格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆