mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-28 01:07:49 +08:00
element_patterns.md: cleanup
This commit is contained in:
parent
1d39c26148
commit
91772ef880
@ -1,6 +1,6 @@
|
||||
[//]: # (title: Element Patterns)
|
||||
# Element Patterns
|
||||
|
||||
<!-- Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
|
||||
<!-- Copyright 2000-2023 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -->
|
||||
|
||||
<link-summary rel="excerpt"/>
|
||||
<p id="excerpt">
|
||||
@ -16,15 +16,15 @@ Their two main applications inside the IntelliJ Platform are:
|
||||
However, plugin authors rarely implement the [`ElementPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/ElementPattern.java) interface directly.
|
||||
Instead, we recommend using the high-level pattern classes provided by the IntelliJ Platform:
|
||||
|
||||
| Class | Main Contents | Notable Examples |
|
||||
|---------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| Class | Main Contents | Notable Examples |
|
||||
|-----------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
||||
| [`StandardPatterns`](%gh-ic%/platform/core-api/src/com/intellij/patterns/StandardPatterns.java) | Factory for string and char pattern (see below); Logical operations like and, or, not | [`LogbackReferenceContributor`](%gh-ic%/plugins/groovy/src/org/jetbrains/plugins/groovy/ext/logback/LogbackReferenceContributor.kt), [`RegExpCompletionContributor`](%gh-ic%/RegExpSupport/src/org/intellij/lang/regexp/RegExpCompletionContributor.java) |
|
||||
| [`PlatformPatterns`](%gh-ic%/platform/core-api/src/com/intellij/patterns/PlatformPatterns.java) | Factory for PSI-, IElement-, and VirtualFile-patterns | [`FxmlReferencesContributor`](%gh-ic%/plugins/javaFX/src/org/jetbrains/plugins/javaFX/fxml/refs/FxmlReferencesContributor.java), [`PyDataclassCompletionContributor`](%gh-ic%/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyDataclassCompletionContributor.kt) |
|
||||
| [`PsiElementPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/PsiElementPattern.java) | Patterns for PSI; Checks for children, parents, or neighboring leaves | [`XmlCompletionContributor`](%gh-ic%/xml/impl/src/com/intellij/codeInsight/completion/XmlCompletionContributor.java) |
|
||||
| [`CollectionPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/CollectionPattern.java) | Filter and check pattern collections; Mainly used to provide functionality for other high-level pattern classes | [`PsiElementPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/PsiElementPattern.java) |
|
||||
| [`TreeElementPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/TreeElementPattern.java) | Patterns specifically for checking (PSI) tree structure | [`PyMetaClassCompletionContributor`](%gh-ic%/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyMetaClassCompletionContributor.java) |
|
||||
| [`StringPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/StringPattern.java) | Check if strings match, have a certain length, have a specific beginning or ending, or are one of a collection of strings | [`AbstractGradleCompletionContributor`](%gh-ic%/plugins/gradle/java/src/codeInsight/AbstractGradleCompletionContributor.kt) |
|
||||
| [`CharPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/CharPattern.java) | Check if characters are whitespace, digits, or Java identifier parts | [`CompletionUtil`](%gh-ic%/platform/analysis-impl/src/com/intellij/codeInsight/completion/CompletionUtil.java) |
|
||||
| [`PsiElementPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/PsiElementPattern.java) | Patterns for PSI; Checks for children, parents, or neighboring leaves | [`XmlCompletionContributor`](%gh-ic%/xml/impl/src/com/intellij/codeInsight/completion/XmlCompletionContributor.java) |
|
||||
| [`CollectionPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/CollectionPattern.java) | Filter and check pattern collections; Mainly used to provide functionality for other high-level pattern classes | [`PsiElementPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/PsiElementPattern.java) |
|
||||
| [`TreeElementPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/TreeElementPattern.java) | Patterns specifically for checking (PSI) tree structure | [`PyMetaClassCompletionContributor`](%gh-ic%/python/python-psi-impl/src/com/jetbrains/python/codeInsight/completion/PyMetaClassCompletionContributor.java) |
|
||||
| [`StringPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/StringPattern.java) | Check if strings match, have a certain length, have a specific beginning or ending, or are one of a collection of strings | [`AbstractGradleCompletionContributor`](%gh-ic%/plugins/gradle/java/src/codeInsight/AbstractGradleCompletionContributor.kt) |
|
||||
| [`CharPattern`](%gh-ic%/platform/core-api/src/com/intellij/patterns/CharPattern.java) | Check if characters are whitespace, digits, or Java identifier parts | [`CompletionUtil`](%gh-ic%/platform/analysis-impl/src/com/intellij/codeInsight/completion/CompletionUtil.java) |
|
||||
|
||||
Some built-in languages in the IntelliJ Platform implement their own pattern classes and can provide additional examples:
|
||||
|
||||
@ -54,7 +54,7 @@ As shown in the code above, element patterns can be stacked and combined to crea
|
||||
PsiElementPattern.Capture<PsiElement> AFTER_COMMA_OR_BRACKET_IN_ARRAY =
|
||||
psiElement().
|
||||
afterLeaf("[", ",").
|
||||
withSuperParent(2,JsonArray.class).
|
||||
withSuperParent(2, JsonArray.class).
|
||||
andNot(
|
||||
psiElement().
|
||||
withParent(JsonStringLiteral.class)
|
||||
|
Loading…
x
Reference in New Issue
Block a user