A library that realizes multi-line strings in Java multiline-string

Introduction

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 [].

license

Not mentioned in the README, but according to pom.xml, it looks like "Common Public License Version 1.0" is.

Prerequisites

JDK 6 or above. Confirmed with JDK 8.

Preparation

I will write only the outline. For more information, see Maven project with Eclipse benelog / multiline Wiki.

  1. Definition of dependencies
  1. Definition of Annotation Processing

How to use

Describe as follows.

    // @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>

How it works

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.

in conclusion

[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

A library that realizes multi-line strings in Java multiline-string
A bat file that uses Java in windows
Write a class that can be ordered in Java
Find a subset in Java
Find a Java library for Bayesian networks that might work
[MQTT / Java] Implemented a class that does MQTT Pub / Sub in Java
Java version notation that changes in Java 10
3 Implement a simple interpreter in Java
I created a PDF in Java.
How to implement a job that uses Java API in JobScheduler
I wrote a Stalin sort that feels like a mess in Java
A simple sample callback in Java
Cast an array of Strings to a List of Integers in Java
Get stuck in a Java primer
How to concatenate strings in java
How to test a private method in Java and partially mock that method
[Java] Implement a function that uses a class implemented in the Builder pattern
About returning a reference in a Java Getter
What is a class in Java language (3 /?)
When seeking multiple in a Java array
[Creating] A memorandum about coding in Java
[Java] Use cryptography in the standard library
Java creates a table in a Word document
Java creates a pie chart in Excel
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
Create a TODO app in Java 7 Create Header
Try making a calculator app in Java
Implement something like a stack in Java
Split a string with ". (Dot)" in Java
Creating a matrix class in Java Part 1
[Java] Let's make a DB access library!
How to publish a library in jCenter
[Java] Difference between equals and == in a character string that is a reference type
Let's create a versatile file storage (?) Operation library by abstracting file storage / acquisition in Java
Java that outputs vmg format file in eml format
I made a primality test program in Java
GetInstance () from a @Singleton class in Groovy from Java
Two ways to start a thread in Java + @
Read a string in a PDF file with Java
A story about the JDK in the Java 11 era
How to display a web page in Java
Measure the size of a folder in Java
Code to escape a JSON string in Java
Try to create a bulletin board in Java
A note when you want Tuple in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I wrote a primality test program in Java
I made a rock-paper-scissors game in Java (CLI)
I made a Ruby extension library in C
Library "OSHI" to get system information in Java
A quick review of Java learned in class
I wrote a prime factorization program in Java
General-purpose StringConverter class that utilizes generics in Java8