package com.monits.linters.matchers;

import javax.annotation.Nonnull;

import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;

import com.android.tools.lint.Warning;

public class WarningMatcher extends BaseMatcher<Warning> {
	private final String fileName;
	private final String message;
	private final int line;

	/**
	 * Constructor
	 *
	 * @param fileName The file name where the warning is reported
	 * @param errorMessage The warning message
	 * @param line The line number where the warning is reported
	 */
	public WarningMatcher(@Nonnull final String fileName, @Nonnull final String errorMessage,
			final int line) {
		this.fileName = fileName;
		message = errorMessage;
		this.line = line;
	}

	@Override
	public boolean matches(final Object obj) {
		if (obj instanceof Warning) {
			final Warning warning = (Warning) obj;

			boolean criteriaMatches = true;

			criteriaMatches &= warning.file.getName().equals(fileName);

			criteriaMatches &= warning.line == line;

			criteriaMatches &= warning.message.equals(message);

			return criteriaMatches;
		} else {
			return false;
		}
	}

	@Override
	public void describeTo(final Description description) {
		description
			.appendText("Warning with:\n")
			.appendText("fileName=").appendValue(fileName).appendText(",")
			.appendText("message=").appendValue(message).appendText(",")
			.appendText("line=").appendValue(line);
	}

	@Override
	public String toString() {
		return "WarningMatcher [ fileName=" + fileName + ", "
			+ "message=" + message + ", line=" + line + " ]";
	}
}

@@ -662,16 +662,21 @@
 Name;%0A%09%09
+this.
 message 
@@ -691,16 +691,16 @@
 essage;%0A
-
 %09%09this.l
@@ -945,16 +945,399 @@
 Name);%0A%0A
+%09%09%09// https://android.googlesource.com/platform/tools/base/+/1efa1e4500083a544191c5f2395ef67c0ec37aa5/%0A%09%09%09// lint/cli/src/main/java/com/android/tools/lint/TextReporter.java#118%0A%09%09%09// The code line reported in the Warning class is the previous code line,%0A%09%09%09// when they are reporting the issue they are adding a 1.%0A%09%09%09// We need to subtract a 1 to match with the reported code line.%0A
 %09%09%09crite
@@ -1366,24 +1366,28 @@
 line == line
+ - 1
 ;%0A%0A%09%09%09criter

fix code line