| 1 | /* |
| 2 | * Copyright 2009 The Closure Compiler Authors. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.google.debugging.sourcemap; |
| 18 | |
| 19 | |
| 20 | import java.io.IOException; |
| 21 | import java.util.List; |
| 22 | |
| 23 | import javax.annotation.Nullable; |
| 24 | |
| 25 | /** |
| 26 | * Collects information mapping the generated (compiled) source back to |
| 27 | * its original source for debugging purposes |
| 28 | * |
| 29 | * @author [email protected] (John Lenz) |
| 30 | */ |
| 31 | public interface SourceMapGenerator { |
| 32 | |
| 33 | /** |
| 34 | * Appends the source map to the given buffer. |
| 35 | * |
| 36 | * @param out The stream to which the map will be appended. |
| 37 | * @param name The name of the generated source file that this source map |
| 38 | * represents. |
| 39 | */ |
| 40 | void appendTo(Appendable out, String name) throws IOException; |
| 41 | |
| 42 | /** |
| 43 | * Appends the index source map to the given buffer. |
| 44 | * |
| 45 | * @param out The stream to which the map will be appended. |
| 46 | * @param name The name of the generated source file that this source map |
| 47 | * represents. |
| 48 | * @param sections An ordered list of map sections to include in the index. |
| 49 | * @throws IOException |
| 50 | */ |
| 51 | void appendIndexMapTo( |
| 52 | Appendable out, String name, List<SourceMapSection> sections) |
| 53 | throws IOException; |
| 54 | |
| 55 | /** |
| 56 | * Resets the source map for reuse. A reset needs to be called between |
| 57 | * each generated output file. |
| 58 | */ |
| 59 | void reset(); |
| 60 | |
| 61 | /** |
| 62 | * Adds a mapping for the given node. Mappings must be added in order. |
| 63 | * @param sourceName The file name to use in the generate source map |
| 64 | * to represent this source. |
| 65 | * @param symbolName The symbol name associated with this position in the |
| 66 | * source map. |
| 67 | * @param sourceStartPosition The starting position in the original source for |
| 68 | * represented range outputStartPosition to outputEndPosition in the |
| 69 | * generated file. |
| 70 | * @param outputStartPosition The position on the starting line |
| 71 | * @param outputEndPosition The position on the ending line. |
| 72 | */ |
| 73 | void addMapping(String sourceName, @Nullable String symbolName, |
| 74 | FilePosition sourceStartPosition, |
| 75 | FilePosition outputStartPosition, FilePosition outputEndPosition); |
| 76 | |
| 77 | /** |
| 78 | * Sets the prefix used for wrapping the generated source file before |
| 79 | * it is written. This ensures that the source map is adjusted for the |
| 80 | * change in character offsets. |
| 81 | * |
| 82 | * @param prefix The prefix that is added before the generated source code. |
| 83 | */ |
| 84 | void setWrapperPrefix(String prefix); |
| 85 | |
| 86 | /** |
| 87 | * Sets the source code that exists in the buffer for which the |
| 88 | * generated code is being generated. This ensures that the source map |
| 89 | * accurately reflects the fact that the source is being appended to |
| 90 | * an existing buffer and as such, does not start at line 0, position 0 |
| 91 | * but rather some other line and position. |
| 92 | * |
| 93 | * @param offsetLine The index of the current line being printed. |
| 94 | * @param offsetIndex The column index of the current character being printed. |
| 95 | */ |
| 96 | void setStartingPosition(int offsetLine, int offsetIndex); |
| 97 | |
| 98 | /** |
| 99 | * Whether to perform additional validation on the source map. |
| 100 | * @param validate |
| 101 | */ |
| 102 | void validate(boolean validate); |
| 103 | } |