Java Code Examples for com.intellij.patterns.PlatformPatterns#or()

The following examples show how to use com.intellij.patterns.PlatformPatterns#or() . 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: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * {% include foo ? '' : '' %}
 * {% extends foo ? '' : '' %}
 */
public static ElementPattern<PsiElement> getTagTernaryPattern(@NotNull IElementType type) {
    //noinspection unchecked
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT)
            .withParent(
                PlatformPatterns.psiElement(type)
            )
            .afterLeafSkipping(
                STRING_WRAP_PATTERN,
                PlatformPatterns.psiElement(TwigTokenTypes.QUESTION)
            )
            .withLanguage(TwigLanguage.INSTANCE),
        PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT)
            .withParent(
                PlatformPatterns.psiElement(type)
            )
            .afterLeafSkipping(
                STRING_WRAP_PATTERN,
                PlatformPatterns.psiElement(TwigTokenTypes.COLON)
            )
            .withLanguage(TwigLanguage.INSTANCE)
    );
}
 
Example 2
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * {% trans with {'%name%': 'Fabien'} from "app" %}
 * {% transchoice count with {'%name%': 'Fabien'} from "app" %}
 */
public static ElementPattern<PsiElement> getTranslationTokenTagFromPattern() {
    //noinspection unchecked

    // we need to use withText check, because twig tags dont have childrenAllowToVisit to search for tag name
    return PlatformPatterns.or(
        PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER)
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.TAG).withText(
                    PlatformPatterns.string().matches("\\{%\\s+(trans|transchoice).*")
                )
            )
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText("from")
            ).withLanguage(TwigLanguage.INSTANCE),
        PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT)
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.TAG).withText(
                    PlatformPatterns.string().matches("\\{%\\s+(trans|transchoice).*")
                )
            )
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText("from")
            ).withLanguage(TwigLanguage.INSTANCE)
    );
}
 
Example 3
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * use getStringAfterTagNamePattern @TODO
 *
 * {% trans_default_domain '<carpet>' %}
 * {% trans_default_domain <carpet> %}
 */
public static ElementPattern<PsiElement> getTransDefaultDomainPattern() {
    //noinspection unchecked
    return PlatformPatterns.or(
        PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER)
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.TAG)
            )
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText("trans_default_domain")
            ).withLanguage(TwigLanguage.INSTANCE),
        PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT)
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.TAG)
            )
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText("trans_default_domain")
            ).withLanguage(TwigLanguage.INSTANCE)
    );
}
 
Example 4
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * {% from _self import foo %}
 * {% from 'template_name' import foo %}
 */
public static ElementPattern<PsiElement> getFromTemplateElementPattern() {
    return PlatformPatterns.or(
        PlatformPatterns
            .psiElement(TwigTokenTypes.STRING_TEXT)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText(PlatformPatterns.string().oneOf("from"))
            )
            .withLanguage(TwigLanguage.INSTANCE),
        PlatformPatterns
            .psiElement(TwigTokenTypes.RESERVED_ID)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText(PlatformPatterns.string().oneOf("from"))
            )
            .withLanguage(TwigLanguage.INSTANCE)
    );

}
 
Example 5
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * Pattern @Foo(Foo::<caret>), @Foo(name=Foo::<caret>)
 */
@NotNull
public static ElementPattern<PsiElement> getDocStaticPattern() {
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_STATIC),
        PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT).withText("::") // array lexer workaround having text element in array; WI-32801
    );
}
 
Example 6
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * {% if foo <carpet> %}
 * {% if foo.bar <carpet> %}
 * {% if "foo.bar" <carpet> %}
 * {% if 'foo.bar' <carpet> %}
 */
