Java源码示例:org.jetbrains.yaml.YAMLTokenTypes

示例1
/**
 * Find controller definition in yaml structor
 *
 * foo:
 *   defaults: { _controller: "Bundle:Foo:Bar" }
 *   controller: "Bundle:Foo:Bar"
 */
private void attachRouteActions(@NotNull Collection<LineMarkerInfo> lineMarkerInfos, @NotNull PsiElement psiElement) {
    if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
        return;
    }

    PsiElement yamlKeyValue = psiElement.getParent();
    if(!(yamlKeyValue instanceof YAMLKeyValue)) {
        return;
    }

    String yamlController = RouteHelper.getYamlController((YAMLKeyValue) yamlKeyValue);
    if(yamlController != null) {
        PsiElement[] methods = RouteHelper.getMethodsOnControllerShortcut(psiElement.getProject(), yamlController);
        if(methods.length > 0) {
            NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.TWIG_CONTROLLER_LINE_MARKER).
                setTargets(methods).
                setTooltipText("Navigate to action");

            lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
        }
    }
}
 
示例2
/**
 * !php/const <caret>
 */
public static ElementPattern<PsiElement> getPhpConstPattern() {
    return
        PlatformPatterns
            .psiElement()
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(YAMLTokenTypes.WHITESPACE)
                ),
                PlatformPatterns.or(
                    PlatformPatterns.psiElement().withText("!php/const"),
                    PlatformPatterns.psiElement().withText("!php/const:")
                )
            );
}
 
示例3
private void annotateCallMethod(@NotNull final PsiElement psiElement, @NotNull ProblemsHolder holder, ContainerCollectionResolver.LazyServiceCollector collector) {

        if(StandardPatterns.and(
            YamlElementPatternHelper.getInsideKeyValue("tags"),
            YamlElementPatternHelper.getSingleLineScalarKey("method")
        ).accepts(psiElement)) {
            visitYamlMethodTagKey(psiElement, holder, collector);
        }

        if((PlatformPatterns.psiElement(YAMLTokenTypes.TEXT).accepts(psiElement)
            || PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_DSTRING).accepts(psiElement)))
        {
            visitYamlMethod(psiElement, holder, collector);
        }

    }
 
示例4
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> result) {
    if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) {
        return;
    }

    LazyConfigTreeSignatures function = null;

    for (PsiElement psiElement : psiElements) {
        if(psiElement.getNode().getElementType() == YAMLTokenTypes.SCALAR_KEY && YamlElementPatternHelper.getRootConfigKeyPattern().accepts(psiElement)) {
            if(function == null) {
                function = new LazyConfigTreeSignatures(psiElements.get(0).getProject());
            }
            visitRootElements(result, psiElement, function);
        }
    }
}
 
示例5
/**
 * Remove TODO; moved to core
 */
@Deprecated
@NotNull
public static String findEol(@NotNull PsiElement psiElement) {

    for(PsiElement child: YamlHelper.getChildrenFix(psiElement)) {
        if(PlatformPatterns.psiElement(YAMLTokenTypes.EOL).accepts(child)) {
            return child.getText();
        }
    }

    PsiElement[] indentPsiElements = PsiTreeUtil.collectElements(psiElement.getContainingFile(), element ->
        PlatformPatterns.psiElement(YAMLTokenTypes.EOL).accepts(element)
    );

    if(indentPsiElements.length > 0) {
        return indentPsiElements[0].getText();
    }

    return "\n";
}
 
示例6
/**
 * key: !my_tag <caret>
 */
public static boolean isElementAfterYamlTag(PsiElement psiElement) {
    if (!(psiElement instanceof LeafPsiElement)) {
        return false;
    }

    // key: !my_tag <caret>\n
    if (((LeafPsiElement) psiElement).getElementType() == YAMLTokenTypes.EOL) {
        PsiElement prevElement = PsiTreeUtil.getDeepestVisibleLast(psiElement);
        if (prevElement instanceof LeafPsiElement) {
            if (((LeafPsiElement) prevElement).getElementType() == YAMLTokenTypes.TAG) {
                return ((LeafPsiElement) prevElement).getText().startsWith("!");
            }
        }
    }

    return PsiTreeUtil.findSiblingBackward(psiElement, YAMLTokenTypes.TAG, null) != null;
}
 
