When writing code of the form:
String.format("blah %s %s", value1);
IntelliJ will warn that there is a mismatch between the number of format patterns and actual arguments: too few arguments for format string (found:1, expected: 2)
.
Is there any way to apply this logic to custom methods? For example:
/** @see String#format(String, Object...) */
public String myMethod(String msg, Object... args){
return String.format("blah " + msg, args);
}
...
myMethod("%s %s", value1);
The point being that I'd like IDEA to tell me I messed up.
As shown in the example, I already document these methods that delegate to String.format()
.
Ideally, I'd prefer to avoid duplicating that documentation - though I'd be willing to transform it into a custom format, or possibly an annotation (preferably not an IDEA annotation though).
You can configure additional "formatter methods" in the inspection settings:
If you configure the inspection profile to "Project Default", and check in the related files (in .idea folder), then everybody who checks out the project and also uses IDEA will benefit from that.