private void setAffectedLines(final BugInstance warning, final Bug bug) {
   Iterator<BugAnnotation> annotationIterator = warning.annotationIterator();
   while (annotationIterator.hasNext()) {
     BugAnnotation bugAnnotation = annotationIterator.next();
     if (bugAnnotation instanceof SourceLineAnnotation) {
       SourceLineAnnotation annotation = (SourceLineAnnotation) bugAnnotation;
       bug.addLineRange(new LineRange(annotation.getStartLine(), annotation.getEndLine()));
     }
   }
 }
 private String findSourceFile(
     final Project project,
     final SourceFinder sourceFinder,
     final SourceLineAnnotation sourceLine) {
   try {
     SourceFile sourceFile = sourceFinder.findSourceFile(sourceLine);
     return sourceFile.getFullFileName();
   } catch (IOException exception) {
     StringBuilder sb = new StringBuilder("Can't resolve absolute file name for file ");
     sb.append(sourceLine.getSourceFile());
     if (isFirstError) {
       sb.append(", dir list = ");
       sb.append(project.getSourceDirList());
       isFirstError = false;
     }
     Logger.getLogger(getClass().getName()).log(Level.WARNING, sb.toString());
     return sourceLine.getPackageName().replace(DOT, SLASH) + SLASH + sourceLine.getSourceFile();
   }
 }
  /**
   * Returns the parsed FindBugs analysis file. This scanner accepts files in the native FindBugs
   * format.
   *
   * @param file the FindBugs analysis file
   * @param sources a collection of folders to scan for source files
   * @param moduleName name of maven module
   * @param hashToMessageMapping mapping of hash codes to messages
   * @param categories mapping from bug types to their categories
   * @return the parsed result (stored in the module instance)
   * @throws IOException if the file could not be parsed
   * @throws DocumentException in case of a parser exception
   */
  private Collection<FileAnnotation> parse(
      final InputStream file,
      final Collection<String> sources,
      final String moduleName,
      final Map<String, String> hashToMessageMapping,
      final Map<String, String> categories)
      throws IOException, DocumentException {
    SortedBugCollection collection = readXml(file);

    Project project = collection.getProject();
    for (String sourceFolder : sources) {
      project.addSourceDir(sourceFolder);
    }

    SourceFinder sourceFinder = new SourceFinder(project);
    String actualName = extractModuleName(moduleName, project);

    TreeStringBuilder stringPool = new TreeStringBuilder();
    List<FileAnnotation> annotations = new ArrayList<FileAnnotation>();
    Collection<BugInstance> bugs = collection.getCollection();

    for (BugInstance warning : bugs) {

      SourceLineAnnotation sourceLine = warning.getPrimarySourceLineAnnotation();

      String message = warning.getMessage();
      String type = warning.getType();
      if (message.contains("TEST: Unknown")) {
        message = FindBugsMessages.getInstance().getShortMessage(type, LocaleProvider.getLocale());
      }
      String category = categories.get(type);
      if (category
          == null) { // alternately, only if warning.getBugPattern().getType().equals("UNKNOWN")
        category = warning.getBugPattern().getCategory();
      }
      Bug bug =
          new Bug(
              getPriority(warning),
              StringUtils.defaultIfEmpty(
                  hashToMessageMapping.get(warning.getInstanceHash()), message),
              category,
              type,
              sourceLine.getStartLine(),
              sourceLine.getEndLine());
      bug.setInstanceHash(warning.getInstanceHash());
      bug.setRank(warning.getBugRank());

      boolean ignore = setCloudInformation(collection, warning, bug);
      if (!ignore) {
        bug.setNotAProblem(false);
        bug.setFileName(findSourceFile(project, sourceFinder, sourceLine));
        bug.setPackageName(warning.getPrimaryClass().getPackageName());
        bug.setModuleName(actualName);
        setAffectedLines(warning, bug);

        annotations.add(bug);
        bug.intern(stringPool);
      }
    }

    return applyFilters(annotations);
  }