可以将Guice配置为在堆栈跟踪中隐藏类路径吗? [英] Can Guice be configured to hide the class path in stack traces?

查看:62
本文介绍了可以将Guice配置为在堆栈跟踪中隐藏类路径吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Guice的堆栈跟踪可能变得非常冗长,以至于很难阅读。下面是一个示例:

Guice's stack traces can get so verbose that they are very painful to read. Here's an example:

1) No implementation for java.util.Set<com.mydomain.myapp.android.activities.catbrowser.generalizedbrowser.listview.helpers.databaseitem.itemmanipulators.ItemManipulator<com.mydomain.myapp.flash.Cat>> annotated with @com.google.inject.assistedinject.Assisted(value=) was bound.
  while locating java.util.Set<com.mydomain.myapp.android.activities.catbrowser.generalizedbrowser.listview.helpers.databaseitem.itemmanipulators.ItemManipulator<com.mydomain.myapp.flash.Cat>> annotated with @com.google.inject.assistedinject.Assisted(value=)

...

如果我可以隐藏类路径,则它看起来像:

If I could hide the classpath, it would look like:

1) No implementation for Set<ItemManipulator<Cat>> annotated with @Assisted(value=) was bound.
  while locating Set<ItemManipulator<Cat>> annotated with @Assisted(value=)

是否有任何方法可以配置Guice来做到这一点?

Is there any way to configure Guice to do this?

推荐答案

所以答案是否定的。

如果您看< a href = http://code.google.com/p/google-guice/source/browse/ rel = nofollow> guice源代码,您会找到 com.google .inject.internal.Errors 类,用于生成错误消息。在此类中,的编码方式如下:

If you take look at guice source code you will find com.google.inject.internal.Errors class that is responsible for building error messages. In this class it is coded that the Key is converting the following way:

  new Converter<Key>(Key.class) {
    public String toString(Key key) {
      if (key.getAnnotationType() != null) {
        return key.getTypeLiteral() + " annotated with "
            + (key.getAnnotation() != null ? key.getAnnotation() : key.getAnnotationType());
      } else {
        return key.getTypeLiteral().toString();
      }
    }
  }

下一步是看看 TypeLiteral#toString 方法:

  @Override public final String toString() {
    return MoreTypes.typeToString(type);
  }

其中 MoreTypes#typeToString 是无法配置的静态方法

Where MoreTypes#typeToString is a static method that cannot be configured

  public static String typeToString(Type type) {
    return type instanceof Class ? ((Class) type).getName() : type.toString();
  }

这篇关于可以将Guice配置为在堆栈跟踪中隐藏类路径吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