public static ElementPattern<PsiElement> getAfterOperatorPattern() {
    // @TODO: make it some nicer. can wrap it with whitespace

    //noinspection unchecked
    ElementPattern<PsiElement> or = PlatformPatterns.or(
        PlatformPatterns.psiElement(PsiWhiteSpace.class),
        PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
        PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER),
        PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
        PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT),
        PlatformPatterns.psiElement(TwigTokenTypes.DOT),
        PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE),
        PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
        PlatformPatterns.psiElement(TwigTokenTypes.RBRACE),
        PlatformPatterns.psiElement(TwigTokenTypes.LBRACE_SQ),
        PlatformPatterns.psiElement(TwigTokenTypes.RBRACE_SQ),
        PlatformPatterns.psiElement(TwigTokenTypes.NUMBER),
        PlatformPatterns.psiElement(TwigTokenTypes.FILTER)
    );

    //noinspection unchecked
    ElementPattern<PsiElement> anIf = PlatformPatterns.or(
        PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText("if"),
        PlatformPatterns.psiElement(TwigTokenTypes.AND),
        PlatformPatterns.psiElement(TwigTokenTypes.OR)
    );

    return PlatformPatterns
        .psiElement(TwigTokenTypes.IDENTIFIER)
        .afterLeaf(PlatformPatterns.not(
            PlatformPatterns.psiElement(TwigTokenTypes.DOT)
        ))
        .withParent(
            PlatformPatterns.psiElement(TwigElementTypes.IF_TAG)
        )
        .afterLeafSkipping(or, anIf)
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example 7
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * Extract text {% if foo is "foo foo" %}
 */
public static ElementPattern<PsiElement> getAfterIsTokenTextPattern() {
    //noinspection unchecked
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(TwigTokenTypes.IS),
        PlatformPatterns.psiElement(TwigTokenTypes.NOT)
    );
}
 
Example 8
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * {{ foo({'foo<caret>bar': 'foo'}}) }}
 * {{ foo({'foobar': 'foo', 'foo<caret>bar': 'foo'}}) }}
 */
public static ElementPattern<PsiElement> getFunctionWithFirstParameterAsKeyLiteralPattern(@NotNull String... functionName) {
    return PlatformPatterns.or(
        PlatformPatterns
            // ",'foo'", {'foo'"
            .psiElement(TwigTokenTypes.STRING_TEXT).afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.LBRACE_CURL).withParent(
                PlatformPatterns.psiElement(TwigElementTypes.LITERAL).afterLeafSkipping(
                    PlatformPatterns.or(
                        PlatformPatterns.psiElement(TwigTokenTypes.LBRACE),
                        PlatformPatterns.psiElement(PsiWhiteSpace.class),
                        PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
                    ),
                    PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText(PlatformPatterns.string().oneOf(functionName))
                )
            )
        ).withLanguage(TwigLanguage.INSTANCE),
        PlatformPatterns
            // ",'foo'", {'foo'"
            .psiElement(TwigTokenTypes.STRING_TEXT).afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.COMMA).afterLeafSkipping(
                PlatformPatterns.psiElement().with(new MyBeforeColonAndInsideLiteralPatternCondition()),
                PlatformPatterns.psiElement(TwigTokenTypes.COLON)
            )
        )
    );
}
 
Example 9
Source File: RouteLineMarkerProvider.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
private ElementPattern<PsiElement> getPositionPattern() {

    return PlatformPatterns.or(
        PlatformPatterns.psiElement(PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE).withParent(StringLiteralExpression.class),
        PlatformPatterns.psiElement(PhpTokenTypes.STRING_LITERAL).withParent(StringLiteralExpression.class)
    );
}
 
Example 10
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public static ElementPattern<PsiElement> getDocBlockTag() {
    return
        PlatformPatterns.or(
            PlatformPatterns.psiElement()
                .withSuperParent(1, PhpDocPsiElement.class)
                     .withParent(PhpDocComment.class)
            .withLanguage(PhpLanguage.INSTANCE)
        ,
            // all "@<caret>"
            PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TAG_NAME)
                .withLanguage(PhpLanguage.INSTANCE)
        );
}
 
Example 11
Source File: SmartyPattern.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
/**
 * {tag attribute="<caret>"}
 * {tag attribute=<caret>}
 */
