当前位置: 首页>>代码示例>>Java>>正文


Java Dependency.getParameterIndex方法代码示例

本文整理汇总了Java中com.google.inject.spi.Dependency.getParameterIndex方法的典型用法代码示例。如果您正苦于以下问题:Java Dependency.getParameterIndex方法的具体用法?Java Dependency.getParameterIndex怎么用?Java Dependency.getParameterIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.inject.spi.Dependency的用法示例。


在下文中一共展示了Dependency.getParameterIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkForNull

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
 * Returns {@code value} if it is non-null allowed to be null. Otherwise a message is added and
 * an {@code ErrorsException} is thrown.
 */
public <T> T checkForNull(T value, Object source, Dependency<?> dependency)
    throws ErrorsException {
  if (value != null || dependency.isNullable() ) {
    return value;
  }

  int parameterIndex = dependency.getParameterIndex();
  String parameterName = (parameterIndex != -1)
      ? "parameter " + parameterIndex + " of "
      : "";
  addMessage("null returned by binding at %s%n but %s%s is not @Nullable",
      source, parameterName, dependency.getInjectionPoint().getMember());

  throw toException();
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:20,代码来源:Errors.java

示例2: findInjectionPoint

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
@Nullable
private static InjectionPoint findInjectionPoint(List<DependencyAndSource> dependencyChain) {
    if (dependencyChain.size() < 3) {
        new AssertionError("Provider is not included in the dependency chain").printStackTrace();
    }

    // @Inject InjectionPoint is the last, so we can skip it
    for (int i = dependencyChain.size() - 2; i >= 0; i--) {
        final Dependency<?> dependency = dependencyChain.get(i).getDependency();
        if (dependency == null) {
            return null;
        }
        final com.google.inject.spi.InjectionPoint spiInjectionPoint = dependency.getInjectionPoint();
        if (spiInjectionPoint != null) {
            final TypeToken<?> source = TypeToken.of(spiInjectionPoint.getDeclaringType().getType());
            final Member member = spiInjectionPoint.getMember();
            final InjectionPoint injectionPoint;
            if (member instanceof Field) {
                final Field field = (Field) member;
                injectionPoint = new InjectionPoint(source, TypeToken.of(field.getGenericType()), field.getAnnotations());
            } else if (member instanceof Executable) {
                final Executable executable = (Executable) member;
                final Annotation[][] parameterAnnotations = executable.getParameterAnnotations();
                final Type[] parameterTypes = executable.getGenericParameterTypes();
                final int index = dependency.getParameterIndex();
                injectionPoint = new InjectionPoint(source, TypeToken.of(parameterTypes[index]), parameterAnnotations[index]);
            } else {
                throw new IllegalStateException("Unsupported Member type: " + member.getClass().getName());
            }
            return injectionPoint;
        }
    }

    return null;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:36,代码来源:InjectionPointProvider.java

示例3: onNullInjectedIntoNonNullableDependency

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
/**
 * Returns {@code value} if it is non-null or allowed to be null. Otherwise a message is added and
 * an {@code InternalProvisionException} is thrown.
 */
static void onNullInjectedIntoNonNullableDependency(Object source, Dependency<?> dependency)
    throws InternalProvisionException {
  // Hack to allow null parameters to @Provides methods, for backwards compatibility.
  if (dependency.getInjectionPoint().getMember() instanceof Method) {
    Method annotated = (Method) dependency.getInjectionPoint().getMember();
    if (annotated.isAnnotationPresent(Provides.class)) {
      switch (InternalFlags.getNullableProvidesOption()) {
        case ERROR:
          break; // break out & let the below exception happen
        case IGNORE:
          return; // user doesn't care about injecting nulls to [email protected]
        case WARN:
          // Warn only once, otherwise we spam logs too much.
          if (warnedDependencies.add(dependency)) {
            logger.log(
                Level.WARNING,
                "Guice injected null into {0} (a {1}), please mark it @Nullable."
                    + " Use -Dguice_check_nullable_provides_params=ERROR to turn this into an"
                    + " error.",
                new Object[] {
                  Messages.formatParameter(dependency), Messages.convert(dependency.getKey())
                });
          }
          return;
      }
    }
  }

  Object formattedDependency =
      (dependency.getParameterIndex() != -1)
          ? Messages.formatParameter(dependency)
          : StackTraceElements.forMember(dependency.getInjectionPoint().getMember());

  throw InternalProvisionException.create(
          "null returned by binding at %s%n but %s is not @Nullable", source, formattedDependency)
      .addSource(source);
}
 
开发者ID:google,项目名称:guice,代码行数:42,代码来源:InternalProvisionException.java

示例4: formatParameter

import com.google.inject.spi.Dependency; //导入方法依赖的package包/类
static String formatParameter(Dependency<?> dependency) {
  int ordinal = dependency.getParameterIndex() + 1;
  return String.format(
      "the %s%s parameter of %s",
      ordinal,
      getOrdinalSuffix(ordinal),
      StackTraceElements.forMember(dependency.getInjectionPoint().getMember()));
}
 
开发者ID:google,项目名称:guice,代码行数:9,代码来源:Messages.java


注:本文中的com.google.inject.spi.Dependency.getParameterIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。