com.google.inject.internal.Annotations.getKey()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(15.2k)|赞(0)|评价(0)|浏览(95)

本文整理了Java中com.google.inject.internal.Annotations.getKey()方法的一些代码示例,展示了Annotations.getKey()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Annotations.getKey()方法的具体详情如下:
包路径:com.google.inject.internal.Annotations
类名称:Annotations
方法名:getKey

Annotations.getKey介绍

[英]Gets a key for the given type, member and annotations.
[中]获取给定类型、成员和批注的键。

代码示例

代码示例来源:origin: com.google.inject/guice

private ImmutableList<Dependency<?>> forMember(
  Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) {
 Errors errors = new Errors(member);
 List<Dependency<?>> dependencies = Lists.newArrayList();
 int index = 0;
 for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
  try {
   Annotation[] parameterAnnotations = paramterAnnotations[index];
   Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
   dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
   index++;
  } catch (ConfigurationException e) {
   errors.merge(e.getErrorMessages());
  } catch (ErrorsException e) {
   errors.merge(e.getErrors());
  }
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 return ImmutableList.copyOf(dependencies);
}

代码示例来源:origin: com.google.inject/guice

InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
 this.member = field;
 this.declaringType = declaringType;
 this.optional = optional;
 Annotation[] annotations = field.getAnnotations();
 Errors errors = new Errors(field);
 Key<?> key = null;
 try {
  key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
 } catch (ConfigurationException e) {
  errors.merge(e.getErrorMessages());
 } catch (ErrorsException e) {
  errors.merge(e.getErrors());
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 this.dependencies =
   ImmutableList.<Dependency<?>>of(
     newDependency(key, Nullability.allowsNull(annotations), -1));
}

代码示例来源:origin: io.github.gwtplus.gin/gin

/**
 * Matching logic for {@literal @}{@link Inject} constructor and method
 * parameters.
 *
 * This returns true if all assisted parameters required by the constructor
 * are provided by the factory method.
 */
private boolean injectConstructorHasMatchingParams(TypeLiteral<?> type,
  Constructor<?> constructor, List<Key<?>> paramList, Errors errors) throws ErrorsException {
 List<TypeLiteral<?>> params = type.getParameterTypes(constructor);
 Annotation[][] paramAnnotations = constructor.getParameterAnnotations();
 int p = 0;
 for (TypeLiteral<?> param : params) {
  Key<?> paramKey = getKey(param, constructor, paramAnnotations[p++], errors);
  if(paramKey.getAnnotationType() == Assisted.class && !paramList.contains(paramKey)) {
   return false;
  }
 }
 return true;
}

代码示例来源:origin: org.jukito/jukito

public static List<Key<?>> getMethodKeys(Method method, Errors errors) {
    Annotation allParameterAnnotations[][] = method.getParameterAnnotations();
    List<Key<?>> result = new ArrayList<Key<?>>(allParameterAnnotations.length);
    Iterator<Annotation[]> annotationsIterator = Arrays.asList(allParameterAnnotations).iterator();
    TypeLiteral<?> type = TypeLiteral.get(method.getDeclaringClass());
    for (TypeLiteral<?> parameterType : type.getParameterTypes(method)) {
      try {
        Annotation[] parameterAnnotations = annotationsIterator.next();
        result.add(Annotations.getKey(parameterType, method, parameterAnnotations, errors));
      } catch (ConfigurationException e) {
        errors.merge(e.getErrorMessages());
      } catch (ErrorsException e) {
        errors.merge(e.getErrors());
      }
    }
    return result;
  }
}

代码示例来源:origin: ArcBees/Jukito

public static List<Key<?>> getMethodKeys(Method method, Errors errors) {
    Annotation allParameterAnnotations[][] = method.getParameterAnnotations();
    List<Key<?>> result = new ArrayList<Key<?>>(allParameterAnnotations.length);
    Iterator<Annotation[]> annotationsIterator = Arrays.asList(allParameterAnnotations).iterator();
    TypeLiteral<?> type = TypeLiteral.get(method.getDeclaringClass());
    for (TypeLiteral<?> parameterType : type.getParameterTypes(method)) {
      try {
        Annotation[] parameterAnnotations = annotationsIterator.next();
        result.add(Annotations.getKey(parameterType, method, parameterAnnotations, errors));
      } catch (ConfigurationException e) {
        errors.merge(e.getErrorMessages());
      } catch (ErrorsException e) {
        errors.merge(e.getErrors());
      }
    }
    return result;
  }
}

代码示例来源:origin: org.sonatype.sisu/sisu-guice

private ImmutableList<Dependency<?>> forMember(
  Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) {
 Errors errors = new Errors(member);
 List<Dependency<?>> dependencies = Lists.newArrayList();
 int index = 0;
 for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
  try {
   Annotation[] parameterAnnotations = paramterAnnotations[index];
   Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
   dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
   index++;
  } catch (ConfigurationException e) {
   errors.merge(e.getErrorMessages());
  } catch (ErrorsException e) {
   errors.merge(e.getErrors());
  }
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 return ImmutableList.copyOf(dependencies);
}

