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


Java InjectionPoint.getMember方法代码示例

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


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

示例1: checkOnlyAcceptsPlayer

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
private static boolean checkOnlyAcceptsPlayer(Class<? extends JCmd> executor) {
    for (InjectionPoint point : InjectionPoint.forInstanceMethodsAndFields(executor)) {
        if (!(point.getMember() instanceof Field))
            continue;

        Key<?> key = point.getDependencies().get(0).getKey();
        if (key.getTypeLiteral().getRawType().equals(Player.class)) {
            return true;
        }
    }

    return false;
}
 
开发者ID:Twister915,项目名称:pl,代码行数:14,代码来源:JCommandExecutor.java

示例2: addStaticInjectionRequest

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
void addStaticInjectionRequest(Class<?> type, Object source) {
  assertNotFinalized();
  staticInjectionRequests.add(type);

  // Calculate required bindings and add to dependencies
  for (InjectionPoint injectionPoint : InjectionPoint.forStaticMethodsAndFields(type)) {
    Member member = injectionPoint.getMember();
    if (member instanceof Method) {
      addDependencies(guiceUtil.getDependencies(Dependency.GINJECTOR,
          MethodLiteral.get((Method) member, TypeLiteral.get(member.getDeclaringClass()))));
    } else if (member instanceof Field) {
      FieldLiteral<?> field =
          FieldLiteral.get((Field) member, TypeLiteral.get(member.getDeclaringClass()));
      Key<?> key = guiceUtil.getKey(field);
      addDependency(new Dependency(
          Dependency.GINJECTOR, key, guiceUtil.isOptional(field), false,
          source.toString()));
    }
  }
}
 
开发者ID:google-code-export,项目名称:google-gin,代码行数:21,代码来源:GinjectorBindings.java

示例3: injectValues

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
private void injectValues(final Object target, final boolean sharedFields) throws IllegalAccessException {
    for (InjectionPoint point : injectionPoints) {
        if (!(point.getMember() instanceof Field)) {
            throw new GuiceyExtensionException("Method injection is not supported; use field injection instead");
        }

        final Field field = (Field) point.getMember();
        if (field.isAnnotationPresent(Shared.class) != sharedFields) {
            continue;
        }

        final Object value = externalRuleAdapter.getInjector().getInstance(point.getDependencies().get(0).getKey());
        field.setAccessible(true);
        field.set(target, value);
    }
}
 
开发者ID:xvik,项目名称:dropwizard-guicey,代码行数:17,代码来源:GuiceyInterceptor.java

示例4: getInjectors

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
/** Returns the injectors for the specified injection points. */
ImmutableList<SingleMemberInjector> getInjectors(
    Set<InjectionPoint> injectionPoints, Errors errors) {
  List<SingleMemberInjector> injectors = Lists.newArrayList();
  for (InjectionPoint injectionPoint : injectionPoints) {
    try {
      Errors errorsForMember =
          injectionPoint.isOptional()
              ? new Errors(injectionPoint)
              : errors.withSource(injectionPoint);
      SingleMemberInjector injector =
          injectionPoint.getMember() instanceof Field
              ? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember)
              : new SingleMethodInjector(this.injector, injectionPoint, errorsForMember);
      injectors.add(injector);
    } catch (ErrorsException ignoredForNow) {
      // ignored for now
    }
  }
  return ImmutableList.copyOf(injectors);
}
 
开发者ID:google,项目名称:guice,代码行数:22,代码来源:MembersInjectorStore.java

示例5: formatInjectionPoint

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
private static void formatInjectionPoint(
    Formatter formatter,
    Dependency<?> dependency,
    InjectionPoint injectionPoint,
    ElementSource elementSource) {
  Member member = injectionPoint.getMember();
  Class<? extends Member> memberType = Classes.memberType(member);

  if (memberType == Field.class) {
    dependency = injectionPoint.getDependencies().get(0);
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for field at %s%n", StackTraceElements.forMember(member));

  } else if (dependency != null) {
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for %s%n", formatParameter(dependency));

  } else {
    formatSource(formatter, injectionPoint.getMember());
  }
}
 
开发者ID:google,项目名称:guice,代码行数:22,代码来源:Messages.java

示例6: getInjectors

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
/**
 * Returns the injectors for the specified injection points.
 */
