/** * Creates a new character based source from a character sequence. The given characters must not * mutate after they were accessed for the first time. * <p> * Example usage: {@link SourceSnippets#fromAString} * * @param language the language id, must not be <code>null</code> * @param characters the character sequence or string, must not be <code>null</code> * @param name the name of the source, if <code>null</code> then <code>"Unnamed"</code> will be * used as name. * @since 1.0 */ public static LiteralBuilder newBuilder(String language, CharSequence characters, String name) { return EMPTY.new LiteralBuilder(language, characters).name(name); }
/** * Creates a new byte based source from a byte sequence. The given bytes must not mutate after * they were accessed for the first time. * <p> * Example usage: {@link SourceSnippets#fromBytes} * * @param language the language id, must not be <code>null</code> * @param bytes the byte sequence or string, must not be <code>null</code> * @param name the name of the source, if <code>null</code> then <code>"Unnamed"</code> will be * used as name. * @since 1.0 */ public static LiteralBuilder newBuilder(String language, ByteSequence bytes, String name) { return EMPTY.new LiteralBuilder(language, bytes).name(name); }
/** * Creates new character based source from a reader. * * <p> * Example usage: {@link SourceSnippets#fromReader} * * @since 1.0 */ public static SourceBuilder newBuilder(String language, Reader source, String name) { return EMPTY.new LiteralBuilder(language, source).name(name); }
public Source getSource() { if (source == null) { String text = toString(); source = Source.newBuilder(RegexLanguage.ID, text, text).name(text).mimeType(RegexLanguage.MIME_TYPE).build(); } return source; }