代码示例来源:origin: com.jwebmp.inject/guice

private ImmutableList<Dependency<?>> forMember(
  Member member, TypeLiteral<?> type, Annotation[][] paramterAnnotations) {
 Errors errors = new Errors(member);
 List<Dependency<?>> dependencies = Lists.newArrayList();
 int index = 0;
 for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
  try {
   Annotation[] parameterAnnotations = paramterAnnotations[index];
   Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
   dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
   index++;
  } catch (ConfigurationException e) {
   errors.merge(e.getErrorMessages());
  } catch (ErrorsException e) {
   errors.merge(e.getErrors());
  }
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 return ImmutableList.copyOf(dependencies);
}

代码示例来源:origin: Nextdoor/bender

private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type,
  Annotation[][] paramterAnnotations) {
 Errors errors = new Errors(member);
 Iterator<Annotation[]> annotationsIterator = Arrays.asList(paramterAnnotations).iterator();
 List<Dependency<?>> dependencies = Lists.newArrayList();
 int index = 0;
 for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
  try {
   Annotation[] parameterAnnotations = annotationsIterator.next();
   Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
   dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
   index++;
  } catch (ConfigurationException e) {
   errors.merge(e.getErrorMessages());
  } catch (ErrorsException e) {
   errors.merge(e.getErrors());
  }
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 return ImmutableList.copyOf(dependencies);
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.inject

private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type,
  Annotation[][] paramterAnnotations) {
 Errors errors = new Errors(member);
 Iterator<Annotation[]> annotationsIterator = Arrays.asList(paramterAnnotations).iterator();
 List<Dependency<?>> dependencies = Lists.newArrayList();
 int index = 0;
 for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
  try {
   Annotation[] parameterAnnotations = annotationsIterator.next();
   Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
   dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
   index++;
  } catch (ConfigurationException e) {
   errors.merge(e.getErrorMessages());
  } catch (ErrorsException e) {
   errors.merge(e.getErrors());
  }
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 return ImmutableList.copyOf(dependencies);
}

代码示例来源:origin: com.google/inject

private ImmutableList<Dependency<?>> forMember(Member member, TypeLiteral<?> type,
  Annotation[][] paramterAnnotations) {
 Errors errors = new Errors(member);
 Iterator<Annotation[]> annotationsIterator = Arrays.asList(paramterAnnotations).iterator();
 List<Dependency<?>> dependencies = Lists.newArrayList();
 int index = 0;
 for (TypeLiteral<?> parameterType : type.getParameterTypes(member)) {
  try {
   Annotation[] parameterAnnotations = annotationsIterator.next();
   Key<?> key = Annotations.getKey(parameterType, member, parameterAnnotations, errors);
   dependencies.add(newDependency(key, Nullability.allowsNull(parameterAnnotations), index));
   index++;
  } catch (ConfigurationException e) {
   errors.merge(e.getErrorMessages());
  } catch (ErrorsException e) {
   errors.merge(e.getErrors());
  }
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 return ImmutableList.copyOf(dependencies);
}

代码示例来源:origin: org.xbib/guice

InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
  this.member = field;
  this.declaringType = declaringType;
  this.optional = optional;
  Annotation[] annotations = field.getAnnotations();
  Errors errors = new Errors(field);
  Key<?> key = null;
  try {
    key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
  } catch (ConfigurationException e) {
    errors.merge(e.getErrorMessages());
  } catch (ErrorsException e) {
    errors.merge(e.getErrors());
  }
  errors.throwConfigurationExceptionIfErrorsExist();
  this.dependencies = ImmutableList.<Dependency<?>>of(
      newDependency(key, Nullability.allowsNull(annotations), -1));
}

代码示例来源:origin: org.sonatype.sisu/sisu-guice

InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
 this.member = field;
 this.declaringType = declaringType;
 this.optional = optional;
 Annotation[] annotations = field.getAnnotations();
 Errors errors = new Errors(field);
 Key<?> key = null;
 try {
  key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
 } catch (ConfigurationException e) {
  errors.merge(e.getErrorMessages());
 } catch (ErrorsException e) {
  errors.merge(e.getErrors());
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 this.dependencies =
   ImmutableList.<Dependency<?>>of(
     newDependency(key, Nullability.allowsNull(annotations), -1));
}

代码示例来源:origin: com.jwebmp.inject/guice

InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
 this.member = field;
 this.declaringType = declaringType;
 this.optional = optional;
 Annotation[] annotations = field.getAnnotations();
 Errors errors = new Errors(field);
 Key<?> key = null;
 try {
  key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
 } catch (ConfigurationException e) {
  errors.merge(e.getErrorMessages());
 } catch (ErrorsException e) {
  errors.merge(e.getErrors());
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 this.dependencies =
   ImmutableList.<Dependency<?>>of(
     newDependency(key, Nullability.allowsNull(annotations), -1));
}

