Debian Codegraph @

src/com/google/javascript/jscomp/SyntheticAst.java

raw symbols SCIP
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.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 * An AST generated totally by the compiler.
26 *
27 * @author [email protected] (Nick Santos)
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 }