org.jetbrains.yaml.psi.YAMLSequence Java Examples

The following examples show how to use org.jetbrains.yaml.psi.YAMLSequence. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MissingRequiredPropertiesAnnotator.java    From intellij-kubernetes with Apache License 2.0 6 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder annotationHolder) {
    if (!KubernetesYamlPsiUtil.isKubernetesFile(element)) {
        return;
    }
    final ModelProvider modelProvider = ModelProvider.INSTANCE;
    final ResourceTypeKey resourceKey = KubernetesYamlPsiUtil.findResourceKey(element);
    if (resourceKey != null && element instanceof YAMLKeyValue) {
        final YAMLKeyValue keyValue = (YAMLKeyValue) element;
        final Model model = KubernetesYamlPsiUtil.modelForKey(modelProvider, resourceKey, keyValue);
        if (model != null && keyValue.getKey() != null) {
            if (keyValue.getValue() instanceof YAMLMapping) {
                final YAMLMapping mapping = (YAMLMapping) keyValue.getValue();
                addErrors(annotationHolder, model, keyValue.getKey(), mapping);
            } else if (keyValue.getValue() instanceof YAMLSequence) {
                final YAMLSequence sequence = (YAMLSequence) keyValue.getValue();
                for (final YAMLSequenceItem item : sequence.getItems()) {
                    if (item.getValue() instanceof YAMLMapping) {
                        addErrors(annotationHolder, model, item.getFirstChild(), (YAMLMapping) item.getValue());
                    }
                }
            }
        }
    }
}
 
Example #2
Source File: Traversal.java    From intellij-swagger with MIT License 5 votes vote down vote up
public List<PsiElement> getChildrenOfArrayObject(final PsiElement psiElement) {
  return Arrays.stream(psiElement.getChildren())
      .filter(child -> child instanceof JsonArray || child instanceof YAMLSequence)
      .map(el -> Arrays.asList(el.getChildren()))
      .flatMap(Collection::stream)
      .collect(Collectors.toList());
}
 
Example #3
Source File: PathFinder.java    From intellij-swagger with MIT License 5 votes vote down vote up
public List<? extends PsiNamedElement> findDirectNamedChildren(
    final String path, final PsiElement psiElement) {
  Predicate<PsiElement> childFilter =
      child ->
          child instanceof NavigatablePsiElement
              && !(child instanceof JsonStringLiteral)
              && !(child instanceof YAMLSequence)
              && !(child instanceof JsonArray);

  return findChildrenByPathFrom(new PathExpression(path), psiElement, childFilter);
}
 
Example #4
Source File: DataTypeCheckerAnnotator.java    From intellij-kubernetes with Apache License 2.0 5 votes vote down vote up
@Override
public void annotate(@NotNull final PsiElement element, @NotNull final AnnotationHolder annotationHolder) {
    if (!KubernetesYamlPsiUtil.isKubernetesFile(element)) {
        return;
    }
    final ModelProvider modelProvider = ModelProvider.INSTANCE;
    final ResourceTypeKey resourceKey = KubernetesYamlPsiUtil.findResourceKey(element);
    if (resourceKey != null && element instanceof YAMLKeyValue) {
        final YAMLKeyValue keyValue = (YAMLKeyValue) element;
        final Property property = KubernetesYamlPsiUtil.propertyForKey(modelProvider, resourceKey, keyValue);
        final YAMLValue value = keyValue.getValue();
        if (property != null && property.getType() != null && value != null) {
            switch (property.getType()) {
                case ARRAY:
                    if (!(value instanceof YAMLSequence)) {
                        annotationHolder.createErrorAnnotation(value, "The content of " + keyValue.getKeyText() + " should be an array.");
                    }
                    break;
                case OBJECT:
                    if (!(value instanceof YAMLMapping)) {
                        annotationHolder.createErrorAnnotation(value, "The content of " + keyValue.getKeyText() + " should be an object.");
                    }
                    break;
            }
        }
    }
}
 
Example #5
Source File: YamlCompletionContributor.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Override
public boolean invokeAutoPopup(@NotNull PsiElement position, char typeChar) {
    // Only for Yaml tag places (scalar values)
    //   key: !<caret>
    if (!YamlElementPatternHelper.getSingleLineTextOrTag().accepts(position)
        && !(position.getPrevSibling() instanceof YAMLKeyValue)
        && !(position.getParent() instanceof YAMLSequenceItem)
        && !(position.getParent() instanceof YAMLSequence)
    ) {
        return super.invokeAutoPopup(position, typeChar);
    }

    return typeChar == '!';
}