I found a rule that makes sure JavaDoc's exist for public methods -> "Public types, methods and fields (API) should be documented with Javadoc", however, it doesn't appear to validate the param names are correct. For example, the JavaDoc below should fail because 'badName' does not match 'aParam'. Is there another rule I can use to validate JavaDoc's are documented correctly?
/**
* #param badName String
*/
public void myMethod(String aParam) {}
There are no rules in the SonarJava plugin that validate JavaDoc parameter names. Searching for all available Java rules, there are only three that are directly related to JavaDoc:
Deprecated elements should have both the annotation and the Javadoc tag
Public types, methods and fields (API) should be documented with Javadoc
Packages should have a javadoc file 'package-info.java'
However, if you install the Checkstyle plugin, you get some more Javadoc rules that may be close enough to what you are looking for. Here are some of their JavaDoc checks:
JavadocMethod: Checks the Javadoc of a method or constructor.
JavadocPackage: Checks that all packages have a package documentation.
JavadocParagraph: Checks Javadoc paragraphs.
JavadocStyle: Custom Checkstyle Check to validate Javadoc.
JavadocTagContinuationIndentation: Checks the indentation of the continuation lines in at-clauses.
JavadocType: Checks the Javadoc of a type.
JavadocVariable: Checks that a variable has Javadoc comment.
Related
As #ConfigMapping uses interfaces, there are no ways to implement toString(); I cannot view all values and nested values without a lot of manual work(reflection and switch case to deal with each type).
Any plan to support easy view of all levels of properties? Like a super class to inherit which handles this manual toString() like building?
In SmallRye config doc page I read this:
ToString#
If the config mapping contains a toString method declaration, the config mapping instance will include a proper implementation of the toString method.
But I added #Override String toString(); method everywhere, Quarkus just complains about cannot find property "to_string".
OK I found this issue which is implemented in this commit, which exactly adds the sentence I read into the doc; but still not very clear to me.
Adding a String toString() method in your #ConfigMapping will generate the expected toString() implementation.
This is only available starting from SmallRye Config 2.11.0 and Quarkus 2.12.0.Final, which came out just a few weeks ago. Previous versions will just try to resolve the method as a configuration property. From your description, it seems that is the case, so you may be using an older Quarkus version that does not support this feature yet.
I'm using SQ 6.0 and I have some POJOs which are (de)serialized by Spring/Jackson. For immutability reasons all members are passed to the constructor, so SQ complains with "Constructor has X parameters, which is greater than 7 authorized".
Since the constructor is annotated with #JsonCreator the number of arguments should imho be ignored, is there a way to configure this?
In your case would indeed make sense to have a way to exclude those constructors the same way constructors with #RequestMapping annotation are automatically excluded : https://jira.sonarsource.com/browse/RSPEC-2415. The short answer is no, there is no way. I'm going to open a thread on the SonarQube mailing list on this subject to see what we could do at mid-term.
You can filter out available implementations through the "target" attribute of the #Reference as shown below:
#Reference(target="(k1=v1)")
ISomeServiceContract svc1;
My question is about the filter value. The documentation says very little about it and I am confused.
http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html#reference states the following for the "target" attribute:
"A service target filter to select specific services to be made available".
Do filter values in SCR plugin have a specific syntax (i.e. why do I even need the parenthesis surrounding key equals value specification)? Does it allow you to specify things like "(k1=v1&&k2=v2)" or "(k1=v1||k2=v2&&(...))".
The syntax is explained in chapter "3.2.7 Filter syntax" of OSGi Core specification. The filters you define in the SCR annotation are OSGi filters. Some examples:
(k1=v1)
(&(k2=v1)(k2=v2))
(&(|(k1=v1)(k2=v2))(k3=v3))
The syntax that OSGi specifies is the same as for LDAP search filters.
#RequestMapping("/form")
public String form(Model model, Integer id)
For example ,spring can know parameter id's name is id and bind request param's value to it in runtime
This is a feature of javac introduced in JDK 8. You need to include -parameters javac command line option to activate it. Then you will be able to get parameter names like this:
String name = String.class.getMethod("substring", int.class).getParameters()[0].getName()
System.out.println(name);
From Spring documentation 3.3 Java 8 (as well as 6 and 7)
You can also use Java 8’s parameter name discovery (based on the
-parameters compiler flag) as an alternative to compiling your code with debug information enabled.
As specified in the javadoc for ParameterNameDiscoverer class:
Parameter name discovery is not always possible, but various
strategies are available to try, such as looking for debug information
that may have been emitted at compile time, and looking for argname
annotation values optionally accompanying AspectJ annotated methods.
This is the link to related JIRA item in Spring project Java 8 parameter name discovery for methods and constructors
JDK Enhancement Proposal JEP 118: Access to Parameter Names at Runtime
It's the WebDataBinder who does it for you.
http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/WebDataBinder.html
As you can see on the api, WebDataBinder is for data binding from web request parameters to JavaBean objects.
WebDataBinder is also responsible for validation and conversion, so that's why if you have customized editor or validator, you have to add them to your webDataBinder in the controller like below.
#Controller
public class HelloController {
#InitBinder
protected void initBinder(WebDataBinder binder) {
binder.setValidator(yourValidator);
binder.registerCustomEditor(the clazz to conver to.class, "the name of the parameter", yourEditor);
}
...
for more information, you have to check the document
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/validation.html
I have a model object which is defined outside of my play application, it is an auto-generated entity produced from wsdl. This means that I can't reliably add validation annotations to its fields. I thought about extending the class and in fact that's what I've done, and I wonder if its possible to add validation tags to the extended version? An immediate problem that I see with that however is that it also has children who's members would also need validation tags added, and if i were to extend them, they would not be used by play's binder. I guess what I need is some kind of custom validator, but from what I can see they are aimed at validation single properties, not entire object models.
Any pointers or suggestions would be great
Cheers!
NFV
You could write custom validator for your class and use:
public static void myController(#CheckWith(MyValidator.class) myParameter)
in controller to test if objects are valid. Then just manually validate them inside MyValidator (it has to extend play.data.validation.Check).
Check play documentation for more info about custom validators.