Guice 可以配置为隐藏堆栈跟踪中的类路径吗?

发布于 2024-12-25 18:50:48 字数 924 浏览 5 评论 0原文

Guice 的堆栈跟踪可能会变得非常冗长,以至于读起来非常痛苦。这是一个例子:

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=)

...

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

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

有没有办法配置 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=)

Is there any way to configure Guice to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怎樣才叫好 2025-01-01 18:50:48

所以答案是否定的。

如果您查看 guice 源代码,您会发现 com.google.inject.internal.Errors 类负责构建错误消息。在此类中,Key 的编码方式如下:

  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< /code> 是静态方法,无法配置

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

So the answer is no.

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();
      }
    }
  }

Next step is to take a look at TypeLiteral#toString method:

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

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();
  }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文