45 * A module ExportEntry record. |
45 * A module ExportEntry record. |
46 * |
46 * |
47 * @see <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-source-text-module-records">es6 modules</a> |
47 * @see <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-source-text-module-records">es6 modules</a> |
48 */ |
48 */ |
49 public static final class ExportEntry { |
49 public static final class ExportEntry { |
50 private final String exportName; |
50 private final IdentNode exportName; |
51 private final String moduleRequest; |
51 private final IdentNode moduleRequest; |
52 private final String importName; |
52 private final IdentNode importName; |
53 private final String localName; |
53 private final IdentNode localName; |
54 |
54 |
55 private ExportEntry(final String exportName, final String moduleRequest, final String importName, final String localName) { |
55 private final int startPosition; |
|
56 private final int endPosition; |
|
57 |
|
58 private ExportEntry(final IdentNode exportName, final IdentNode moduleRequest, final IdentNode importName, |
|
59 final IdentNode localName, final int startPosition, final int endPosition) { |
56 this.exportName = exportName; |
60 this.exportName = exportName; |
57 this.moduleRequest = moduleRequest; |
61 this.moduleRequest = moduleRequest; |
58 this.importName = importName; |
62 this.importName = importName; |
59 this.localName = localName; |
63 this.localName = localName; |
|
64 this.startPosition = startPosition; |
|
65 this.endPosition = endPosition; |
60 } |
66 } |
61 |
67 |
62 /** |
68 /** |
63 * Creates a {@code export *} export entry. |
69 * Creates a {@code export *} export entry. |
64 * |
70 * |
|
71 * @param starName the star name |
65 * @param moduleRequest the module request |
72 * @param moduleRequest the module request |
|
73 * @param startPosition the start position |
|
74 * @param endPosition the end position |
66 * @return the export entry |
75 * @return the export entry |
67 */ |
76 */ |
68 public static ExportEntry exportStarFrom(final String moduleRequest) { |
77 public static ExportEntry exportStarFrom(final IdentNode starName, final IdentNode moduleRequest, final int startPosition, final int endPosition) { |
69 return new ExportEntry(null, moduleRequest, STAR_NAME, null); |
78 return new ExportEntry(null, moduleRequest, starName, null, startPosition, endPosition); |
70 } |
79 } |
71 |
80 |
72 /** |
81 /** |
73 * Creates a {@code export default} export entry. |
82 * Creates a {@code export default} export entry with a local name. |
74 * |
83 * |
|
84 * @param defaultName the default name |
|
85 * @param localName the local name |
|
86 * @param startPosition the start position |
|
87 * @param endPosition the end position |
75 * @return the export entry |
88 * @return the export entry |
76 */ |
89 */ |
77 public static ExportEntry exportDefault() { |
90 public static ExportEntry exportDefault(final IdentNode defaultName, final IdentNode localName, final int startPosition, final int endPosition) { |
78 return exportDefault(DEFAULT_EXPORT_BINDING_NAME); |
91 return new ExportEntry(defaultName, null, null, localName, startPosition, endPosition); |
79 } |
|
80 |
|
81 /** |
|
82 * Creates a {@code export default} export entry with a local name. |
|
83 * |
|
84 * @param localName the local name |
|
85 * @return the export entry |
|
86 */ |
|
87 public static ExportEntry exportDefault(final String localName) { |
|
88 return new ExportEntry(DEFAULT_NAME, null, null, localName); |
|
89 } |
92 } |
90 |
93 |
91 /** |
94 /** |
92 * Creates a export entry with a local name and export name. |
95 * Creates a export entry with a local name and export name. |
93 * |
96 * |
94 * @param exportName the export name |
97 * @param exportName the export name |
95 * @param localName the local name |
98 * @param localName the local name |
|
99 * @param startPosition the start position |
|
100 * @param endPosition the end position |
96 * @return the export entry |
101 * @return the export entry |
97 */ |
102 */ |
98 public static ExportEntry exportSpecifier(final String exportName, final String localName) { |
103 public static ExportEntry exportSpecifier(final IdentNode exportName, final IdentNode localName, final int startPosition, final int endPosition) { |
99 return new ExportEntry(exportName, null, null, localName); |
104 return new ExportEntry(exportName, null, null, localName, startPosition, endPosition); |
100 } |
105 } |
|
106 |
101 |
107 |
102 /** |
108 /** |
103 * Creates a export entry with an export name. |
109 * Creates a export entry with an export name. |
104 * |
110 * |
105 * @param exportName the export name |
111 * @param exportName the export name |
|
112 * @param startPosition the start position |
|
113 * @param endPosition the end position |
106 * @return the export entry |
114 * @return the export entry |
107 */ |
115 */ |
108 public static ExportEntry exportSpecifier(final String exportName) { |
116 public static ExportEntry exportSpecifier(final IdentNode exportName, final int startPosition, final int endPosition) { |
109 return exportSpecifier(exportName, exportName); |
117 return exportSpecifier(exportName, exportName, startPosition, endPosition); |
110 } |
118 } |
111 |
119 |
112 /** |
120 /** |
113 * Create a copy of this entry with the specified {@code module request} string. |
121 * Create a copy of this entry with the specified {@code module request} string. |
114 * |
122 * |
115 * @param moduleRequest the module request |
123 * @param moduleRequest the module request |
|
124 * @param endPosition the new endPosition |
116 * @return the new export entry |
125 * @return the new export entry |
117 */ |
126 */ |
118 public ExportEntry withFrom(@SuppressWarnings("hiding") final String moduleRequest) { |
127 public ExportEntry withFrom(@SuppressWarnings("hiding") final IdentNode moduleRequest, final int endPosition) { |
119 return new ExportEntry(exportName, moduleRequest, localName, null); |
128 // Note that "from" moves localName to inputName, and localName becomes null |
|
129 return new ExportEntry(exportName, moduleRequest, localName, null, startPosition, endPosition); |
120 } |
130 } |
121 |
131 |
122 /** |
132 /** |
123 * Returns the entry's export name. |
133 * Returns the entry's export name. |
124 * |
134 * |
125 * @return the export name |
135 * @return the export name |
126 */ |
136 */ |
127 public String getExportName() { |
137 public IdentNode getExportName() { |
128 return exportName; |
138 return exportName; |
129 } |
139 } |
130 |
140 |
131 /** |
141 /** |
132 * Returns the entry's module request. |
142 * Returns the entry's module request. |
133 * |
143 * |
134 * @return the module request |
144 * @return the module request |
135 */ |
145 */ |
136 public String getModuleRequest() { |
146 public IdentNode getModuleRequest() { |
137 return moduleRequest; |
147 return moduleRequest; |
138 } |
148 } |
139 |
149 |
140 /** |
150 /** |
141 * Returns the entry's import name. |
151 * Returns the entry's import name. |
142 * |
152 * |
143 * @return the import name |
153 * @return the import name |
144 */ |
154 */ |
145 public String getImportName() { |
155 public IdentNode getImportName() { |
146 return importName; |
156 return importName; |
147 } |
157 } |
148 |
158 |
149 /** |
159 /** |
150 * Returns the entry's local name. |
160 * Returns the entry's local name. |
151 * |
161 * |
152 * @return the local name |
162 * @return the local name |
153 */ |
163 */ |
154 public String getLocalName() { |
164 public IdentNode getLocalName() { |
155 return localName; |
165 return localName; |
|
166 } |
|
167 |
|
168 /** |
|
169 * Returns the entry's start position. |
|
170 * |
|
171 * @return the start position |
|
172 */ |
|
173 public int getStartPosition() { |
|
174 return startPosition; |
|
175 } |
|
176 |
|
177 /** |
|
178 * Returns the entry's end position. |
|
179 * |
|
180 * @return the end position |
|
181 */ |
|
182 public int getEndPosition() { |
|
183 return endPosition; |
156 } |
184 } |
157 |
185 |
158 @Override |
186 @Override |
159 public String toString() { |
187 public String toString() { |
160 return "ExportEntry [exportName=" + exportName + ", moduleRequest=" + moduleRequest + ", importName=" + importName + ", localName=" + localName + "]"; |
188 return "ExportEntry [exportName=" + exportName + ", moduleRequest=" + moduleRequest + ", importName=" + importName + ", localName=" + localName + "]"; |
165 * An ImportEntry record. |
193 * An ImportEntry record. |
166 * |
194 * |
167 * @see <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-source-text-module-records">es6 modules</a> |
195 * @see <a href="http://www.ecma-international.org/ecma-262/6.0/#sec-source-text-module-records">es6 modules</a> |
168 */ |
196 */ |
169 public static final class ImportEntry { |
197 public static final class ImportEntry { |
170 private final String moduleRequest; |
198 private final IdentNode moduleRequest; |
171 private final String importName; |
199 private final IdentNode importName; |
172 private final String localName; |
200 private final IdentNode localName; |
173 |
201 |
174 private ImportEntry(final String moduleRequest, final String importName, final String localName) { |
202 private final int startPosition; |
|
203 private final int endPosition; |
|
204 |
|
205 private ImportEntry(final IdentNode moduleRequest, final IdentNode importName, final IdentNode localName, |
|
206 final int startPosition, final int endPosition) { |
175 this.moduleRequest = moduleRequest; |
207 this.moduleRequest = moduleRequest; |
176 this.importName = importName; |
208 this.importName = importName; |
177 this.localName = localName; |
209 this.localName = localName; |
178 } |
210 this.startPosition = startPosition; |
179 |
211 this.endPosition = endPosition; |
180 /** |
|
181 * Creates an import entry with default name. |
|
182 * |
|
183 * @param localName the local name |
|
184 * @return the import entry |
|
185 */ |
|
186 public static ImportEntry importDefault(final String localName) { |
|
187 return new ImportEntry(null, DEFAULT_NAME, localName); |
|
188 } |
|
189 |
|
190 /** |
|
191 * Creates an import entry with {@code *} import name. |
|
192 * |
|
193 * @param localName the local name |
|
194 * @return the import entry |
|
195 */ |
|
196 public static ImportEntry importStarAsNameSpaceFrom(final String localName) { |
|
197 return new ImportEntry(null, STAR_NAME, localName); |
|
198 } |
212 } |
199 |
213 |
200 /** |
214 /** |
201 * Creates an import entry with the given import and local names. |
215 * Creates an import entry with the given import and local names. |
202 * |
216 * |
203 * @param importName the import name |
217 * @param importName the import name |
204 * @param localName the local name |
218 * @param localName the local name |
|
219 * @param startPosition the start position |
|
220 * @param endPosition the end position |
205 * @return the import entry |
221 * @return the import entry |
206 */ |
222 */ |
207 public static ImportEntry importSpecifier(final String importName, final String localName) { |
223 public static ImportEntry importSpecifier(final IdentNode importName, final IdentNode localName, final int startPosition, final int endPosition) { |
208 return new ImportEntry(null, importName, localName); |
224 return new ImportEntry(null, importName, localName, startPosition, endPosition); |
209 } |
225 } |
210 |
226 |
211 /** |
227 /** |
212 * Creates a new import entry with the given import name. |
228 * Creates a new import entry with the given import name. |
213 * |
229 * |
214 * @param importName the import name |
230 * @param importName the import name |
|
231 * @param startPosition the start position |
|
232 * @param endPosition the end position |
215 * @return the import entry |
233 * @return the import entry |
216 */ |
234 */ |
217 public static ImportEntry importSpecifier(final String importName) { |
235 public static ImportEntry importSpecifier(final IdentNode importName, final int startPosition, final int endPosition) { |
218 return importSpecifier(importName, importName); |
236 return importSpecifier(importName, importName, startPosition, endPosition); |
219 } |
237 } |
220 |
238 |
221 /** |
239 /** |
222 * Returns a copy of this import entry with the given module request. |
240 * Returns a copy of this import entry with the given module request and end position. |
223 * |
241 * |
224 * @param moduleRequest the module request |
242 * @param moduleRequest the module request |
|
243 * @param endPosition the new end position |
225 * @return the new import entry |
244 * @return the new import entry |
226 */ |
245 */ |
227 public ImportEntry withFrom(@SuppressWarnings("hiding") final String moduleRequest) { |
246 public ImportEntry withFrom(@SuppressWarnings("hiding") final IdentNode moduleRequest, final int endPosition) { |
228 return new ImportEntry(moduleRequest, importName, localName); |
247 return new ImportEntry(moduleRequest, importName, localName, startPosition, endPosition); |
229 } |
248 } |
230 |
249 |
231 /** |
250 /** |
232 * Returns the entry's module request. |
251 * Returns the entry's module request. |
233 * |
252 * |
234 * @return the module request |
253 * @return the module request |
235 */ |
254 */ |
236 public String getModuleRequest() { |
255 public IdentNode getModuleRequest() { |
237 return moduleRequest; |
256 return moduleRequest; |
238 } |
257 } |
239 |
258 |
240 /** |
259 /** |
241 * Returns the entry's import name. |
260 * Returns the entry's import name. |
242 * |
261 * |
243 * @return the import name |
262 * @return the import name |
244 */ |
263 */ |
245 public String getImportName() { |
264 public IdentNode getImportName() { |
246 return importName; |
265 return importName; |
247 } |
266 } |
248 |
267 |
249 /** |
268 /** |
250 * Returns the entry's local name. |
269 * Returns the entry's local name. |
251 * |
270 * |
252 * @return the local name |
271 * @return the local name |
253 */ |
272 */ |
254 public String getLocalName() { |
273 public IdentNode getLocalName() { |
255 return localName; |
274 return localName; |
|
275 } |
|
276 |
|
277 /** |
|
278 * Returns the entry's start position. |
|
279 * |
|
280 * @return the start position |
|
281 */ |
|
282 public int getStartPosition() { |
|
283 return startPosition; |
|
284 } |
|
285 |
|
286 /** |
|
287 * Returns the entry's end position. |
|
288 * |
|
289 * @return the end position |
|
290 */ |
|
291 public int getEndPosition() { |
|
292 return endPosition; |
256 } |
293 } |
257 |
294 |
258 @Override |
295 @Override |
259 public String toString() { |
296 public String toString() { |
260 return "ImportEntry [moduleRequest=" + moduleRequest + ", importName=" + importName + ", localName=" + localName + "]"; |
297 return "ImportEntry [moduleRequest=" + moduleRequest + ", importName=" + importName + ", localName=" + localName + "]"; |