Skip to content

qaralotte/fstring

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Format String

Format-String in compile-time

Installation

JDK 8 above

<dependency>
    <groupId>io.github.qaralotte</groupId>
    <artifactId>fstring</artifactId>
    <version>1.0.0</version>
</dependency>

Usage

Add @FormatString to any Class or Method

@FormatString
public class MyTestClass
...

or

@FormatString
private void myTestFunc()
...

Now you can use format string

// output -> Hello World
String world = "World";
System.out.println("Hello {world}");

// output -> 51
int a = 3, b = 2;
System.out.println("{s + b}{s - b}");

// output -> The second element of the array is: 456
String[] arr = {"123", "456", "789"};
System.out.println("The second element of the array is: {arr[1]}");

// output -> wow, fstring in java
public String getTitle(String s) {
    return s;
}
System.out.println("wow, {this.getTitle(\\"fstring\\") in java}");
System.out.println("wow, {this.getTitle(`fstring`) in java}"); // use ` instead of "

// output -> b is 1
int b = 1;
System.out.println("{b == 1 ? `b is 1`: `b not is 1`}");

// output -> hello {`579-333`} world
@FormatString`
public String myTestFunc(int a, int b) {
    return "{a + b}{b - b}";
}
System.out.println("hello {`{myTestFunc(123, 456)}`} world");

Dependencies

JavaParser

License

Format-String complies is released under the Apache