示例7
@NotNull
private PsiElementPattern.Capture<PsiElement> yamlKeyChildOfInArray() {

    return PlatformPatterns
        .psiElement(YAMLTokenTypes.SCALAR_KEY)
        .withSuperParent(2, YAMLMapping.class)
        .withSuperParent(1, YAMLKeyValue.class)
        .withLanguage(YAMLLanguage.INSTANCE);
}
 
示例8
public static ElementPattern<PsiElement> getWithFirstRootKey() {

        return PlatformPatterns.and(PlatformPatterns.or(
                // foo:
                //   <caret>
                PlatformPatterns
                        .psiElement().with(new ParentPathPatternCondition(
                        YAMLScalar.class, YAMLMapping.class,
                        YAMLKeyValue.class, YAMLMapping.class,
                        YAMLDocument.class
                ))
                        .withLanguage(YAMLLanguage.INSTANCE),

                // foo:
                //   <caret> (on incomplete)
                PlatformPatterns
                        .psiElement().afterLeaf(
                        PlatformPatterns.psiElement(YAMLTokenTypes.INDENT).with(
                                new ParentPathPatternCondition(YAMLKeyValue.class, YAMLMapping.class, YAMLDocument.class)
                        )
                )
                        .withLanguage(YAMLLanguage.INSTANCE),

                // foo:
                //   fo<caret>:
                PlatformPatterns.psiElement().with(new ParentPathPatternCondition(
                        YAMLKeyValue.class, YAMLMapping.class,
                        YAMLKeyValue.class, YAMLMapping.class,
                        YAMLDocument.class)
                )
        ));
    }
 
示例9
public YamlWordScanner() {
  super(
      new YAMLFlexLexer(),
      TokenSet.create(YAMLTokenTypes.SCALAR_KEY),
      TokenSet.create(YAMLTokenTypes.COMMENT),
      TokenSet.create(
          YAMLTokenTypes.SCALAR_STRING, YAMLTokenTypes.SCALAR_DSTRING, YAMLTokenTypes.TEXT));
  setMayHaveFileRefsInLiterals(true);
}
 
示例10
/**
 * fields:
 *  i<caret>d: []
 *
 * embedOne:
 *  add<caret>ress: []
 */
public static PsiElementPattern.Capture<PsiElement> getYamlFieldName() {
    return PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_KEY)
        .withParent(
            PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(
                PlatformPatterns.psiElement(YAMLCompoundValue.class).withParent(
                    PlatformPatterns.psiElement(YAMLKeyValue.class).withName(PlatformPatterns.string().oneOf(
                        "id", "fields", "embedOne", "embedMany", "referenceOne", "referenceMany", "oneToOne", "oneToMany", "manyToOne", "manyToMany"
                    ))
                )
            )
        );
}
 
示例11
@NotNull
public PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    if (!Symfony2ProjectComponent.isEnabled(holder.getProject())) {
        return super.buildVisitor(holder, isOnTheFly);
    }

    return new PsiElementVisitor() {
        @Override
        public void visitElement(PsiElement psiElement) {
            if ((YamlElementPatternHelper.getSingleLineScalarKey("class", "factory_class").accepts(psiElement) || YamlElementPatternHelper.getParameterClassPattern().accepts(psiElement)) && YamlElementPatternHelper.getInsideServiceKeyPattern().accepts(psiElement)) {
                // foobar.foo:
                //   class: Foobar\Foo
                invoke(psiElement, holder);
            } else if (psiElement.getNode().getElementType() == YAMLTokenTypes.SCALAR_KEY && YamlElementPatternHelper.getServiceIdKeyValuePattern().accepts(psiElement.getParent())) {
                // Foobar\Foo: ~
                String text = PsiElementUtils.getText(psiElement);
                if (StringUtils.isNotBlank(text) && YamlHelper.isClassServiceId(text) && text.contains("\\")) {
                    PsiElement yamlKeyValue = psiElement.getParent();
                    if (yamlKeyValue instanceof YAMLKeyValue && YamlHelper.getYamlKeyValue((YAMLKeyValue) yamlKeyValue, "resource") == null && YamlHelper.getYamlKeyValue((YAMLKeyValue) yamlKeyValue, "exclude") == null) {
                        invoke(psiElement, holder);
                    }
                }
            }

            super.visitElement(psiElement);
        }
    };
}
 
