Closed ghost closed 8 years ago
I was looking into it and I'm not quite sure what the best way is.
We already have a JDocComment javaDoc()
method for classes, enum constants, field vars, methods and packages.
But this class will always create multi line comments like
/**
* Description
*
* @param any
* Input value
* @return
* Input value plus "X".
* @throws NullPointerException
* If input is null
* @since JCodeModel 2.8.5
*/
What I could suggest is to add a boolean
member singleLineComment
that prints all of these parameters like
// Description
// @param any
// Input value
// @return
// Input value plus "X".
// @throws NullPointerException
// If input is null
// @since JCodeModel 2.8.5
Would that make sense to you?
I'm actually looking for a way to add comments in front of the package declaration of a class. Usually this seems to be the place where to put such things as license information and such autogenerated comments as above.
So it is not really about single line comments. It is about "license header" inside the class but before the package - right?
Yes. It could be single line
// single line header comment
package some.package;
...
or multiline
/*
* multi line header comment
*/
package some.package;
...
But it should be written to the generated file before the package declaration.
This is a bit tricky and I think there are 2 alternatives:
I'd prefer the 2nd alternative. As - especially for the autogenerated header - one might want to put the name of the actual source file used to generate the Java code in there. That would not be possible, if all files in the same JCodeModel
would get the same header comment...
I'm not too much into jcodemodel but I think one could add a method JDefinedClass.header(String)
and check for the parentContainer
and discard the header, if the parent is a JClass
, or throw an IllegalArgumentException
or similar (don't know what is usually done by JCodeModel in such kind of situations...)
I added method JDocComment headerComment
in JDefinedClass
. This should do the trick for you.
Great, thanks a lot!
Any ETA for 2.8.5 to be available?
It would be great if you can test the SNAPSHOT version and if it works, I will release it in a couple of hours.
Could test by today's evening 18:00 CET. If you can wait for the release until than, I could give you feedback.
Fine for me. I wont release before 20:00 (same timezone). SNAPSHOT is on Maven central.
Sorry can't find no SNAPSHOT version on Maven Central...
There is a special SNAPSHOT repo at https://oss.sonatype.org/content/repositories/snapshots/
The deep link is https://oss.sonatype.org/content/repositories/snapshots/com/helger/jcodemodel/2.8.5-SNAPSHOT/
Hm, 2.8.5-SNAPSHOT
can not be resolved from oss.sonatype.org for some reason.
repositories {
maven {
url 'https://oss.sonatype.org/content/repositories/snapshots/'
}
}
dependencies {
compile group: 'com.helger', name: 'jcodemodel', version: '2.8.5-SNAPSHOT'
}
But the build says:
Could not resolve: com.helger:jcodemodel:2.8.5-SNAPSHOT
However I finally used today's 104939-17
jar directly and the comments work like a charm for me. Unfortunately switching to your JCodeModel fork from Kohsuke's version is not straight forward, as you are using different naming schemes. But it looks like I'll stick with com.helger.jcodemodel
:-)
Welcome to jcodemodel :)
Great you finally managed to test it. I don't know Groovy but maybe SNAPSHOT repos need to be enabled manually somewhere...
I needed to change the namespace because in some cases jcodemodel may be used in parallel with the old Sun codemodel. With this change we're on the safe side. Infos on my naming can be found at https://github.com/phax/meta/blob/master/CodeingStyleguide.md
Release is in progress
BTW, for static headers, there is already a solution: PrologCodeWriter
.
Good to know ;-) I just quickly looked at it, and it does not give as much flexibility as the new solution. But it is an easy way to add the same header to all files (if you like // comments)
Please add support for header comments like this one from the google protobuf compiler: