| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.google.javascript.jscomp; |
| 18 |
|
| 19 |
import com.google.javascript.rhino.IR; |
| 20 |
import com.google.javascript.rhino.InputId; |
| 21 |
import com.google.javascript.rhino.Node; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
public class SyntheticAst implements SourceAst { |
| 30 |
private static final long serialVersionUID = 1L; |
| 31 |
|
| 32 |
private final InputId inputId; |
| 33 |
private final SourceFile sourceFile; |
| 34 |
|
| 35 |
private Node root; |
| 36 |
|
| 37 |
SyntheticAst(String sourceName) { |
| 38 |
this.inputId = new InputId(sourceName); |
| 39 |
this.sourceFile = new SourceFile(sourceName); |
| 40 |
clearAst(); |
| 41 |
} |
| 42 |
|
| 43 |
@Override |
| 44 |
public Node getAstRoot(AbstractCompiler compiler) { |
| 45 |
return root; |
| 46 |
} |
| 47 |
|
| 48 |
@Override |
| 49 |
public void clearAst() { |
| 50 |
root = IR.script(); |
| 51 |
root.setInputId(inputId); |
| 52 |
root.setStaticSourceFile(sourceFile); |
| 53 |
} |
| 54 |
|
| 55 |
@Override |
| 56 |
public InputId getInputId() { |
| 57 |
return inputId; |
| 58 |
} |
| 59 |
|
| 60 |
@Override |
| 61 |
public SourceFile getSourceFile() { |
| 62 |
return sourceFile; |
| 63 |
} |
| 64 |
|
| 65 |
@Override |
| 66 |
public void setSourceFile(SourceFile file) { |
| 67 |
throw new IllegalStateException( |
| 68 |
"Cannot set a source file for a synthetic AST"); |
| 69 |
} |
| 70 |
} |