Mercurial > hg > truffle
annotate truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/source/Source.java @ 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.
author | Jaroslav Tulach <jaroslav.tulach@oracle.com> |
---|---|
date | Thu, 30 Jul 2015 17:36:34 +0200 |
parents | f26b6524e5e0 |
children | 0f0e34039769 |
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.*; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
30 import java.util.*; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
31 |
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
|
32 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
|
33 import com.oracle.truffle.api.instrument.*; |
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
|
34 import java.nio.ByteBuffer; |
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
|
35 import java.nio.CharBuffer; |
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
|
36 import java.nio.charset.CharacterCodingException; |
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
|
37 import java.nio.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
|
38 import java.nio.charset.CharsetDecoder; |
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
|
39 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
40 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
41 * 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
|
42 * several ways: |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
43 * <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
|
44 * <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
|
45 * 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
|
46 * 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
|
47 * <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
|
48 * <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
|
49 * 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
|
50 * 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
|
51 * 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
|
52 * 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
|
53 * <p> |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
54 * <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
|
55 * 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
|
56 * optionally <em>cached</em>. <br> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
57 * 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
|
58 * 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
|
59 * 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
|
60 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
61 * <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
|
62 * 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
|
63 * 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
|
64 * 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
|
65 * <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
|
66 * <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
|
67 * (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
|
68 * 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
|
69 * <p> |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
70 * <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
|
71 * {@link Source}.<br> |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
72 * 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
|
73 * 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
|
74 * <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
|
75 * <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
|
76 * 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
|
77 * 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
|
78 * 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
|
79 * </ul> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
80 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
81 * <strong>File cache:</strong> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
82 * <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
|
83 * <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
|
84 * <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
|
85 * enabled) cached.</li> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
86 * <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
|
87 * {@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
|
88 * <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
|
89 * reload.</li> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
90 * </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
|
91 * <p> |
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
|
92 * |
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
|
93 * @see SourceTag |
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
|
94 * @see SourceListener |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
95 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
96 public abstract class Source { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
97 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
98 // 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
|
99 // 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
|
100 |
20906
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
101 public enum Tags implements SourceTag { |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
102 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
103 /** |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
104 * From bytes. |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
105 */ |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
106 FROM_BYTES("bytes", "read from bytes"), |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
107 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
108 /** |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
109 * Read from a file. |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
110 */ |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
111 FROM_FILE("file", "read from a file"), |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
112 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
113 /** |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
114 * From literal text. |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
115 */ |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
116 FROM_LITERAL("literal", "from literal text"), |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
117 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
118 /** |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
119 * From a {@linkplain java.io.Reader Reader}. |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
120 */ |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
121 FROM_READER("reader", "read from a Java Reader"), |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
122 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
123 /** |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
124 * Read from a URL. |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
125 */ |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
126 FROM_URL("URL", "read from a URL"); |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
127 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
128 private final String name; |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
129 private final String description; |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
130 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
131 private Tags(String name, String description) { |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
132 this.name = name; |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
133 this.description = description; |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
134 } |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
135 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
136 public String getName() { |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
137 return name; |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
138 } |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
139 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
140 public String getDescription() { |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
141 return description; |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
142 } |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
143 |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
144 } |
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
145 |
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
|
146 /** |
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
|
147 * All Sources that have been created. |
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
|
148 */ |
20022
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
149 private static final List<WeakReference<Source>> allSources = Collections.synchronizedList(new ArrayList<WeakReference<Source>>()); |
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
|
150 |
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
|
151 /** |
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
|
152 * 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
|
153 */ |
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
|
154 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
|
155 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
156 private static boolean fileCacheEnabled = true; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
157 |
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
|
158 private static final List<SourceListener> sourceListeners = new ArrayList<>(); |
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
|
159 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
160 /** |
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
|
161 * 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
|
162 */ |
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
|
163 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
|
164 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
|
165 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
|
166 } |
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
|
167 |
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
|
168 /** |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
169 * 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
|
170 * then cached. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
171 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
172 * @param fileName name |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
173 * @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
|
174 * @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
|
175 * @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
|
176 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
177 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
|
178 |
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
|
179 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
|
180 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
|
181 if (source == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
182 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
|
183 if (!file.canRead()) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
184 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
|
185 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
186 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
|
187 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
|
188 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
|
189 if (source == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
190 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
|
191 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
|
192 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
193 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
194 if (reset) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
195 source.reset(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
196 } |
20906
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
197 notifyNewSource(source).tagAs(Tags.FROM_FILE); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
198 return source; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
199 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
200 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
201 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
202 * 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
|
203 * then cached. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
204 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
205 * @param fileName name |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
206 * @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
|
207 * @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
|
208 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
209 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
|
210 return fromFileName(fileName, false); |
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 /** |
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
|
214 * Gets the canonical representation of a source file, whose contents have already been read and |
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
|
215 * need not be read again. It is confirmed that the file resolves to a file name, so it can be |
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
|
216 * indexed by canonical path. It is not confirmed that the text supplied agrees with the file's |
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
|
217 * contents or even whether the file is readable. |
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
|
218 * |
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
|
219 * @param chars textual source code already read from the file |
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
|
220 * @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
|
221 * @return canonical representation of the file's contents. |
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
|
222 * @throws IOException if the file cannot be found |
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
|
223 */ |
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
|
224 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
|
225 CompilerAsserts.neverPartOfCompilation(); |
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
|
226 |
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
|
227 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
|
228 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
|
229 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
|
230 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
|
231 // 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 source = new FileSource(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
|
237 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
|
238 } |
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
|
239 } |
20906
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
240 notifyNewSource(source).tagAs(Tags.FROM_FILE); |
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
|
241 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
|
242 } |
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
|
243 |
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
|
244 /** |
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
|
245 * 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
|
246 * |
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
|
247 * @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
|
248 * @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
|
249 * @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
|
250 */ |
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
|
251 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
|
252 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
|
253 |
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
|
254 assert chars != null; |
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
|
255 final LiteralSource source = new LiteralSource(description, chars.toString()); |
20906
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
256 notifyNewSource(source).tagAs(Tags.FROM_LITERAL); |
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
|
257 return source; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
258 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
259 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
260 /** |
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
|
261 * 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
|
262 * 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
|
263 * |
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
|
264 * @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
|
265 * @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
|
266 */ |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
267 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
|
268 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
|
269 |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
270 final Source source = 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
|
271 notifyNewSource(source).tagAs(Tags.FROM_LITERAL); |
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
|
272 return source; |
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
|
273 } |
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
|
274 |
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
|
275 /** |
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
|
276 * 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
|
277 * 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
|
278 * 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
|
279 * |
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
|
280 * @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
|
281 * @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
|
282 * @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
|
283 */ |
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
|
284 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
|
285 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
|
286 |
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
|
287 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
|
288 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
|
289 notifyNewSource(source).tagAs(Tags.FROM_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
|
290 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
|
291 } |
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
|
292 |
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
|
293 /** |
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
|
294 * 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
|
295 * 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
|
296 * 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
|
297 * 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
|
298 * |
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
|
299 * @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
|
300 * @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
|
301 */ |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
302 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
|
303 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
|
304 |
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
|
305 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
|
306 nameToSource.put(name, new WeakReference<>(source)); |
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
|
307 notifyNewSource(source).tagAs(Tags.FROM_LITERAL); |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
308 return source; |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
309 } |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
310 |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
311 /** |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
312 * 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
|
313 * an existing {@link Source}. |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
314 * |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
315 * @param base an existing Source instance |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
316 * @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
|
317 * @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
|
318 * @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
|
319 * @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
|
320 */ |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
321 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
|
322 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
|
323 |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
324 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
|
325 return subSource; |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
326 } |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
327 |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
328 /** |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
329 * 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
|
330 * the end of an existing {@link Source}. |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
331 * |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
332 * @param base an existing Source instance |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
333 * @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
|
334 * @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
|
335 * @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
|
336 */ |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
337 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
|
338 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
|
339 |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
340 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
|
341 } |
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
|
342 |
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
|
343 /** |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
344 * 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
|
345 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
346 * @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
|
347 * @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
|
348 * @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
|
349 * @throws IOException if reading fails |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
350 */ |
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
|
351 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
|
352 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
|
353 |
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
|
354 final URLSource source = URLSource.get(url, description); |
20906
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
355 notifyNewSource(source).tagAs(Tags.FROM_URL); |
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
|
356 return source; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
357 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
358 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
359 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
360 * 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
|
361 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
362 * @param reader |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
363 * @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
|
364 * @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
|
365 * @throws IOException if reading fails |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
366 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
367 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
|
368 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
|
369 |
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
|
370 final LiteralSource source = new LiteralSource(description, read(reader)); |
20906
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
371 notifyNewSource(source).tagAs(Tags.FROM_READER); |
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
|
372 return source; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
373 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
374 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
375 /** |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
376 * 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
|
377 * 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
|
378 * 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
|
379 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
380 * @param bytes the raw bytes of the source |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
381 * @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
|
382 * @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
|
383 * @return a newly created, non-indexed source representation |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
384 */ |
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
|
385 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
|
386 return fromBytes(bytes, 0, bytes.length, description, charset); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
387 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
388 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
389 /** |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
390 * 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
|
391 * 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
|
392 * 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
|
393 * relative to byteIndex. |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
394 * |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
395 * @param bytes the raw bytes of the source |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
396 * @param byteIndex where the string starts in the byte array |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
397 * @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
|
398 * @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
|
399 * @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
|
400 * @return a newly created, non-indexed source representation |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
401 */ |
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
|
402 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
|
403 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
|
404 |
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
|
405 final BytesSource source = new BytesSource(description, bytes, byteIndex, length, charset); |
20906
c8b83aa6cc82
Truffle/Source: remove proposed standard SourceTags; migrate the tags related to Source provenance into thte Source class.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
20038
diff
changeset
|
406 notifyNewSource(source).tagAs(Tags.FROM_BYTES); |
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
|
407 return source; |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
408 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
409 |
16989
19faa7ca37c1
Truffle/Source: use a synchronized hash table
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16140
diff
changeset
|
410 // 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
|
411 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
412 * 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
|
413 * 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
|
414 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
415 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
|
416 fileCacheEnabled = enabled; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
417 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
418 |
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
|
419 /** |
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
|
420 * Returns all {@link Source}s holding a particular {@link SyntaxTag}, or the whole collection |
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
|
421 * of Sources if the specified tag is {@code null}. |
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
|
422 * |
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
|
423 * @return A collection of Sources containing the given tag. |
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
|
424 */ |
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
|
425 public static Collection<Source> findSourcesTaggedAs(SourceTag tag) { |
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
|
426 final List<Source> taggedSources = new ArrayList<>(); |
20022
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
427 synchronized (allSources) { |
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
428 for (WeakReference<Source> ref : allSources) { |
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
429 Source source = ref.get(); |
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
430 if (source != null) { |
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
431 if (tag == null || source.isTaggedAs(tag)) { |
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
432 taggedSources.add(ref.get()); |
eebf140fa6e4
syncronize the access to Source.allSources. Should fix random crashes we experienced before.
Christian Wirth <christian.wirth@oracle.com>
parents:
19697
diff
changeset
|
433 } |
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
|
434 } |
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
|
435 } |
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
|
436 } |
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
|
437 return taggedSources; |
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
|
438 } |
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
|
439 |
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
|
440 /** |
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
|
441 * Adds a {@link SourceListener} to receive events. |
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
|
442 */ |
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
|
443 public static void addSourceListener(SourceListener listener) { |
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
|
444 assert listener != null; |
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
|
445 sourceListeners.add(listener); |
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
|
446 } |
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
|
447 |
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
|
448 /** |
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
|
449 * Removes a {@link SourceListener}. Ignored if listener not found. |
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
|
450 */ |
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
|
451 public static void removeSourceListener(SourceListener listener) { |
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
|
452 sourceListeners.remove(listener); |
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
|
453 } |
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
|
454 |
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
|
455 private static Source notifyNewSource(Source source) { |
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
|
456 allSources.add(new WeakReference<>(source)); |
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
|
457 for (SourceListener listener : sourceListeners) { |
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
|
458 listener.sourceCreated(source); |
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
|
459 } |
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
|
460 return source; |
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
|
461 } |
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
|
462 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
463 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
|
464 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
|
465 final StringBuilder builder = new StringBuilder(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
466 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
|
467 |
21989
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
468 try { |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
469 while (true) { |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
470 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
|
471 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
|
472 break; |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
473 } |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
474 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
|
475 } |
21989
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
476 } finally { |
72010b401152
Truffle/Source: close the Reader when finished.
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21987
diff
changeset
|
477 bufferedReader.close(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
478 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
479 return builder.toString(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
480 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
481 |
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
|
482 private final ArrayList<SourceTag> tags = new ArrayList<>(); |
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
|
483 |
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
|
484 private Source() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
485 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
486 |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
487 private TextMap textMap = null; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
488 |
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
|
489 abstract void reset(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
490 |
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
|
491 public final boolean isTaggedAs(SourceTag tag) { |
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
|
492 assert tag != null; |
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
|
493 return tags.contains(tag); |
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
|
494 } |
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
|
495 |
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
|
496 public final Collection<SourceTag> getSourceTags() { |
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
|
497 return Collections.unmodifiableCollection(tags); |
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
|
498 } |
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
|
499 |
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
|
500 /** |
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
|
501 * Adds a {@linkplain SourceTag tag} to the set of tags associated with this {@link Source}; |
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
|
502 * {@code no-op} if already in the set. |
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
|
503 * |
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
|
504 * @return this |
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
|
505 */ |
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
|
506 public final Source tagAs(SourceTag tag) { |
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
|
507 assert tag != null; |
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
|
508 if (!tags.contains(tag)) { |
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
|
509 tags.add(tag); |
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
|
510 for (SourceListener listener : sourceListeners) { |
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
|
511 listener.sourceTaggedAs(this, tag); |
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
|
512 } |
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
|
513 } |
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
|
514 return this; |
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
|
515 } |
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
|
516 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
517 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
518 * 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
|
519 * 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
|
520 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
521 * @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
|
522 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
523 public abstract String getName(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
524 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
525 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
526 * 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
|
527 * 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
|
528 * full path. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
529 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
530 * @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
|
531 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
532 public abstract String getShortName(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
533 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
534 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
535 * 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
|
536 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
537 public abstract String getPath(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
538 |
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 * 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
|
541 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
542 public abstract URL getURL(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
543 |
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 * Access to the source contents. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
546 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
547 public abstract Reader getReader(); |
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 * Access to the source contents. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
551 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
552 public final InputStream getInputStream() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
553 return new ByteArrayInputStream(getCode().getBytes()); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
554 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
555 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
556 /** |
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
|
557 * 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
|
558 */ |
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
|
559 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
|
560 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
|
561 } |
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
|
562 |
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
|
563 /** |
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
|
564 * 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
|
565 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
566 public abstract String getCode(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
567 |
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
|
568 /** |
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
|
569 * 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
|
570 */ |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
571 public String getCode(int charIndex, int charLength) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
572 return getCode().substring(charIndex, charIndex + charLength); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
573 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
574 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
575 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
576 * 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
|
577 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
578 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
|
579 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
|
580 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
|
581 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
|
582 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
583 |
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 * 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
|
586 * 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
|
587 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
588 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
|
589 return getTextMap().lineCount(); |
16068
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 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
592 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
593 * 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
|
594 * position. |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
595 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
596 * @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
|
597 */ |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
598 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
|
599 return getTextMap().offsetToLine(offset); |
16068
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 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
602 /** |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
603 * 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
|
604 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
605 * @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
|
606 */ |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
607 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
|
608 return getTextMap().offsetToCol(offset); |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
609 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
610 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
611 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
612 * 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
|
613 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
614 * @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
|
615 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
616 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
|
617 return getTextMap().lineStartOffset(lineNumber); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
618 } |
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 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
621 * 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
|
622 * numbered line. |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
623 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
624 * @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
|
625 */ |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
626 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
|
627 return getTextMap().lineLength(lineNumber); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
628 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
629 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
630 /** |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
631 * 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
|
632 * |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
633 * @param chars the text to append |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
634 * @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
|
635 */ |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
636 public void appendCode(CharSequence chars) { |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
637 throw new UnsupportedOperationException(); |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
638 } |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
639 |
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
640 /** |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
641 * 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
|
642 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
643 * 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
|
644 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
645 * 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
|
646 * {@link Source} representations are canonical. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
647 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
648 * @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
|
649 * @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
|
650 * @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
|
651 * @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
|
652 * @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
|
653 * @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
|
654 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
655 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
|
656 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
|
657 } |
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 * 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
|
661 * {@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
|
662 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
663 * 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
|
664 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
665 * 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
|
666 * {@link Source} representations are canonical. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
667 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
668 * @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
|
669 * @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
|
670 * @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
|
671 * @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
|
672 * @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
|
673 * @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
|
674 * @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
|
675 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
676 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
|
677 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
|
678 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
|
679 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
|
680 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
681 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
|
682 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
|
683 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
684 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
685 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
686 * 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
|
687 * {@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
|
688 * source. |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
689 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
690 * 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
|
691 * <p> |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
692 * 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
|
693 * {@link Source} representations are canonical. |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
694 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
695 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
696 * @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
|
697 * @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
|
698 * @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
|
699 * @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
|
700 * @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
|
701 * source |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
702 * @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
|
703 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
704 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
|
705 checkRange(charIndex, length); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
706 final int startLine = getLineNumber(charIndex); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
707 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
|
708 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
|
709 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
710 |
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
|
711 void checkRange(int charIndex, int length) { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
712 if (!(charIndex >= 0 && length >= 0 && charIndex + length <= getCode().length())) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
713 throw new IllegalArgumentException("text positions out of range"); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
714 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
715 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
716 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
717 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
718 * 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
|
719 * 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
|
720 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
721 * @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
|
722 * @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
|
723 * @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
|
724 * @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
|
725 * @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
|
726 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
727 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
|
728 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
|
729 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
|
730 return createSection(identifier, charIndex, length); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
731 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
732 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
733 /** |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
734 * 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
|
735 * 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
|
736 * |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
737 * @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
|
738 * @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
|
739 */ |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
740 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
|
741 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
|
742 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
743 |
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
|
744 /** |
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 * 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
|
746 * 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
|
747 */ |
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
|
748 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
|
749 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
|
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 |
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
|
752 final TextMap getTextMap() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
753 if (textMap == null) { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
754 textMap = createTextMap(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
755 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
756 return textMap; |
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 |
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
|
759 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
|
760 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
|
761 } |
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
|
762 |
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
|
763 TextMap createTextMap() { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
764 final String code = getCode(); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
765 if (code == null) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
766 throw new RuntimeException("can't read file " + getName()); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
767 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
768 return TextMap.fromString(code); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
769 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
770 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
771 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
|
772 |
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
|
773 private final String description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
774 private final String code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
775 |
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
|
776 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
|
777 this.description = description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
778 this.code = code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
779 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
780 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
781 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
782 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
|
783 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
784 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
785 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
786 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
787 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
|
788 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
789 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
790 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
791 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
792 public String getCode() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
793 return code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
794 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
795 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
796 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
797 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
|
798 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
799 } |
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 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
802 public URL getURL() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
803 return null; |
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 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
806 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
807 public Reader getReader() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
808 return new StringReader(code); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
809 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
810 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
811 @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
|
812 void reset() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
813 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
814 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
815 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
816 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
|
817 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
|
818 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
819 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
820 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
821 public boolean equals(Object obj) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
822 if (this == obj) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
823 return true; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
824 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
825 if (obj == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
826 return false; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
827 } |
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
|
828 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
|
829 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
|
830 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
|
831 } |
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
|
832 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
|
833 } |
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
|
834 } |
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
|
835 |
21291
70bbc530a2d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
21271
diff
changeset
|
836 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
|
837 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
|
838 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
|
839 |
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
|
840 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
|
841 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
|
842 } |
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
|
843 |
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
|
844 @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
|
845 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
|
846 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
|
847 } |
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
|
848 |
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
|
849 @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
|
850 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
|
851 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
|
852 } |
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
|
853 |
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
|
854 @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
|
855 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
|
856 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
|
857 } |
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
|
858 |
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
|
859 @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
|
860 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
|
861 return description; |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
862 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
863 |
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
|
864 @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
|
865 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
|
866 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
|
867 } |
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
|
868 |
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
|
869 @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
|
870 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
|
871 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
|
872 } |
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
|
873 |
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
|
874 @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
|
875 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
|
876 } |
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
|
877 |
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
|
878 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
|
879 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
|
880 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
|
881 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
|
882 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
|
883 } |
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
|
884 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
|
885 } |
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
|
886 |
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
|
887 @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
|
888 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
|
889 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
|
890 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
|
891 } |
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
|
892 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
893 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
894 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
895 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
|
896 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
897 private final File file; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
898 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
|
899 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
|
900 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
901 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
|
902 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
|
903 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
904 public FileSource(File file, String name, String 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
|
905 this(file, name, path, 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
|
906 } |
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
|
907 |
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
|
908 public FileSource(File file, String name, String path, CharSequence chars) { |
18980
ae0eb836e6f4
store absolute file in FileSource
Lukas Stadler <lukas.stadler@oracle.com>
parents:
18979
diff
changeset
|
909 this.file = file.getAbsoluteFile(); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
910 this.name = name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
911 this.path = 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
|
912 if (chars != 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
|
913 this.code = chars.toString(); |
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
|
914 } |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
915 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
916 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
917 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
918 public String getName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
919 return name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
920 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
921 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
922 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
923 public String getShortName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
924 return file.getName(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
925 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
926 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
927 @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
|
928 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
|
929 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
|
930 } |
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
|
931 |
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
|
932 @Override |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
933 public String getCode() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
934 if (fileCacheEnabled) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
935 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
|
936 try { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
937 code = read(getReader()); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
938 timeStamp = file.lastModified(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
939 } catch (IOException e) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
940 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
941 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
942 return code; |
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 try { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
945 return read(new FileReader(file)); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
946 } catch (IOException e) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
947 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
948 return null; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
949 } |
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 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
952 public String getPath() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
953 return path; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
954 } |
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 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
957 public URL getURL() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
958 return null; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
959 } |
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 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
962 public Reader getReader() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
963 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
|
964 return new StringReader(code); |
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 try { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
967 return new FileReader(file); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
968 } catch (FileNotFoundException e) { |
18979
bdb24e259c11
include original exception in FileSource.getReader
Lukas Stadler <lukas.stadler@oracle.com>
parents:
18676
diff
changeset
|
969 |
bdb24e259c11
include original exception in FileSource.getReader
Lukas Stadler <lukas.stadler@oracle.com>
parents:
18676
diff
changeset
|
970 throw new RuntimeException("Can't find file " + path, e); |
16068
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 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
973 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
974 @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
|
975 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
|
976 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
|
977 } |
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
|
978 |
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
|
979 @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
|
980 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
|
981 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
|
982 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
|
983 } |
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
|
984 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
|
985 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
|
986 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
|
987 } |
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
|
988 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
|
989 } |
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
|
990 |
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
|
991 @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
|
992 void reset() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
993 this.code = null; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
994 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
995 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
996 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
997 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
|
998 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
999 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
|
1000 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1001 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
|
1002 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
|
1003 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
|
1004 if (source == null) { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1005 source = new URLSource(url, name); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1006 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
|
1007 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1008 return source; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1009 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1010 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1011 private final URL url; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1012 private final String name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1013 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
|
1014 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1015 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
|
1016 this.url = url; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1017 this.name = name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1018 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
|
1019 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1020 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1021 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1022 public String getName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1023 return name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1024 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1025 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1026 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1027 public String getShortName() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1028 return name; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1029 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1030 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1031 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1032 public String getPath() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1033 return url.getPath(); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1034 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1035 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1036 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1037 public URL getURL() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1038 return url; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1039 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1040 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1041 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1042 public Reader getReader() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1043 return new StringReader(code); |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1044 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1045 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1046 @Override |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1047 public String getCode() { |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1048 return code; |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1049 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1050 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1051 @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
|
1052 void reset() { |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1053 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1054 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1055 |
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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 |
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
|
1061 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
|
1062 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
|
1063 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
|
1064 } |
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
|
1065 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
|
1066 } |
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
|
1067 |
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
|
1068 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
|
1069 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
|
1070 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
|
1071 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
|
1072 } |
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
|
1073 |
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
|
1074 @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
|
1075 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
|
1076 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
|
1077 } |
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
|
1078 |
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
|
1079 @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
|
1080 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
|
1081 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
|
1082 } |
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
|
1083 |
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
|
1084 @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
|
1085 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
|
1086 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
|
1087 } |
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
|
1088 |
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
|
1089 @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
|
1090 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
|
1091 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
|
1092 } |
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
|
1093 |
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
|
1094 @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
|
1095 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
|
1096 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
|
1097 } |
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
|
1098 |
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
|
1099 @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
|
1100 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
|
1101 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
|
1102 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
|
1103 } |
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
|
1104 |
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
|
1105 @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
|
1106 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
|
1107 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
|
1108 } |
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
|
1109 } |
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
|
1110 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1111 private static final class BytesSource extends Source { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1112 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1113 private final String name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1114 private final byte[] bytes; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1115 private final int byteIndex; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1116 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
|
1117 private final CharsetDecoder decoder; |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1118 |
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
|
1119 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
|
1120 this.name = name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1121 this.bytes = bytes; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1122 this.byteIndex = byteIndex; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1123 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
|
1124 this.decoder = decoder.newDecoder(); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1125 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1126 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1127 @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
|
1128 void reset() { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1129 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1130 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1131 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1132 public String getName() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1133 return name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1134 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1135 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1136 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1137 public String getShortName() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1138 return name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1139 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1140 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1141 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1142 public String getPath() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1143 return name; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1144 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1145 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1146 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1147 public URL getURL() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1148 return null; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1149 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1150 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1151 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1152 public Reader getReader() { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1153 return null; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1154 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1155 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1156 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1157 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
|
1158 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
|
1159 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
|
1160 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
|
1161 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
|
1162 } 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
|
1163 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
|
1164 } |
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
|
1165 return chb.toString(); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1166 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1167 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1168 @Override |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1169 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
|
1170 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
|
1171 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
|
1172 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
|
1173 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
|
1174 } 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
|
1175 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
|
1176 } |
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
|
1177 return chb.toString(); |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1178 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1179 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1180 @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
|
1181 void checkRange(int charIndex, int rangeLength) { |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1182 if (!(charIndex >= 0 && rangeLength >= 0 && charIndex + rangeLength <= length)) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1183 throw new IllegalArgumentException("text positions out of range"); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1184 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1185 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1186 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1187 @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
|
1188 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
|
1189 return TextMap.fromString(getCode()); |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1190 } |
16130
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 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1194 * 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
|
1195 * newline characters. The coordinate systems are: |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1196 * <ul> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1197 * <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
|
1198 * 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
|
1199 * <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
|
1200 * text is at (1,1).</li> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1201 * </ul> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1202 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1203 * 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
|
1204 * 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
|
1205 * 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
|
1206 * 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
|
1207 * 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
|
1208 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1209 * 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
|
1210 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1211 * 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
|
1212 * 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
|
1213 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1214 * <strong>Limitations:</strong> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1215 * <ul> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1216 * <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
|
1217 * <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
|
1218 * <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
|
1219 * </ul> |
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 private static final class TextMap { |
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 // 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
|
1224 private final int[] nlOffsets; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1225 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1226 // 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
|
1227 private final int textLength; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1228 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1229 // Is the final text character a newline? |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1230 final boolean finalNL; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1231 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1232 public TextMap(int[] nlOffsets, int textLength, boolean finalNL) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1233 this.nlOffsets = nlOffsets; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1234 this.textLength = textLength; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1235 this.finalNL = finalNL; |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1236 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1237 |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1238 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1239 * 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
|
1240 * lines/columns. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1241 */ |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1242 public static TextMap fromString(String text) { |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1243 final int textLength = text.length(); |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1244 final ArrayList<Integer> lines = new ArrayList<>(); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1245 lines.add(0); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1246 int offset = 0; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1247 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1248 while (offset < text.length()) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1249 final int nlIndex = text.indexOf('\n', offset); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1250 if (nlIndex >= 0) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1251 offset = nlIndex + 1; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1252 lines.add(offset); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1253 } else { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1254 break; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1255 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1256 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1257 lines.add(Integer.MAX_VALUE); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1258 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1259 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
|
1260 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
|
1261 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
|
1262 } |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1263 |
17066
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1264 final boolean finalNL = textLength > 0 && (textLength == nlOffsets[nlOffsets.length - 2]); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1265 |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1266 return new TextMap(nlOffsets, textLength, finalNL); |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1267 } |
0bcefb0f8488
Truffle: byte[] sources.
Chris Seaton <chris.seaton@oracle.com>
parents:
16989
diff
changeset
|
1268 |
16130
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 * 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
|
1271 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1272 * @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
|
1273 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1274 public int offsetToLine(int offset) throws IllegalArgumentException { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1275 if (offset < 0 || offset >= textLength) { |
22036
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1276 if (offset == 0 && textLength == 0) { |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1277 return 1; |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1278 } |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1279 throw new IllegalArgumentException("offset out of bounds"); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1280 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1281 int line = 1; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1282 while (offset >= nlOffsets[line]) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1283 line++; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1284 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1285 return line; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1286 } |
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 * 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
|
1290 * character. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1291 * <p> |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1292 * 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
|
1293 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1294 * @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
|
1295 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1296 public int offsetToCol(int offset) throws IllegalArgumentException { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1297 return 1 + offset - nlOffsets[offsetToLine(offset) - 1]; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1298 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1299 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1300 /** |
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
|
1301 * 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
|
1302 */ |
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
|
1303 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
|
1304 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
|
1305 } |
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
|
1306 |
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
|
1307 /** |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1308 * 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
|
1309 * 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
|
1310 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1311 public int lineCount() { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1312 if (textLength == 0) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1313 return 0; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1314 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1315 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
|
1316 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1317 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1318 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1319 * 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
|
1320 * 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
|
1321 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1322 * @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
|
1323 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1324 public int lineStartOffset(int line) throws IllegalArgumentException { |
22036
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1325 if (textLength == 0) { |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1326 return 0; |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1327 } |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1328 if (lineOutOfRange(line)) { |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1329 throw new IllegalArgumentException("line out of bounds"); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1330 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1331 return nlOffsets[line - 1]; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1332 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1333 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1334 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1335 * 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
|
1336 * <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
|
1337 * |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1338 * @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
|
1339 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1340 public int lineLength(int line) throws IllegalArgumentException { |
22036
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1341 if (textLength == 0) { |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1342 return 0; |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1343 } |
f26b6524e5e0
fixes for empty sources
Mick Jordan <mick.jordan@oracle.com>
parents:
21989
diff
changeset
|
1344 if (lineOutOfRange(line)) { |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1345 throw new IllegalArgumentException("line out of bounds"); |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1346 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1347 if (line == nlOffsets.length - 1 && !finalNL) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1348 return textLength - nlOffsets[line - 1]; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1349 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1350 return (nlOffsets[line] - nlOffsets[line - 1]) - 1; |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1351 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1352 } |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1353 |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1354 /** |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1355 * Is the line number out of range. |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1356 */ |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1357 private boolean lineOutOfRange(int line) { |
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1358 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
|
1359 } |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1360 |
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1361 } |
16130
6f7d3f3703d3
Truffle/Source:
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16068
diff
changeset
|
1362 |
16068
74e142bd2b12
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
diff
changeset
|
1363 } |