/plugins/CamelComplete/tags/release-2_7_2/src/com/illengineer/jcc/CTagsFileProvider.java

# · Java · 56 lines · 42 code · 9 blank · 5 comment · 8 complexity · 605990d61b45c215d8f296d55518c72f MD5 · raw file

  1. package com.illengineer.jcc;
  2. import java.util.*;
  3. import java.io.*;
  4. /*
  5. This provider takes a File indicating a tags file as output by ctags,
  6. and loads identifier names from it.
  7. */
  8. public class CTagsFileProvider implements IdentifierProvider, Serializable
  9. {
  10. private ArrayList<String> identifierList;
  11. private String fileName;
  12. private File ctagsFile;
  13. public CTagsFileProvider(File f) {
  14. ctagsFile = f;
  15. fileName = ctagsFile.getName();
  16. }
  17. public void process() {
  18. identifierList = new ArrayList<String>();
  19. try {
  20. BufferedReader reader = new BufferedReader(new FileReader(ctagsFile));
  21. String line;
  22. int tabloc;
  23. while(true) {
  24. line = reader.readLine();
  25. if (line == null) break;
  26. if (line.length() == 0) continue;
  27. if (line.charAt(0) == '!') continue; // a ctags comment line
  28. tabloc = line.indexOf('\t');
  29. if (tabloc == -1) // malformed line?
  30. continue;
  31. identifierList.add(line.substring(0, tabloc));
  32. }
  33. reader.close();
  34. } catch (IOException ex) {
  35. // We'll just keep the identifiers we read before the error.
  36. }
  37. }
  38. public void forget() {
  39. identifierList = new ArrayList<String>();
  40. }
  41. public Iterator<String> iterator() {
  42. return identifierList.iterator();
  43. }
  44. public String toString() {
  45. return "CTags, " + fileName;
  46. }
  47. }