示例12
@Override
public void collectSlowLineMarkers(@NotNull List<PsiElement> psiElements, @NotNull Collection<LineMarkerInfo> result) {
    if(psiElements.size() == 0 || !Symfony2ProjectComponent.isEnabled(psiElements.get(0))) {
        return;
    }

    LazyDecoratedParentServiceValues lazyDecoratedServices = null;


    for (PsiElement psiElement : psiElements) {
        if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
            continue;
        }

        PsiElement yamlKeyValue = psiElement.getParent();
        if(!(yamlKeyValue instanceof YAMLKeyValue) || !YamlElementPatternHelper.getServiceIdKeyValuePattern().accepts(yamlKeyValue)) {
            continue;
        }

        if(lazyDecoratedServices == null) {
            lazyDecoratedServices = new LazyDecoratedParentServiceValues(psiElement.getProject());
        }

        // services -> service_name
        visitServiceId(psiElement, (YAMLKeyValue) yamlKeyValue, result, lazyDecoratedServices);
    }
}
 
示例13
private void attachEntityClass(@NotNull Collection<LineMarkerInfo> lineMarkerInfos, @NotNull PsiElement psiElement) {
    if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
        return;
    }

    PsiElement yamlKeyValue = psiElement.getParent();
    if(!(yamlKeyValue instanceof YAMLKeyValue)) {
        return;
    }

    if(yamlKeyValue.getParent() instanceof YAMLMapping && yamlKeyValue.getParent().getParent() instanceof YAMLDocument) {
        PsiFile containingFile;
        try {
            containingFile = yamlKeyValue.getContainingFile();
        } catch (PsiInvalidElementAccessException e) {
            return;
        }

        String fileName = containingFile.getName();
        if(isMetadataFile(fileName)) {
            String keyText = ((YAMLKeyValue) yamlKeyValue).getKeyText();
            if(StringUtils.isNotBlank(keyText)) {
                Collection<PhpClass> phpClasses = PhpElementsUtil.getClassesInterface(psiElement.getProject(), keyText);
                if(phpClasses.size() > 0) {
                    NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.DOCTRINE_LINE_MARKER).
                        setTargets(phpClasses).
                        setTooltipText("Navigate to class");

                    lineMarkerInfos.add(builder.createLineMarkerInfo(psiElement));
                }
            }
        }
    }
}
 
示例14
public static ElementPattern<PsiElement> getSingleLineScalarKey(String... keyName) {
    // key: | and key: "quote" is valid here
    // getKeyPattern
    return PlatformPatterns.or(
            PlatformPatterns
                    .psiElement(YAMLTokenTypes.TEXT)
                    .withParent(PlatformPatterns.psiElement(YAMLScalar.class)
                            .withParent(PlatformPatterns
                                    .psiElement(YAMLKeyValue.class)
                                    .withName(
                                            PlatformPatterns.string().oneOf(keyName)
                                    )
                            ))
                    .withLanguage(YAMLLanguage.INSTANCE)
        ,
        PlatformPatterns
            .psiElement(YAMLTokenTypes.SCALAR_DSTRING)
                .withParent(PlatformPatterns.psiElement(YAMLScalar.class)
                        .withParent(PlatformPatterns
                                .psiElement(YAMLKeyValue.class)
                                .withName(
                                        PlatformPatterns.string().oneOf(keyName)
                                )
                        ))
            .withLanguage(YAMLLanguage.INSTANCE),
        PlatformPatterns
            .psiElement(YAMLTokenTypes.SCALAR_STRING)
                .withParent(PlatformPatterns.psiElement(YAMLScalar.class)
                        .withParent(PlatformPatterns
                                .psiElement(YAMLKeyValue.class)
                                .withName(
                                        PlatformPatterns.string().oneOf(keyName)
                                )
                        ))
            .withLanguage(YAMLLanguage.INSTANCE)
    );
}
 
