createByPattern¶
Creates a PSI element from a textual pattern with $0, $1, … placeholders replaced by the corresponding args.
The pattern is a piece of Kotlin source with numbered placeholders. String and Name arguments are inserted as text before factory parses the pattern. PSI arguments are represented by parseable placeholder text and then structurally replace the corresponding nodes in the parsed result instead of being rendered as text.
Supported argument types are KtExpression, KtTypeReference, String, Name, and PsiChildRange.
For example, psiFactory.createExpressionByPattern("$0 + $1", left, right) creates an addition expression whose operands have the PSI structure of left and right.
Prefer the specialized entry points (KtPsiFactory.createExpressionByPattern and friends) when creating a known kind of element.
Parameters¶
-
reformat: whether to reformat the created element according to the code style
-
factory: parses the pattern with textual arguments and PSI placeholder text inserted
Throws¶
IllegalArgumentException-
if the pattern is malformed, an argument is unsupported, the argument and placeholder counts differ, or a parsed placeholder cannot be matched to the expected PSI element type