package sizzle.functions;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

/**
 * Boa domain-specific functions
 * 
 * @author rdyer
 * 
 */
public class BoaIntrinsics {
	private static String[] fixingRegex = {
		"fix",
		"(bug|issue)(s)?[\\s]+(#)?\\s*[0-9]+",
		"bug\\s+id(s)?\\s*=\\s*[0-9]+"
	};

	private static List<Pattern> fixingPatterns = new ArrayList<Pattern>();

	static {
		for (String s : BoaIntrinsics.fixingRegex)
			fixingPatterns.add(Pattern.compile(s));
	}

	/**
	 * Is a log message indicating it is a fixing revision?
	 * 
	 * @param log the revision's log message to mine
	 * @return true if the log indicates a fixing revision
	 */
	@FunctionSpec(name = "isfixingrevision", returnType = "bool", formalParameters = { "string" })
	public static boolean isfixingrevision(final String log) {
		for (Pattern p : fixingPatterns)
			if (p.matcher(log).matches())
				return true;

		return false;
	}

	/**
	 * Does a Revision contain a file of the specified type? This only compares based on file extension.
	 * 
	 * @param rev the Revision to examine
	 * @param ext the file extension to look for
	 * @return true if the Revision contains at least 1 file with the specified extension
	 */
	@FunctionSpec(name = "hasfiletype", returnType = "bool", formalParameters = { "Revision", "string" })
	public static boolean hasfile(final sizzle.types.Code.Revision rev, String ext) {
		for (int i = 0; i < rev.getFilesCount(); i++)
			if (rev.getFiles(i).getName().toLowerCase().endsWith("." + ext.toLowerCase()))
				return true;
		return false;
	}
}

@@ -67,24 +67,56 @@
 .util.List;%0A
+import java.util.regex.Matcher;%0A
 import java.
@@ -135,16 +135,16 @@
 attern;%0A
-
 %0A/**%0A * 
@@ -385,23 +385,23 @@
 ist%3C
-Patt
+Match
 er
-n
 %3E fixing
 Patt
@@ -396,23 +396,23 @@
 %3E fixing
-Patt
+Match
 er
-n
 s = new 
@@ -421,23 +421,23 @@
 rayList%3C
-Patt
+Match
 er
-n
 %3E();%0A%0A%09s
@@ -498,23 +498,23 @@
 %09%09fixing
-Patt
+Match
 er
-n
 s.add(Pa
@@ -529,16 +529,28 @@
 mpile(s)
+.matcher(%22%22)
 );%0A%09%7D%0A%0A%09
@@ -893,17 +893,17 @@
 or (
-Pattern p
+Matcher m
  : f
@@ -907,23 +907,23 @@
 : fixing
-Patt
+Match
 er
-n
 s)%0A%09%09%09if
@@ -928,17 +928,15 @@
 if (
-p.matcher
+m.reset
 (log

change fixing revision code to cache matchers instead of patterns