问题
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?
回答1:
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();
}
来源:https://stackoverflow.com/questions/8766843/can-guice-be-configured-to-hide-the-class-path-in-stack-traces