/** * * * @since 1.0 */ public static Source create(String language, CharSequence source) { return newBuilder(language, source, "Unnamed").buildLiteral(); }
@Override public Source getSource() { return Source.create(getLanguage(), script); }
ProfilingNode(ListenerImpl config, EventContext context) { super(config, context); PolyglotLanguage languageToUse = null; if (location != null) { languageToUse = config.engine.idToLanguage.get(location.getSource().getLanguage()); } if (languageToUse == null) { // should not happen but just in case fallback to host language assert false; languageToUse = config.engine.hostLanguage; } this.language = languageToUse; }
/** * Uses configuration of this builder to create new {@link Source} object. The method throws * an {@link IOException} if an error loading the source occured. * * @return the source object * @since 1.0 */ public Source build() throws IOException { Source source = getImpl().build(language, origin, uri, name, mimeType, content, interactive, internal, cached); // make sure origin is not consumed again if builder is used twice if (source.hasBytes()) { this.content = source.getBytes(); } else { assert source.hasCharacters(); this.content = source.getCharacters(); } return source; }
/** * Given a 0-based character offset, return the 1-based number of the column at the position. * Causes the contents of this source to be loaded if they are loaded lazily. * * @throws UnsupportedOperationException if this source cannot contain {@link #hasCharacters() * characters}. * @throws IllegalArgumentException if the offset is outside the text contents * @since 1.0 */ public int getColumnNumber(int offset) throws IllegalArgumentException { return getImpl().getColumnNumber(impl, offset); }
trace("sourceString = '" + sourceString + "'"); final Source source = Source.newBuilder(language, sourceString, "testMisplacedColumnBreakpoint." + language).buildLiteral(); Assert.assertTrue(Integer.toString(bpId), bp[0] > 0); Assert.assertTrue(Integer.toString(bpId), bp[1] > 0); int line = source.getLineNumber(bp[0] - 1); int column = source.getColumnNumber(bp[0] - 1); if (TRACE) { trace("TESTING BP_" + bpId + ": " + bp[0] + " (" + line + ":" + column + ") => " + bp[1] + ":");
trace("sourceString = '" + sourceString + "'"); final Source source = Source.newBuilder(language, sourceString, "testMisplacedLineBreakpoint." + language).build(); com.oracle.truffle.api.source.Source tsource = DebuggerTester.getSourceImpl(source); for (int l = 1; l < source.getLineCount(); l++) { if (!bps.containsKey(l)) { Assert.fail("Line " + l + " is missing."); int line = bentry.getKey(); int indexResolved = bentry.getValue(); int lineResolved = source.getLineNumber(indexResolved - 1); if (TRACE) { trace("TESTING breakpoint '" + line + "' => " + lineResolved + ":");
input = ""; } else if (bufferSource != null) { input = bufferSource.getCharacters() + "\n" + input; source = Source.newBuilder(currentLanguage.getId(), input, "<shell>").interactive(true).build(); context.eval(source); bufferSource = null; console.getHistory().replace(source.getCharacters());
int numLines = source.getLineCount(); int numColumns = 0; for (int i = 1; i <= numLines; i++) { int ll = source.getLineLength(i); if (ll > numColumns) { numColumns = ll;
/** * Returns the first installed language that supports evaluating sources for a given MIME type. * Returns <code>null</code> if no language was found that supports a given MIME type. The * languages are queried in the same order as returned by {@link Engine#getLanguages()}. * * @since 1.0 */ public static String findLanguage(String mimeType) { return org.graalvm.polyglot.Source.findLanguage(mimeType); }
@Override public Source newSource(String language, Object impl) { return new Source(language, impl); }
/** * {@inheritDoc} * * @since 1.0 */ @Override public int hashCode() { return getImpl().hashCode(impl); }
trace("sourceString = '" + sourceString + "'"); final Source source = Source.newBuilder(language, sourceString, "testMisplacedColumnBreakpoint." + language).build(); Assert.assertTrue(Integer.toString(bpId), bp[0] > 0); Assert.assertTrue(Integer.toString(bpId), bp[1] > 0); int line = source.getLineNumber(bp[0] - 1); int column = source.getColumnNumber(bp[0] - 1); if (TRACE) { trace("TESTING BP_" + bpId + ": " + bp[0] + " (" + line + ":" + column + ") => " + bp[1] + ":");
trace("sourceString = '" + sourceString + "'"); final Source source = Source.newBuilder(language, sourceString, "testMisplacedLineBreakpoint." + language).buildLiteral(); com.oracle.truffle.api.source.Source tsource = DebuggerTester.getSourceImpl(source); for (int l = 1; l < source.getLineCount(); l++) { if (!bps.containsKey(l)) { Assert.fail("Line " + l + " is missing."); int line = bentry.getKey(); int indexResolved = bentry.getValue(); int lineResolved = source.getLineNumber(indexResolved - 1); if (TRACE) { trace("TESTING breakpoint '" + line + "' => " + lineResolved + ":");
int numLines = source.getLineCount(); int numColumns = 0; for (int i = 1; i <= numLines; i++) { int ll = source.getLineLength(i); if (ll > numColumns) { numColumns = ll;
@Override protected String findLanguage() { try { return Source.findLanguage(new File(file)); } catch (IOException e) { return null; } }
@Override public Source newSource(String language, Object impl) { return new Source(language, impl); }
/** * Shortcut for creating a source object from a language and char sequence. The given characters * must not mutate after they were accessed for the first time. * * @since 1.0 */ public static Source create(String language, CharSequence source) { return newBuilder(language, source, "Unnamed").buildLiteral(); }
/** * Returns the first installed language that supports evaluating sources for a given MIME type. * Returns <code>null</code> if no language was found that supports a given MIME type. The * languages are queried in the same order as returned by {@link Engine#getLanguages()}. * Mime-types don't adhere to the MIME type format will return <code>null</code>. * * @since 1.0 */ public static String findLanguage(String mimeType) { return getImpl().findLanguage(mimeType); }
/** * Evaluates a source by using the {@linkplain Source#getLanguage() language} specified in the * source. The result is accessible as {@link Value value} and never <code>null</code>. The * first time a source is evaluated it will be parsed, consecutive invocations of eval with the * same source will only execute the already parsed code. * <p> * <b>Basic Example:</b> * * <pre> * Context context = Context.create(); * Source source = Source.newBuilder("js", "42").name("mysource.js").build(); * Value result = context.eval(source); * assert result.asInt() == 42; * context.close(); * </pre> * * @param source a source object to evaluate * @throws PolyglotException in case parsing or evaluation of the guest language code failed. * @throws IllegalStateException if the context is already closed, the current thread is not * allowed to access this context or if the language of the given source is not * installed. * @return result of the evaluation. The returned instance is is never <code>null</code>, but * the result might represent a {@link Value#isNull() null} value. * @since 1.0 */ public Value eval(Source source) { return impl.eval(source.getLanguage(), source.impl); }