comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/source/NullSourceSection.java @ 16068:74e142bd2b12

Truffle/Source: major API revision - All source-related classes now in com.oracle.truffle.api.source - SourceFactory replaced with factory methods on Source - Revision, renaming, and documentation to methods on Source and SourceSection - NullSourceSection is now a utility class
author Michael Van De Vanter <michael.van.de.vanter@oracle.com>
date Fri, 06 Jun 2014 22:13:00 -0700
parents
children 33bdafbf285d
comparison
equal deleted inserted replaced
16067:915ebb306fcc 16068:74e142bd2b12
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.oracle.truffle.api.source;
26
27 /**
28 * A special subtype of {@link SourceSection} that represents unavailable source, e.g. for language
29 * <em>builtins</em>.
30 */
31 public class NullSourceSection implements SourceSection {
32
33 private final String kind;
34 private final String name;
35 private final String asCode;
36
37 /**
38 * Placeholder for source that is unavailable, e.g. for language <em>builtins</em>.
39 *
40 * @param kind the general category, e.g. "JS builtin"
41 * @param name specific name for this section
42 */
43 public NullSourceSection(String kind, String name) {
44 this(kind, name, kind);
45 }
46
47 /**
48 * Placeholder for source that is unavailable, e.g. for language <em>builtins</em>.
49 *
50 * @param kind the general category, e.g. "JS builtin"
51 * @param name specific name for this section
52 * @param asCode string to return when {@link #getCode()} is called
53 */
54 public NullSourceSection(String kind, String name, String asCode) {
55 this.kind = kind;
56 this.name = name;
57 this.asCode = asCode;
58 }
59
60 public final Source getSource() {
61 return null;
62 }
63
64 public final int getStartLine() {
65 throw new UnsupportedOperationException(this.toString());
66 }
67
68 public final LineLocation getLineLocation() {
69 throw new UnsupportedOperationException(this.toString());
70 }
71
72 public final int getStartColumn() {
73 throw new UnsupportedOperationException(this.toString());
74 }
75
76 public final int getCharIndex() {
77 throw new UnsupportedOperationException(this.toString());
78 }
79
80 public final int getCharLength() {
81 throw new UnsupportedOperationException(this.toString());
82 }
83
84 public final int getCharEndIndex() {
85 throw new UnsupportedOperationException(this.toString());
86 }
87
88 public final String getIdentifier() {
89 return name;
90 }
91
92 public final String getCode() {
93 return asCode;
94 }
95
96 public final String getShortDescription() {
97 return kind + ": " + name;
98 }
99
100 @Override
101 public String toString() {
102 return getShortDescription();
103 }
104
105 }