Skip to content

Commit

Permalink
Restore binary backward compatibility for GeneratedFiles
Browse files Browse the repository at this point in the history
  • Loading branch information
snicoll committed Jul 3, 2024
1 parent 78d594c commit 99e8978
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* @author Stephane Nicoll
* @since 6.0
*/
public class FileSystemGeneratedFiles extends GeneratedFiles {
public class FileSystemGeneratedFiles implements GeneratedFiles {

private final Function<Kind, Path> roots;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
* @see InMemoryGeneratedFiles
* @see FileSystemGeneratedFiles
*/
public abstract class GeneratedFiles {
public interface GeneratedFiles {

/**
* Add a generated {@link Kind#SOURCE source file} with content from the
* given {@link JavaFile}.
* @param javaFile the java file to add
*/
public void addSourceFile(JavaFile javaFile) {
default void addSourceFile(JavaFile javaFile) {
validatePackage(javaFile.packageName, javaFile.typeSpec.name);
String className = javaFile.packageName + "." + javaFile.typeSpec.name;
addSourceFile(className, javaFile::writeTo);
Expand All @@ -59,7 +59,7 @@ public void addSourceFile(JavaFile javaFile) {
* of the file
* @param content the contents of the file
*/
public void addSourceFile(String className, CharSequence content) {
default void addSourceFile(String className, CharSequence content) {
addSourceFile(className, appendable -> appendable.append(content));
}

Expand All @@ -71,7 +71,7 @@ public void addSourceFile(String className, CharSequence content) {
* @param content a {@link ThrowingConsumer} that accepts an
* {@link Appendable} which will receive the file contents
*/
public void addSourceFile(String className, ThrowingConsumer<Appendable> content) {
default void addSourceFile(String className, ThrowingConsumer<Appendable> content) {
addFile(Kind.SOURCE, getClassNamePath(className), content);
}

Expand All @@ -83,7 +83,7 @@ public void addSourceFile(String className, ThrowingConsumer<Appendable> content
* @param content an {@link InputStreamSource} that will provide an input
* stream containing the file contents
*/
public void addSourceFile(String className, InputStreamSource content) {
default void addSourceFile(String className, InputStreamSource content) {
addFile(Kind.SOURCE, getClassNamePath(className), content);
}

Expand All @@ -93,7 +93,7 @@ public void addSourceFile(String className, InputStreamSource content) {
* @param path the relative path of the file
* @param content the contents of the file
*/
public void addResourceFile(String path, CharSequence content) {
default void addResourceFile(String path, CharSequence content) {
addResourceFile(path, appendable -> appendable.append(content));
}

Expand All @@ -104,7 +104,7 @@ public void addResourceFile(String path, CharSequence content) {
* @param content a {@link ThrowingConsumer} that accepts an
* {@link Appendable} which will receive the file contents
*/
public void addResourceFile(String path, ThrowingConsumer<Appendable> content) {
default void addResourceFile(String path, ThrowingConsumer<Appendable> content) {
addFile(Kind.RESOURCE, path, content);
}

Expand All @@ -115,7 +115,7 @@ public void addResourceFile(String path, ThrowingConsumer<Appendable> content) {
* @param content an {@link InputStreamSource} that will provide an input
* stream containing the file contents
*/
public void addResourceFile(String path, InputStreamSource content) {
default void addResourceFile(String path, InputStreamSource content) {
addFile(Kind.RESOURCE, path, content);
}

Expand All @@ -126,7 +126,7 @@ public void addResourceFile(String path, InputStreamSource content) {
* @param content an {@link InputStreamSource} that will provide an input
* stream containing the file contents
*/
public void addClassFile(String path, InputStreamSource content) {
default void addClassFile(String path, InputStreamSource content) {
addFile(Kind.CLASS, path, content);
}

Expand All @@ -137,7 +137,7 @@ public void addClassFile(String path, InputStreamSource content) {
* @param path the relative path of the file
* @param content the contents of the file
*/
public void addFile(Kind kind, String path, CharSequence content) {
default void addFile(Kind kind, String path, CharSequence content) {
addFile(kind, path, appendable -> appendable.append(content));
}

Expand All @@ -149,7 +149,7 @@ public void addFile(Kind kind, String path, CharSequence content) {
* @param content a {@link ThrowingConsumer} that accepts an
* {@link Appendable} which will receive the file contents
*/
public void addFile(Kind kind, String path, ThrowingConsumer<Appendable> content) {
default void addFile(Kind kind, String path, ThrowingConsumer<Appendable> content) {
Assert.notNull(content, "'content' must not be null");
addFile(kind, path, new AppendableConsumerInputStreamSource(content));
}
Expand All @@ -162,7 +162,7 @@ public void addFile(Kind kind, String path, ThrowingConsumer<Appendable> content
* @param content an {@link InputStreamSource} that will provide an input
* stream containing the file contents
*/
public void addFile(Kind kind, String path, InputStreamSource content) {
default void addFile(Kind kind, String path, InputStreamSource content) {
Assert.notNull(kind, "'kind' must not be null");
Assert.hasLength(path, "'path' must not be empty");
Assert.notNull(content, "'content' must not be null");
Expand All @@ -179,7 +179,7 @@ public void addFile(Kind kind, String path, InputStreamSource content) {
* @param handler a consumer of a {@link FileHandler} for the file
* @since 6.2
*/
public abstract void handleFile(Kind kind, String path, ThrowingConsumer<FileHandler> handler);
void handleFile(Kind kind, String path, ThrowingConsumer<FileHandler> handler);

private static String getClassNamePath(String className) {
Assert.hasLength(className, "'className' must not be empty");
Expand Down Expand Up @@ -214,7 +214,7 @@ private static boolean isJavaIdentifier(String className) {
/**
* The various kinds of generated files that are supported.
*/
public enum Kind {
enum Kind {

/**
* A source file containing Java code that should be compiled.
Expand All @@ -241,7 +241,7 @@ public enum Kind {
*
* @since 6.2
*/
public abstract static class FileHandler {
abstract class FileHandler {

private final boolean exists;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @author Stephane Nicoll
* @since 6.0
*/
public class InMemoryGeneratedFiles extends GeneratedFiles {
public class InMemoryGeneratedFiles implements GeneratedFiles {

private final Map<Kind, Map<String, InputStreamSource>> files = new HashMap<>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ private GeneratedFileAssert assertThatFileAdded(Kind kind, String path)
}


static class TestGeneratedFiles extends GeneratedFiles {
static class TestGeneratedFiles implements GeneratedFiles {

private Kind kind;

Expand Down

0 comments on commit 99e8978

Please sign in to comment.