summaryrefslogtreecommitdiff
path: root/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java
diff options
context:
space:
mode:
Diffstat (limited to 'container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java')
-rw-r--r--container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java32
1 files changed, 32 insertions, 0 deletions
diff --git a/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java
new file mode 100644
index 0000000..e07a11f
--- /dev/null
+++ b/container-compiler-plugin/src/test/java/io/trygvis/container/compiler/JavaSourceFromString.java
@@ -0,0 +1,32 @@
+package io.trygvis.container.compiler;
+
+import javax.tools.JavaFileObject;
+import javax.tools.SimpleJavaFileObject;
+import java.net.URI;
+
+/**
+ * A file object used to represent source coming from a string.
+ */
+public class JavaSourceFromString extends SimpleJavaFileObject {
+ /**
+ * The source code of this "file".
+ */
+ final String code;
+
+ /**
+ * Constructs a new JavaSourceFromString.
+ *
+ * @param name the name of the compilation unit represented by this file object
+ * @param code the source code for the compilation unit represented by this file object
+ */
+ JavaSourceFromString(String name, String code) {
+ super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension),
+ Kind.SOURCE);
+ this.code = code;
+ }
+
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) {
+ return code;
+ }
+}