PageRenderTime 18ms CodeModel.GetById 7ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/javascript/src/main/java/com/google/test/metric/javascript/FileRepository.java

http://testability-explorer.googlecode.com/
Java | 49 lines | 24 code | 5 blank | 20 comment | 1 complexity | d46a9d69833eaf7b34e48519e30665c7 MD5 | raw file
 1/*
 2 * Copyright 2007 Google Inc.
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 5 * use this file except in compliance with the License. You may obtain a copy of
 6 * 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, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.google.test.metric.javascript;
17
18import org.mozilla.javascript.ast.AstRoot;
19import org.mozilla.javascript.Parser;
20
21import java.io.Reader;
22import java.io.StringReader;
23import java.io.IOException;
24import java.util.Map;
25import java.util.HashMap;
26import java.util.List;
27import java.util.LinkedList;
28
29/**
30 * Stores the set of javascript input files
31 *
32 * @author alexeagle@google.com (Alex Eagle)
33 */
34public class FileRepository {
35  private final Map<String, Reader> files = new HashMap<String, Reader>();
36
37  public void addSourceFile(String filename, String contents) {
38    files.put(filename, new StringReader(contents));
39  }
40
41  public List<AstRoot> getAsts() throws IOException {
42    List<AstRoot> asts = new LinkedList<AstRoot>();
43    for (Map.Entry<String, Reader> file : files.entrySet()) {
44      Parser parser = new Parser();
45      asts.add(parser.parse(file.getValue(), file.getKey(), 1));
46    }
47    return asts;
48  }
49}