Class PackageNameCompressor


  • final class PackageNameCompressor
    extends java.lang.Object
    Munges an error message to remove/shorten package names and adds a legend at the end.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      private static java.lang.String buildClassNameLegend​(java.util.Map<java.lang.String,​java.lang.String> replacementMap)  
      (package private) static java.lang.String compressPackagesInMessage​(java.lang.String input)
      Compresses an error message by stripping the packages out of class names and adding them to a legend at the bottom of the error.
      private static com.google.common.collect.ImmutableSet<java.lang.String> replaceFullNames​(java.lang.String input, java.util.Map<java.lang.String,​java.lang.String> replacementMap, java.lang.StringBuilder output)
      Replaces full class names in input and append the replaced content to output and then returns a set of short names that were used as replacement.
      private static java.util.Map<java.lang.String,​java.lang.String> shortenNames​(java.util.Collection<java.lang.String> names)
      Returns a map from short name to full name after resolving conflicts.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PACKAGES_SKIPPED_IN_LEGEND

        private static final com.google.common.collect.ImmutableSet<java.lang.String> PACKAGES_SKIPPED_IN_LEGEND
      • PACKAGE_SPLITTER

        private static final com.google.common.base.Splitter PACKAGE_SPLITTER
      • PACKAGE_JOINER

        private static final com.google.common.base.Joiner PACKAGE_JOINER
      • CLASSNAME_PATTERN

        private static final java.util.regex.Pattern CLASSNAME_PATTERN
      • QUOTED_PATTERN

        private static final java.util.regex.Pattern QUOTED_PATTERN
    • Constructor Detail

      • PackageNameCompressor

        private PackageNameCompressor()
    • Method Detail

      • compressPackagesInMessage

        static java.lang.String compressPackagesInMessage​(java.lang.String input)
        Compresses an error message by stripping the packages out of class names and adding them to a legend at the bottom of the error.
      • replaceFullNames

        private static com.google.common.collect.ImmutableSet<java.lang.String> replaceFullNames​(java.lang.String input,
                                                                                                 java.util.Map<java.lang.String,​java.lang.String> replacementMap,
                                                                                                 java.lang.StringBuilder output)
        Replaces full class names in input and append the replaced content to output and then returns a set of short names that were used as replacement.

        String literals that are quoted in the input will be added to the output unchanged. So any full class name that only appear in the string literal will not be included in the returned short names set.

      • buildClassNameLegend

        private static java.lang.String buildClassNameLegend​(java.util.Map<java.lang.String,​java.lang.String> replacementMap)
      • shortenNames

        private static java.util.Map<java.lang.String,​java.lang.String> shortenNames​(java.util.Collection<java.lang.String> names)
        Returns a map from short name to full name after resolving conflicts. This resolves conflicts by adding on segments of the package name until they are unique. For example, com.foo.Baz and com.bar.Baz will conflict on Baz and then resolve with foo.Baz and bar.Baz as replacements.