示例15
public static ElementPattern<PsiElement> getSingleLineText() {
    return
        PlatformPatterns
            .psiElement(YAMLTokenTypes.TEXT)
            .withParent(PlatformPatterns.psiElement(YAMLScalar.class)
                .withParent(PlatformPatterns.or(
                    PlatformPatterns.psiElement(YAMLKeyValue.class),
                    PlatformPatterns.psiElement(YAMLSequenceItem.class)
                    )
                )
            )
            .withLanguage(YAMLLanguage.INSTANCE)
    ;
}
 
示例16
public static ElementPattern<PsiElement> getSingleLineTextOrTag() {
        return PlatformPatterns.or(
            PlatformPatterns
                .psiElement(YAMLTokenTypes.TEXT)
                .withParent(PlatformPatterns.psiElement(YAMLScalar.class)
//                    .withParent(PlatformPatterns
//                            .psiElement(YAMLKeyValue.class)
//                    )
                )
                .withLanguage(YAMLLanguage.INSTANCE),
            PlatformPatterns
                .psiElement(YAMLTokenTypes.TAG)
                .withLanguage(YAMLLanguage.INSTANCE)
        );
    }
 
示例17
/**
 * services:
 *   My<caret>Class: ~
 */
public static ElementPattern<PsiElement> getServicesKeyPattern() {
    return PlatformPatterns
        .psiElement(YAMLTokenTypes.SCALAR_KEY).withParent(
            PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(
                PlatformPatterns.psiElement(YAMLMapping.class).withParent(
                    PlatformPatterns.psiElement(YAMLKeyValue.class).with(YAML_KEY_SERVICES)
                )
            )
        );
}
 
示例18
/**
 * PsiFile / Document:
 *   serv<caret>ices: ~
 */
public static PsiElementPattern.Capture<PsiElement> getRootConfigKeyPattern() {
    return PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_KEY).withParent(
        PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(
            PlatformPatterns.psiElement(YAMLMapping.class).withParent(
                PlatformPatterns.psiElement(YAMLDocument.class)
            )
        )
    ).inFile(getConfigFileNamePattern());
}
 
示例19
private boolean hasNewConst(@NotNull PsiElement psiElement) {
    PsiElement prevSibling = psiElement.getPrevSibling();
    while (prevSibling != null) {
        IElementType elementType = prevSibling.getNode().getElementType();
        if (elementType == YAMLTokenTypes.TEXT || elementType == YAMLTokenTypes.SCALAR_DSTRING || elementType == YAMLTokenTypes.SCALAR_STRING || elementType == YAMLTokenTypes.TAG) {
            String psiText = PsiElementUtils.getText(prevSibling);

            return psiText.equals("!php/const");
        }

        prevSibling = prevSibling.getPrevSibling();
    }

    return false;
}
 
示例20
/**
 * 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;
}
 
示例21
public static boolean isStringValue(@NotNull PsiElement psiElement) {
    // @TODO use new YAMLScalar element
    return PlatformPatterns.psiElement(YAMLTokenTypes.TEXT).accepts(psiElement)
        || PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_DSTRING).accepts(psiElement)
        || PlatformPatterns.psiElement(YAMLTokenTypes.SCALAR_STRING).accepts(psiElement)
        ;
}
 
示例22
/**
 * key: foo\n
 * <caret>
 */
