reader.close(); } catch (IOException e) { logger.logMessage(ConsoleLogger.WARNING, e.getMessage()); return; }
reader.close();
    private void viewSource(Project project, AnalysisRun analysisRun, final SourceLineAnnotation srcLine) {        // Get rid of old source code text        sourceTextArea.setText("");                // There is nothing to do without a source annotation        // TODO: actually, might want to put a message in the source window        // explaining that we don't have the source file, and that        // they might want to recompile with debugging info turned on.        if (srcLine == null)            return;                // Look up the source file for this class.        sourceFinder.setSourceBaseList(project.getSourceDirList());        String sourceFile = analysisRun.getSourceFile(srcLine.getClassName());        if (sourceFile == null || sourceFile.equals("<Unknown>")) {            logger.logMessage(ConsoleLogger.WARNING, "No source file for class " + srcLine.getClassName());            return;        }                // Try to open the source file and display its contents        // in the source text area.        try {            InputStream in = sourceFinder.openSource(srcLine.getPackageName(), sourceFile);            BufferedReader reader = new BufferedReader(new InputStreamReader(in));                        String line;            while ((line = reader.readLine()) != null) {                sourceTextArea.append(line + "\n");            }                        reader.close();        } catch (IOException e) {            logger.logMessage(ConsoleLogger.WARNING, e.getMessage());            return;        }        // Highlight the annotation.        // There seems to be some bug in Swing that sometimes prevents this code        // from working when executed immediately after populating the        // text in the text area.  My guess is that when a large amount of text        // is added, Swing defers some UI update work until "later" that is needed        // to compute the visibility of text in the text area.        // So, post some code to do the update to the Swing event queue.        // Not really an ideal solution, but it seems to work.        SwingUtilities.invokeLater(new Runnable() {            public void run() {                // Highlight the lines from the source annotation.                // Note that the source lines start at 1, while the line numbers                // in the text area start at 0.                try {                    int startLine = srcLine.getStartLine() - 1;                    int endLine = srcLine.getEndLine();                                        // Scroll the window so the annotation text will be SELECTION_VOFFSET                    // lines from the top.                    int viewLine = Math.max(startLine - SELECTION_VOFFSET, 0);                    int viewBegin = sourceTextArea.getLineStartOffset(viewLine);                    //sourceTextArea.scrollRectToVisible(sourceTextArea.modelToView(viewBegin));                    Rectangle viewRect = sourceTextArea.modelToView(viewBegin);                    sourceTextAreaScrollPane.getViewport().setViewPosition(new Point(viewRect.x, viewRect.y));                                        // Select (and highlight) the annotation.                    int selBegin = sourceTextArea.getLineStartOffset(startLine);                    int selEnd = sourceTextArea.getLineStartOffset(endLine);                    sourceTextArea.select(selBegin, selEnd);                    sourceTextArea.getCaret().setSelectionVisible(true);                } catch (javax.swing.text.BadLocationException e) {                    logger.logMessage(ConsoleLogger.ERROR, e.toString());                }            }        });            }