package edu.umd.cs.findbugs.tools;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.bcel.Constants;

import edu.umd.cs.findbugs.util.Util;

/*
 * FindBugs - Find Bugs in Java programs
 * Copyright (C) 2006, 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
 */

/**
 * Filter a property database, only passing through the annotations on public or
 * protected methods
 */
public class FilterPropertyDatabase {

	final static int FLAGS = Constants.ACC_PROTECTED | Constants.ACC_PUBLIC;

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		InputStream inSource = System.in;
		if (args.length > 0)
			inSource = new FileInputStream(args[0]);
		process(inSource);

	}

	/**
     * @param inSource
     * @throws UnsupportedEncodingException
     * @throws IOException
     */
    private static void process(InputStream inSource) throws UnsupportedEncodingException, IOException {
	    BufferedReader in = new BufferedReader(Util.getReader(inSource));
		Pattern p = Pattern.compile(",([0-9]+)\\|");
		while (true) {
			String s = in.readLine();
			if (s == null)
				break;
			Matcher m = p.matcher(s);
			if (m.find()) {
				int value = Integer.parseInt(m.group(1));
				if ((value & FLAGS) != 0)
					System.out.println(s);
			}

		}
    }

}

@@ -1638,20 +1638,17 @@
 %7D%0A%0A%09/**%0A
-    
+%09
  * @para
@@ -1658,20 +1658,17 @@
 nSource%0A
-    
+%09
  * @thro
@@ -1699,20 +1699,17 @@
 ception%0A
-    
+%09
  * @thro
@@ -1727,20 +1727,14 @@
 ion%0A
-     */%0A    
+%09 */%0A%09
 priv
@@ -1831,20 +1831,17 @@
 tion %7B%0A%09
-    
+%09
 Buffered
@@ -1851,16 +1851,38 @@
 der in =
+ null;%0A%09%09try %7B%0A%09%09%09in =
  new Buf
@@ -1920,18 +1920,20 @@
 urce));%0A
+%0A
 %09%09
+%09
 Pattern 
@@ -1971,16 +1971,17 @@
 %5C%7C%22);%0A%09%09
+%09
 while (t
@@ -1987,16 +1987,17 @@
 true) %7B%0A
+%09
 %09%09%09Strin
@@ -2016,24 +2016,25 @@
 dLine();%0A%09%09%09
+%09
 if (s == nul
@@ -2036,16 +2036,17 @@
 = null)%0A
+%09
 %09%09%09%09brea
@@ -2051,16 +2051,17 @@
 eak;%0A%09%09%09
+%09
 Matcher 
@@ -2078,16 +2078,17 @@
 her(s);%0A
+%09
 %09%09%09if (m
@@ -2102,16 +2102,17 @@
 ) %7B%0A%09%09%09%09
+%09
 int valu
@@ -2145,24 +2145,25 @@
 up(1));%0A%09%09%09%09
+%09
 if ((value &
@@ -2176,16 +2176,17 @@
 ) != 0)%0A
+%09
 %09%09%09%09%09Sys
@@ -2212,19 +2212,63 @@
 %0A%09%09%09
+%09
 %7D%0A%0A
+%09
 %09%09%7D%0A
-    
+%09%09%7D finally %7B%0A%09%09%09Util.closeSilently(in);%0A%09%09%7D%0A%09
 %7D%0A%0A%7D

fix findbugs warning