/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. */
  16. package com.google.test.metric.javascript;
  17. import org.mozilla.javascript.ast.AstRoot;
  18. import org.mozilla.javascript.Parser;
  19. import java.io.Reader;
  20. import java.io.StringReader;
  21. import java.io.IOException;
  22. import java.util.Map;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.LinkedList;
  26. /**
  27. * Stores the set of javascript input files
  28. *
  29. * @author alexeagle@google.com (Alex Eagle)
  30. */
  31. public class FileRepository {
  32. private final Map<String, Reader> files = new HashMap<String, Reader>();
  33. public void addSourceFile(String filename, String contents) {
  34. files.put(filename, new StringReader(contents));
  35. }
  36. public List<AstRoot> getAsts() throws IOException {
  37. List<AstRoot> asts = new LinkedList<AstRoot>();
  38. for (Map.Entry<String, Reader> file : files.entrySet()) {
  39. Parser parser = new Parser();
  40. asts.add(parser.parse(file.getValue(), file.getKey(), 1));
  41. }
  42. return asts;
  43. }
  44. }