io.micronaut.context.ApplicationContext.containsProperties()方法的使用及代码示例

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

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

ApplicationContext.containsProperties介绍

暂无

代码示例

代码示例来源:origin: io.micronaut/micronaut-inject

/**
 * If this bean is a {@link ConfigurationProperties} bean return whether any properties for it are configured
 * within the context.
 *
 * @param resolutionContext the resolution context
 * @param context           The context
 * @param subProperty       The subproperty to check
 * @return True if it does
 */
@SuppressWarnings({"WeakerAccess", "SameParameterValue"})
@Internal
@UsedByGeneratedCode
protected final boolean containsProperties(@SuppressWarnings("unused") BeanResolutionContext resolutionContext, BeanContext context, String subProperty) {
  boolean isSubProperty = StringUtils.isNotEmpty(subProperty);
  if (!isSubProperty && !requiredComponents.isEmpty()) {
    // if the bean requires dependency injection we disable this optimization
    return true;
  }
  if (isConfigurationProperties && context instanceof ApplicationContext) {
    AnnotationMetadata annotationMetadata = getAnnotationMetadata();
    ApplicationContext appCtx = (ApplicationContext) context;
    if (annotationMetadata.getValue(ConfigurationProperties.class, "cliPrefix").isPresent()) {
      return true;
    } else {
      String path = getConfigurationPropertiesPath(resolutionContext);
      return appCtx.containsProperties(path);
    }
  }
  return false;
}

代码示例来源:origin: io.micronaut/inject

/**
 * If this bean is a {@link ConfigurationProperties} bean return whether any properties for it are configured
 * within the context.
 *
 * @param resolutionContext the resolution context
 * @param context           The context
 * @param subProperty       The subproperty to check
 * @return True if it does
 */
@SuppressWarnings({"WeakerAccess", "SameParameterValue"})
@Internal
@UsedByGeneratedCode
protected final boolean containsProperties(@SuppressWarnings("unused") BeanResolutionContext resolutionContext, BeanContext context, String subProperty) {
  boolean isSubProperty = StringUtils.isNotEmpty(subProperty);
  if (!isSubProperty && !requiredComponents.isEmpty()) {
    // if the bean requires dependency injection we disable this optimization
    return true;
  }
  if (isConfigurationProperties && context instanceof ApplicationContext) {
    AnnotationMetadata annotationMetadata = getAnnotationMetadata();
    ApplicationContext appCtx = (ApplicationContext) context;
    if (annotationMetadata.getValue(ConfigurationProperties.class, "cliPrefix").isPresent()) {
      return true;
    } else {
      String path = getConfigurationPropertiesPath(resolutionContext);
      return appCtx.containsProperties(path);
    }
  }
  return false;
}

代码示例来源:origin: io.micronaut/inject

/**
 * Obtains a value for the given field argument.
 *
 * @param resolutionContext The resolution context
 * @param context           The bean context
 * @param fieldIndex        The field index
 * @return True if it does
 */
@Internal
@UsedByGeneratedCode
protected final boolean containsValueForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex) {
  if (context instanceof ApplicationContext) {
    FieldInjectionPoint injectionPoint = fieldInjectionPoints.get(fieldIndex);
    final AnnotationMetadata annotationMetadata = injectionPoint.getAnnotationMetadata();
    String valueAnnVal = annotationMetadata.getValue(Value.class, String.class).orElse(null);
    String valString = resolvePropertyValueName(resolutionContext, injectionPoint, valueAnnVal, annotationMetadata);
    ApplicationContext applicationContext = (ApplicationContext) context;
    Class fieldType = injectionPoint.getType();
    boolean isConfigProps = fieldType.isAnnotationPresent(ConfigurationProperties.class);
    boolean result = isConfigProps || Map.class.isAssignableFrom(fieldType) ? applicationContext.containsProperties(valString) : applicationContext.containsProperty(valString);
    if (!result && isConfigurationProperties()) {
      String cliOption = resolveCliOption(injectionPoint.getName());
      if (cliOption != null) {
        return applicationContext.containsProperty(cliOption);
      }
    }
    return result;
  }
  return false;
}

代码示例来源:origin: io.micronaut/micronaut-inject

/**
 * Obtains a value for the given field argument.
 *
 * @param resolutionContext The resolution context
 * @param context           The bean context
 * @param fieldIndex        The field index
 * @return True if it does
 */
@Internal
@UsedByGeneratedCode
protected final boolean containsValueForField(BeanResolutionContext resolutionContext, BeanContext context, int fieldIndex) {
  if (context instanceof ApplicationContext) {
    FieldInjectionPoint injectionPoint = fieldInjectionPoints.get(fieldIndex);
    final AnnotationMetadata annotationMetadata = injectionPoint.getAnnotationMetadata();
    String valueAnnVal = annotationMetadata.getValue(Value.class, String.class).orElse(null);
    String valString = resolvePropertyValueName(resolutionContext, injectionPoint, valueAnnVal, annotationMetadata);
    ApplicationContext applicationContext = (ApplicationContext) context;
    Class fieldType = injectionPoint.getType();
    boolean isConfigProps = fieldType.isAnnotationPresent(ConfigurationProperties.class);
    boolean result = isConfigProps || Map.class.isAssignableFrom(fieldType) ? applicationContext.containsProperties(valString) : applicationContext.containsProperty(valString);
    if (!result && isConfigurationProperties()) {
      String cliOption = resolveCliOption(injectionPoint.getName());
      if (cliOption != null) {
        return applicationContext.containsProperty(cliOption);
      }
    }
    return result;
  }
  return false;
}

代码示例来源:origin: io.micronaut/micronaut-inject

Class type = argument.getType();
boolean isConfigProps = type.isAnnotationPresent(ConfigurationProperties.class);
boolean result = isConfigProps || Map.class.isAssignableFrom(type) ? applicationContext.containsProperties(valString) : applicationContext.containsProperty(valString);
if (!result && isConfigurationProperties()) {
  String cliOption = resolveCliOption(argument.getName());

代码示例来源:origin: io.micronaut/inject

Class type = argument.getType();
boolean isConfigProps = type.isAnnotationPresent(ConfigurationProperties.class);
boolean result = isConfigProps || Map.class.isAssignableFrom(type) ? applicationContext.containsProperties(valString) : applicationContext.containsProperty(valString);
if (!result && isConfigurationProperties()) {
  String cliOption = resolveCliOption(argument.getName());

相关文章