下面列出了com.intellij.psi.PsiRecursiveElementVisitor#com.jetbrains.php.lang.parser.PhpElementTypes 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Provide array key pattern. we need incomplete array key support, too.
*
* foo(['<caret>'])
* foo(['<caret>' => 'foobar'])
*/
@NotNull
public static PsiElementPattern.Capture<PsiElement> getParameterListArrayValuePattern() {
return PlatformPatterns.psiElement()
.withParent(PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
PlatformPatterns.or(
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE)
.withParent(PlatformPatterns.psiElement(ArrayCreationExpression.class)
.withParent(ParameterList.class)
),
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_KEY)
.withParent(PlatformPatterns.psiElement(ArrayHashElement.class)
.withParent(PlatformPatterns.psiElement(ArrayCreationExpression.class)
.withParent(ParameterList.class)
)
)
))
);
}
@Nullable
static public String getArrayHashValue(ArrayCreationExpression arrayCreationExpression, String keyName) {
ArrayHashElement translationArrayHashElement = PsiElementUtils.getChildrenOfType(arrayCreationExpression, PlatformPatterns.psiElement(ArrayHashElement.class)
.withFirstChild(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withText(
PlatformPatterns.string().oneOf("'" + keyName + "'", "\"" + keyName + "\"")
)
)
);
if (translationArrayHashElement == null) {
return null;
}
if (!(translationArrayHashElement.getValue() instanceof StringLiteralExpression)) {
return null;
}
StringLiteralExpression valueString = (StringLiteralExpression) translationArrayHashElement.getValue();
if (valueString == null) {
return null;
}
return valueString.getContents();
}
/**
* $this->methodName('service_name')
* $this->methodName(SERVICE::NAME)
* $this->methodName($this->name)
*/
static public boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
if(!PlatformPatterns
.psiElement(PhpElementTypes.METHOD_REFERENCE)
.withChild(PlatformPatterns
.psiElement(PhpElementTypes.PARAMETER_LIST)
.withFirstChild(PlatformPatterns.or(
PlatformPatterns.psiElement(PhpElementTypes.STRING),
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
))
).accepts(psiElement)) {
return false;
}
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) psiElement).getName();
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
}
private static Set<String> getDeprecatedClassConstantsFromFile(@NotNull PsiFile file) {
PsiElement[] elements = PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
);
return Arrays.stream(elements)
.map(stringLiteral -> ((StringLiteralExpression) stringLiteral).getContents())
.map(s -> "\\" + s)
.map(s -> s.replace("::", "."))
.collect(Collectors.toSet());
}
private static Set<String> getDeprecatedClassNamesFromFile(@NotNull PsiFile file) {
PsiElement[] elements = PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el));
return Arrays.stream(elements)
.map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents())
.collect(Collectors.toSet());
}
private static Set<String> getDeprecatedConstantNamesFromFile(PsiFile file) {
PsiElement[] elements = PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
);
return Arrays.stream(elements)
.map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents())
.collect(Collectors.toSet());
}
private static Set<String> getDeprecatedGlobalFunctionCallsFromFile(PsiFile file) {
PsiElement[] elements = PsiTreeUtil.collectElements(file, el -> PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY)
.withAncestor(
4,
PlatformPatterns.psiElement(PhpElementTypes.RETURN)
)
)
.accepts(el)
);
return Arrays.stream(elements)
.map(stringLiteral -> "\\" + ((StringLiteralExpression) stringLiteral).getContents())
.collect(Collectors.toSet());
}
public static ElementPattern<PsiElement> hasArrayHashElementPattern(@NotNull String arrayKey, String arrayValue) {
if (arrayValue != null) {
return PlatformPatterns
.and(
PlatformPatterns.psiElement().withChild(
arrayKeyWithString(arrayKey, PhpElementTypes.ARRAY_KEY)
),
PlatformPatterns.psiElement().withChild(
arrayKeyWithString(arrayValue, PhpElementTypes.ARRAY_VALUE)
)
);
}
return PlatformPatterns.psiElement().withChild(
arrayKeyWithString(arrayKey, PhpElementTypes.ARRAY_KEY)
);
}
@NotNull
public static PsiElementPattern.Capture<PsiElement> arrayAssignmentValueWithIndexPattern(@NotNull String targetIndex) {
return PlatformPatterns.psiElement().withParent(
PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
PlatformPatterns.or(
// ['eval' => '<caret>']
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_VALUE).withParent(
PlatformPatterns.psiElement(ArrayHashElement.class).withChild(
elementWithStringLiteral(PhpElementTypes.ARRAY_KEY, targetIndex)
)
),
// $GLOBALS['eval'] = '<caret>';
PlatformPatterns.psiElement(PhpElementTypes.ASSIGNMENT_EXPRESSION).withChild(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_ACCESS_EXPRESSION).withChild(
elementWithStringLiteral(PhpElementTypes.ARRAY_INDEX, targetIndex)
)
)
)
)
);
}
/**
* Is the element is a parameter of $APPLICATION->IncludeComponent() call
*/
private static boolean isValidComponentCall(Object o, String component) {
PsiElement parameters = ((PsiElement) o).getParent(); if (parameters instanceof ParameterList) {
if (component != null) {
PsiElement[] params = ((ParameterList) parameters).getParameters(); if (params.length == 0 || params[0].getNode().getElementType() != PhpElementTypes.STRING || !((StringLiteralExpression) params[0]).getContents().equals(component))
return false;
}
PsiElement psiMethod = parameters.getParent(); if (psiMethod instanceof MethodReference) {
MethodReference method = (MethodReference) psiMethod;
/* CBitrixComponent::includeComponentClass() */
if (method.getClassReference() instanceof ClassReference && method.isStatic())
return "CBitrixComponent".equals(method.getClassReference().getName())
&& "includeComponentClass".equals(method.getName());
/* $APPLICATION->IncludeComponent() */
if (method.getClassReference() instanceof Variable && !method.isStatic())
return "APPLICATION".equals(method.getClassReference().getName())
&& "IncludeComponent".equals(method.getName());
}
}
return false;
}
/**
* $this->methodName('service_name')
* $this->methodName(SERVICE::NAME)
* $this->methodName($this->name)
*/
static public boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
if(!PlatformPatterns
.psiElement(PhpElementTypes.METHOD_REFERENCE)
.withChild(PlatformPatterns
.psiElement(PhpElementTypes.PARAMETER_LIST)
.withFirstChild(PlatformPatterns.or(
PlatformPatterns.psiElement(PhpElementTypes.STRING),
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
))
).accepts(psiElement)) {
return false;
}
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) psiElement).getName();
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
}
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {
PsiElement parent = parameter.getElement().getParent();
if(!(parent instanceof StringLiteralExpression)) {
return false;
}
PsiElement arrayValue = parent.getParent();
if(arrayValue == null || arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
return false;
}
PsiElement arrayCreation = arrayValue.getParent();
if(!(arrayCreation instanceof ArrayCreationExpression)) {
return false;
}
PsiElement phpReturn = arrayCreation.getParent();
if(!(phpReturn instanceof PhpReturn)) {
return false;
}
return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
/**
* [$this, '']
* array($this, '')
*/
@NotNull
@Override
public PsiElementPattern.Capture<PsiElement> getPattern() {
return PlatformPatterns.psiElement().withParent(
PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).afterLeafSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withText(",")
).afterSiblingSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).withFirstNonWhitespaceChild(
PlatformPatterns.psiElement(Variable.class)
).afterLeafSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withText(PlatformPatterns.string().oneOf("[", "("))
)
)
)
);
}
/**
* "@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);
}
/**
* Get array string values mapped with their PsiElements
*
* ["value", "value2"]
*/
@NotNull
static public Map<String, PsiElement> getArrayValuesAsMap(@NotNull ArrayCreationExpression arrayCreationExpression) {
List<PsiElement> arrayValues = PhpPsiUtil.getChildren(arrayCreationExpression, new Condition<PsiElement>() {
@Override
public boolean value(PsiElement psiElement) {
return psiElement.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE;
}
});
Map<String, PsiElement> keys = new HashMap<String, PsiElement>();
for (PsiElement child : arrayValues) {
String stringValue = PhpElementsUtil.getStringValue(child.getFirstChild());
if(stringValue != null && StringUtils.isNotBlank(stringValue)) {
keys.put(stringValue, child);
}
}
return keys;
}
/**
* $this->methodName('service_name')
* $this->methodName(SERVICE::NAME)
* $this->methodName($this->name)
*/
static public boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
if(!PlatformPatterns
.psiElement(PhpElementTypes.METHOD_REFERENCE)
.withChild(PlatformPatterns
.psiElement(PhpElementTypes.PARAMETER_LIST)
.withFirstChild(PlatformPatterns.or(
PlatformPatterns.psiElement(PhpElementTypes.STRING),
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
))
).accepts(psiElement)) {
return false;
}
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) psiElement).getName();
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
}
/**
* foo => 'goo'
* foo => ['goo', ... ]
*/
@Nullable
public static String getMethodNameForEventValue(@NotNull PhpPsiElement value) {
if(value instanceof StringLiteralExpression) {
return ((StringLiteralExpression) value).getContents();
}
if(value instanceof ArrayCreationExpression) {
PhpPsiElement firstPsiChild = value.getFirstPsiChild();
if(firstPsiChild != null && firstPsiChild.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
StringLiteralExpression stringLiteral = ObjectUtils.tryCast(firstPsiChild.getFirstPsiChild(), StringLiteralExpression.class);
if(stringLiteral != null) {
return stringLiteral.getContents();
}
}
return null;
}
return null;
}
private static String getHashKey(@NotNull StringLiteralExpression psiElement) {
PsiElement arrayValue = psiElement.getParent();
if(arrayValue != null && arrayValue.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE) {
PsiElement arrayHash = arrayValue.getParent();
if(arrayHash instanceof ArrayHashElement) {
PhpPsiElement key = ((ArrayHashElement) arrayHash).getKey();
if(key instanceof StringLiteralExpression) {
String contents = ((StringLiteralExpression) key).getContents();
if(StringUtils.isNotBlank(contents)) {
return contents;
}
}
}
}
return null;
}
public static boolean isAfterArrayKey(PsiElement psiElement, String arrayKeyName) {
PsiElement literal = psiElement.getContext();
if(!(literal instanceof StringLiteralExpression)) {
return false;
}
PsiElement arrayValue = literal.getParent();
if(arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
return false;
}
PsiElement arrayHashElement = arrayValue.getParent();
if(!(arrayHashElement instanceof ArrayHashElement)) {
return false;
}
PsiElement arrayKey = ((ArrayHashElement) arrayHashElement).getKey();
String keyString = PhpElementsUtil.getStringValue(arrayKey);
return arrayKeyName.equals(keyString);
}
/**
* $this->methodName('service_name')
* $this->methodName(SERVICE::NAME)
* $this->methodName($this->name)
*/
static public boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
if(!PlatformPatterns
.psiElement(PhpElementTypes.METHOD_REFERENCE)
.withChild(PlatformPatterns
.psiElement(PhpElementTypes.PARAMETER_LIST)
.withFirstChild(PlatformPatterns.or(
PlatformPatterns.psiElement(PhpElementTypes.STRING),
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
))
).accepts(psiElement)) {
return false;
}
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) psiElement).getName();
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
}
@Override
public boolean matches(@NotNull LanguageMatcherParameter parameter) {
PsiElement parent = parameter.getElement().getParent();
if(!(parent instanceof StringLiteralExpression)) {
return false;
}
PsiElement arrayValue = parent.getParent();
if(arrayValue == null || arrayValue.getNode().getElementType() != PhpElementTypes.ARRAY_VALUE) {
return false;
}
PsiElement arrayCreation = arrayValue.getParent();
if(!(arrayCreation instanceof ArrayCreationExpression)) {
return false;
}
PsiElement phpReturn = arrayCreation.getParent();
if(!(phpReturn instanceof PhpReturn)) {
return false;
}
return PhpMatcherUtil.isMachingReturnArray(parameter.getSignatures(), phpReturn);
}
/**
* [$this, '']
* array($this, '')
*/
@NotNull
@Override
public PsiElementPattern.Capture<PsiElement> getPattern() {
return PlatformPatterns.psiElement().withParent(
PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).afterLeafSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withText(",")
).afterSiblingSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE).withFirstNonWhitespaceChild(
PlatformPatterns.psiElement(Variable.class)
).afterLeafSkipping(
PlatformPatterns.psiElement(PsiWhiteSpace.class),
PlatformPatterns.psiElement().withText(PlatformPatterns.string().oneOf("[", "("))
)
)
)
);
}
/**
* A array value inside array and method reference
*
* $menu->addChild([
* 'route' => '<caret>',
* ]);
*/
@Nullable
public static Result match(@NotNull PsiElement psiElement, @NotNull Matcher matcher) {
PsiElement arrayValue = psiElement.getParent();
if(PsiElementAssertUtil.isNotNullAndIsElementType(arrayValue, PhpElementTypes.ARRAY_VALUE)) {
PsiElement arrayHashElement = arrayValue.getParent();
if(arrayHashElement instanceof ArrayHashElement) {
PhpPsiElement arrayKey = ((ArrayHashElement) arrayHashElement).getKey();
if(arrayKey != null && ArrayUtils.contains(matcher.getArrayKeys(), PhpElementsUtil.getStringValue(arrayKey))) {
PsiElement arrayCreationExpression = arrayHashElement.getParent();
if(arrayCreationExpression instanceof ArrayCreationExpression) {
Pair<NewExpressionCall, NewExpression> matchPair = matchesMethodCall((ArrayCreationExpression) arrayCreationExpression, matcher.getNewExpressionCalls());
if(matchPair != null) {
return new Result(matchPair.getFirst(), matchPair.getSecond(), arrayKey);
}
}
}
}
}
return null;
}
/**
* A array value inside array and method reference
*
* $menu->addChild([
* 'route' => '<caret>',
* ]);
*/
@Nullable
public static Result match(@NotNull PsiElement psiElement, @NotNull Matcher matcher) {
PsiElement arrayValue = psiElement.getParent();
if(PsiElementAssertUtil.isNotNullAndIsElementType(arrayValue, PhpElementTypes.ARRAY_VALUE)) {
PsiElement arrayHashElement = arrayValue.getParent();
if(arrayHashElement instanceof ArrayHashElement) {
PhpPsiElement arrayKey = ((ArrayHashElement) arrayHashElement).getKey();
if(arrayKey instanceof StringLiteralExpression && ArrayUtils.contains(matcher.getArrayKeys(), ((StringLiteralExpression) arrayKey).getContents())) {
PsiElement arrayCreationExpression = arrayHashElement.getParent();
if(arrayCreationExpression instanceof ArrayCreationExpression) {
Pair<PhpMethodReferenceCall, MethodReference> matchPair = matchesMethodCall(arrayCreationExpression, matcher.getMethodCalls());
if(matchPair != null) {
return new Result(matchPair.getFirst(), matchPair.getSecond(), (StringLiteralExpression) arrayKey);
}
}
}
}
}
return null;
}
/**
* Get array string values mapped with their PsiElements
*
* ["value", "value2"]
*/
@NotNull
static public Map<String, PsiElement> getArrayValuesAsMap(@NotNull ArrayCreationExpression arrayCreationExpression) {
Collection<PsiElement> arrayValues = PhpPsiUtil.getChildren(arrayCreationExpression, psiElement ->
psiElement.getNode().getElementType() == PhpElementTypes.ARRAY_VALUE
);
Map<String, PsiElement> keys = new HashMap<>();
for (PsiElement child : arrayValues) {
String stringValue = PhpElementsUtil.getStringValue(child.getFirstChild());
if(StringUtils.isNotBlank(stringValue)) {
keys.put(stringValue, child);
}
}
return keys;
}
/**
* array('foo' => FOO.class, 'foo1' => 'bar', 1 => 'foo')
*/
@NotNull
static public Map<String, PsiElement> getArrayKeyValueMapWithValueAsPsiElement(@NotNull ArrayCreationExpression arrayCreationExpression) {
HashMap<String, PsiElement> keys = new HashMap<>();
for(ArrayHashElement arrayHashElement: arrayCreationExpression.getHashElements()) {
PhpPsiElement child = arrayHashElement.getKey();
if(child != null && ((child instanceof StringLiteralExpression) || PhpPatterns.psiElement(PhpElementTypes.NUMBER).accepts(child))) {
String key;
if(child instanceof StringLiteralExpression) {
key = ((StringLiteralExpression) child).getContents();
} else {
key = child.getText();
}
if(key == null || StringUtils.isBlank(key)) {
continue;
}
keys.put(key, arrayHashElement.getValue());
}
}
return keys;
}
/**
* $this->methodName('service_name')
* $this->methodName(SERVICE::NAME)
* $this->methodName($this->name)
*/
static public boolean isMethodWithFirstStringOrFieldReference(PsiElement psiElement, String... methodName) {
if(!PlatformPatterns
.psiElement(PhpElementTypes.METHOD_REFERENCE)
.withChild(PlatformPatterns
.psiElement(PhpElementTypes.PARAMETER_LIST)
.withFirstChild(PlatformPatterns.or(
PlatformPatterns.psiElement(PhpElementTypes.STRING),
PlatformPatterns.psiElement(PhpElementTypes.FIELD_REFERENCE),
PlatformPatterns.psiElement(PhpElementTypes.CLASS_CONSTANT_REFERENCE)
))
).accepts(psiElement)) {
return false;
}
// cant we move it up to PlatformPatterns? withName condition dont looks working
String methodRefName = ((MethodReference) psiElement).getName();
return null != methodRefName && Arrays.asList(methodName).contains(methodRefName);
}
static public PsiElementPattern.Capture<StringLiteralExpression> getFunctionWithFirstStringPattern(@NotNull String... functionName) {
return PlatformPatterns
.psiElement(StringLiteralExpression.class)
.withParent(
PlatformPatterns.psiElement(ParameterList.class)
.withFirstChild(
PlatformPatterns.psiElement(PhpElementTypes.STRING)
)
.withParent(
PlatformPatterns.psiElement(FunctionReference.class).with(new PatternCondition<FunctionReference>("function match") {
@Override
public boolean accepts(@NotNull FunctionReference functionReference, ProcessingContext processingContext) {
return ArrayUtils.contains(functionName, functionReference.getName());
}
})
)
)
.withLanguage(PhpLanguage.INSTANCE);
}
@Nullable
static public String getArrayHashValue(ArrayCreationExpression arrayCreationExpression, String keyName) {
ArrayHashElement translationArrayHashElement = PsiElementUtils.getChildrenOfType(arrayCreationExpression, PlatformPatterns.psiElement(ArrayHashElement.class)
.withFirstChild(
PlatformPatterns.psiElement(PhpElementTypes.ARRAY_KEY).withText(
PlatformPatterns.string().oneOf("'" + keyName + "'", "\"" + keyName + "\"")
)
)
);
if(translationArrayHashElement == null) {
return null;
}
if(!(translationArrayHashElement.getValue() instanceof StringLiteralExpression)) {
return null;
}
StringLiteralExpression valueString = (StringLiteralExpression) translationArrayHashElement.getValue();
if(valueString == null) {
return null;
}
return valueString.getContents();
}
/**
* Provide array key pattern. we need incomplete array key support, too.
*
* foo(['<caret>'])
* foo(['<caret>' => 'foobar'])
*/
@NotNull
public static PsiElementPattern.Capture<PsiElement> getParameterListArrayValuePattern() {
return PlatformPatterns.psiElement()
.withParent(PlatformPatterns.psiElement(StringLiteralExpression.class).withParent(
PlatformPatterns.or(
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_VALUE)
.withParent(PlatformPatterns.psiElement(ArrayCreationExpression.class)
.withParent(ParameterList.class)
),
PlatformPatterns.psiElement().withElementType(PhpElementTypes.ARRAY_KEY)
.withParent(PlatformPatterns.psiElement(ArrayHashElement.class)
.withParent(PlatformPatterns.psiElement(ArrayCreationExpression.class)
.withParent(ParameterList.class)
)
)
))
);
}