The problem when writing code in Java was "how to express a character string that spans multiple lines". If it works in a production environment, you can save it to a file, but if you use it for unit tests, you want to keep the code and data as close as possible.
I thought this was impossible, but I found a library called multiline-string [].
Not mentioned in the README, but according to pom.xml, it looks like "Common Public License Version 1.0" is.
JDK 6 or above. Confirmed with JDK 8.
I will write only the outline. For more information, see Maven project with Eclipse benelog / multiline Wiki.
Describe as follows.
@ Multiline
/ **
~ * /
) (normal comments are not possible)@formatter: off
, @formatter: on
to turn off autoformatting@formatter
is a feature of the IDE, so check your IDE settings. // @formatter:off
/**
<xml version="1.0" encoding="utf-8" ?>
<root>
</root>
*/
// @formatter:on
@Multiline
public static String XML;
The output of this string is as follows.
<xml version="1.0" encoding="utf-8" ?>
<root>
</root>
It is mentioned at the beginning of multiline-string [], but it was originally based on this article. I could have introduced this, but I thought it would be easier to use if it was in the Maven repository, so I introduced multiline-string [].
As you can see in this article, I'm getting Javadoc comments with the [javax.lang.model.util.Elements # getDocComment (Element)] [] method of the Pluggable Annotation Processing API.
[Pluggable Annotation Processing API (JSR269)] JSR269 seemed difficult and I hadn't touched it yet, but I thought I'd try to make it myself (´ω`)
Recommended Posts