代码示例来源:origin: io.bootique.jersey/bootique-jersey

@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
  if (injectee.getRequiredType() instanceof Class) {
    TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
    Errors errors = new Errors(injectee.getParent());
    Key<?> key;
    try {
      key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
          injectee.getParent().getDeclaredAnnotations(), errors);
    } catch (ErrorsException e) {
      errors.merge(e.getErrors());
      throw new ConfigurationException(errors.getMessages());
    }
    return injector.getInstance(key);
  }
  throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}

代码示例来源:origin: com.nhl.bootique.jersey.client/bootique-jersey-client

@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
  if (injectee.getRequiredType() instanceof Class) {
    TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
    Errors errors = new Errors(injectee.getParent());
    Key<?> key;
    try {
      key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
          injectee.getParent().getDeclaredAnnotations(), errors);
    } catch (ErrorsException e) {
      errors.merge(e.getErrors());
      throw new ConfigurationException(errors.getMessages());
    }
    return injector.getInstance(key);
  }
  throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}

代码示例来源:origin: io.bootique.jersey.client/bootique-jersey-client

@Override
public Object resolve(Injectee injectee, ServiceHandle<?> serviceHandle) {
  if (injectee.getRequiredType() instanceof Class) {
    TypeLiteral<?> typeLiteral = TypeLiteral.get(injectee.getRequiredType());
    Errors errors = new Errors(injectee.getParent());
    Key<?> key;
    try {
      key = Annotations.getKey(typeLiteral, (Member) injectee.getParent(),
          injectee.getParent().getDeclaredAnnotations(), errors);
    } catch (ErrorsException e) {
      errors.merge(e.getErrors());
      throw new ConfigurationException(errors.getMessages());
    }
    return injector.getInstance(key);
  }
  throw new IllegalStateException("Can't process injection point: " + injectee.getRequiredType());
}

代码示例来源:origin: info.magnolia/magnolia-core

private Key<?> getKey(ParameterInfo parameter) {
    try {

      // Get TypeLiteral for this parameter
      TypeLiteral<?> declaringType = TypeLiteral.get(parameter.getDeclaringClass());
      List<TypeLiteral<?>> parameterTypes = declaringType.getParameterTypes(parameter.getConstructor());
      TypeLiteral<?> parameterType = parameterTypes.get(parameter.getParameterIndex());

      // Create Key object for this parameter
      Errors errors = new Errors(parameter.getConstructor());
      return Annotations.getKey(
          parameterType,
          parameter.getConstructor(),
          parameter.getParameterAnnotations(),
          errors);

    } catch (ErrorsException e) {
      throw new MgnlInstantiationException(e.getMessage(), e);
    }
  }
}

代码示例来源:origin: Nextdoor/bender

InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
 this.member = field;
 this.declaringType = declaringType;
 this.optional = optional;
 Annotation[] annotations = field.getAnnotations();
 Errors errors = new Errors(field);
 Key<?> key = null;
 try {
  key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
 } catch (ConfigurationException e) {
  errors.merge(e.getErrorMessages());
 } catch (ErrorsException e) {
  errors.merge(e.getErrors());
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 this.dependencies = ImmutableList.<Dependency<?>>of(
   newDependency(key, Nullability.allowsNull(annotations), -1));
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/com.google.inject

InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
 this.member = field;
 this.declaringType = declaringType;
 this.optional = optional;
 Annotation[] annotations = field.getAnnotations();
 Errors errors = new Errors(field);
 Key<?> key = null;
 try {
  key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
 } catch (ConfigurationException e) {
  errors.merge(e.getErrorMessages());
 } catch (ErrorsException e) {
  errors.merge(e.getErrors());
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 this.dependencies = ImmutableList.<Dependency<?>>of(
   newDependency(key, Nullability.allowsNull(annotations), -1));
}

代码示例来源:origin: com.google/inject

InjectionPoint(TypeLiteral<?> declaringType, Field field, boolean optional) {
 this.member = field;
 this.declaringType = declaringType;
 this.optional = optional;
 Annotation[] annotations = field.getAnnotations();
 Errors errors = new Errors(field);
 Key<?> key = null;
 try {
  key = Annotations.getKey(declaringType.getFieldType(field), field, annotations, errors);
 } catch (ConfigurationException e) {
  errors.merge(e.getErrorMessages());
 } catch (ErrorsException e) {
  errors.merge(e.getErrors());
 }
 errors.throwConfigurationExceptionIfErrorsExist();
 this.dependencies = ImmutableList.<Dependency<?>>of(
   newDependency(key, Nullability.allowsNull(annotations), -1));
}

相关文章