/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003, University of Maryland
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs;

import java.util.*;
import org.apache.bcel.classfile.JavaClass;

/**
 * A simple BugReporter which simply prints the formatted message
 * to the output stream.
 *
 * @author David Li
 */
public class EmacsBugReporter extends TextUIBugReporter {

	private HashSet<BugInstance> seenAlready = new HashSet<BugInstance>();

        private Project project;

        EmacsBugReporter (Project project) {
                super();
                this.project = project;
        }

	public void observeClass(JavaClass javaClass) {
		// Don't need to do anything special, since we won't be
		// reporting statistics.
	}

	protected void printBug(BugInstance bugInstance) {
                SourceLineAnnotation line = 
                        bugInstance.getPrimarySourceLineAnnotation();
                if (line == null) {
                        outputStream.print(bugInstance.getMessage());
                } else {
			String fullPath = project.getSourceFilePath(line.getSourceFile());
			if (fullPath == null) {
				// Source path lookup failed; just print out
				// our guess at the relative path.
				String pkgName = line.getPackageName();
				if (pkgName.equals("")) {
					fullPath = line.getSourceFile();
				} else {
					fullPath = pkgName.replace('.', '/') + "/" + line.getSourceFile();
				}
			}
                        outputStream.print(fullPath + ":" 
                                           + line.getStartLine() + ":" 
                                           + line.getEndLine() + " "
                                           + bugInstance.getMessage());
                }
            
                switch(bugInstance.getPriority()) {
		case Detector.LOW_PRIORITY:
			outputStream.print(" (L) ");
			break;
		case Detector.NORMAL_PRIORITY:
			outputStream.print(" (M) ");
			break;
		case Detector.HIGH_PRIORITY:
			outputStream.print(" (H) ");
			break;
		}

                outputStream.println();
	}

	protected void doReportBug(BugInstance bugInstance) {
		if (seenAlready.add(bugInstance)) {
			printBug(bugInstance);
			notifyObservers(bugInstance);
		}
	}

	public void finish() {
		outputStream.close();
	}
}

/*
 * Local Variables:
 * eval: (c-set-style "bsd")
 * End:
 */ 

@@ -860,16 +860,65 @@
 dbugs;%0A%0A
+import edu.umd.cs.daveho.ba.*;%0Aimport java.io.*;%0A
 import j
@@ -925,24 +925,24 @@
 ava.util.*;%0A
-
 import org.a
@@ -1232,163 +1232,8 @@
 );%0A%0A
-        private Project project;%0A%0A        EmacsBugReporter (Project project) %7B%0A                super();%0A                this.project = project;%0A        %7D%0A%0A
 %09pub
@@ -1672,55 +1672,61 @@
 %09%09%09S
-tring fullPath = project.getSourceFilePath(line
+ourceFinder sourceFinder = AnalysisContext.instance()
 .get
@@ -1737,30 +1737,34 @@
 ceFi
-le()
+nder(
 );%0A%09%09%09
-if (
+String 
 fullPath
  == 
@@ -1763,128 +1763,113 @@
 Path
- == null) %7B%0A%09%09%09%09// Source path lookup failed; just print out%0A%09%09%09%09// our guess at the relative path.%0A%09%09%09%09String 
+;%0A%09%09%09String pkgName = line.getPackageName();%0A%09%09%09try %7B%0A%09%09%09%09fullPath = sourceFinder.findSourceFile(
 pkgName
- =
+,
  lin
@@ -1869,38 +1869,85 @@
 me, line.get
-PackageName();
+SourceFile()).getFullFileName();%0A%09%09%09%7D catch (IOException e) %7B
 %0A%09%09%09%09if (pkg
@@ -1962,18 +1962,16 @@
 als(%22%22))
- %7B
 %0A%09%09%09%09%09fu
@@ -2005,24 +2005,20 @@
 ();%0A%09%09%09%09
-%7D 
 else
- %7B
 %0A%09%09%09%09%09fu
@@ -2086,19 +2086,14 @@
 ();%0A
-%09%09%09%09%7D%0A
 %09%09%09%7D%0A
+%0A
     

Use SourceFinder to find source files.