class RemoveComments {

  public String remove(FakeFile file) {
    if (file == null) {
      throw new IllegalArgumentException("You can't pass a null file as argument.");
    }

    StringBuilder result = new StringBuilder();
    boolean openComment = false;
    String line = file.getLine();
    while (line != null) {
      char previous = ANY_CHAR;

      for (char c : line.toCharArray()) {
        if (openComment) {
          if (c == SLASH && previous == ASTERISK) {
            openComment = false;
          }
        } else {
          if (c == ASTERISK && previous == SLASH) {
            openComment = true;
            result.deleteCharAt(result.length() - 1);
          } else {
            result.append(c);
          }
        }
        previous = c;
      }
      line = file.getLine();
    }
    return result.toString();
  }

}