/*
* Copyright (c) 2013 - present Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

package utils;

import java.nio.file.Path;

public class InferError {

  private String errorType;
  private Path errorFile;
  private String errorMethod;
  private int errorLine;

  public InferError(String errorType, Path errorFile, String errorMethod, int errorLine) {
    this.errorType = errorType;
    this.errorMethod = errorMethod;
    this.errorLine = errorLine;
    this.errorFile = errorFile;
  }

  public InferError(String errorType, Path errorFile, String errorMethod) {
    this.errorType = errorType;
    this.errorFile = errorFile;
    this.errorMethod = errorMethod;
    this.errorLine = -1;
  }

  public static InferError inferError(String errorMethod, Path errorFile, String errorType) {
    return new InferError(errorMethod, errorFile, errorType);
  }

  public String getErrorType() {
    return errorType;
  }

  public String getErrorMethod() {
    return errorMethod;
  }

  public Path getErrorFile() {
    return errorFile;
  }

  public int getErrorLine() {
    return errorLine;
  }

  public String toStringNoLine() {
    return errorType + " at " + errorFile + ", method " + errorMethod;
  }

  public String toString() {
    if (errorLine > 0)
      return toStringNoLine() + " (line " + errorLine + ")";
    else return toStringNoLine();
  }

  public String toStringFileMethod() {
    return errorFile + ", method " + errorMethod;
  }

  public String toStringErrorTypeMethod() {
    return errorType + " at " + errorMethod;
  }

  public boolean matchType(String type) {
    return this.errorType.equals(type);
  }

  public boolean matchFile(Path file) {
    return this.errorFile.equals(file);
  }

  public boolean matchMethod(String method) {
    return this.errorMethod.equals(method);
  }

  public boolean matchLine(int line) {
    return this.errorLine < 0 || line < 0
        || (this.errorLine == line);
  }

}

@@ -338,16 +338,44 @@
 le.Path;
+%0Aimport java.io.IOException;
 %0A%0Apublic
@@ -696,16 +696,105 @@
 orLine;%0A
+    try %7B%0A      this.errorFile = errorFile.toRealPath();%0A    %7D catch (IOException e) %7B%0A  
     this
@@ -809,32 +809,38 @@
 le = errorFile;%0A
+    %7D%0A
   %7D%0A%0A  public In
@@ -2008,24 +2008,148 @@
 ath file) %7B%0A
+    Path realFile;%0A    try %7B%0A      realFile = file.toRealPath();%0A    %7D catch (IOException e) %7B%0A      realFile = file;%0A    %7D%0A
     return t
@@ -2169,17 +2169,21 @@
 .equals(
-f
+realF
 ile);%0A  

Fix handling of symbolic links in tests