public static boolean isElementAfterEol(PsiElement psiElement) {
    if (psiElement.getParent() instanceof YAMLPlainTextImpl) {
        psiElement = psiElement.getParent();
    }
    return PsiElementUtils.getPrevSiblingOfType(psiElement, PlatformPatterns.psiElement(YAMLTokenTypes.EOL)) != null;
}
 
示例23
@NotNull
public TokenSet getWhitespaceTokens()
{
    return TokenSet.create(YAMLTokenTypes.WHITESPACE);
}
 
示例24
@NotNull
public TokenSet getStringLiteralElements()
{
    return TokenSet.create(YAMLTokenTypes.SCALAR_STRING, YAMLTokenTypes.SCALAR_DSTRING, YAMLTokenTypes.TEXT);
}
 
示例25
/**
 * Set linemarker for targetEntity in possible yaml entity files
 *
 * foo:
 *   targetEntity: Class
 */
private void attachRelationClass(@NotNull Collection<LineMarkerInfo> lineMarkerInfos, @NotNull PsiElement psiElement) {
    if(psiElement.getNode().getElementType() != YAMLTokenTypes.SCALAR_KEY) {
        return;
    }

    PsiElement yamlKeyValue = psiElement.getParent();
    if(!(yamlKeyValue instanceof YAMLKeyValue)) {
        return;
    }

    String keyText = ((YAMLKeyValue) yamlKeyValue).getKeyText();
    if(!(keyText.equalsIgnoreCase("targetEntity") || keyText.equalsIgnoreCase("targetDocument"))) {
        return;
    }

    String valueText = ((YAMLKeyValue) yamlKeyValue).getValueText();
    if(StringUtils.isBlank(valueText)) {
        return;
    }

    Collection<PhpClass> classesInterface = DoctrineMetadataUtil.getClassInsideScope(yamlKeyValue, valueText);
    if(classesInterface.size() == 0) {
        return;
    }

    // get relation key
    PsiElement parent = yamlKeyValue.getParent();
    if(parent != null) {
        PsiElement yamlKeyValueTarget = parent.getParent();
        if(yamlKeyValueTarget instanceof YAMLKeyValue) {
            NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.DOCTRINE_LINE_MARKER).
                setTargets(classesInterface).
                setTooltipText("Navigate to file");

            PsiElement key = ((YAMLKeyValue) yamlKeyValueTarget).getKey();
            if(key != null) {
                lineMarkerInfos.add(builder.createLineMarkerInfo(key));
            }
        }
    }
}
 
示例26
/**
 * Collects Twig path in given yaml configuration
 *
 * twig:
 *  paths:
 *   "%kernel.root_dir%/../src/vendor/bundle/Resources/views": core
 */
@NotNull
public static Collection<Pair<String, String>> getTwigPathFromYamlConfig(@NotNull YAMLFile yamlFile) {
    YAMLKeyValue yamlKeyValue = YAMLUtil.getQualifiedKeyInFile(yamlFile, "twig", "paths");
    if(yamlKeyValue == null) {
        return Collections.emptyList();
    }

    YAMLValue value = yamlKeyValue.getValue();
    if(!(value instanceof YAMLMapping)) {
        return Collections.emptyList();
    }

    Collection<Pair<String, String>> pair = new ArrayList<>();

    for (YAMLPsiElement element : value.getYAMLElements()) {
        if(!(element instanceof YAMLKeyValue)) {
            continue;
        }

        String keyText = ((YAMLKeyValue) element).getKeyText();
        if(StringUtils.isBlank(keyText)) {
            continue;
        }

        keyText = keyText.replace("\\", "/").replaceAll("/+", "/");

        // empty value is empty string on out side:
        // "foo: "
        String valueText = "";

        YAMLValue yamlValue = ((YAMLKeyValue) element).getValue();
        if (yamlValue != null) {
            valueText = ((YAMLKeyValue) element).getValueText();
        } else {
            // workaround for foo: !foobar
            // as we got tag element
            PsiElement key = ((YAMLKeyValue) element).getKey();
            if(key != null) {
                PsiElement nextSiblingOfType = PsiElementUtils.getNextSiblingOfType(key, PlatformPatterns.psiElement(YAMLTokenTypes.TAG));
                if(nextSiblingOfType != null) {
                    String text = nextSiblingOfType.getText();
                    if(text.startsWith("!")) {
                        valueText = StringUtils.stripStart(text, "!");
                    }
                }
            }
        }

        // Symfony 3.4 / 4.0: namespace overwrite: "@!Foo" => "@Foo"
        valueText = StringUtils.stripStart(valueText, "!");

        // normalize null value
        if(valueText.equals("~")) {
            valueText = "";
        }

        pair.add(Pair.create(valueText, keyText));
    }

    return pair;
}
 