ImmutableList<SingleMemberInjector> getInjectors(
    Set<InjectionPoint> injectionPoints, Errors errors) {
  List<SingleMemberInjector> injectors = Lists.newArrayList();
  for (InjectionPoint injectionPoint : injectionPoints) {
    try {
      Errors errorsForMember = injectionPoint.isOptional()
          ? new Errors(injectionPoint)
          : errors.withSource(injectionPoint);
      SingleMemberInjector injector = injectionPoint.getMember() instanceof Field
          ? new SingleFieldInjector(this.injector, injectionPoint, errorsForMember)
          : new SingleMethodInjector(this.injector, injectionPoint, errorsForMember);
      injectors.add(injector);
    } catch (ErrorsException ignoredForNow) {
      // ignored for now
    }
  }
  return ImmutableList.copyOf(injectors);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:22,代码来源:MembersInjectorStore.java

示例7: formatInjectionPoint

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
public static void formatInjectionPoint(Formatter formatter, Dependency<?> dependency,
    InjectionPoint injectionPoint, ElementSource elementSource) {
  Member member = injectionPoint.getMember();
  Class<? extends Member> memberType = Classes.memberType(member);

  if (memberType == Field.class) {
    dependency = injectionPoint.getDependencies().get(0);
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for field at %s%n", StackTraceElements.forMember(member));

  } else if (dependency != null) {
    formatter.format("  while locating %s%n", convert(dependency.getKey(), elementSource));
    formatter.format("    for parameter %s at %s%n",
        dependency.getParameterIndex(), StackTraceElements.forMember(member));

  } else {
    formatSource(formatter, injectionPoint.getMember());
  }
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:20,代码来源:Errors.java

示例8: prepareMethod

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
@Override
public <T> Key<T> prepareMethod(
    Binder binder, Annotation rawAnnotation, Key<T> key, InjectionPoint injectionPoint) {
  Method providesMethod = (Method) injectionPoint.getMember();
  Provides annotation = (Provides) rawAnnotation;
  if (providesMethod.isAnnotationPresent(IntoSet.class)) {
    return processSetBinding(binder, key);
  } else if (providesMethod.isAnnotationPresent(ElementsIntoSet.class)) {
    binder.addError("@ElementsIntoSet contributions are not suppored by Guice.", providesMethod);
    return key;
  } else if (providesMethod.isAnnotationPresent(IntoMap.class)) {
    /* TODO(cgruber) implement map bindings */
    binder.addError("Map bindings are not yet supported.");
    return key;
  }

  switch (annotation.type()) {
    case UNIQUE:
      return key;
    case SET:
      return processSetBinding(binder, key);
    case SET_VALUES:
      binder.addError(
          Type.SET_VALUES.name() + " contributions are not supported by Guice.", providesMethod);
      return key;
    default:
      binder.addError("Unknown @Provides type " + annotation.type() + ".", providesMethod);
      return key;
  }
}
 
开发者ID:google,项目名称:guice,代码行数:31,代码来源:DaggerMethodScanner.java

示例9: ProxyConstructor

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // the constructor promises to construct 'T's
ProxyConstructor(
    Enhancer enhancer,
    InjectionPoint injectionPoint,
    Callback[] callbacks,
    ImmutableMap<Method, List<MethodInterceptor>> methodInterceptors) {
  this.enhanced = enhancer.createClass(); // this returns a cached class if possible
  this.injectionPoint = injectionPoint;
  this.constructor = (Constructor<T>) injectionPoint.getMember();
  this.callbacks = callbacks;
  this.methodInterceptors = methodInterceptors;
  this.fastClass = newFastClassForMember(enhanced, constructor);
  this.constructorIndex = fastClass.getIndex(constructor.getParameterTypes());
}
 
开发者ID:google,项目名称:guice,代码行数:15,代码来源:ProxyFactory.java

示例10: SingleMethodInjector

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
SingleMethodInjector(InjectorImpl injector, InjectionPoint injectionPoint, Errors errors)
    throws ErrorsException {
  this.injectionPoint = injectionPoint;
  final Method method = (Method) injectionPoint.getMember();
  methodInvoker = createMethodInvoker(method);
  parameterInjectors = injector.getParametersInjectors(injectionPoint.getDependencies(), errors);
}
 
开发者ID:google,项目名称:guice,代码行数:8,代码来源:SingleMethodInjector.java

示例11: SingleFieldInjector

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
public SingleFieldInjector(InjectorImpl injector, InjectionPoint injectionPoint, Errors errors)
    throws ErrorsException {
  this.injectionPoint = injectionPoint;
  this.field = (Field) injectionPoint.getMember();
  this.dependency = injectionPoint.getDependencies().get(0);

  // Ewwwww...
  field.setAccessible(true);
  binding = injector.getBindingOrThrow(dependency.getKey(), errors, JitLimitation.NO_JIT);
}
 
开发者ID:google,项目名称:guice,代码行数:11,代码来源:SingleFieldInjector.java

示例12: ProxyConstructor

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // the constructor promises to construct 'T's
ProxyConstructor(Enhancer enhancer, InjectionPoint injectionPoint, Callback[] callbacks,
    ImmutableMap<Method, List<MethodInterceptor>> methodInterceptors) {
  this.enhanced = enhancer.createClass(); // this returns a cached class if possible
  this.injectionPoint = injectionPoint;
  this.constructor = (Constructor<T>) injectionPoint.getMember();
  this.callbacks = callbacks;
  this.methodInterceptors = methodInterceptors;

  FastClass fastClass = newFastClass(enhanced, BytecodeGen.Visibility.forMember(constructor));
  this.fastConstructor = fastClass.getConstructor(constructor.getParameterTypes());
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:13,代码来源:ProxyFactory.java

示例13: configure

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
@Override
protected void configure() {
    final InjectionPoint point = InjectionPoint.forConstructorOf(innerType);
    final Constructor<I> constructor = (Constructor<I>) point.getMember();
    constructor.setAccessible(true);

    if(point.getDependencies().isEmpty() || !Types.isAssignable(point.getDependencies().get(0).getKey().getTypeLiteral(), outerType)) {
        addError("Expected %s to take %s as the first parameter of its injectable constructor", innerType, outerType);
        return;
    }

    final Set<Dependency<?>> dependencies = point.getDependencies()
                                                 .stream()
                                                 .skip(1)
                                                 .collect(Collectors.toImmutableSet());

    final List<Provider<?>> providers = dependencies.stream()
                                                    .map(dep -> getProvider(dep.getKey()))
                                                    .collect(Collectors.toImmutableList());

    final MembersInjector<I> membersInjector = getMembersInjector(innerType);

    class FactoryImpl implements InnerFactory<O, I>, HasDependencies {
        @Override
        public Set<Dependency<?>> getDependencies() {
            return dependencies;
        }

        public I create(O outer) {
            final Object[] args = new Object[providers.size() + 1];

            args[0] = outer;

            for(int i = 0; i < providers.size(); i++) {
                args[i + 1] = providers.get(i).get();
            }

            return Injection.wrappingExceptions(() -> {
                final I instance = constructor.newInstance(args);
                membersInjector.injectMembers(instance);
                return instance;
            });
        }
    }

    bind(factoryKey).toInstance(new FactoryImpl());
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:48,代码来源:InnerFactoryManifest.java

示例14: prepareMethod

import com.google.inject.spi.InjectionPoint; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked", "rawtypes"}) // mapKey doesn't know its key type
@Override
public <T> Key<T> prepareMethod(
    Binder binder, Annotation annotation, Key<T> key, InjectionPoint injectionPoint) {
  Method method = (Method) injectionPoint.getMember();
  AnnotationOrError mapKey = findMapKeyAnnotation(binder, method);
  if (annotation instanceof Provides) {
    if (mapKey.annotation != null) {
      binder.addError("Found a MapKey annotation on non map binding at %s.", method);
    }
    // no key rewriting for plain old @Provides
    return key;
  }
  if (annotation instanceof ProvidesIntoSet) {
    if (mapKey.annotation != null) {
      binder.addError("Found a MapKey annotation on non map binding at %s.", method);
    }
    return RealMultibinder.newRealSetBinder(binder, key).getKeyForNewItem();
  } else if (annotation instanceof ProvidesIntoMap) {
    if (mapKey.error) {
      // Already failed on the MapKey, don't bother doing more work.
      return key;
    }
    if (mapKey.annotation == null) {
      // If no MapKey, make an error and abort.
      binder.addError("No MapKey found for map binding at %s.", method);
      return key;
    }
    TypeAndValue typeAndValue = typeAndValueOfMapKey(mapKey.annotation);
    return RealMapBinder.newRealMapBinder(binder, typeAndValue.type, key)
        .getKeyForNewValue(typeAndValue.value);
  } else if (annotation instanceof ProvidesIntoOptional) {
    if (mapKey.annotation != null) {
      binder.addError("Found a MapKey annotation on non map binding at %s.", method);
    }
    switch (((ProvidesIntoOptional) annotation).value()) {
      case DEFAULT:
        return RealOptionalBinder.newRealOptionalBinder(binder, key).getKeyForDefaultBinding();
      case ACTUAL:
        return RealOptionalBinder.newRealOptionalBinder(binder, key).getKeyForActualBinding();
    }
  }
  throw new IllegalStateException("Invalid annotation: " + annotation);
}
 
开发者ID:google,项目名称:guice,代码行数:45,代码来源:ProvidesMethodScanner.java


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