Java Code Examples for com.intellij.patterns.PsiElementPattern#Capture
The following examples show how to use
com.intellij.patterns.PsiElementPattern#Capture .
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: ToolboxJsonCompletionContributor.java From idea-php-toolbox with MIT License | 6 votes |
/** * foo:[{"key": "<caret>"}] */ public PsiElementPattern.Capture<PsiElement> getAfterPropertyAndInsideArrayObjectPattern(@NotNull String key) { return PlatformPatterns.psiElement().inFile(getMetadataFilePattern()).withParent( PlatformPatterns.psiElement(JsonStringLiteral.class).with(FirstItemInTreePatternCondition.getInstance()).withParent( PlatformPatterns.psiElement(JsonProperty.class).withParent( PlatformPatterns.psiElement(JsonObject.class).withParent( PlatformPatterns.psiElement(JsonArray.class).withParent( PlatformPatterns.psiElement(JsonProperty.class).withFirstChild( PlatformPatterns.psiElement(JsonStringLiteral.class).withText("\"" + key + "\"") ) ) ) ) ) ); }
Example 2
Source File: YiiContibutorHelper.java From yiistorm with MIT License | 6 votes |
public static PsiElementPattern.Capture<PsiElement> methodParamsList(String methodName, StringPattern className) { return PlatformPatterns.psiElement().withElementType(PhpElementTypes.PARAMETER_LIST) .withParent( PlatformPatterns.psiElement() .withElementType(PhpElementTypes.METHOD_REFERENCE) .referencing( PhpPatterns.psiElement().withElementType( PhpElementTypes.CLASS_METHOD ).withName(methodName) .withParent( PhpPatterns.psiElement().withName( className )) ) ); }
Example 3
Source File: BladePattern.java From idea-php-laravel-plugin with MIT License | 6 votes |
/** * "@foobar(['<caret>'])" * * whereas "foobar" is registered a directive */ public static PsiElementPattern.Capture<PsiElement> getArrayParameterDirectiveForElementType(@NotNull IElementType... elementType) { return PlatformPatterns.psiElement() .withParent( PlatformPatterns.psiElement(StringLiteralExpression.class) .withParent( PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent( PlatformPatterns.psiElement(ArrayCreationExpression.class) .withParent(ParameterList.class) ) ) .with( new MyDirectiveInjectionElementPatternCondition(elementType) ) ) .withLanguage(PhpLanguage.INSTANCE); }
Example 4
Source File: SmartyPattern.java From idea-php-shopware-plugin with MIT License | 5 votes |
public static PsiElementPattern.Capture<PsiElement> getFilePattern() { // getName dont work return PlatformPatterns.psiElement(SmartyTokenTypes.STRING_LITERAL).withParent( PlatformPatterns.psiElement(SmartyCompositeElementTypes.ATTRIBUTE_VALUE).withParent( PlatformPatterns.psiElement(SmartyCompositeElementTypes.ATTRIBUTE).withText(PlatformPatterns.string().contains("file=")) ) ); }
Example 5
Source File: CSharpPatterns.java From consulo-csharp with Apache License 2.0 | 5 votes |
@Nonnull public static PsiElementPattern.Capture<PsiElement> fieldStart() { return StandardPatterns.psiElement().withElementType(CSharpTokens.IDENTIFIER).withSuperParent(3, CSharpFieldDeclaration.class).with(new PatternCondition<PsiElement>("field-type-no-qualifier") { @Override @RequiredReadAction public boolean accepts(@Nonnull PsiElement element, ProcessingContext context) { CSharpFieldDeclaration declaration = PsiTreeUtil.getParentOfType(element, CSharpFieldDeclaration.class); if(declaration == null) { return false; } DotNetType type = declaration.getType(); if(!(type instanceof CSharpUserType)) { return false; } CSharpReferenceExpression referenceExpression = ((CSharpUserType) type).getReferenceExpression(); if(referenceExpression.getQualifier() != null) { return false; } return true; } }); }
Example 6
Source File: YiiContibutorHelper.java From yiistorm with MIT License | 5 votes |
public static PsiElementPattern.Capture<PsiElement> arrayInMethodWithName(String methodName) { return PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_CREATION_EXPRESSION) .withParent( PlatformPatterns.psiElement().withElementType(PhpElementTypes.METHOD_REFERENCE) .referencing(PhpPatterns.psiElement().withElementType(PhpElementTypes.CLASS_METHOD) .withName(methodName) ) ); }
Example 7
Source File: YamlReferenceContributor.java From intellij-swagger with MIT License | 5 votes |
private PsiElementPattern.Capture<YAMLQuotedText> localDefinitionsPattern() { return psiElement(YAMLQuotedText.class) .andOr( psiElement() .withParent(psiElement(YAMLKeyValue.class).withName(SwaggerConstants.REF_KEY)), psiElement().withSuperParent(3, psiElement(YAMLKeyValue.class).withName("mapping"))) .withText(StandardPatterns.string().contains(SwaggerConstants.REFERENCE_PREFIX)) .withoutText(FILE_NAME_PATTERN) .withoutText(URL_PATTERN) .withLanguage(YAMLLanguage.INSTANCE); }
Example 8
Source File: MissingModulePHPInspection.java From idea-php-typo3-plugin with MIT License | 5 votes |
@NotNull private PsiElementPattern.Capture<PsiElement> getLoadRequireJsModulePattern() { return PlatformPatterns.psiElement().withSuperParent( 2, PlatformPatterns.psiElement(MethodReference.class) ); }
Example 9
Source File: HaxeSmartCompletionContributor.java From intellij-haxe with Apache License 2.0 | 5 votes |
public HaxeSmartCompletionContributor() { final PsiElementPattern.Capture<PsiElement> idInExpression = psiElement().withSuperParent(1, HaxeIdentifier.class).withSuperParent(2, HaxeReference.class); extend(CompletionType.SMART, idInExpression.and(psiElement().withSuperParent(3, HaxeVarInit.class)), new CompletionProvider<CompletionParameters>() { @Override protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { tryAddVariantsForEnums(result, parameters.getPosition()); } }); }
Example 10
Source File: YiiReferenceContributor.java From yiistorm with MIT License | 5 votes |
/** * Check element is param is parameterList in method reference * * @param name * @return */ private PsiElementPattern.Capture<PsiElement> isParamListInMethodWithName(String name) { return PlatformPatterns.psiElement(PhpElementTypes.PARAMETER_LIST) .withParent( PlatformPatterns.psiElement(PhpElementTypes.METHOD_REFERENCE) .withText(StandardPatterns.string().matches(name)) ); }
Example 11
Source File: I18nReferenceContributor.java From yiistorm with MIT License | 5 votes |
public PsiElementPattern.Capture categoryPattern() { return PlatformPatterns.psiElement(PsiElement.class) .withElementType(PhpElementTypes.STRING) .withParent(YiiContibutorHelper.methodParamsList("t", StandardPatterns.string().oneOf("Yii", "YiiBase"))) .insideStarting( PlatformPatterns.psiElement().withElementType(PhpElementTypes.PARAMETER_LIST) ) .withLanguage(PhpLanguage.INSTANCE); }
Example 12
Source File: JsonReferenceContributor.java From intellij-swagger with MIT License | 5 votes |
private PsiElementPattern.Capture<JsonLiteral> localDefinitionsPattern() { return psiElement(JsonLiteral.class) .andOr( psiElement() .withParent(psiElement(JsonProperty.class).withName(SwaggerConstants.REF_KEY)), psiElement().withSuperParent(3, psiElement(JsonProperty.class).withName("mapping"))) .withText(StandardPatterns.string().contains(SwaggerConstants.REFERENCE_PREFIX)) .withoutText(FILE_NAME_PATTERN) .withoutText(URL_PATTERN) .withLanguage(JsonLanguage.INSTANCE); }
Example 13
Source File: ToolboxJsonCompletionContributor.java From idea-php-toolbox with MIT License | 5 votes |
/** * foo:[{"key": "<caret>"}] */ public PsiElementPattern.Capture<PsiElement> getPropertyAfterRootPattern() { return PlatformPatterns.psiElement().inFile(getMetadataFilePattern()).withParent( PlatformPatterns.psiElement(JsonStringLiteral.class).withParent( PlatformPatterns.psiElement(JsonProperty.class).withParent( PlatformPatterns.psiElement(JsonObject.class).withParent( PlatformPatterns.psiElement(JsonFile.class) ) ) ) ); }
Example 14
Source File: ToolboxJsonCompletionContributor.java From idea-php-toolbox with MIT License | 5 votes |
/** * "key": "<caret>" */ public PsiElementPattern.Capture<PsiElement> getNextToPropertyPattern(@NotNull String key) { return PlatformPatterns.psiElement().inFile(getMetadataFilePattern()).withParent( PlatformPatterns.psiElement(JsonStringLiteral.class).withParent( PlatformPatterns.psiElement(JsonProperty.class).withFirstChild( PlatformPatterns.psiElement(JsonStringLiteral.class).withText("\"" + key + "\"") ) ) ); }
Example 15
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * 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) ); }
Example 16
Source File: TranslationTagGotoCompletionRegistrar.java From idea-php-symfony2-plugin with MIT License | 4 votes |
@NotNull private PsiElementPattern.Capture<XmlToken> getTranslationTagValuePattern() { return PlatformPatterns.psiElement(XmlToken.class) .inVirtualFile(new VirtualFilePattern().withExtension("twig")) .withLanguage(XMLLanguage.INSTANCE); }
Example 17
Source File: TCAPatterns.java From idea-php-typo3-plugin with MIT License | 4 votes |
@Contract(pure = true) public static PsiElementPattern.Capture<PsiElement> isWizard() { return PlatformPatterns.psiElement() .withSuperParent(5, arrayKeyWithString("wizards", PhpElementTypes.ARRAY_KEY)); }
Example 18
Source File: TCAPatterns.java From idea-php-typo3-plugin with MIT License | 4 votes |
private static PsiElementPattern.Capture<ArrayHashElement> arrayKeyWithString(@NotNull String arrayKey, IElementType arrayKey2) { return PlatformPatterns.psiElement(ArrayHashElement.class).withChild( elementWithStringLiteral(arrayKey2, arrayKey) ); }
Example 19
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 4 votes |
/** * {{ 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: TranslationIndex.java From idea-php-typo3-plugin with MIT License | 4 votes |
@NotNull abstract PsiElementPattern.Capture<PsiElement> getElementPattern();