Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java @ 22102:04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Fri, 21 Aug 2015 16:10:16 -0700 |
parents | 0556c0056d71 |
children | cf19259edf87 |
rev | line source |
---|---|
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1 /* |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
4 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. Oracle designates this |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
8 * particular file as subject to the "Classpath" exception as provided |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
9 * by Oracle in the LICENSE file that accompanied this code. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
10 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
15 * accompanied this code). |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
16 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU General Public License version |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
20 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
22 * or visit www.oracle.com if you need additional information or have any |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
23 * questions. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
24 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
25 package com.oracle.truffle.api.source; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
26 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
27 import java.io.*; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
28 import java.lang.ref.*; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
29 import java.net.*; |
22093
0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22046
diff
changeset
|
30 import java.nio.*; |
0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22046
diff
changeset
|
31 import java.nio.charset.*; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
32 import java.util.*; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
33 |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
34 import com.oracle.truffle.api.*; |
19697
191c55f08ed2
Truffle: add the ability to "tag" Sources with any number of standard or private tags, for example so that Sources might be marked as "FROM_FILE", "LIBRARY", "BUILTIN", or any other distinction that matters to some tools. Those tags can be applied by the language runtime when sources are created, for example when loading builtins. Alternately, you can listen for newly created sources from outside the implementation, where you might tag sources based on pattern matching against file paths or any other meta-information in the Source.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19690
diff
changeset
|
35 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
36 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
37 * Representation of a guest language source code unit and its contents. Sources originate in |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
38 * several ways: |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
39 * <ul> |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
40 * <li><strong>Literal:</strong> An anonymous text string: not named and not indexed. These should |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
41 * be considered value objects; equality is defined based on contents.<br> |
18672
f17b2a0303db
Truffle/Source: change signature of Source factory methods to take literal text as CharSequence instead of String.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
42 * See {@link Source#fromText(CharSequence, String)}</li> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
43 * <p> |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
44 * <li><strong>Named Literal:</strong> A text string that can be retrieved by name as if it were a |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
45 * file, but without any assumption that the name is related to a file path. Creating a new literal |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
46 * with an already existing name will replace its predecessor in the index.<br> |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
47 * See {@link Source#fromNamedText(CharSequence, String)}<br> |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
48 * See {@link Source#find(String)}</li> |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
49 * <p> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
50 * <li><strong>File:</strong> Each file is represented as a canonical object, indexed by the |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
51 * absolute, canonical path name of the file. File contents are <em>read lazily</em> and contents |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
52 * optionally <em>cached</em>. <br> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
53 * See {@link Source#fromFileName(String)}<br> |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
54 * See {@link Source#fromFileName(String, boolean)}<br> |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
55 * See {@link Source#find(String)}</li> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
56 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
57 * <li><strong>URL:</strong> Each URL source is represented as a canonical object, indexed by the |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
58 * URL. Contents are <em>read eagerly</em> and <em>cached</em>. <br> |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
59 * See {@link Source#fromURL(URL, String)}<br> |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
60 * See {@link Source#find(String)}</li> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
61 * <p> |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
62 * <li><strong>Reader:</strong> Contents are <em>read eagerly</em> and treated as an anonymous |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
63 * (non-indexed) <em>Literal</em> . <br> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
64 * See {@link Source#fromReader(Reader, String)}</li> |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
65 * <p> |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
66 * <li><strong>Sub-Source:</strong> A representation of the contents of a sub-range of another |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
67 * {@link Source}.<br> |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
68 * See @link {@link Source#subSource(Source, int, int)}<br> |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
69 * See @link {@link Source#subSource(Source, int)}</li> |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
70 * <p> |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
71 * <li><strong>AppendableSource:</strong> Literal contents are provided by the client, |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
72 * incrementally, after the instance is created.<br> |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
73 * See {@link Source#fromAppendableText(String)}<br> |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
74 * See {@link Source#fromNamedAppendableText(String)}</li> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
75 * </ul> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
76 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
77 * <strong>File cache:</strong> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
78 * <ol> |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
79 * <li>File content caching is optional, <em>on</em> by default.</li> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
80 * <li>The first access to source file contents will result in the contents being read, and (if |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
81 * enabled) cached.</li> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
82 * <li>If file contents have been cached, access to contents via {@link Source#getInputStream()} or |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
83 * {@link Source#getReader()} will be provided from the cache.</li> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
84 * <li>Any access to file contents via the cache will result in a timestamp check and possible cache |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
85 * reload.</li> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
86 * </ol> |
19697
191c55f08ed2
Truffle: add the ability to "tag" Sources with any number of standard or private tags, for example so that Sources might be marked as "FROM_FILE", "LIBRARY", "BUILTIN", or any other distinction that matters to some tools. Those tags can be applied by the language runtime when sources are created, for example when loading builtins. Alternately, you can listen for newly created sources from outside the implementation, where you might tag sources based on pattern matching against file paths or any other meta-information in the Source.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19690
diff
changeset
|
87 * <p> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
88 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
89 public abstract class Source { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
90 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
91 // TODO (mlvdv) consider canonicalizing and reusing SourceSection instances |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
92 // TOOD (mlvdv) connect SourceSections into a spatial tree for fast geometric lookup |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
93 |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
94 /** |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
95 * Index of all named sources. |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
96 */ |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
97 private static final Map<String, WeakReference<Source>> nameToSource = new HashMap<>(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
98 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
99 private static boolean fileCacheEnabled = true; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
100 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
101 /** |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
102 * Locates an existing instance by the name under which it was indexed. |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
103 */ |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
104 public static Source find(String name) { |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
105 final WeakReference<Source> nameRef = nameToSource.get(name); |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
106 return nameRef == null ? null : nameRef.get(); |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
107 } |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
108 |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
109 /** |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
110 * Gets the canonical representation of a source file, whose contents will be read lazily and |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
111 * then cached. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
112 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
113 * @param fileName name |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
114 * @param reset forces any existing {@link Source} cache to be cleared, forcing a re-read |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
115 * @return canonical representation of the file's contents. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
116 * @throws IOException if the file can not be read |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
117 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
118 public static Source fromFileName(String fileName, boolean reset) throws IOException { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
119 |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
120 final WeakReference<Source> nameRef = nameToSource.get(fileName); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
121 Source source = nameRef == null ? null : nameRef.get(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
122 if (source == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
123 final File file = new File(fileName); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
124 if (!file.canRead()) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
125 throw new IOException("Can't read file " + fileName); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
126 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
127 final String path = file.getCanonicalPath(); |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
128 final WeakReference<Source> pathRef = nameToSource.get(path); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
129 source = pathRef == null ? null : pathRef.get(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
130 if (source == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
131 source = new FileSource(file, fileName, path); |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
132 nameToSource.put(path, new WeakReference<>(source)); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
133 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
134 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
135 if (reset) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
136 source.reset(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
137 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
138 return source; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
139 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
140 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
141 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
142 * Gets the canonical representation of a source file, whose contents will be read lazily and |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
143 * then cached. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
144 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
145 * @param fileName name |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
146 * @return canonical representation of the file's contents. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
147 * @throws IOException if the file can not be read |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
148 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
149 public static Source fromFileName(String fileName) throws IOException { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
150 return fromFileName(fileName, false); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
151 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
152 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
153 /** |
22102
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
154 * Gets the canonical representation of a source file whose contents are the responsibility of |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
155 * the client: |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
156 * <ul> |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
157 * <li>If no Source exists corresponding to the provided file name, then a new Source is created |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
158 * whose contents are those provided. It is confirmed that the file resolves to a file name, so |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
159 * it can be indexed by canonical path. However there is no confirmation that the text supplied |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
160 * agrees with the file's contents or even whether the file is readable.</li> |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
161 * <li>If a Source exists corresponding to the provided file name, and that Source was created |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
162 * originally by this method, then that Source will be returned after replacement of its |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
163 * contents with no further confirmation.</li> |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
164 * <li>If a Source exists corresponding to the provided file name, and that Source was not |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
165 * created originally by this method, then an exception will be raised.</li> |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
166 * </ul> |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
167 * |
22102
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
168 * @param chars textual source code already read from the file, must not be null |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
169 * @param fileName |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
170 * @return canonical representation of the file's contents. |
22102
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
171 * @throws IOException if the file cannot be found, or if an existing Source not created by this |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
172 * method matches the file name |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
173 */ |
19690
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
174 public static Source fromFileName(CharSequence chars, String fileName) throws IOException { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
175 CompilerAsserts.neverPartOfCompilation(); |
22102
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
176 assert chars != null; |
19690
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
177 |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
178 final WeakReference<Source> nameRef = nameToSource.get(fileName); |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
179 Source source = nameRef == null ? null : nameRef.get(); |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
180 if (source == null) { |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
181 final File file = new File(fileName); |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
182 // We are going to trust that the fileName is readable. |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
183 final String path = file.getCanonicalPath(); |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
184 final WeakReference<Source> pathRef = nameToSource.get(path); |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
185 source = pathRef == null ? null : pathRef.get(); |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
186 if (source == null) { |
22102
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
187 source = new ClientManagedFileSource(file, fileName, path, chars); |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
188 nameToSource.put(path, new WeakReference<>(source)); |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
189 } |
22102
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
190 } else if (source instanceof ClientManagedFileSource) { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
191 final ClientManagedFileSource modifiableSource = (ClientManagedFileSource) source; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
192 modifiableSource.setCode(chars); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
193 return modifiableSource; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
194 } else { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
195 throw new IOException("Attempt to modify contents of a file Source"); |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
196 } |
19690
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
197 return source; |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
198 } |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
199 |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
200 /** |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
201 * Creates an anonymous source from literal text: not named and not indexed. |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
202 * |
18672
f17b2a0303db
Truffle/Source: change signature of Source factory methods to take literal text as CharSequence instead of String.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
203 * @param chars textual source code |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
204 * @param description a note about the origin, for error messages and debugging |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
205 * @return a newly created, non-indexed source representation |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
206 */ |
18672
f17b2a0303db
Truffle/Source: change signature of Source factory methods to take literal text as CharSequence instead of String.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
207 public static Source fromText(CharSequence chars, String description) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
208 CompilerAsserts.neverPartOfCompilation(); |
18672
f17b2a0303db
Truffle/Source: change signature of Source factory methods to take literal text as CharSequence instead of String.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
209 assert chars != null; |
22093
0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22046
diff
changeset
|
210 return new LiteralSource(description, chars.toString()); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
211 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
212 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
213 /** |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
214 * Creates an anonymous source from literal text that is provided incrementally after creation: |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
215 * not named and not indexed. |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
216 * |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
217 * @param description a note about the origin, for error messages and debugging |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
218 * @return a newly created, non-indexed, initially empty, appendable source representation |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
219 */ |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
220 public static Source fromAppendableText(String description) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
221 CompilerAsserts.neverPartOfCompilation(); |
22093
0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22046
diff
changeset
|
222 return new AppendableLiteralSource(description); |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
223 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
224 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
225 /** |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
226 * Creates a source from literal text that can be retrieved by name, with no assumptions about |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
227 * the structure or meaning of the name. If the name is already in the index, the new instance |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
228 * will replace the previously existing instance in the index. |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
229 * |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
230 * @param chars textual source code |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
231 * @param name string to use for indexing/lookup |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
232 * @return a newly created, source representation |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
233 */ |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
234 public static Source fromNamedText(CharSequence chars, String name) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
235 CompilerAsserts.neverPartOfCompilation(); |
21270
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
236 final Source source = new LiteralSource(name, chars.toString()); |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
237 nameToSource.put(name, new WeakReference<>(source)); |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
238 return source; |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
239 } |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
240 |
a43c7adc9d99
Truffle/Source: rename asPseudoFile() to fromNamedText(), which more accurately describes its use cases. Rework Javadoc for completeness and clarity.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20906
diff
changeset
|
241 /** |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
242 * Creates a source from literal text that is provided incrementally after creation and which |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
243 * can be retrieved by name, with no assumptions about the structure or meaning of the name. If |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
244 * the name is already in the index, the new instance will replace the previously existing |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
245 * instance in the index. |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
246 * |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
247 * @param name string to use for indexing/lookup |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
248 * @return a newly created, indexed, initially empty, appendable source representation |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
249 */ |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
250 public static Source fromNamedAppendableText(String name) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
251 CompilerAsserts.neverPartOfCompilation(); |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
252 final Source source = new AppendableLiteralSource(name); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
253 nameToSource.put(name, new WeakReference<>(source)); |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
254 return source; |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
255 } |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
256 |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
257 /** |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
258 * Creates a {@linkplain Source Source instance} that represents the contents of a sub-range of |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
259 * an existing {@link Source}. |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
260 * |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
261 * @param base an existing Source instance |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
262 * @param baseCharIndex 0-based index of the first character of the sub-range |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
263 * @param length the number of characters in the sub-range |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
264 * @return a new instance representing a sub-range of another Source |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
265 * @throws IllegalArgumentException if the specified sub-range is not contained in the base |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
266 */ |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
267 public static Source subSource(Source base, int baseCharIndex, int length) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
268 CompilerAsserts.neverPartOfCompilation(); |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
269 final SubSource subSource = SubSource.create(base, baseCharIndex, length); |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
270 return subSource; |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
271 } |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
272 |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
273 /** |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
274 * Creates a {@linkplain Source Source instance} that represents the contents of a sub-range at |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
275 * the end of an existing {@link Source}. |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
276 * |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
277 * @param base an existing Source instance |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
278 * @param baseCharIndex 0-based index of the first character of the sub-range |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
279 * @return a new instance representing a sub-range at the end of another Source |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
280 * @throws IllegalArgumentException if the index is out of range |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
281 */ |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
282 public static Source subSource(Source base, int baseCharIndex) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
283 CompilerAsserts.neverPartOfCompilation(); |
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
284 |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
285 return subSource(base, baseCharIndex, base.getLength() - baseCharIndex); |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
286 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
287 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
288 /** |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
289 * Creates a source whose contents will be read immediately from a URL and cached. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
290 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
291 * @param url |
18672
f17b2a0303db
Truffle/Source: change signature of Source factory methods to take literal text as CharSequence instead of String.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
292 * @param description identifies the origin, possibly useful for debugging |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
293 * @return a newly created, non-indexed source representation |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
294 * @throws IOException if reading fails |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
295 */ |
18672
f17b2a0303db
Truffle/Source: change signature of Source factory methods to take literal text as CharSequence instead of String.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
296 public static Source fromURL(URL url, String description) throws IOException { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
297 CompilerAsserts.neverPartOfCompilation(); |
22093
0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22046
diff
changeset
|
298 return URLSource.get(url, description); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
299 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
300 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
301 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
302 * Creates a source whose contents will be read immediately and cached. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
303 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
304 * @param reader |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
305 * @param description a note about the origin, possibly useful for debugging |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
306 * @return a newly created, non-indexed source representation |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
307 * @throws IOException if reading fails |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
308 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
309 public static Source fromReader(Reader reader, String description) throws IOException { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
310 CompilerAsserts.neverPartOfCompilation(); |
22093
0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22046
diff
changeset
|
311 return new LiteralSource(description, read(reader)); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
312 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
313 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
314 /** |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
315 * Creates a source from raw bytes. This can be used if the encoding of strings in your language |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
316 * is not compatible with Java strings, or if your parser returns byte indices instead of |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
317 * character indices. The returned source is then indexed by byte, not by character. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
318 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
319 * @param bytes the raw bytes of the source |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
320 * @param description a note about the origin, possibly useful for debugging |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
321 * @param charset how to decode the bytes into Java strings |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
322 * @return a newly created, non-indexed source representation |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
323 */ |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
324 public static Source fromBytes(byte[] bytes, String description, Charset charset) { |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
325 return fromBytes(bytes, 0, bytes.length, description, charset); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
326 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
327 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
328 /** |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
329 * Creates a source from raw bytes. This can be used if the encoding of strings in your language |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
330 * is not compatible with Java strings, or if your parser returns byte indices instead of |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
331 * character indices. The returned source is then indexed by byte, not by character. Offsets are |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
332 * relative to byteIndex. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
333 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
334 * @param bytes the raw bytes of the source |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
335 * @param byteIndex where the string starts in the byte array |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
336 * @param length the length of the string in the byte array |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
337 * @param description a note about the origin, possibly useful for debugging |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
338 * @param charset how to decode the bytes into Java strings |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
339 * @return a newly created, non-indexed source representation |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
340 */ |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
341 public static Source fromBytes(byte[] bytes, int byteIndex, int length, String description, Charset charset) { |
21966
5023b913e2ba
Help the partial evaluator / language developer by marking API methods as neverPartOfCompilation() when they are too complicated to be compiled.
Christian Wimmer <christian.wimmer@oracle.com>
parents:
21964
diff
changeset
|
342 CompilerAsserts.neverPartOfCompilation(); |
22093
0f0e34039769
Truffle/instrumentation: remove SourceTag machinery, not used so far. It will eventually be restored in the new API framework.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22046
diff
changeset
|
343 return new BytesSource(description, bytes, byteIndex, length, charset); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
344 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
345 |
16989
19faa7ca37c1
Truffle/Source: use a synchronized hash table
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16140
diff
changeset
|
346 // TODO (mlvdv) enable per-file choice whether to cache? |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
347 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
348 * Enables/disables caching of file contents, <em>disabled</em> by default. Caching of sources |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
349 * created from literal text or readers is always enabled. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
350 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
351 public static void setFileCaching(boolean enabled) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
352 fileCacheEnabled = enabled; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
353 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
354 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
355 private static String read(Reader reader) throws IOException { |
18672
f17b2a0303db
Truffle/Source: change signature of Source factory methods to take literal text as CharSequence instead of String.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18485
diff
changeset
|
356 final BufferedReader bufferedReader = new BufferedReader(reader); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
357 final StringBuilder builder = new StringBuilder(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
358 final char[] buffer = new char[1024]; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
359 |
21989
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
360 try { |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
361 while (true) { |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
362 final int n = bufferedReader.read(buffer); |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
363 if (n == -1) { |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
364 break; |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
365 } |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
366 builder.append(buffer, 0, n); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
367 } |
21989
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
368 } finally { |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
369 bufferedReader.close(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
370 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
371 return builder.toString(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
372 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
373 |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
374 private Source() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
375 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
376 |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
377 private TextMap textMap = null; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
378 |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
379 abstract void reset(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
380 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
381 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
382 * Returns the name of this resource holding a guest language program. An example would be the |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
383 * name of a guest language source code file. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
384 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
385 * @return the name of the guest language program |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
386 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
387 public abstract String getName(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
388 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
389 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
390 * Returns a short version of the name of the resource holding a guest language program (as |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
391 * described in @getName). For example, this could be just the name of the file, rather than a |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
392 * full path. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
393 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
394 * @return the short name of the guest language program |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
395 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
396 public abstract String getShortName(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
397 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
398 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
399 * The normalized, canonical name if the source is a file. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
400 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
401 public abstract String getPath(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
402 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
403 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
404 * The URL if the source is retrieved via URL. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
405 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
406 public abstract URL getURL(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
407 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
408 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
409 * Access to the source contents. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
410 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
411 public abstract Reader getReader(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
412 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
413 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
414 * Access to the source contents. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
415 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
416 public final InputStream getInputStream() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
417 return new ByteArrayInputStream(getCode().getBytes()); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
418 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
419 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
420 /** |
19690
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
421 * Gets the number of characters in the source. |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
422 */ |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
423 public final int getLength() { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
424 return getTextMap().length(); |
19690
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
425 } |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
426 |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
427 /** |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
428 * Returns the complete text of the code. |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
429 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
430 public abstract String getCode(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
431 |
19687
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
432 /** |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
433 * Returns a subsection of the code test. |
787b5aa53401
Truffle: new factory method for files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18980
diff
changeset
|
434 */ |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
435 public String getCode(int charIndex, int charLength) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
436 return getCode().substring(charIndex, charIndex + charLength); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
437 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
438 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
439 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
440 * Gets the text (not including a possible terminating newline) in a (1-based) numbered line. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
441 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
442 public final String getCode(int lineNumber) { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
443 final int offset = getTextMap().lineStartOffset(lineNumber); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
444 final int length = getTextMap().lineLength(lineNumber); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
445 return getCode().substring(offset, offset + length); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
446 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
447 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
448 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
449 * The number of text lines in the source, including empty lines; characters at the end of the |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
450 * source without a terminating newline count as a line. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
451 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
452 public final int getLineCount() { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
453 return getTextMap().lineCount(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
454 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
455 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
456 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
457 * Given a 0-based character offset, return the 1-based number of the line that includes the |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
458 * position. |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
459 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
460 * @throws IllegalArgumentException if the offset is outside the text contents |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
461 */ |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
462 public final int getLineNumber(int offset) throws IllegalArgumentException { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
463 return getTextMap().offsetToLine(offset); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
464 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
465 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
466 /** |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
467 * Given a 0-based character offset, return the 1-based number of the column at the position. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
468 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
469 * @throws IllegalArgumentException if the offset is outside the text contents |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
470 */ |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
471 public final int getColumnNumber(int offset) throws IllegalArgumentException { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
472 return getTextMap().offsetToCol(offset); |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
473 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
474 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
475 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
476 * Given a 1-based line number, return the 0-based offset of the first character in the line. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
477 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
478 * @throws IllegalArgumentException if there is no such line in the text |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
479 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
480 public final int getLineStartOffset(int lineNumber) throws IllegalArgumentException { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
481 return getTextMap().lineStartOffset(lineNumber); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
482 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
483 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
484 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
485 * The number of characters (not counting a possible terminating newline) in a (1-based) |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
486 * numbered line. |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
487 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
488 * @throws IllegalArgumentException if there is no such line in the text |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
489 */ |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
490 public final int getLineLength(int lineNumber) throws IllegalArgumentException { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
491 return getTextMap().lineLength(lineNumber); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
492 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
493 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
494 /** |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
495 * Append text to a Source explicitly created as <em>Appendable</em>. |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
496 * |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
497 * @param chars the text to append |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
498 * @throws UnsupportedOperationException by concrete subclasses that do not support appending |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
499 */ |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
500 public void appendCode(CharSequence chars) { |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
501 throw new UnsupportedOperationException(); |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
502 } |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
503 |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
504 /** |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
505 * Creates a representation of a contiguous region of text in the source. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
506 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
507 * This method performs no checks on the validity of the arguments. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
508 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
509 * The resulting representation defines hash/equality around equivalent location, presuming that |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
510 * {@link Source} representations are canonical. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
511 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
512 * @param identifier terse description of the region |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
513 * @param startLine 1-based line number of the first character in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
514 * @param startColumn 1-based column number of the first character in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
515 * @param charIndex the 0-based index of the first character of the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
516 * @param length the number of characters in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
517 * @return newly created object representing the specified region |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
518 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
519 public final SourceSection createSection(String identifier, int startLine, int startColumn, int charIndex, int length) { |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
520 return new SourceSection(null, this, identifier, startLine, startColumn, charIndex, length); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
521 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
522 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
523 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
524 * Creates a representation of a contiguous region of text in the source. Computes the |
21972
ff6f34159b8a
Providing package-info for most of API packages. Feel free to provide your package-info.java for anything that has API in its name.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21966
diff
changeset
|
525 * {@code charIndex} value by building a {@code TextMap map} of lines in the source. |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
526 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
527 * Checks the position arguments for consistency with the source. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
528 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
529 * The resulting representation defines hash/equality around equivalent location, presuming that |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
530 * {@link Source} representations are canonical. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
531 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
532 * @param identifier terse description of the region |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
533 * @param startLine 1-based line number of the first character in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
534 * @param startColumn 1-based column number of the first character in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
535 * @param length the number of characters in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
536 * @return newly created object representing the specified region |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
537 * @throws IllegalArgumentException if arguments are outside the text of the source |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
538 * @throws IllegalStateException if the source is one of the "null" instances |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
539 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
540 public final SourceSection createSection(String identifier, int startLine, int startColumn, int length) { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
541 final int lineStartOffset = getTextMap().lineStartOffset(startLine); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
542 if (startColumn > getTextMap().lineLength(startLine)) { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
543 throw new IllegalArgumentException("column out of range"); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
544 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
545 final int startOffset = lineStartOffset + startColumn - 1; |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
546 return new SourceSection(null, this, identifier, startLine, startColumn, startOffset, length); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
547 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
548 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
549 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
550 * Creates a representation of a contiguous region of text in the source. Computes the |
21972
ff6f34159b8a
Providing package-info for most of API packages. Feel free to provide your package-info.java for anything that has API in its name.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21966
diff
changeset
|
551 * {@code (startLine, startColumn)} values by building a {@code TextMap map} of lines in the |
ff6f34159b8a
Providing package-info for most of API packages. Feel free to provide your package-info.java for anything that has API in its name.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21966
diff
changeset
|
552 * source. |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
553 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
554 * Checks the position arguments for consistency with the source. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
555 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
556 * The resulting representation defines hash/equality around equivalent location, presuming that |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
557 * {@link Source} representations are canonical. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
558 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
559 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
560 * @param identifier terse description of the region |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
561 * @param charIndex 0-based position of the first character in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
562 * @param length the number of characters in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
563 * @return newly created object representing the specified region |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
564 * @throws IllegalArgumentException if either of the arguments are outside the text of the |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
565 * source |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
566 * @throws IllegalStateException if the source is one of the "null" instances |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
567 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
568 public final SourceSection createSection(String identifier, int charIndex, int length) throws IllegalArgumentException { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
569 checkRange(charIndex, length); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
570 final int startLine = getLineNumber(charIndex); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
571 final int startColumn = charIndex - getLineStartOffset(startLine) + 1; |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
572 return new SourceSection(null, this, identifier, startLine, startColumn, charIndex, length); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
573 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
574 |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
575 void checkRange(int charIndex, int length) { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
576 if (!(charIndex >= 0 && length >= 0 && charIndex + length <= getCode().length())) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
577 throw new IllegalArgumentException("text positions out of range"); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
578 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
579 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
580 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
581 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
582 * Creates a representation of a line of text in the source identified only by line number, from |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
583 * which the character information will be computed. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
584 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
585 * @param identifier terse description of the line |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
586 * @param lineNumber 1-based line number of the first character in the section |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
587 * @return newly created object representing the specified line |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
588 * @throws IllegalArgumentException if the line does not exist the source |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
589 * @throws IllegalStateException if the source is one of the "null" instances |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
590 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
591 public final SourceSection createSection(String identifier, int lineNumber) { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
592 final int charIndex = getTextMap().lineStartOffset(lineNumber); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
593 final int length = getTextMap().lineLength(lineNumber); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
594 return createSection(identifier, charIndex, length); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
595 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
596 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
597 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
598 * Creates a representation of a line number in this source, suitable for use as a hash table |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
599 * key with equality defined to mean equivalent location. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
600 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
601 * @param lineNumber a 1-based line number in this source |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
602 * @return a representation of a line in this source |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
603 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
604 public final LineLocation createLineLocation(int lineNumber) { |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
605 return new LineLocation(this, lineNumber); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
606 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
607 |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
608 /** |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
609 * An object suitable for using as a key into a hashtable that defines equivalence between |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
610 * different source types. |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
611 */ |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
612 Object getHashKey() { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
613 return getName(); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
614 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
615 |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
616 final TextMap getTextMap() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
617 if (textMap == null) { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
618 textMap = createTextMap(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
619 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
620 return textMap; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
621 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
622 |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
623 final void clearTextMap() { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
624 textMap = null; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
625 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
626 |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
627 TextMap createTextMap() { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
628 final String code = getCode(); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
629 if (code == null) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
630 throw new RuntimeException("can't read file " + getName()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
631 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
632 return TextMap.fromString(code); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
633 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
634 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
635 private static final class LiteralSource extends Source { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
636 |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
637 private final String description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
638 private final String code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
639 |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
640 public LiteralSource(String description, String code) { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
641 this.description = description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
642 this.code = code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
643 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
644 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
645 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
646 public String getName() { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
647 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
648 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
649 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
650 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
651 public String getShortName() { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
652 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
653 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
654 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
655 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
656 public String getCode() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
657 return code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
658 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
659 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
660 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
661 public String getPath() { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
662 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
663 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
664 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
665 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
666 public URL getURL() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
667 return null; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
668 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
669 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
670 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
671 public Reader getReader() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
672 return new StringReader(code); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
673 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
674 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
675 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
676 void reset() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
677 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
678 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
679 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
680 public int hashCode() { |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22036
diff
changeset
|
681 return description.hashCode() * code.hashCode(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
682 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
683 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
684 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
685 public boolean equals(Object obj) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
686 if (this == obj) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
687 return true; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
688 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
689 if (obj == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
690 return false; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
691 } |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
692 if (obj instanceof LiteralSource) { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
693 LiteralSource other = (LiteralSource) obj; |
22046
e7c2d36daf72
TruffleLanguage.parse method to convert a source to CallTarget. Basic caching to make sure the code is shared among tenants in one JVM.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
22036
diff
changeset
|
694 return description.equals(other.description) && code.equals(other.code); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
695 } |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
696 return false; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
697 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
698 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
699 |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
700 private static final class AppendableLiteralSource extends Source { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
701 private String description; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
702 final List<CharSequence> codeList = new ArrayList<>(); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
703 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
704 public AppendableLiteralSource(String description) { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
705 this.description = description; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
706 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
707 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
708 @Override |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
709 public String getName() { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
710 return description; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
711 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
712 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
713 @Override |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
714 public String getShortName() { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
715 return description; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
716 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
717 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
718 @Override |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
719 public String getCode() { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
720 return getCodeFromIndex(0); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
721 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
722 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
723 @Override |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
724 public String getPath() { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
725 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
726 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
727 |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
728 @Override |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
729 public URL getURL() { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
730 return null; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
731 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
732 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
733 @Override |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
734 public Reader getReader() { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
735 return new StringReader(getCode()); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
736 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
737 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
738 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
739 void reset() { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
740 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
741 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
742 private String getCodeFromIndex(int index) { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
743 StringBuilder sb = new StringBuilder(); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
744 for (int i = index; i < codeList.size(); i++) { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
745 CharSequence s = codeList.get(i); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
746 sb.append(s); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
747 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
748 return sb.toString(); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
749 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
750 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
751 @Override |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
752 public void appendCode(CharSequence chars) { |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
753 codeList.add(chars); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
754 clearTextMap(); |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
755 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
756 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
757 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
758 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
759 private static final class FileSource extends Source { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
760 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
761 private final File file; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
762 private final String name; // Name used originally to describe the source |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
763 private final String path; // Normalized path description of an actual file |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
764 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
765 private String code = null; // A cache of the file's contents |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
766 private long timeStamp; // timestamp of the cache in the file system |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
767 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
768 public FileSource(File file, String name, String path) { |
18980
ae0eb836e6f4
store absolute file in FileSource
Lukas Stadler <lukas.stadler@oracle.com>
parents:
18979
diff
changeset
|
769 this.file = file.getAbsoluteFile(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
770 this.name = name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
771 this.path = path; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
772 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
773 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
774 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
775 public String getName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
776 return name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
777 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
778 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
779 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
780 public String getShortName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
781 return file.getName(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
782 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
783 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
784 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
785 Object getHashKey() { |
21271
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
786 return path; |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
787 } |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
788 |
1516d26e8f2b
Truffle/Source: add a new kind of Source (both indexed and non-indexed flavors) whose contents are unavailable at creation, but will be provided incrementally.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21270
diff
changeset
|
789 @Override |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
790 public String getCode() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
791 if (fileCacheEnabled) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
792 if (code == null || timeStamp != file.lastModified()) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
793 try { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
794 code = read(getReader()); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
795 timeStamp = file.lastModified(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
796 } catch (IOException e) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
797 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
798 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
799 return code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
800 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
801 try { |
22098
0556c0056d71
read files in UTF-8 encoding
Christian Wirth <christian.wirth@oracle.com>
parents:
22093
diff
changeset
|
802 return read(new InputStreamReader(new FileInputStream(file), "UTF-8")); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
803 } catch (IOException e) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
804 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
805 return null; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
806 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
807 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
808 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
809 public String getPath() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
810 return path; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
811 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
812 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
813 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
814 public URL getURL() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
815 return null; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
816 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
817 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
818 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
819 public Reader getReader() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
820 if (code != null && timeStamp == file.lastModified()) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
821 return new StringReader(code); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
822 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
823 try { |
22098
0556c0056d71
read files in UTF-8 encoding
Christian Wirth <christian.wirth@oracle.com>
parents:
22093
diff
changeset
|
824 return new InputStreamReader(new FileInputStream(file), "UTF-8"); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
825 } catch (FileNotFoundException e) { |
18979
bdb24e259c11
include original exception in FileSource.getReader
Lukas Stadler <lukas.stadler@oracle.com>
parents:
18676
diff
changeset
|
826 |
bdb24e259c11
include original exception in FileSource.getReader
Lukas Stadler <lukas.stadler@oracle.com>
parents:
18676
diff
changeset
|
827 throw new RuntimeException("Can't find file " + path, e); |
22098
0556c0056d71
read files in UTF-8 encoding
Christian Wirth <christian.wirth@oracle.com>
parents:
22093
diff
changeset
|
828 } catch (UnsupportedEncodingException e) { |
0556c0056d71
read files in UTF-8 encoding
Christian Wirth <christian.wirth@oracle.com>
parents:
22093
diff
changeset
|
829 throw new RuntimeException("Unsupported encoding in file " + path, e); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
830 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
831 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
832 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
833 @Override |
18676
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
834 public int hashCode() { |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
835 return path.hashCode(); |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
836 } |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
837 |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
838 @Override |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
839 public boolean equals(Object obj) { |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
840 if (this == obj) { |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
841 return true; |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
842 } |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
843 if (obj instanceof FileSource) { |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
844 FileSource other = (FileSource) obj; |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
845 return path.equals(other.path); |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
846 } |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
847 return false; |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
848 } |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
849 |
1c12cf39281d
Truffle/Source: redefine equality of FileSource objects strictly in terms of the canonicalized file path, for use as hash key.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
18672
diff
changeset
|
850 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
851 void reset() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
852 this.code = null; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
853 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
854 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
855 |
22102
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
856 // TODO (mlvdv) if we keep this, hoist a superclass in common with FileSource. |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
857 private static final class ClientManagedFileSource extends Source { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
858 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
859 private final File file; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
860 private final String name; // Name used originally to describe the source |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
861 private final String path; // Normalized path description of an actual file |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
862 private String code; // The file's contents, as provided by the client |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
863 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
864 public ClientManagedFileSource(File file, String name, String path, CharSequence chars) { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
865 this.file = file.getAbsoluteFile(); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
866 this.name = name; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
867 this.path = path; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
868 setCode(chars); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
869 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
870 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
871 void setCode(CharSequence chars) { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
872 this.code = chars.toString(); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
873 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
874 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
875 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
876 public String getName() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
877 return name; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
878 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
879 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
880 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
881 public String getShortName() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
882 return file.getName(); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
883 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
884 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
885 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
886 Object getHashKey() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
887 return path; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
888 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
889 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
890 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
891 public String getCode() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
892 return code; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
893 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
894 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
895 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
896 public String getPath() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
897 return path; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
898 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
899 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
900 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
901 public URL getURL() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
902 return null; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
903 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
904 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
905 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
906 public Reader getReader() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
907 return new StringReader(code); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
908 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
909 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
910 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
911 public int hashCode() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
912 return path.hashCode(); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
913 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
914 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
915 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
916 public boolean equals(Object obj) { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
917 if (this == obj) { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
918 return true; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
919 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
920 if (obj instanceof ClientManagedFileSource) { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
921 ClientManagedFileSource other = (ClientManagedFileSource) obj; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
922 return path.equals(other.path); |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
923 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
924 return false; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
925 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
926 |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
927 @Override |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
928 void reset() { |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
929 this.code = null; |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
930 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
931 } |
04b13488da2a
Truffle/Source: modify behavior of factory Source.fromFileName((CharSequence, String). If a Source already exists with this file name, and it was created with this method originally, then the original Source will be returned with contents replaced.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
22098
diff
changeset
|
932 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
933 private static final class URLSource extends Source { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
934 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
935 private static final Map<URL, WeakReference<URLSource>> urlToSource = new HashMap<>(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
936 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
937 public static URLSource get(URL url, String name) throws IOException { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
938 WeakReference<URLSource> sourceRef = urlToSource.get(url); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
939 URLSource source = sourceRef == null ? null : sourceRef.get(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
940 if (source == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
941 source = new URLSource(url, name); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
942 urlToSource.put(url, new WeakReference<>(source)); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
943 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
944 return source; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
945 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
946 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
947 private final URL url; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
948 private final String name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
949 private String code = null; // A cache of the source contents |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
950 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
951 public URLSource(URL url, String name) throws IOException { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
952 this.url = url; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
953 this.name = name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
954 code = read(new InputStreamReader(url.openStream())); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
955 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
956 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
957 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
958 public String getName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
959 return name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
960 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
961 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
962 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
963 public String getShortName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
964 return name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
965 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
966 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
967 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
968 public String getPath() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
969 return url.getPath(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
970 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
971 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
972 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
973 public URL getURL() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
974 return url; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
975 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
976 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
977 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
978 public Reader getReader() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
979 return new StringReader(code); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
980 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
981 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
982 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
983 public String getCode() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
984 return code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
985 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
986 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
987 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
988 void reset() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
989 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
990 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
991 |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
992 private static final class SubSource extends Source { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
993 private final Source base; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
994 private final int baseIndex; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
995 private final int subLength; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
996 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
997 private static SubSource create(Source base, int baseIndex, int length) { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
998 if (baseIndex < 0 || length < 0 || baseIndex + length > base.getLength()) { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
999 throw new IllegalArgumentException("text positions out of range"); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1000 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1001 return new SubSource(base, baseIndex, length); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1002 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1003 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1004 private SubSource(Source base, int baseIndex, int length) { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1005 this.base = base; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1006 this.baseIndex = baseIndex; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1007 this.subLength = length; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1008 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1009 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1010 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
1011 void reset() { |
21292
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1012 assert false; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1013 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1014 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1015 @Override |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1016 public String getName() { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1017 return base.getName(); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1018 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1019 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1020 @Override |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1021 public String getShortName() { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1022 return base.getShortName(); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1023 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1024 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1025 @Override |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1026 public String getPath() { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1027 return base.getPath(); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1028 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1029 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1030 @Override |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1031 public URL getURL() { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1032 return null; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1033 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1034 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1035 @Override |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1036 public Reader getReader() { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1037 assert false; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1038 return null; |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1039 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1040 |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1041 @Override |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1042 public String getCode() { |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1043 return base.getCode(baseIndex, subLength); |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1044 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1045 } |
8eadc82f4a93
Truffle/Source: fix an inconsistency in the ordering of the private subclass sources; clean up the getTextMap() abstraction for more safety.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21291
diff
changeset
|
1046 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1047 private static final class BytesSource extends Source { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1048 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1049 private final String name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1050 private final byte[] bytes; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1051 private final int byteIndex; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1052 private final int length; |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1053 private final CharsetDecoder decoder; |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1054 |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1055 public BytesSource(String name, byte[] bytes, int byteIndex, int length, Charset decoder) { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1056 this.name = name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1057 this.bytes = bytes; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1058 this.byteIndex = byteIndex; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1059 this.length = length; |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1060 this.decoder = decoder.newDecoder(); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1061 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1062 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1063 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
1064 void reset() { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1065 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1066 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1067 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1068 public String getName() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1069 return name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1070 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1071 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1072 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1073 public String getShortName() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1074 return name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1075 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1076 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1077 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1078 public String getPath() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1079 return name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1080 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1081 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1082 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1083 public URL getURL() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1084 return null; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1085 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1086 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1087 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1088 public Reader getReader() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1089 return null; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1090 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1091 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1092 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1093 public String getCode() { |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1094 ByteBuffer bb = ByteBuffer.wrap(bytes, byteIndex, length); |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1095 CharBuffer chb; |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1096 try { |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1097 chb = decoder.decode(bb); |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1098 } catch (CharacterCodingException ex) { |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1099 return ""; |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1100 } |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1101 return chb.toString(); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1102 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1103 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1104 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1105 public String getCode(int byteOffset, int codeLength) { |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1106 ByteBuffer bb = ByteBuffer.wrap(bytes, byteIndex + byteOffset, codeLength); |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1107 CharBuffer chb; |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1108 try { |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1109 chb = decoder.decode(bb); |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1110 } catch (CharacterCodingException ex) { |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1111 return ""; |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1112 } |
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1113 return chb.toString(); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1114 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1115 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1116 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
1117 void checkRange(int charIndex, int rangeLength) { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1118 if (!(charIndex >= 0 && rangeLength >= 0 && charIndex + rangeLength <= length)) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1119 throw new IllegalArgumentException("text positions out of range"); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1120 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1121 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1122 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1123 @Override |
21964
9d15f06f3537
Using protected access modifier in non-subclassable class is suspicious. Making package private.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21951
diff
changeset
|
1124 TextMap createTextMap() { |
21987
b2d1c8ff592a
Less classes in the source API package. Merging interfaces and their only implementation into final classes. Hiding NullSourceSection behind factory method. Using JDK's standard CharsetDecoder instead of proprietary BytesDecoder.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
21972
diff
changeset
|
1125 return TextMap.fromString(getCode()); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1126 } |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1127 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1128 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1129 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1130 * A utility for converting between coordinate systems in a string of text interspersed with |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1131 * newline characters. The coordinate systems are: |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1132 * <ul> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1133 * <li>0-based character offset from the beginning of the text, where newline characters count |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1134 * as a single character and the first character in the text occupies position 0.</li> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1135 * <li>1-based position in the 2D space of lines and columns, in which the first position in the |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1136 * text is at (1,1).</li> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1137 * </ul> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1138 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1139 * This utility is based on positions occupied by characters, not text stream positions as in a |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1140 * text editor. The distinction shows up in editors where you can put the cursor just past the |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1141 * last character in a buffer; this is necessary, among other reasons, so that you can put the |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1142 * edit cursor in a new (empty) buffer. For the purposes of this utility, however, there are no |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1143 * character positions in an empty text string and there are no lines in an empty text string. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1144 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1145 * A newline character designates the end of a line and occupies a column position. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1146 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1147 * If the text ends with a character other than a newline, then the characters following the |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1148 * final newline character count as a line, even though not newline-terminated. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1149 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1150 * <strong>Limitations:</strong> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1151 * <ul> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1152 * <li>Does not handle multiple character encodings correctly.</li> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1153 * <li>Treats tabs as occupying 1 column.</li> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1154 * <li>Does not handle multiple-character line termination sequences correctly.</li> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1155 * </ul> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1156 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1157 private static final class TextMap { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1158 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1159 // 0-based offsets of newline characters in the text, with sentinel |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1160 private final int[] nlOffsets; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1161 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1162 // The number of characters in the text, including newlines (which count as 1). |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1163 private final int textLength; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1164 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1165 // Is the final text character a newline? |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1166 final boolean finalNL; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1167 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1168 public TextMap(int[] nlOffsets, int textLength, boolean finalNL) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1169 this.nlOffsets = nlOffsets; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1170 this.textLength = textLength; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1171 this.finalNL = finalNL; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1172 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1173 |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1174 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1175 * Constructs map permitting translation between 0-based character offsets and 1-based |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1176 * lines/columns. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1177 */ |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1178 public static TextMap fromString(String text) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1179 final int textLength = text.length(); |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1180 final ArrayList<Integer> lines = new ArrayList<>(); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1181 lines.add(0); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1182 int offset = 0; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1183 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1184 while (offset < text.length()) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1185 final int nlIndex = text.indexOf('\n', offset); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1186 if (nlIndex >= 0) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1187 offset = nlIndex + 1; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1188 lines.add(offset); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1189 } else { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1190 break; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1191 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1192 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1193 lines.add(Integer.MAX_VALUE); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1194 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1195 final int[] nlOffsets = new int[lines.size()]; |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1196 for (int line = 0; line < lines.size(); line++) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1197 nlOffsets[line] = lines.get(line); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1198 } |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1199 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1200 final boolean finalNL = textLength > 0 && (textLength == nlOffsets[nlOffsets.length - 2]); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1201 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1202 return new TextMap(nlOffsets, textLength, finalNL); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1203 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1204 |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1205 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1206 * Converts 0-based character offset to 1-based number of the line containing the character. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1207 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1208 * @throws IllegalArgumentException if the offset is outside the string. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1209 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1210 public int offsetToLine(int offset) throws IllegalArgumentException { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1211 if (offset < 0 || offset >= textLength) { |
22036
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1212 if (offset == 0 && textLength == 0) { |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1213 return 1; |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1214 } |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1215 throw new IllegalArgumentException("offset out of bounds"); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1216 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1217 int line = 1; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1218 while (offset >= nlOffsets[line]) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1219 line++; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1220 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1221 return line; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1222 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1223 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1224 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1225 * Converts 0-based character offset to 1-based number of the column occupied by the |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1226 * character. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1227 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1228 * Tabs are not expanded; they occupy 1 column. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1229 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1230 * @throws IllegalArgumentException if the offset is outside the string. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1231 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1232 public int offsetToCol(int offset) throws IllegalArgumentException { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1233 return 1 + offset - nlOffsets[offsetToLine(offset) - 1]; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1234 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1235 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1236 /** |
19690
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
1237 * The number of characters in the mapped text. |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
1238 */ |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
1239 public int length() { |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
1240 return textLength; |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
1241 } |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
1242 |
c152a485d747
Truffle: new method Source.getLength() and semantic adjustments to the new factory method for creating files whose contents have already been read.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
19688
diff
changeset
|
1243 /** |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1244 * The number of lines in the text; if characters appear after the final newline, then they |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1245 * also count as a line, even though not newline-terminated. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1246 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1247 public int lineCount() { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1248 if (textLength == 0) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1249 return 0; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1250 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1251 return finalNL ? nlOffsets.length - 2 : nlOffsets.length - 1; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1252 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1253 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1254 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1255 * Converts 1-based line number to the 0-based offset of the line's first character; this |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1256 * would be the offset of a newline if the line is empty. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1257 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1258 * @throws IllegalArgumentException if there is no such line in the text. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1259 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1260 public int lineStartOffset(int line) throws IllegalArgumentException { |
22036
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1261 if (textLength == 0) { |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1262 return 0; |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1263 } |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1264 if (lineOutOfRange(line)) { |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1265 throw new IllegalArgumentException("line out of bounds"); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1266 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1267 return nlOffsets[line - 1]; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1268 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1269 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1270 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1271 * Gets the number of characters in a line, identified by 1-based line number; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1272 * <em>does not</em> include the final newline, if any. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1273 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1274 * @throws IllegalArgumentException if there is no such line in the text. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1275 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1276 public int lineLength(int line) throws IllegalArgumentException { |
22036
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1277 if (textLength == 0) { |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1278 return 0; |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1279 } |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1280 if (lineOutOfRange(line)) { |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1281 throw new IllegalArgumentException("line out of bounds"); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1282 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1283 if (line == nlOffsets.length - 1 && !finalNL) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1284 return textLength - nlOffsets[line - 1]; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1285 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1286 return (nlOffsets[line] - nlOffsets[line - 1]) - 1; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1287 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1288 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1289 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1290 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1291 * Is the line number out of range. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1292 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1293 private boolean lineOutOfRange(int line) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1294 return line <= 0 || line >= nlOffsets.length || (line == nlOffsets.length - 1 && finalNL); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1295 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1296 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1297 } |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1298 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1299 } |