|
27 | 27 | public final class Location {
|
28 | 28 | private final String sourceName;
|
29 | 29 | private final int offset;
|
30 |
| - |
| 30 | + |
31 | 31 | /**
|
32 |
| - * Create a new Location |
| 32 | + * Create a new Location |
33 | 33 | * @param sourceName script's name
|
34 | 34 | * @param offset character offset of script element
|
35 | 35 | */
|
36 | 36 | public Location(String sourceName, int offset) {
|
37 | 37 | this.sourceName = Objects.requireNonNull(sourceName);
|
38 | 38 | this.offset = offset;
|
39 | 39 | }
|
40 |
| - |
| 40 | + |
41 | 41 | /**
|
42 | 42 | * Return the script's name
|
43 | 43 | */
|
@@ -68,43 +68,31 @@ public RuntimeException createError(RuntimeException exception) {
|
68 | 68 |
|
69 | 69 | // This maximum length is theoretically 65535 bytes, but as it's CESU-8 encoded we don't know how large it is in bytes, so be safe
|
70 | 70 | private static final int MAX_NAME_LENGTH = 256;
|
71 |
| - |
| 71 | + |
72 | 72 | /** Computes the file name (mostly important for stacktraces) */
|
73 |
| - public static String computeSourceName(String scriptName, String source) { |
| 73 | + public static String computeSourceName(String scriptName) { |
74 | 74 | StringBuilder fileName = new StringBuilder();
|
75 |
| - if (scriptName.equals(PainlessScriptEngine.INLINE_NAME)) { |
76 |
| - // its an anonymous script, include at least a portion of the source to help identify which one it is |
77 |
| - // but don't create stacktraces with filenames that contain newlines or huge names. |
| 75 | + // its an anonymous script, include at least a portion of the source to help identify which one it is |
| 76 | + // but don't create stacktraces with filenames that contain newlines or huge names. |
78 | 77 |
|
79 |
| - // truncate to the first newline |
80 |
| - int limit = source.indexOf('\n'); |
81 |
| - if (limit >= 0) { |
82 |
| - int limit2 = source.indexOf('\r'); |
83 |
| - if (limit2 >= 0) { |
84 |
| - limit = Math.min(limit, limit2); |
85 |
| - } |
86 |
| - } else { |
87 |
| - limit = source.length(); |
| 78 | + // truncate to the first newline |
| 79 | + int limit = scriptName.indexOf('\n'); |
| 80 | + if (limit >= 0) { |
| 81 | + int limit2 = scriptName.indexOf('\r'); |
| 82 | + if (limit2 >= 0) { |
| 83 | + limit = Math.min(limit, limit2); |
88 | 84 | }
|
| 85 | + } else { |
| 86 | + limit = scriptName.length(); |
| 87 | + } |
89 | 88 |
|
90 |
| - // truncate to our limit |
91 |
| - limit = Math.min(limit, MAX_NAME_LENGTH); |
92 |
| - fileName.append(source, 0, limit); |
| 89 | + // truncate to our limit |
| 90 | + limit = Math.min(limit, MAX_NAME_LENGTH); |
| 91 | + fileName.append(scriptName, 0, limit); |
93 | 92 |
|
94 |
| - // if we truncated, make it obvious |
95 |
| - if (limit != source.length()) { |
96 |
| - fileName.append(" ..."); |
97 |
| - } |
98 |
| - fileName.append(" @ <inline script>"); |
99 |
| - } else { |
100 |
| - // its a named script, just use the name |
101 |
| - // but don't trust this has a reasonable length! |
102 |
| - if (scriptName.length() > MAX_NAME_LENGTH) { |
103 |
| - fileName.append(scriptName, 0, MAX_NAME_LENGTH); |
104 |
| - fileName.append(" ..."); |
105 |
| - } else { |
106 |
| - fileName.append(scriptName); |
107 |
| - } |
| 93 | + // if we truncated, make it obvious |
| 94 | + if (limit != scriptName.length()) { |
| 95 | + fileName.append(" ..."); |
108 | 96 | }
|
109 | 97 | return fileName.toString();
|
110 | 98 | }
|
|
0 commit comments