gpt4 book ai didi

org.jetbrains.yaml.psi.YAMLMapping类的使用及代码示例

转载 作者:知者 更新时间:2024-03-13 13:18:59 41 4
gpt4 key购买 nike

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

YAMLMapping介绍

暂无

代码示例

代码示例来源:origin: zalando/intellij-swagger

@Override
public List<PsiElement> getTags(final PsiFile psiFile) {
 return getRootChildrenOfType(psiFile, YAMLKeyValue.class)
   .stream()
   .filter(yamlKeyValue -> "tags".equals(yamlKeyValue.getName()))
   .map(YAMLKeyValue::getValue)
   .map(YAMLPsiElement::getYAMLElements)
   .flatMap(Collection::stream)
   .filter(el -> el instanceof YAMLSequenceItem)
   .map(YAMLSequenceItem.class::cast)
   .map(YAMLSequenceItem::getYAMLElements)
   .flatMap(Collection::stream)
   .filter(el -> el instanceof YAMLMapping)
   .map(YAMLMapping.class::cast)
   .map(yamlMapping -> yamlMapping.getKeyValueByKey("name"))
   .map(YAMLKeyValue::getValue)
   .filter(Objects::nonNull)
   .collect(Collectors.toList());
}

代码示例来源:origin: zalando/intellij-swagger

