Debian Codegraph @

src/com/google/javascript/jscomp/JSSourceFile.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
20 import com.google.common.annotations.VisibleForTesting;
21 import com.google.common.base.Charsets;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.io.Serializable;
27 import java.nio.charset.Charset;
28
29 /**
30 * An abstract representation of a JavaScript source file, as input to
31 * JSCompiler.
32 *
33 * @author [email protected] (Nick Santos)
34 * @author [email protected] (Andrew Moedinger)
35 * @deprecated JSSourceFile is an empty wrapper around SourceFile. Just
36 * use SourceFile directly.
37 */
38 // TODO(nicksantos): Delete this file.
39 @Deprecated
40 public class JSSourceFile extends SourceFile implements Serializable {
41 private static final long serialVersionUID = 1L;
42
43 public static JSSourceFile fromFile(String fileName, Charset charSet) {
44 return new JSSourceFile(SourceFile.fromFile(fileName, charSet));
45 }
46
47 public static JSSourceFile fromFile(String fileName) {
48 return new JSSourceFile(SourceFile.fromFile(fileName, Charsets.UTF_8));
49 }
50
51 public static JSSourceFile fromFile(File file, Charset charSet) {
52 return new JSSourceFile(SourceFile.fromFile(file, charSet));
53 }
54
55 public static JSSourceFile fromFile(File file) {
56 return new JSSourceFile(SourceFile.fromFile(file, Charsets.UTF_8));
57 }
58
59 public static JSSourceFile fromCode(String fileName, String code) {
60 return new JSSourceFile(SourceFile.fromCode(fileName, code));
61 }
62
63 public static JSSourceFile fromInputStream(String fileName, InputStream s)
64 throws IOException {
65 return new JSSourceFile(SourceFile.fromInputStream(fileName, s));
66 }
67
68 public static JSSourceFile fromGenerator(String fileName,
69 Generator generator) {
70 return new JSSourceFile(SourceFile.fromGenerator(fileName, generator));
71 }
72
73
74 private SourceFile referenced;
75
76 private JSSourceFile(SourceFile referenced) {
77 super(referenced.getName());
78 this.referenced = referenced;
79 }
80
81 @Override
82 public String getCode() throws IOException {
83 return referenced.getCode();
84 }
85
86 @Override
87 public void clearCachedSource() {
88 referenced.clearCachedSource();
89 }
90
91 @Override
92 @VisibleForTesting
93 String getCodeNoCache() {
94 return referenced.getCodeNoCache();
95 }
96 }