示例27
/**
 * provides auto complete on
 *
 * keyName:
 *   refer|
 *   refer|: xxx
 *   refer|
 *
 * @param keyName key name
 */
public static ElementPattern<PsiElement> getOrmParentLookup(String keyName) {
    return PlatformPatterns.or(
        // match
        //
        // keyName:
        //   refer|: xxx
        PlatformPatterns
            .psiElement(YAMLTokenTypes.SCALAR_KEY)
            .withParent(PlatformPatterns
                .psiElement(YAMLKeyValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLCompoundValue.class)
                    .withParent(PlatformPatterns
                        .psiElement(YAMLKeyValue.class)
                        .withName(
                            PlatformPatterns.string().equalTo(keyName)
                        )
                    )
                )
            )
            .inFile(getOrmFilePattern())
            .withLanguage(YAMLLanguage.INSTANCE),

        // match
        //
        // keyName:
        //   xxx: xxx
        //   refer|
        PlatformPatterns
            .psiElement(YAMLPlainTextImpl.class)
            .withParent(PlatformPatterns
                .psiElement(YAMLCompoundValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLKeyValue.class)
                    .withName(
                        PlatformPatterns.string().equalTo(keyName)
                    )
                )
            )
            .inFile(getOrmFilePattern())
            .withLanguage(YAMLLanguage.INSTANCE),

        // match
        //
        // keyName:
        //   refer|
        //   xxx: xxx
        getKeyPattern(keyName)
            .inFile(getOrmFilePattern())
            .withLanguage(YAMLLanguage.INSTANCE)
    );
}
 
示例28
/**
 * provides auto complete on
 *
 * keyName:
 *   refer|
 *   refer|: xxx
 *   refer|
 *
 * @param keyName key name
 */
public static ElementPattern<PsiElement> getParentKeyName(String keyName) {
    return PlatformPatterns.or(
        // match
        //
        // keyName:
        //   refer|: xxx
        PlatformPatterns
            .psiElement(YAMLTokenTypes.SCALAR_KEY)
            .withParent(PlatformPatterns
                .psiElement(YAMLKeyValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLCompoundValue.class)
                    .withParent(PlatformPatterns
                        .psiElement(YAMLKeyValue.class)
                        .withName(
                            PlatformPatterns.string().equalTo(keyName)
                        )
                    )
                )
            )
            .withLanguage(YAMLLanguage.INSTANCE),

        // match
        //
        // keyName:
        //   xxx: xxx
        //   refer|
        PlatformPatterns
            .psiElement(YAMLPlainTextImpl.class)
            .withParent(PlatformPatterns
                .psiElement(YAMLCompoundValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLKeyValue.class)
                    .withName(
                        PlatformPatterns.string().equalTo(keyName)
                    )
                )
            )
            .withLanguage(YAMLLanguage.INSTANCE),

        // match
        //
        // keyName:
        //   refer|
        //   xxx: xxx
        getKeyPattern(keyName)
            .withLanguage(YAMLLanguage.INSTANCE)
    );
}
 
