| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.debugging.sourcemap; |
| 18 |
|
| 19 |
import com.google.common.base.Preconditions; |
| 20 |
import com.google.common.collect.Lists; |
| 21 |
import com.google.common.collect.Maps; |
| 22 |
import com.google.debugging.sourcemap.SourceMapConsumerV3.EntryVisitor; |
| 23 |
|
| 24 |
import java.io.IOException; |
| 25 |
import java.util.ArrayDeque; |
| 26 |
import java.util.Deque; |
| 27 |
import java.util.LinkedHashMap; |
| 28 |
import java.util.List; |
| 29 |
import java.util.Map; |
| 30 |
import java.util.Map.Entry; |
| 31 |
|
| 32 |
import javax.annotation.Nullable; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public class SourceMapGeneratorV3 implements SourceMapGenerator { |
| 41 |
|
| 42 |
private static final int UNMAPPED = -1; |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
private List<Mapping> mappings = Lists.newArrayList(); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
private LinkedHashMap<String, Integer> sourceFileMap = |
| 54 |
Maps.newLinkedHashMap(); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
private LinkedHashMap<String, Integer> originalNameMap = |
| 60 |
Maps.newLinkedHashMap(); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
private String lastSourceFile = null; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
private int lastSourceFileIndex = -1; |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
private Mapping lastMapping; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
private FilePosition offsetPosition = new FilePosition(0, 0); |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
private FilePosition prefixPosition = new FilePosition(0, 0); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
@Override |
| 95 |
public void reset() { |
| 96 |
mappings.clear(); |
| 97 |
lastMapping = null; |
| 98 |
sourceFileMap.clear(); |
| 99 |
originalNameMap.clear(); |
| 100 |
lastSourceFile = null; |
| 101 |
lastSourceFileIndex = -1; |
| 102 |
offsetPosition = new FilePosition(0, 0); |
| 103 |
prefixPosition = new FilePosition(0, 0); |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
@Override |
| 111 |
public void validate(boolean validate) { |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
@Override |
| 123 |
public void setWrapperPrefix(String prefix) { |
| 124 |
|
| 125 |
int prefixLine = 0; |
| 126 |
int prefixIndex = 0; |
| 127 |
|
| 128 |
for (int i = 0; i < prefix.length(); ++i) { |
| 129 |
if (prefix.charAt(i) == '\n') { |
| 130 |
prefixLine++; |
| 131 |
prefixIndex = 0; |
| 132 |
} else { |
| 133 |
prefixIndex++; |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
prefixPosition = new FilePosition(prefixLine, prefixIndex); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
@Override |
| 151 |
public void setStartingPosition(int offsetLine, int offsetIndex) { |
| 152 |
Preconditions.checkState(offsetLine >= 0); |
| 153 |
Preconditions.checkState(offsetIndex >= 0); |
| 154 |
offsetPosition = new FilePosition(offsetLine, offsetIndex); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
@Override |
| 163 |
public void addMapping( |
| 164 |
String sourceName, @Nullable String symbolName, |
| 165 |
FilePosition sourceStartPosition, |
| 166 |
FilePosition startPosition, FilePosition endPosition) { |
| 167 |
|
| 168 |
|
| 169 |
if (sourceName == null || sourceStartPosition.getLine() < 0) { |
| 170 |
return; |
| 171 |
} |
| 172 |
|
| 173 |
FilePosition adjustedStart = startPosition; |
| 174 |
FilePosition adjustedEnd = endPosition; |
| 175 |
|
| 176 |
if (offsetPosition.getLine() != 0 |
| 177 |
|| offsetPosition.getColumn() != 0) { |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
int offsetLine = offsetPosition.getLine(); |
| 183 |
int startOffsetPosition = offsetPosition.getColumn(); |
| 184 |
int endOffsetPosition = offsetPosition.getColumn(); |
| 185 |
|
| 186 |
if (startPosition.getLine() > 0) { |
| 187 |
startOffsetPosition = 0; |
| 188 |
} |
| 189 |
|
| 190 |
if (endPosition.getLine() > 0) { |
| 191 |
endOffsetPosition = 0; |
| 192 |
} |
| 193 |
|
| 194 |
adjustedStart = new FilePosition( |
| 195 |
startPosition.getLine() + offsetLine, |
| 196 |
startPosition.getColumn() + startOffsetPosition); |
| 197 |
|
| 198 |
adjustedEnd = new FilePosition( |
| 199 |
endPosition.getLine() + offsetLine, |
| 200 |
endPosition.getColumn() + endOffsetPosition); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
Mapping mapping = new Mapping(); |
| 205 |
mapping.sourceFile = sourceName; |
| 206 |
mapping.originalPosition = sourceStartPosition; |
| 207 |
mapping.originalName = symbolName; |
| 208 |
mapping.startPosition = adjustedStart; |
| 209 |
mapping.endPosition = adjustedEnd; |
| 210 |
|
| 211 |
|
| 212 |
if (lastMapping != null) { |
| 213 |
int lastLine = lastMapping.startPosition.getLine(); |
| 214 |
int lastColumn = lastMapping.startPosition.getColumn(); |
| 215 |
int nextLine = mapping.startPosition.getLine(); |
| 216 |
int nextColumn = mapping.startPosition.getColumn(); |
| 217 |
Preconditions.checkState(nextLine > lastLine |
| 218 |
|| (nextLine == lastLine && nextColumn >= lastColumn), |
| 219 |
"Incorrect source mappings order, previous : (%s,%s)\n" |
| 220 |
+ "new : (%s,%s)\nnode : %s", |
| 221 |
lastLine, lastColumn, nextLine, nextColumn); |
| 222 |
} |
| 223 |
|
| 224 |
lastMapping = mapping; |
| 225 |
mappings.add(mapping); |
| 226 |
} |
| 227 |
|
| 228 |
class ConsumerEntryVisitor implements EntryVisitor { |
| 229 |
|
| 230 |
@Override |
| 231 |
public void visit( |
| 232 |
String sourceName, String symbolName, |
| 233 |
FilePosition sourceStartPosition, |
| 234 |
FilePosition startPosition, FilePosition endPosition) { |
| 235 |
addMapping(sourceName, symbolName, |
| 236 |
sourceStartPosition, startPosition, endPosition); |
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
public void mergeMapSection(int line, int column, String mapSectionContents) |
| 241 |
throws SourceMapParseException { |
| 242 |
setStartingPosition(line, column); |
| 243 |
SourceMapConsumerV3 section = new SourceMapConsumerV3(); |
| 244 |
section.parse(mapSectionContents); |
| 245 |
section.visitMappings(new ConsumerEntryVisitor()); |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
@Override |
| 275 |
public void appendTo(Appendable out, String name) throws IOException { |
| 276 |
int maxLine = prepMappings(); |
| 277 |
|
| 278 |
|
| 279 |
out.append("{\n"); |
| 280 |
appendFirstField(out, "version", "3"); |
| 281 |
appendField(out, "file", escapeString(name)); |
| 282 |
appendField(out, "lineCount", String.valueOf(maxLine + 1)); |
| 283 |
|
| 284 |
|
| 285 |
appendFieldStart(out, "mappings"); |
| 286 |
|
| 287 |
(new LineMapper(out)).appendLineMappings(); |
| 288 |
|
| 289 |
appendFieldEnd(out); |
| 290 |
|
| 291 |
|
| 292 |
appendFieldStart(out, "sources"); |
| 293 |
out.append("["); |
| 294 |
addSourceNameMap(out); |
| 295 |
out.append("]"); |
| 296 |
appendFieldEnd(out); |
| 297 |
|
| 298 |
|
| 299 |
appendFieldStart(out, "names"); |
| 300 |
out.append("["); |
| 301 |
addSymbolNameMap(out); |
| 302 |
out.append("]"); |
| 303 |
appendFieldEnd(out); |
| 304 |
|
| 305 |
out.append("\n}\n"); |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
private void addSourceNameMap(Appendable out) throws IOException { |
| 312 |
addNameMap(out, sourceFileMap); |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
private void addSymbolNameMap(Appendable out) throws IOException { |
| 319 |
addNameMap(out, originalNameMap); |
| 320 |
} |
| 321 |
|
| 322 |
private void addNameMap(Appendable out, Map<String, Integer> map) |
| 323 |
throws IOException { |
| 324 |
int i = 0; |
| 325 |
for (Entry<String, Integer> entry : map.entrySet()) { |
| 326 |
String key = entry.getKey(); |
| 327 |
if (i != 0) { |
| 328 |
out.append(","); |
| 329 |
} |
| 330 |
out.append(escapeString(key)); |
| 331 |
i++; |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
private static String escapeString(String value) { |
| 339 |
return Util.escapeString(value); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
private static void appendFirstField( |
| 345 |
Appendable out, String name, CharSequence value) |
| 346 |
throws IOException { |
| 347 |
out.append("\""); |
| 348 |
out.append(name); |
| 349 |
out.append("\""); |
| 350 |
out.append(":"); |
| 351 |
out.append(value); |
| 352 |
} |
| 353 |
|
| 354 |
private static void appendField( |
| 355 |
Appendable out, String name, CharSequence value) |
| 356 |
throws IOException { |
| 357 |
out.append(",\n"); |
| 358 |
out.append("\""); |
| 359 |
out.append(name); |
| 360 |
out.append("\""); |
| 361 |
out.append(":"); |
| 362 |
out.append(value); |
| 363 |
} |
| 364 |
|
| 365 |
private static void appendFieldStart(Appendable out, String name) |
| 366 |
throws IOException { |
| 367 |
appendField(out, name, ""); |
| 368 |
} |
| 369 |
|
| 370 |
@SuppressWarnings("unused") |
| 371 |
private static void appendFieldEnd(Appendable out) |
| 372 |
throws IOException { |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
private int prepMappings() throws IOException { |
| 379 |
|
| 380 |
(new MappingTraversal()).traverse(new UsedMappingCheck()); |
| 381 |
|
| 382 |
|
| 383 |
int id = 0; |
| 384 |
int maxLine = 0; |
| 385 |
for (Mapping m : mappings) { |
| 386 |
if (m.used) { |
| 387 |
m.id = id++; |
| 388 |
int endPositionLine = m.endPosition.getLine(); |
| 389 |
maxLine = Math.max(maxLine, endPositionLine); |
| 390 |
} |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
return maxLine + prefixPosition.getLine(); |
| 395 |
} |
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
static class Mapping { |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
int id = UNMAPPED; |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
String sourceFile; |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
FilePosition originalPosition; |
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
FilePosition startPosition; |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
FilePosition endPosition; |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
String originalName; |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
boolean used = false; |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
private class UsedMappingCheck implements MappingVisitor { |
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
@Override |
| 451 |
public void visit(Mapping m, int line, int col, int nextLine, int nextCol) |
| 452 |
throws IOException { |
| 453 |
if (m != null) { |
| 454 |
m.used = true; |
| 455 |
} |
| 456 |
} |
| 457 |
} |
| 458 |
|
| 459 |
private interface MappingVisitor { |
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
void visit(Mapping m, int line, int col, int endLine, int endCol) |
| 470 |
throws IOException; |
| 471 |
} |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
private class MappingTraversal { |
| 478 |
|
| 479 |
private int line; |
| 480 |
private int col; |
| 481 |
|
| 482 |
MappingTraversal() { |
| 483 |
} |
| 484 |
|
| 485 |
|
| 486 |
void traverse(MappingVisitor v) throws IOException { |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
Deque<Mapping> stack = new ArrayDeque<Mapping>(); |
| 491 |
for (Mapping m : mappings) { |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
while (!stack.isEmpty() && !isOverlapped(stack.peek(), m)) { |
| 497 |
Mapping previous = stack.pop(); |
| 498 |
maybeVisit(v, previous); |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
Mapping parent = stack.peek(); |
| 504 |
maybeVisitParent(v, parent, m); |
| 505 |
|
| 506 |
stack.push(m); |
| 507 |
} |
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
while (!stack.isEmpty()) { |
| 512 |
Mapping m = stack.pop(); |
| 513 |
maybeVisit(v, m); |
| 514 |
} |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
private int getAdjustedLine(FilePosition p) { |
| 521 |
return p.getLine() + prefixPosition.getLine(); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
private int getAdjustedCol(FilePosition p) { |
| 528 |
int rawLine = p.getLine(); |
| 529 |
int rawCol = p.getColumn(); |
| 530 |
|
| 531 |
return (rawLine != 0) |
| 532 |
? rawCol : rawCol + prefixPosition.getColumn(); |
| 533 |
} |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
private boolean isOverlapped(Mapping m1, Mapping m2) { |
| 539 |
|
| 540 |
int l1 = m1.endPosition.getLine(); |
| 541 |
int l2 = m2.startPosition.getLine(); |
| 542 |
int c1 = m1.endPosition.getColumn(); |
| 543 |
int c2 = m2.startPosition.getColumn(); |
| 544 |
|
| 545 |
return (l1 == l2 && c1 >= c2) || l1 > l2; |
| 546 |
} |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
private void maybeVisit(MappingVisitor v, Mapping m) throws IOException { |
| 553 |
int nextLine = getAdjustedLine(m.endPosition); |
| 554 |
int nextCol = getAdjustedCol(m.endPosition); |
| 555 |
|
| 556 |
|
| 557 |
if (line < nextLine || (line == nextLine && col < nextCol)) { |
| 558 |
visit(v, m, nextLine, nextCol); |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
private void maybeVisitParent(MappingVisitor v, Mapping parent, Mapping m) |
| 566 |
throws IOException { |
| 567 |
int nextLine = getAdjustedLine(m.startPosition); |
| 568 |
int nextCol = getAdjustedCol(m.startPosition); |
| 569 |
|
| 570 |
Preconditions.checkState(line < nextLine || col <= nextCol); |
| 571 |
if (line < nextLine || (line == nextLine && col < nextCol)) { |
| 572 |
visit(v, parent, nextLine, nextCol); |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
private void visit(MappingVisitor v, Mapping m, |
| 581 |
int nextLine, int nextCol) |
| 582 |
throws IOException { |
| 583 |
Preconditions.checkState(line <= nextLine); |
| 584 |
Preconditions.checkState(line < nextLine || col < nextCol); |
| 585 |
|
| 586 |
if (line == nextLine && col == nextCol) { |
| 587 |
|
| 588 |
Preconditions.checkState(false); |
| 589 |
return; |
| 590 |
} |
| 591 |
|
| 592 |
v.visit(m, line, col, nextLine, nextCol); |
| 593 |
|
| 594 |
line = nextLine; |
| 595 |
col = nextCol; |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
@Override |
| 609 |
public void appendIndexMapTo( |
| 610 |
Appendable out, String name, List<SourceMapSection> sections) |
| 611 |
throws IOException { |
| 612 |
|
| 613 |
out.append("{\n"); |
| 614 |
appendFirstField(out, "version", "3"); |
| 615 |
appendField(out, "file", escapeString(name)); |
| 616 |
|
| 617 |
|
| 618 |
appendFieldStart(out, "sections"); |
| 619 |
out.append("[\n"); |
| 620 |
boolean first = true; |
| 621 |
for (SourceMapSection section : sections) { |
| 622 |
if (first) { |
| 623 |
first = false; |
| 624 |
} else { |
| 625 |
out.append(",\n"); |
| 626 |
} |
| 627 |
out.append("{\n"); |
| 628 |
appendFirstField(out, "offset", |
| 629 |
offsetValue(section.getLine(), section.getColumn())); |
| 630 |
if (section.getSectionType() == SourceMapSection.SectionType.URL) { |
| 631 |
appendField(out, "url", escapeString(section.getSectionValue())); |
| 632 |
} else if (section.getSectionType() == SourceMapSection.SectionType.MAP) { |
| 633 |
appendField(out, "map", section.getSectionValue()); |
| 634 |
} else { |
| 635 |
throw new IOException("Unexpected section type"); |
| 636 |
} |
| 637 |
out.append("\n}"); |
| 638 |
} |
| 639 |
|
| 640 |
out.append("\n]"); |
| 641 |
appendFieldEnd(out); |
| 642 |
|
| 643 |
out.append("\n}\n"); |
| 644 |
} |
| 645 |
|
| 646 |
private CharSequence offsetValue(int line, int column) throws IOException { |
| 647 |
StringBuilder out = new StringBuilder(); |
| 648 |
out.append("{\n"); |
| 649 |
appendFirstField(out, "line", String.valueOf(line)); |
| 650 |
appendField(out, "column", String.valueOf(column)); |
| 651 |
out.append("\n}"); |
| 652 |
return out; |
| 653 |
} |
| 654 |
|
| 655 |
private int getSourceId(String sourceName) { |
| 656 |
if (sourceName != lastSourceFile) { |
| 657 |
lastSourceFile = sourceName; |
| 658 |
Integer index = sourceFileMap.get(sourceName); |
| 659 |
if (index != null) { |
| 660 |
lastSourceFileIndex = index; |
| 661 |
} else { |
| 662 |
lastSourceFileIndex = sourceFileMap.size(); |
| 663 |
sourceFileMap.put(sourceName, lastSourceFileIndex); |
| 664 |
} |
| 665 |
} |
| 666 |
return lastSourceFileIndex; |
| 667 |
} |
| 668 |
|
| 669 |
private int getNameId(String symbolName) { |
| 670 |
int originalNameIndex; |
| 671 |
Integer index = originalNameMap.get(symbolName); |
| 672 |
if (index != null) { |
| 673 |
originalNameIndex = index; |
| 674 |
} else { |
| 675 |
originalNameIndex = originalNameMap.size(); |
| 676 |
originalNameMap.put(symbolName, originalNameIndex); |
| 677 |
} |
| 678 |
return originalNameIndex; |
| 679 |
} |
| 680 |
|
| 681 |
private class LineMapper implements MappingVisitor { |
| 682 |
|
| 683 |
private final Appendable out; |
| 684 |
|
| 685 |
private int previousLine = -1; |
| 686 |
private int previousColumn = 0; |
| 687 |
|
| 688 |
|
| 689 |
private int previousSourceFileId; |
| 690 |
private int previousSourceLine; |
| 691 |
private int previousSourceColumn; |
| 692 |
private int previousNameId; |
| 693 |
|
| 694 |
LineMapper(Appendable out) { |
| 695 |
this.out = out; |
| 696 |
} |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
@Override |
| 702 |
public void visit(Mapping m, int line, int col, int nextLine, int nextCol) |
| 703 |
throws IOException { |
| 704 |
|
| 705 |
if (previousLine != line) { |
| 706 |
previousColumn = 0; |
| 707 |
} |
| 708 |
|
| 709 |
if (line != nextLine || col != nextCol) { |
| 710 |
if (previousLine == line) { |
| 711 |
out.append(','); |
| 712 |
} |
| 713 |
writeEntry(m, col); |
| 714 |
previousLine = line; |
| 715 |
previousColumn = col; |
| 716 |
} |
| 717 |
|
| 718 |
for (int i = line; i <= nextLine; i++) { |
| 719 |
if (i == nextLine) { |
| 720 |
break; |
| 721 |
} |
| 722 |
|
| 723 |
closeLine(false); |
| 724 |
openLine(false); |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
void writeEntry(Mapping m, int column) throws IOException { |
| 735 |
|
| 736 |
Base64VLQ.encode(out, column - previousColumn); |
| 737 |
previousColumn = column; |
| 738 |
if (m != null) { |
| 739 |
|
| 740 |
int sourceId = getSourceId(m.sourceFile); |
| 741 |
Base64VLQ.encode(out, sourceId - previousSourceFileId); |
| 742 |
previousSourceFileId = sourceId; |
| 743 |
|
| 744 |
|
| 745 |
int srcline = m.originalPosition.getLine(); |
| 746 |
int srcColumn = m.originalPosition.getColumn(); |
| 747 |
Base64VLQ.encode(out, srcline - previousSourceLine); |
| 748 |
previousSourceLine = srcline; |
| 749 |
|
| 750 |
Base64VLQ.encode(out, srcColumn - previousSourceColumn); |
| 751 |
previousSourceColumn = srcColumn; |
| 752 |
|
| 753 |
if (m.originalName != null) { |
| 754 |
|
| 755 |
int nameId = getNameId(m.originalName); |
| 756 |
Base64VLQ.encode(out, (nameId - previousNameId)); |
| 757 |
previousNameId = nameId; |
| 758 |
} |
| 759 |
} |
| 760 |
} |
| 761 |
|
| 762 |
|
| 763 |
void appendLineMappings() throws IOException { |
| 764 |
|
| 765 |
openLine(true); |
| 766 |
|
| 767 |
(new MappingTraversal()).traverse(this); |
| 768 |
|
| 769 |
|
| 770 |
closeLine(true); |
| 771 |
} |
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
private void openLine(boolean firstEntry) throws IOException { |
| 777 |
if (firstEntry) { |
| 778 |
out.append('\"'); |
| 779 |
} |
| 780 |
} |
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
private void closeLine(boolean finalEntry) throws IOException { |
| 786 |
out.append(';'); |
| 787 |
if (finalEntry) { |
| 788 |
out.append('\"'); |
| 789 |
} |
| 790 |
} |
| 791 |
} |
| 792 |
|
| 793 |
} |