code: static Path resolveFile(Path reference, String path) throws IOException {
          if (reference == null) {
              Path file = canonicalFileLocation(Paths.get(path));
              if (Files.exists(file)) {
                  if (Files.isRegularFile(file)) {
                      return file;
                  }
                  throw new FileNotFoundException(path + " is a directory, expected file");
              }
              throw new FileNotFoundException("File " + path + " not found");
          } else if (path.startsWith("/")) {
              throw new FileNotFoundException("Absolute path includes not allowed: " + path);
          } else {
              // Referenced files are referenced from the real file,
              // not from symlink location, in case of sym-linked files.
              // this way include references are always consistent, but
              // files can be referenced via symlinks if needed.
              reference = readCanonicalPath(reference);
              if (!Files.isDirectory(reference)) {
                  reference = reference.getParent();
              }
              Path file = canonicalFileLocation(reference.resolve(path));
  
              if (Files.exists(file)) {
                  if (Files.isRegularFile(file)) {
                      return file;
                  }
                  throw new FileNotFoundException(path + " is a directory, expected file");
              }
              throw new FileNotFoundException("Included file " + path + " not found");
          }
      }
docs: Resolve a file path within the source roots.
  
  @param reference A file or directory reference
  @param path The file reference to resolve.
  @return The resolved file.
  @throws FileNotFoundException When the file is not found.
  @throws IOException When unable to make canonical path.