|
9 | 9 | import com.jetbrains.php.lang.documentation.phpdoc.lexer.PhpDocTokenTypes;
|
10 | 10 | import com.jetbrains.php.lang.documentation.phpdoc.parser.PhpDocElementTypes;
|
11 | 11 | import com.jetbrains.php.lang.documentation.phpdoc.psi.tags.PhpDocTag;
|
| 12 | +import com.jetbrains.php.lang.parser.PhpElementTypes; |
| 13 | +import com.jetbrains.php.lang.patterns.PhpPatterns; |
12 | 14 | import com.jetbrains.php.lang.psi.elements.*;
|
13 | 15 | import com.jetbrains.php.lang.psi.elements.impl.ParameterListImpl;
|
14 | 16 | import de.espend.idea.php.annotation.util.AnnotationUtil;
|
@@ -76,6 +78,34 @@ public static ElementPattern<? extends PsiElement> getConstructorCallArgumentPat
|
76 | 78 | );
|
77 | 79 | }
|
78 | 80 |
|
| 81 | + public static ElementPattern<? extends PsiElement> getConstructorCallWithArrayArgumentPattern( |
| 82 | + @NotNull String classFQN, |
| 83 | + @NotNull String argumentName, |
| 84 | + int argumentIndex, |
| 85 | + @NotNull String keyName |
| 86 | + ) { |
| 87 | + return PlatformPatterns.psiElement() |
| 88 | + .withParent(PlatformPatterns |
| 89 | + .psiElement(PhpPsiElement.class) |
| 90 | + .withElementType(PhpElementTypes.ARRAY_VALUE) |
| 91 | + .withParent(PlatformPatterns |
| 92 | + .psiElement(ArrayHashElement.class) |
| 93 | + .with(new IsArrayHashElementKey(keyName)) |
| 94 | + .withParent(PlatformPatterns |
| 95 | + .psiElement(ArrayCreationExpression.class) |
| 96 | + .with(new IsArgument(argumentName, argumentIndex)) |
| 97 | + .withParent(PlatformPatterns |
| 98 | + .psiElement(ParameterList.class) |
| 99 | + .withParent( |
| 100 | + PlatformPatterns.psiElement(NewExpression.class) |
| 101 | + .with(new IsConstructorReference(classFQN)) |
| 102 | + ) |
| 103 | + ) |
| 104 | + ) |
| 105 | + ) |
| 106 | + ); |
| 107 | + } |
| 108 | + |
79 | 109 | public static ElementPattern<? extends PsiElement> getFunctionCallArgumentPattern(
|
80 | 110 | @NotNull String functionFQN,
|
81 | 111 | @NotNull String argumentName,
|
@@ -178,6 +208,26 @@ public boolean accepts(@NotNull PhpAttribute phpAttribute, ProcessingContext con
|
178 | 208 | }
|
179 | 209 | }
|
180 | 210 |
|
| 211 | + private static class IsArrayHashElementKey extends PatternCondition<ArrayHashElement> { |
| 212 | + @NotNull |
| 213 | + private final String name; |
| 214 | + |
| 215 | + public IsArrayHashElementKey(@NotNull String name) { |
| 216 | + super(String.format("IsArrayHashElementKey(%s)", name)); |
| 217 | + this.name = name; |
| 218 | + } |
| 219 | + |
| 220 | + @Override |
| 221 | + public boolean accepts(@NotNull ArrayHashElement arrayHashElement, ProcessingContext context) { |
| 222 | + var key = arrayHashElement.getKey(); |
| 223 | + if (key instanceof StringLiteralExpression) { |
| 224 | + return ((StringLiteralExpression) key).getContents().equals(name); |
| 225 | + } |
| 226 | + |
| 227 | + return false; |
| 228 | + } |
| 229 | + } |
| 230 | + |
181 | 231 | private static class IsArgument extends PatternCondition<PsiElement> {
|
182 | 232 | @NotNull
|
183 | 233 | private final String name;
|
|
0 commit comments