@Override public String toString() { return typeConverter + " which matches " + typeMatcher + " (bound at " + Errors.convert(source) + ")"; } }
@Override public String getSource() { return sources.isEmpty() ? SourceProvider.UNKNOWN_SOURCE.toString() : Errors.convert(sources.get(sources.size() - 1)).toString(); }
@Override public String toString() { return scanner + " which scans for " + scanner.annotationClasses() + " (bound at " + Errors.convert(source) + ")"; } }
public Errors conversionTypeError( String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, Object converted) { return addMessage( "Type mismatch converting '%s' (bound at %s) to %s%n" + " using %s.%n" + " Converter returned %s.", stringValue, convert(source), type, typeConverterBinding, converted); }
/** * When serialized, we eagerly convert sources to strings. This hurts our formatting, but it * guarantees that the receiving end will be able to read the message. */ private Object writeReplace() throws ObjectStreamException { Object[] sourcesAsStrings = sources.toArray(); for (int i = 0; i < sourcesAsStrings.length; i++) { sourcesAsStrings[i] = Errors.convert(sourcesAsStrings[i]).toString(); } return new Message(ImmutableList.copyOf(sourcesAsStrings), message, cause); }
public Errors errorCheckingDuplicateBinding(Key<?> key, Object source, Throwable t) { return addMessage( "A binding to %s was already configured at %s and an error was thrown " + "while checking duplicate bindings. Error: %s", key, convert(source), t); }
public Errors converterReturnedNull( String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding) { return addMessage( "Received null converting '%s' (bound at %s) to %s%n using %s.", stringValue, convert(source), type, typeConverterBinding); }
public Errors scopeAnnotationOnAbstractType( Class<? extends Annotation> scopeAnnotation, Class<?> type, Object source) { return addMessage( "%s is annotated with %s, but scope annotations are not supported " + "for abstract types.%n Bound at %s.", type, scopeAnnotation, convert(source)); }
public Errors ambiguousTypeConversion( String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding a, TypeConverterBinding b) { return addMessage( "Multiple converters can convert '%s' (bound at %s) to %s:%n" + " %s and%n" + " %s.%n" + " Please adjust your type converter configuration to avoid overlapping matches.", stringValue, convert(source), type, a, b); }
public Errors bindingAlreadySet(Key<?> key, Object source) { return addMessage("A binding to %s was already configured at %s.", key, convert(source)); }
public Errors conversionError( String stringValue, Object source, TypeLiteral<?> type, TypeConverterBinding typeConverterBinding, RuntimeException cause) { return errorInUserCode( cause, "Error converting '%s' (bound at %s) to %s%n using %s.%n Reason: %s", stringValue, convert(source), type, typeConverterBinding, cause); }
private static <K, V> void reportDuplicateKeysError( Multimap<K, Binding<V>> duplicates, Errors errors) { StringBuilder sb = new StringBuilder("Map injection failed due to duplicated key "); boolean first = true; for (Map.Entry<K, Collection<Binding<V>>> entry : duplicates.asMap().entrySet()) { K dupKey = entry.getKey(); if (first) { first = false; sb.append("\"" + dupKey + "\", from bindings:\n"); } else { sb.append("\n and key: \"" + dupKey + "\", from bindings:\n"); } for (Binding<V> dup : entry.getValue()) { sb.append("\t at " + Errors.convert(dup.getSource()) + "\n"); } } // TODO(user): Add a different error for every duplicated key errors.addMessage(sb.toString()); }
public void add(Key<?> key, State state, Object source) { if (backingMap == null) { backingMap = Maps.newHashMap(); } // if it's an instanceof Class, it was a JIT binding, which we don't // want to retain. if (source instanceof Class || source == SourceProvider.UNKNOWN_SOURCE) { source = null; } Multiset<Object> sources = backingMap.get(key); if (sources == null) { sources = LinkedHashMultiset.create(); backingMap.put(key, sources); } Object convertedSource = Errors.convert(source); sources.add(convertedSource); // Avoid all the extra work if we can. if (state.parent() != State.NONE) { Set<KeyAndSource> keyAndSources = evictionCache.getIfPresent(state); if (keyAndSources == null) { evictionCache.put(state, keyAndSources = Sets.newHashSet()); } keyAndSources.add(new KeyAndSource(key, convertedSource)); } }
fmt.format("%s is holding locks the following singletons in the cycle:%n", lockedThread); for (Key<?> lockedKey : lockedKeys) { fmt.format("%s%n", Errors.convert(lockedKey));
public Errors errorNotifyingTypeListener( TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause) { return errorInUserCode( cause, "Error notifying TypeListener %s (bound at %s) of %s.%n Reason: %s", listener.getListener(), convert(listener.getSource()), type, cause); }
@Override public Void visit(ScopeBinding scopeBinding) { ScopeBinding overideBinding = overridesScopeAnnotations.remove(scopeBinding.getAnnotationType()); if (overideBinding == null) { super.visit(scopeBinding); } else { List<Object> usedSources = scopeInstancesInUse.get(scopeBinding.getScope()); if (usedSources != null) { StringBuilder sb = new StringBuilder( "The scope for @%s is bound directly and cannot be overridden."); sb.append("%n original binding at " + Errors.convert(scopeBinding.getSource())); for (Object usedSource : usedSources) { sb.append("%n bound directly at " + Errors.convert(usedSource) + ""); } binder .withSource(overideBinding.getSource()) .addError(sb.toString(), scopeBinding.getAnnotationType().getSimpleName()); } } return null; } }.writeAll(scopeBindings);
Formatter fmt = new Formatter(); Messages.formatSource(fmt, bindingMap.get(bindingKey).getSource()); String match = String.format("%s bound%s", convert(bindingKey), fmt.toString()); possibleMatches.add(match);
private static Context getContext(Key<?> key) { Context context = localContext.get(); if (context == null) { throw new OutOfScopeException( "Cannot access scoped [" + Errors.convert(key) + "]. Either we are not currently inside an HTTP Servlet request, or you may" + " have forgotten to apply " + GuiceFilter.class.getName() + " as a servlet filter for this request."); } return context; }
fail(); } catch (ProvisionException oose) { assertContains(oose.getMessage(), "Cannot access scoped [" + Errors.convert(key) + "]");
public Errors errorNotifyingTypeListener( TypeListenerBinding listener, TypeLiteral<?> type, Throwable cause) { return errorInUserCode( cause, "Error notifying TypeListener %s (bound at %s) of %s.%n Reason: %s", listener.getListener(), convert(listener.getSource()), type, cause); }