private Optional<PsiElement> addProperty(YAMLMapping yamlMapping, YAMLKeyValue yamlKeyValue) {
 final List<YAMLKeyValue> keyValues = Lists.newArrayList(yamlMapping.getKeyValues());
 return Optional.ofNullable(ContainerUtil.getLastItem(keyValues))
   .map(
     lastKeyValue -> {
      final PsiElement addedKeyValue = yamlMapping.addAfter(yamlKeyValue, lastKeyValue);
      yamlMapping.addBefore(
        new YAMLElementGenerator(yamlMapping.getProject()).createEol(), addedKeyValue);
      return addedKeyValue;
     });
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * Symfony 3.3: "class" is optional; use service name for its it
 *
 * Foo\Bar:
 *  arguments: ~
 */
@Nullable
public static String getServiceClassFromServiceMapping(@NotNull YAMLMapping yamlMapping) {
  YAMLKeyValue classKeyValue = yamlMapping.getKeyValueByKey("class");
  // Symfony 3.3: "class" is optional; use service id for class
  // Foo\Bar:
  //   arguments: ~
  if(classKeyValue != null) {
    return classKeyValue.getValueText();
  }
  PsiElement parent = yamlMapping.getParent();
  if(parent instanceof YAMLKeyValue) {
    String keyText = ((YAMLKeyValue) parent).getKeyText();
    if(YamlHelper.isClassServiceId(keyText)) {
      return keyText;
    }
  }
  return null;
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

@NotNull
public static Collection<YAMLKeyValue> getTopLevelKeyValues(@NotNull YAMLFile yamlFile) {
  YAMLDocument yamlDocument = PsiTreeUtil.getChildOfType(yamlFile, YAMLDocument.class);
  if(yamlDocument == null) {
    return Collections.emptyList();
  }
  YAMLValue topLevelValue = yamlDocument.getTopLevelValue();
  if(!(topLevelValue instanceof YAMLMapping)) {
    return Collections.emptyList();
  }
  return ((YAMLMapping) topLevelValue).getKeyValues();
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

@Override
protected void run(@NotNull Result result) throws Throwable {
  finalChildOfType.putKeyValue(next);
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 *  Simplify getting of array psi elements in array or sequence context
 *
 * arguments: [@foo]
 * arguments:
 *   - @foo
 *
 * TODO: can be handled nice know because on new yaml plugin
 */
@Nullable
public static List<PsiElement> getYamlArrayOnSequenceOrArrayElements(@NotNull YAMLCompoundValue yamlCompoundValue) {
  if (yamlCompoundValue instanceof YAMLSequence) {
    return new ArrayList<>(((YAMLSequence) yamlCompoundValue).getItems());
  }
  if (yamlCompoundValue instanceof YAMLMapping) {
    return new ArrayList<>(((YAMLMapping) yamlCompoundValue).getKeyValues());
  }
  return null;
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * Bridge to allow YAMLKeyValue adding child key-values elements.
 * Yaml plugin provides key adding only on YAMLMapping
 *
 * ser<caret>vice:
 *   foo: "aaa"
 *
 */
@Nullable
public static YAMLKeyValue putKeyValue(@NotNull YAMLKeyValue yamlKeyValue, @NotNull String keyName, @NotNull String valueText) {
  // create "foo: foo"
  YAMLKeyValue newYamlKeyValue = YAMLElementGenerator.getInstance(yamlKeyValue.getProject())
    .createYamlKeyValue(keyName, valueText);
  YAMLMapping childOfAnyType = PsiTreeUtil.findChildOfAnyType(yamlKeyValue, YAMLMapping.class);
  if(childOfAnyType == null) {
    return null;
  }
  childOfAnyType.putKeyValue(newYamlKeyValue);
  return newYamlKeyValue;
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * Visit all children key values of a parent key value
 */
private static void visitNextKeyValues(@NotNull YAMLKeyValue yamlKeyValue, @NotNull Consumer<YAMLKeyValue> consumer) {
  List<YAMLPsiElement> yamlElements = yamlKeyValue.getYAMLElements();
  // @TODO: multiple?
  if(yamlElements.size() != 1) {
    return;
  }
  YAMLPsiElement next = yamlElements.iterator().next();
  if(!(next instanceof YAMLMapping)) {
    return;
  }
  for (YAMLKeyValue keyValue : ((YAMLMapping) next).getKeyValues()) {
    consumer.consume(keyValue);
  }
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

YAMLKeyValue aClass = childOfType.getKeyValueByKey("class");
if(aClass != null) {
return new ServiceYamlContainer(yamlServiceKeyValue, childOfType.getKeyValueByKey("arguments"), serviceClass);

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

for (YAMLKeyValue yamlKey : ((YAMLMapping) topLevelValue).getKeyValues()) {
  String keyText = yamlKey.getKeyText();
  if(StringUtils.isBlank(keyText)) {

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

@Nullable
public static YAMLKeyValue getYamlKeyValue(@Nullable PsiElement yamlCompoundValue, String keyName, boolean ignoreCase) {
  if (!(yamlCompoundValue instanceof YAMLMapping)) {
    return null;
  }
  if (!ignoreCase) {
    return ((YAMLMapping) yamlCompoundValue).getKeyValueByKey(keyName);
  }
  
  YAMLKeyValue classKeyValue;
  classKeyValue = PsiElementUtils.getChildrenOfType(yamlCompoundValue, PlatformPatterns.psiElement(YAMLKeyValue.class).withName(PlatformPatterns.string().oneOfIgnoreCase(keyName)));
  if(classKeyValue == null) {
    return null;
  }
  return classKeyValue;
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

Collection<YAMLKeyValue> keyValues = ((YAMLMapping) topLevelValue).getKeyValues();
if(keyValues.size() > 0) {
  for(YAMLKeyValue yamlKeyValue: EntityHelper.getYamlModelFieldKeyValues(keyValues.iterator().next()).values()) {

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * Find last known KeyValue of key path, so that we can merge new incoming keys
 */
@NotNull
private static Pair<YAMLKeyValue, String[]> findLastKnownKeyInFile(@NotNull YAMLFile file, @NotNull String... keys) {
  YAMLKeyValue last = null;
  YAMLMapping mapping = ObjectUtils.tryCast(file.getDocuments().get(0).getTopLevelValue(), YAMLMapping.class);
  for (int i = 0; i < keys.length; i++) {
    String s = keys[i];
    if (mapping == null) {
      return Pair.create(last, Arrays.copyOfRange(keys, i, keys.length));
    }
    YAMLKeyValue keyValue = mapping.getKeyValueByKey(s);
    if (keyValue == null) {
      return Pair.create(last, Arrays.copyOfRange(keys, i, keys.length));
    }
    last = keyValue;
    mapping = ObjectUtils.tryCast(keyValue.getValue(), YAMLMapping.class);
  }
  return Pair.create(last, new String[]{});
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

PsiElement yamlKeyValueLastChild = yamlKeyValue.getLastChild();
if (yamlKeyValueLastChild instanceof YAMLMapping) {
  for (YAMLKeyValue keyValue : ((YAMLMapping) yamlKeyValueLastChild).getKeyValues()) {
    visitEnvironmentSquenceItems(consumer, keyValue);

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

YAMLKeyValue classKeyValue = parentMapping.getKeyValueByKey("class");
if (classKeyValue != null) {
  String valueText = classKeyValue.getValueText();

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

/**
 * Try to find a valid indent value, which are spaces which we need to fill
 */
public static int getIndentSpaceForFile(@NotNull YAMLFile yamlFile) {
  List<YAMLDocument> documents = yamlFile.getDocuments();
  YAMLMapping mapping = ObjectUtils.tryCast(documents.get(0).getTopLevelValue(), YAMLMapping.class);
  if(mapping != null) {
    // first first INDENT element in mapping
    PsiElementPattern.Capture<PsiElement> pattern = PlatformPatterns
      .psiElement(YAMLTokenTypes.INDENT)
      .with(new PsiElementPatternCondition());
    for (YAMLPsiElement yamlPsiElement : mapping.getKeyValues()) {
      // get first value
      PsiElement firstChild = yamlPsiElement.getFirstChild();
      if(firstChild == null) {
        continue;
      }
      // first valid INDENT
      PsiElement nextSiblingOfType = PsiElementUtils.getNextSiblingOfType(firstChild, pattern);
      if(nextSiblingOfType != null && nextSiblingOfType.getTextLength() > 0) {
        return nextSiblingOfType.getTextLength();
      }
    }
  }
  // default value
  return 4;
}

代码示例来源:origin: Haehnchen/idea-php-symfony2-plugin

YAMLKeyValue roles = ((YAMLMapping) value1).getKeyValueByKey("roles");
if(roles == null) {
  continue;

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com