示例29
public static ElementPattern<PsiElement> getWithFirstRootKey() {
    return PlatformPatterns.or(
        // foo:
        //   <caret>
        PlatformPatterns
            .psiElement().with(new ParentPathPatternCondition(
                YAMLScalar.class, YAMLMapping.class,
                YAMLKeyValue.class, YAMLMapping.class,
                YAMLDocument.class
            ))
            .withLanguage(YAMLLanguage.INSTANCE),

        // foo:
        //   <caret> (on incomplete)
        PlatformPatterns
            .psiElement().afterLeaf(
                PlatformPatterns.psiElement(YAMLTokenTypes.INDENT).with(
                    new ParentPathPatternCondition(YAMLKeyValue.class, YAMLMapping.class, YAMLDocument.class)
                )
            )
            .withLanguage(YAMLLanguage.INSTANCE),

        // match
        //
        // foo:
        //   <caret>: bar
        //   <caret>:
        //   <caret>a:
        PlatformPatterns
            .psiElement().with(new ParentPathPatternCondition(
                YAMLScalar.class, YAMLKeyValue.class,
                YAMLMapping.class, YAMLKeyValue.class,
                YAMLMapping.class, YAMLDocument.class)
            )
            .withLanguage(YAMLLanguage.INSTANCE),

        // foo:
        //   fo<caret>:
        PlatformPatterns.psiElement().with(new ParentPathPatternCondition(
            YAMLKeyValue.class, YAMLMapping.class,
            YAMLKeyValue.class, YAMLMapping.class,
            YAMLDocument.class)
        )
    );
}
 
示例30
/**
 * provides auto complete on
 *
 * tree:
 *   xxx:
 *     refer|
 *     refer|: xxx
 *     refer|
 */
public static ElementPattern<PsiElement> getFilterOnPrevParent(String... tree) {
    return PlatformPatterns.or(

        // match
        //
        // tree:
        //   xxx:
        //     refer|: xxx
        PlatformPatterns
        .psiElement(YAMLTokenTypes.SCALAR_KEY)
        .withParent(PlatformPatterns
            .psiElement(YAMLKeyValue.class)
            .withParent(PlatformPatterns
                .psiElement(YAMLCompoundValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLKeyValue.class)
                    .withParent(PlatformPatterns
                        .psiElement(YAMLCompoundValue.class)
                        .withParent(PlatformPatterns
                            .psiElement(YAMLKeyValue.class)
                            .withName(PlatformPatterns
                                .string().oneOfIgnoreCase(tree)
                            )
                        )
                    )
                )
            )
        )
        .inFile(getOrmFilePattern())
        .withLanguage(YAMLLanguage.INSTANCE),

        // match
        //
        // tree:
        //   xxx:
        //     xxx: xxx
        //     refer|
        PlatformPatterns
            .psiElement(YAMLPlainTextImpl.class)
            .withParent(PlatformPatterns
                .psiElement(YAMLCompoundValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLKeyValue.class)
                    .withParent(PlatformPatterns
                        .psiElement(YAMLCompoundValue.class)
                        .withParent(PlatformPatterns
                            .psiElement(YAMLKeyValue.class)
                            .withName(PlatformPatterns
                                .string().oneOfIgnoreCase(tree)
                            )
                        )
                    )
                )
            )
            .inFile(getOrmFilePattern())
            .withLanguage(YAMLLanguage.INSTANCE),

        // match
        //
        // tree:
        //   xxx:
        //     refer|
        //     xxx: xxx
        PlatformPatterns
            .psiElement(YAMLPlainTextImpl.class)
            .withParent(PlatformPatterns
                .psiElement(YAMLKeyValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLCompoundValue.class)
                    .withParent(PlatformPatterns
                        .psiElement(YAMLKeyValue.class)
                        .withName(PlatformPatterns
                            .string().oneOfIgnoreCase(tree)
                        )
                    )
                )
            )
            .inFile(getOrmFilePattern())
            .withLanguage(YAMLLanguage.INSTANCE)
    );
}