Example #1
0
  static synchronized String sourceLine(Location location, int lineNumber) throws IOException {
    if (lineNumber == -1) {
      throw new IllegalArgumentException();
    }

    try {
      String fileName = location.sourceName();

      Iterator iter = sourceCache.iterator();
      SourceCode code = null;
      while (iter.hasNext()) {
        SourceCode candidate = (SourceCode) iter.next();
        if (candidate.fileName().equals(fileName)) {
          code = candidate;
          iter.remove();
          break;
        }
      }
      if (code == null) {
        BufferedReader reader = sourceReader(location);
        if (reader == null) {
          throw new FileNotFoundException(fileName);
        }
        code = new SourceCode(fileName, reader);
        if (sourceCache.size() == SOURCE_CACHE_SIZE) {
          sourceCache.remove(sourceCache.size() - 1);
        }
      }
      sourceCache.add(0, code);
      return code.sourceLine(lineNumber);
    } catch (AbsentInformationException e) {
      throw new IllegalArgumentException();
    }
  }
Example #2
0
 static void setExcludes(String excludeString) {
   StringTokenizer t = new StringTokenizer(excludeString, " ,;");
   List list = new ArrayList();
   while (t.hasMoreTokens()) {
     list.add(t.nextToken());
   }
   excludes = list;
 }
Example #3
0
 SourceCode(String fileName, BufferedReader reader) throws IOException {
   this.fileName = fileName;
   try {
     String line = reader.readLine();
     while (line != null) {
       sourceLines.add(line);
       line = reader.readLine();
     }
   } finally {
     reader.close();
   }
 }