-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathJavaSourceFromString.java
More file actions
42 lines (37 loc) · 1.46 KB
/
JavaSourceFromString.java
File metadata and controls
42 lines (37 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright 2013-2026 chronicle.software; SPDX-License-Identifier: Apache-2.0
*/
package net.openhft.compiler;
import org.jetbrains.annotations.NotNull;
import javax.tools.SimpleJavaFileObject;
import java.net.URI;
/*
* An internal SimpleJavaFileObject implementation representing Java source
* code provided as a String, allowing the Java compiler to read source
* directly from memory. Example URI: string:///com/example/Hello.java. The
* contents are expected to be UTF-8.
*/
class JavaSourceFromString extends SimpleJavaFileObject {
/**
* The source code of this "file".
*/
private final String code;
/**
* Constructs a new JavaSourceFromString.
*
* @param name the name of the compilation unit represented by this file object
* (annotated with {@link org.jetbrains.annotations.NotNull})
* @param code the source code for the compilation unit represented by this file object
*/
JavaSourceFromString(@NotNull String name, String code) {
super(URI.create("string:///" + name.replace('.', '/') + Kind.SOURCE.extension),
Kind.SOURCE);
this.code = code;
}
/** Returns the Java source code. */
@SuppressWarnings("RefusedBequest") // Directly returns the stored code string, ignoring encoding-error handling because the source is already held in memory.
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return code;
}
}