public static ElementPattern<PsiElement> getTagAttributePattern(@NotNull String tag, @NotNull String attribute) {
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(SmartyTokenTypes.IDENTIFIER)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(SmartyTokenTypes.EQ),
                    PlatformPatterns.psiElement(SmartyTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(SmartyTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(SmartyTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(SmartyTokenTypes.IDENTIFIER).withText(attribute)
            )
            .withParent(
                PlatformPatterns.psiElement(SmartyCompositeElementTypes.TAG).withText(PlatformPatterns.string().startsWith("{" + tag))
            ),

        PlatformPatterns.psiElement(SmartyTokenTypes.STRING_LITERAL)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(SmartyTokenTypes.EQ),
                    PlatformPatterns.psiElement(SmartyTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(SmartyTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(SmartyTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(SmartyTokenTypes.IDENTIFIER).withText(attribute)
            )
            .withParent(
                PlatformPatterns.psiElement(SmartyCompositeElementTypes.TAG).withText(PlatformPatterns.string().startsWith("{" + tag))
            )
    );
}
 
Example 12
Source File: GraphQLCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
private void completeImpementsKeyword() {
    CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
            final PsiElement completionElement = parameters.getPosition();
            final GraphQLTypeSystemDefinition typeDefinition = PsiTreeUtil.getParentOfType(completionElement, GraphQLObjectTypeDefinition.class, GraphQLObjectTypeExtensionDefinition.class, GraphQLInterfaceTypeDefinition.class, GraphQLInterfaceTypeExtensionDefinition.class);
            if (typeDefinition instanceof GraphQLObjectTypeDefinition && ((GraphQLObjectTypeDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            if (typeDefinition instanceof GraphQLObjectTypeExtensionDefinition && ((GraphQLObjectTypeExtensionDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            if (typeDefinition instanceof GraphQLInterfaceTypeDefinition && ((GraphQLInterfaceTypeDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            if (typeDefinition instanceof GraphQLInterfaceTypeExtensionDefinition && ((GraphQLInterfaceTypeExtensionDefinition) typeDefinition).getImplementsInterfaces() != null) {
                return;
            }
            result.addElement(LookupElementBuilder.create("implements").withBoldness(true).withInsertHandler(AddSpaceInsertHandler.INSTANCE_WITH_AUTO_POPUP));
        }
    };
    final ElementPattern<PsiElement> insideTypeDefElement = PlatformPatterns.or(
            psiElement().inside(GraphQLObjectTypeDefinition.class),
            psiElement().inside(GraphQLObjectTypeExtensionDefinition.class),
            psiElement().inside(GraphQLInterfaceTypeDefinition.class),
            psiElement().inside(GraphQLInterfaceTypeExtensionDefinition.class)
    );
    extend(CompletionType.BASIC, psiElement(GraphQLElementTypes.NAME).afterLeaf(psiElement(GraphQLElementTypes.NAME).inside(insideTypeDefElement)), provider);
}
 
Example 13
Source File: PhpElementsUtil.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * return 'value' inside class method
 */
static public ElementPattern<PhpExpression> getMethodReturnPattern() {
    return PlatformPatterns.or(
            PlatformPatterns.psiElement(StringLiteralExpression.class)
                    .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
                    .withLanguage(PhpLanguage.INSTANCE),
            PlatformPatterns.psiElement(ClassConstantReference.class)
                    .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
                    .withLanguage(PhpLanguage.INSTANCE)
    );
}
 
Example 14
Source File: FluidPatterns.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static ElementPattern<? extends PsiElement> inlineArgumentNamePattern() {

        return PlatformPatterns.or(
            /*
             * "{ f:foo(<caret>) }"
             * "{ f:foo(u<caret>) }"
             */
            PlatformPatterns
                .psiElement(FluidTypes.IDENTIFIER)
                .withParent(
                    PlatformPatterns.psiElement(FluidFieldExpr.class).afterSibling(
                        PlatformPatterns.psiElement(FluidViewHelperExpr.class)
                    )
                ),
            /* 2018.1 fallback */
            PlatformPatterns
                .psiElement(FluidTypes.IDENTIFIER)
                .withParent(
                    PlatformPatterns.psiElement(FluidInlineChain.class).withFirstChild(
                        PlatformPatterns.psiElement(FluidViewHelperExpr.class)
                    )
                ),
            /*
             * "{ f:foo(u<caret>:) }"
             */
            PlatformPatterns
                .psiElement(FluidTypes.IDENTIFIER)
                .withParent(
                    PlatformPatterns.psiElement(FluidArgumentKey.class)
                )
        );
    }
 
Example 15
Source File: PhpElementsUtil.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * return 'value' inside class method
 */
static public ElementPattern<PhpExpression> getMethodReturnPattern() {
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(StringLiteralExpression.class)
            .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
            .withLanguage(PhpLanguage.INSTANCE),
        PlatformPatterns.psiElement(ClassConstantReference.class)
            .withParent(PlatformPatterns.psiElement(PhpReturn.class).inside(Method.class))
            .withLanguage(PhpLanguage.INSTANCE)
    );
}
 
Example 16
Source File: FluidPatterns.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static ElementPattern<PsiElement> getAccessorPattern() {

        return PlatformPatterns
            .or(
                getAccessorAfterDotPattern(),
                getAccessorInIdentifierPattern()
            );
    }
 
Example 17
Source File: TCAPatterns.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
public static ElementPattern<PsiElement> elementWithStringLiteral(IElementType elementType, @NotNull String value) {

    return PlatformPatterns.or(
            PlatformPatterns.psiElement(elementType).withText("\"" + value + "\""),
            PlatformPatterns.psiElement(elementType).withText("'" + value + "'")
    );
}
 
Example 18
Source File: GraphQLCompletionContributor.java    From js-graphql-intellij-plugin with MIT License 4 votes vote down vote up
private void completeTypeNameToExtend() {
    CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
        @Override
        protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
            final PsiElement completionElement = parameters.getPosition();
            final GraphQLTypeExtension typeExtension = PsiTreeUtil.getParentOfType(completionElement, GraphQLTypeExtension.class);
            final TypeDefinitionRegistry typeDefinitionRegistry = GraphQLTypeDefinitionRegistryServiceImpl.getService(completionElement.getProject()).getRegistry(parameters.getOriginalFile());
            if (typeExtension != null && typeDefinitionRegistry != null) {
                final List<TypeDefinition<?>> types = Lists.newArrayList();
                if (typeExtension instanceof GraphQLScalarTypeExtensionDefinition) {
                    // scalars aren't fully fledged types in the registry
                    types.addAll(typeDefinitionRegistry.scalars().values());
                } else {
                    // "real" types
                    Class<? extends TypeDefinition<?>> applicableTypes = null;
                    if (typeExtension instanceof GraphQLObjectTypeExtensionDefinition) {
                        applicableTypes = ObjectTypeDefinition.class;
                    } else if (typeExtension instanceof GraphQLInterfaceTypeExtensionDefinition) {
                        applicableTypes = InterfaceTypeDefinition.class;
                    } else if (typeExtension instanceof GraphQLUnionTypeExtensionDefinition) {
                        applicableTypes = UnionTypeDefinition.class;
                    } else if (typeExtension instanceof GraphQLEnumTypeExtensionDefinition) {
                        applicableTypes = EnumTypeDefinition.class;
                    } else if (typeExtension instanceof GraphQLInputObjectTypeExtensionDefinition) {
                        applicableTypes = InputObjectTypeDefinition.class;
                    }
                    if (applicableTypes != null) {
                        types.addAll(typeDefinitionRegistry.getTypes(applicableTypes));
                    }
                }
                types.forEach(type -> {
                    LookupElementBuilder element = LookupElementBuilder.create(type.getName()).withInsertHandler(AddSpaceInsertHandler.INSTANCE);
                    result.addElement(element);
                });
            }
        }
    };
    final ElementPattern<PsiElement> extendKeywords = PlatformPatterns.or(
            psiElement(GraphQLElementTypes.TYPE_KEYWORD),
            psiElement(GraphQLElementTypes.INTERFACE_KEYWORD),
            psiElement(GraphQLElementTypes.SCALAR_KEYWORD),
            psiElement(GraphQLElementTypes.UNION_KEYWORD),
            psiElement(GraphQLElementTypes.ENUM_KEYWORD),
            psiElement(GraphQLElementTypes.INPUT_KEYWORD)
    );
    extend(CompletionType.BASIC, psiElement(GraphQLElementTypes.NAME).inside(GraphQLTypeExtension.class).afterLeaf(extendKeywords), provider);
}
 
Example 19
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * {{ foo(12, {'foo<caret>bar': 'foo'}}) }}
 * {{ foo(12, {'foobar': 'foo', 'foo<caret>bar': 'foo'}}) }}
 */
public static ElementPattern<PsiElement> getFunctionWithSecondParameterAsKeyLiteralPattern(@NotNull String... functionName) {
    //noinspection unchecked
    PsiElementPattern.Capture<PsiElement> parameterPattern = PlatformPatterns.psiElement(TwigElementTypes.LITERAL).afterLeafSkipping(
        PlatformPatterns.or(
            PlatformPatterns.psiElement(PsiWhiteSpace.class),
            PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
        ),
        PlatformPatterns.psiElement(TwigTokenTypes.COMMA).afterLeafSkipping(
            PlatformPatterns.or(PARAMETER_WHITE_LIST),
            PlatformPatterns.psiElement(TwigTokenTypes.LBRACE).afterLeafSkipping(PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                PlatformPatterns.psiElement(TwigTokenTypes.NUMBER)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText(PlatformPatterns.string().oneOf(functionName))
            )
        )
    );

    return
        PlatformPatterns.or(
            // {{ foo({'foobar': 'foo', 'foo<caret>bar': 'foo'}}) }}
            PlatformPatterns
                .psiElement(TwigTokenTypes.STRING_TEXT).afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.COMMA).withParent(parameterPattern)
            ).withLanguage(TwigLanguage.INSTANCE),
            // {{ foo(12, {'foo<caret>bar': 'foo'}}) }}
            PlatformPatterns
                .psiElement(TwigTokenTypes.STRING_TEXT).afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                    PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.LBRACE_CURL).withParent(parameterPattern)
            )
                .withLanguage(TwigLanguage.INSTANCE)
        );
}
 
Example 20
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * Array values are not detected by lexer, lets do the magic on our own
 *
 * {{ foo(['foobar', 'foo<caret>bar']) }}
 * {{ foo(['fo<caret>obar']) }}
 */
public static ElementPattern<PsiElement> getFunctionWithFirstParameterAsArrayPattern(@NotNull String... functionName) {
    //noinspection unchecked

    // "foo(<caret>"
    PsiElementPattern.Capture<PsiElement> functionPattern = PlatformPatterns
        .psiElement(TwigTokenTypes.LBRACE_SQ)
        .afterLeafSkipping(
            PlatformPatterns.psiElement(PsiWhiteSpace.class),
            PlatformPatterns.psiElement(TwigTokenTypes.LBRACE).afterLeafSkipping(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText(PlatformPatterns.string().oneOf(functionName))
            )
        );

    return
        PlatformPatterns.or(
            // {{ foo(['fo<caret>obar']) }}
            PlatformPatterns
                .psiElement(TwigTokenTypes.STRING_TEXT).afterLeafSkipping(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement().withElementType(PlatformPatterns.elementType().or(
                    TwigTokenTypes.SINGLE_QUOTE,
                    TwigTokenTypes.DOUBLE_QUOTE
                )).afterLeafSkipping(
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                    functionPattern
                )
            ).withLanguage(TwigLanguage.INSTANCE),

            // {{ foo(['foobar', 'foo<caret>bar']) }}
            PlatformPatterns
                .psiElement(TwigTokenTypes.STRING_TEXT).afterLeafSkipping(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement().withElementType(PlatformPatterns.elementType().or(
                    TwigTokenTypes.SINGLE_QUOTE,
                    TwigTokenTypes.DOUBLE_QUOTE
                )).afterLeafSkipping(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.COMMA).afterLeafSkipping(
                        PlatformPatterns.or(
                            PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
                            PlatformPatterns.psiElement(PsiWhiteSpace.class),
                            PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT),
                            PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                            PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE),
                            PlatformPatterns.psiElement(TwigTokenTypes.COMMA)
                        ),
                        functionPattern
                    )
                )
            ).withLanguage(TwigLanguage.INSTANCE)
        );
}