Package com.google.inject.internal

Examples of com.google.inject.internal.MatcherAndConverter


  }

  private void internalConvertToTypes(Matcher<? super TypeLiteral<?>> typeMatcher,
      TypeConverter converter) {
    injector.state.addConverter(
        new MatcherAndConverter(typeMatcher, converter, SourceProvider.UNKNOWN_SOURCE));
  }
View Full Code Here


    injector.state.addConverter(
        new MatcherAndConverter(typeMatcher, converter, SourceProvider.UNKNOWN_SOURCE));
  }

  @Override public Boolean visitTypeConverterBinding(TypeConverterBinding command) {
    injector.state.addConverter(new MatcherAndConverter(
        command.getTypeMatcher(), command.getTypeConverter(), command.getSource()));
    return true;
  }
View Full Code Here

    converters.add(matcherAndConverter);
  }

  public MatcherAndConverter getConverter(
      String stringValue, TypeLiteral<?> type, Errors errors, Object source) {
    MatcherAndConverter matchingConverter = null;
    for (State s = this; s != State.NONE; s = s.parent()) {
      for (MatcherAndConverter converter : s.getConvertersThisLevel()) {
        if (converter.getTypeMatcher().matches(type)) {
          if (matchingConverter != null) {
            errors.ambiguousTypeConversion(stringValue, source, type, matchingConverter, converter);
View Full Code Here

    String stringValue = stringBinding.getProvider().get();
    Object source = stringBinding.getSource();

    // Find a matching type converter.
    TypeLiteral<T> type = key.getTypeLiteral();
    MatcherAndConverter matchingConverter = state.getConverter(stringValue, type, errors, source);

    if (matchingConverter == null) {
      // No converter can handle the given type.
      return null;
    }

    // Try to convert the string. A failed conversion results in an error.
    try {
      @SuppressWarnings("unchecked") // This cast is safe because we double check below.
      T converted = (T) matchingConverter.getTypeConverter().convert(stringValue, type);

      if (converted == null) {
        throw errors.converterReturnedNull(stringValue, source, type, matchingConverter)
            .toException();
      }
View Full Code Here

TOP

Related Classes of com.google.inject.internal.MatcherAndConverter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.