org.jetbrains.yaml.YAMLTokenTypes Java Examples

The following examples show how to use org.jetbrains.yaml.YAMLTokenTypes. 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: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * !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:")
                )
            );
}
 
Example #2
Source File: YamlHelper.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: EventMethodCallInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
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);
        }

    }
 
Example #4
Source File: ConfigLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@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);
        }
    }
}
 
Example #5
Source File: TranslationInsertUtil.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * 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";
}
 
Example #6
Source File: YamlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * 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));
        }
    }
}
 
Example #7
Source File: YamlHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #8
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * 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());
}
 
Example #9
Source File: YamlGoToDeclarationHandler.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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;
}
 
Example #10
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * 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)
                )
            )
        );
}
 
Example #11
Source File: SiteConfigurationCompletionContributor.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
private PsiElementPattern.Capture<PsiElement> yamlKeyChildOfInArray() {

    return PlatformPatterns
        .psiElement(YAMLTokenTypes.SCALAR_KEY)
        .withSuperParent(2, YAMLMapping.class)
        .withSuperParent(1, YAMLKeyValue.class)
        .withLanguage(YAMLLanguage.INSTANCE);
}
 
Example #12
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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)
        );
    }
 
Example #13
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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)
    ;
}
 
Example #14
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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)
    );
}
 
Example #15
Source File: YamlHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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)
        ;
}
 
Example #16
Source File: YamlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
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));
                }
            }
        }
    }
}
 
Example #17
Source File: YamlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example #18
Source File: YamlClassInspection.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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);
        }
    };
}
 
Example #19
Source File: DoctrineMetadataPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * 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"
                    ))
                )
            )
        );
}
 
Example #20
Source File: YamlWordScanner.java    From intellij-swagger with MIT License 5 votes vote down vote up
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);
}
 
Example #21
Source File: YamlElementPatternHelper.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
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)
                )
        ));
    }
 
Example #22
Source File: YamlHelper.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example #23
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * 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)
    );
}
 
Example #24
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * simplified getFilterOnPrevParent :)
* 
 * services:
 *   foo.name:
 *     "complete": foo
 */
public static ElementPattern<PsiElement> getSuperParentArrayKey(String... tree) {
    return PlatformPatterns.or(
        // foo:
        //   <caret> (on incomplete)
        PlatformPatterns.psiElement().afterLeaf(
            PlatformPatterns.psiElement(YAMLTokenTypes.INDENT).withParent(
                PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(
                    PlatformPatterns.psiElement(YAMLMapping.class).withParent(
                        PlatformPatterns.psiElement(YAMLKeyValue.class).withName(PlatformPatterns
                            .string().oneOfIgnoreCase(tree)
                        )
                    )
                )
            )
        ),

        /**
         * services:
         *   foo:
         *     cla<caret>:
         */
        PlatformPatterns.psiElement().withParent(
            PlatformPatterns.psiElement(YAMLScalar.class).withParent(
                PlatformPatterns.psiElement(YAMLMapping.class).withParent(
                    PlatformPatterns.psiElement(YAMLKeyValue.class).withParent(
                        PlatformPatterns.psiElement(YAMLMapping.class).withParent(
                            PlatformPatterns.psiElement(YAMLKeyValue.class).withName(PlatformPatterns
                                .string().oneOfIgnoreCase(tree)
                            )
                        )
                    )
                )
            )
        ),

        // match
        //
        // tree:
        //   xxx:
        //     refer|: xxx
        PlatformPatterns
            .psiElement(YAMLTokenTypes.SCALAR_KEY)
            .withParent(PlatformPatterns
                .psiElement(YAMLKeyValue.class)
                .withParent(PlatformPatterns
                    .psiElement(YAMLMapping.class)
                    .withParent(PlatformPatterns
                        .psiElement(YAMLKeyValue.class)
                        .withParent(PlatformPatterns
                            .psiElement(YAMLMapping.class)
                            .withParent(PlatformPatterns
                                .psiElement(YAMLKeyValue.class)
                                .withName(PlatformPatterns
                                    .string().oneOfIgnoreCase(tree)
                                )
                            )
                        )
                    )
                )
            )
            .withLanguage(YAMLLanguage.INSTANCE)
    );
}
 
Example #25
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * 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)
    );
}
 
Example #26
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
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)
        )
    );
}
 
Example #27
Source File: YamlElementPatternHelper.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * 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)
    );
}
 
Example #28
Source File: TwigUtil.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * 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;
}
 
Example #29
Source File: YamlLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * 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));
            }
        }
    }
}
 
Example #30
Source File: RamlParserDefinition.java    From mule-intellij-plugins with Apache License 2.0 4 votes vote down vote up
@NotNull
public TokenSet getStringLiteralElements()
{
    return TokenSet.create(YAMLTokenTypes.SCALAR_STRING, YAMLTokenTypes.SCALAR_DSTRING, YAMLTokenTypes.TEXT);
}