Add Path methods
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
58b23974b1
commit
d7c6bc1605
|
@ -17,6 +17,7 @@ import javax.lang.model.type.TypeMirror;
|
|||
import javax.lang.model.util.Elements;
|
||||
import javax.tools.Diagnostic;
|
||||
import java.io.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_17)
|
||||
|
@ -224,6 +225,19 @@ public class GsonCompileProcessor extends AbstractProcessor2 {
|
|||
.build()
|
||||
);
|
||||
|
||||
spec.addMethod(
|
||||
MethodSpec.methodBuilder("read")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||
.addParameter(Path.class, "path")
|
||||
.addException(IOException.class)
|
||||
.returns(classType)
|
||||
.addCode("""
|
||||
try ($T br = $T.newBufferedReader(path)) {
|
||||
return read(br);
|
||||
}""", BufferedReader.class, Files.class)
|
||||
.build()
|
||||
);
|
||||
|
||||
spec.addMethod(
|
||||
MethodSpec.methodBuilder("write")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||
|
@ -237,6 +251,19 @@ public class GsonCompileProcessor extends AbstractProcessor2 {
|
|||
.build()
|
||||
);
|
||||
|
||||
spec.addMethod(
|
||||
MethodSpec.methodBuilder("write")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||
.addParameter(Path.class, "path")
|
||||
.addParameter(classType, "value")
|
||||
.addException(IOException.class)
|
||||
.addCode("""
|
||||
try ($1T bw = $2T.newBufferedWriter(path, $3T.CREATE, $3T.WRITE, $3T.TRUNCATE_EXISTING)) {
|
||||
write(bw, value);
|
||||
}""", BufferedWriter.class, Files.class, StandardOpenOption.class)
|
||||
.build()
|
||||
);
|
||||
|
||||
spec.addMethod(
|
||||
MethodSpec.methodBuilder("toJson")
|
||||
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
|
||||
|
|
Loading…
Reference in New Issue