<commit_before>/*
 * Copyright 2016 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.template.soy.error;

import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ascii;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import javax.annotation.Nullable;

/** Utility methods for constructing Soy error messages. */
public final class SoyErrors {

  /**
   * Given a collection of strings and a name that isn't contained in it. Return a message that
   * suggests one of the names.
   *
   * <p>Returns the empty string if {@code allNames} is empty or there is no close match.
   */
  public static String getDidYouMeanMessage(Iterable<String> allNames, String wrongName) {
    String closestName = getClosest(allNames, wrongName);
    if (closestName != null) {
      return String.format(" Did you mean '%s'?", closestName);
    }
    return "";
  }

  /**
   * Same as {@link #getDidYouMeanMessage(Iterable, String)} but with some additional heuristics for
   * proto fields.
   */
  public static String getDidYouMeanMessageForProtoFields(
      ImmutableSet<String> fields, String fieldName) {
    // TODO(lukes): when we have map/case enum support add more cases here.
    if (fields.contains(fieldName + "List")) {
      return String.format(" Did you mean '%sList'?", fieldName);
    } else {
      return getDidYouMeanMessage(fields, fieldName);<commit_msg>Add typo suggestion support to proto map fields.<commit_after>/*
 * Copyright 2016 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.template.soy.error;

import static com.google.common.base.Preconditions.checkArgument;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Ascii;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import javax.annotation.Nullable;

/** Utility methods for constructing Soy error messages. */
public final class SoyErrors {

  /**
   * Given a collection of strings and a name that isn't contained in it. Return a message that
   * suggests one of the names.
   *
   * <p>Returns the empty string if {@code allNames} is empty or there is no close match.
   */
  public static String getDidYouMeanMessage(Iterable<String> allNames, String wrongName) {
    String closestName = getClosest(allNames, wrongName);
    if (closestName != null) {
      return String.format(" Did you mean '%s'?", closestName);
    }
    return "";
  }

  /**
   * Same as {@link #getDidYouMeanMessage(Iterable, String)} but with some additional heuristics for
   * proto fields.
   */
  public static String getDidYouMeanMessageForProtoFields(
      ImmutableSet<String> fields, String fieldName) {
    // TODO(b/27616446): when we have case enum support add a case here.
    if (fields.contains(fieldName + "List")) {
      return String.format(" Did you mean '%sList'?", fieldName);
    } else if (fields.contains(fieldName + "Map")) {
      return String.format(" Did you mean '%sMap'?", fieldName);
    } else {
      return getDidYouMeanMessage(fields, fieldName);
{'fraction_non_alphanumeric': 0.0949905482041588, 'fraction_numerical': 0.005671077504725898, 'mean_word_length': 3.804767309875142, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3103524', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1144, 'n_words': 445}