class MessageFormatCheck implements ReviewParticipant {

	@Override
	public Review review(PropertyFileDescriptor descriptor, Property master, Property slave) {
		if(master==null || slave==null || master.getValue()==null || slave.getValue()==null)
			return null;
		Matcher masterMatcher = PATTERN.matcher(master.getValue());
		Set<String> masterPatterns = new HashSet<String>();
		while(masterMatcher.find())
		{
			masterPatterns.add("{"+masterMatcher.group(1)+"}");
		}
		Set<String> mustHavePatterns = new HashSet<String>(masterPatterns);
		
		Matcher slaveMatcher = PATTERN.matcher(slave.getValue());
		while(slaveMatcher.find())
		{
			String patternNumber = slaveMatcher.group(1);
			String pattern = "{"+patternNumber+"}";
			if(!masterPatterns.contains(pattern))
			{
				Review review = PropertiesFactory.eINSTANCE.createReview();
				review.setCreated(System.currentTimeMillis());
				String message = "Translation contains message format ''{0}'' which is not present in the template language";
				review.setMessage(MessageFormat.format(message, pattern));
				review.setUser("Jabylon");
				review.setReviewType("Message Format");
				review.setSeverity(Severity.ERROR);
				return review;
			}
			mustHavePatterns.remove(pattern);
		}
		if(!mustHavePatterns.isEmpty())
		{
			Review review = PropertiesFactory.eINSTANCE.createReview();
			String message = "The template language contains message format ''{0}'' which is not referenced in the translation";
			review.setMessage(MessageFormat.format(message, mustHavePatterns.iterator().next()));
			review.setUser("Jabylon");
			review.setSeverity(Severity.ERROR);
			review.setReviewType(getReviewType());
			return review;
		}
		
		return null;
	}

	public  MessageFormatCheck();

}