com.jetbrains.php.lang.parser.PhpElementTypes Java Examples
The following examples show how to use
com.jetbrains.php.lang.parser.PhpElementTypes.
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: PhpElementsUtil.java From idea-php-generics-plugin with MIT License | 6 votes |
/** * 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) ) ) )) ); }
Example #2
Source File: PhpElementsUtil.java From Thinkphp5-Plugin with MIT License | 6 votes |
/** * $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); }
Example #3
Source File: DeprecationUtility.java From idea-php-typo3-plugin with MIT License | 6 votes |
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()); }
Example #4
Source File: TCAPatterns.java From idea-php-typo3-plugin with MIT License | 6 votes |
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) ); }
Example #5
Source File: DeprecationUtility.java From idea-php-typo3-plugin with MIT License | 6 votes |
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()); }
Example #6
Source File: TCAPatterns.java From idea-php-typo3-plugin with MIT License | 6 votes |
@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) ) ) ) ) ); }
Example #7
Source File: BxReferencePatterns.java From bxfs with MIT License | 6 votes |
/** * 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; }
Example #8
Source File: DeprecationUtility.java From idea-php-typo3-plugin with MIT License | 6 votes |
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()); }
Example #9
Source File: PhpArrayCallbackGotoCompletion.java From idea-php-toolbox with MIT License | 6 votes |
/** * [$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("[", "(")) ) ) ) ); }
Example #10
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 #11
Source File: PhpElementsUtil.java From idea-php-laravel-plugin with MIT License | 6 votes |
/** * 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; }
Example #12
Source File: PhpElementsUtil.java From idea-php-laravel-plugin with MIT License | 6 votes |
/** * $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); }
Example #13
Source File: SubscriberIndexUtil.java From idea-php-shopware-plugin with MIT License | 6 votes |
/** * 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; }
Example #14
Source File: ShopwareSubscriperMethodInspection.java From idea-php-shopware-plugin with MIT License | 6 votes |
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; }
Example #15
Source File: DrupalPattern.java From idea-php-drupal-symfony2-bridge with MIT License | 6 votes |
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); }
Example #16
Source File: PhpElementsUtil.java From idea-php-toolbox with MIT License | 6 votes |
/** * $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); }
Example #17
Source File: ReturnArraySignatureRegistrarMatcher.java From idea-php-toolbox with MIT License | 6 votes |
@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); }
Example #18
Source File: PhpArrayCallbackGotoCompletion.java From idea-php-toolbox with MIT License | 6 votes |
/** * [$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("[", "(")) ) ) ) ); }
Example #19
Source File: ArrayValueWithKeyAndNewExpressionMatcher.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * 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; }
Example #20
Source File: ArrayValueWithKeyAndMethodMatcher.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * 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; }
Example #21
Source File: PhpElementsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * 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; }
Example #22
Source File: PhpElementsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * 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; }
Example #23
Source File: PhpElementsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * $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); }
Example #24
Source File: PhpElementsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
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); }
Example #25
Source File: PhpElementsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@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(); }
Example #26
Source File: PhpElementsUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * 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) ) ) )) ); }
Example #27
Source File: ColumnNameCompletionProvider.java From idea-php-annotation-plugin with MIT License | 6 votes |
@Override public void getPropertyValueCompletions(AnnotationPropertyParameter annotationPropertyParameter, AnnotationCompletionProviderParameter completionParameter) { String propertyName = annotationPropertyParameter.getPropertyName(); if(propertyName == null) { return; } if(propertyName.equals("name") && PhpLangUtil.equalsClassNames(annotationPropertyParameter.getPhpClass().getPresentableFQN(), "Doctrine\\ORM\\Mapping\\Column")) { PhpDocComment phpDocComment = PsiTreeUtil.getParentOfType(annotationPropertyParameter.getElement(), PhpDocComment.class); if(phpDocComment != null) { PhpPsiElement classField = phpDocComment.getNextPsiSibling(); if(classField != null && classField.getNode().getElementType() == PhpElementTypes.CLASS_FIELDS) { Field field = PsiTreeUtil.getChildOfType(classField, Field.class); if(field != null) { String name = field.getName(); if(StringUtils.isNotBlank(name)) { completionParameter.getResult().addElement(LookupElementBuilder.create(underscore(name))); } } } } } }
Example #28
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 #29
Source File: YiiRefsHelper.java From yiistorm with MIT License | 6 votes |
public static boolean isWidgetRenderView(String path, PsiElement el) { if (!path.contains("Controller.php")) { PsiElementPattern.Capture p = PlatformPatterns.psiElement().withElementType(PhpElementTypes.CLASS) .withSuperParent(5, PlatformPatterns.psiElement().withName("CWidget")); PsiElementPattern.Capture renderMethod = PlatformPatterns.psiElement().withParent( YiiContibutorHelper.paramListInMethodWithName("render") ); PsiElementPattern.Capture renderPartialMethod = PlatformPatterns.psiElement().withParent( YiiContibutorHelper.paramListInMethodWithName("renderPartial") ); PsiElement[] elc = el.getContainingFile().getChildren(); if (elc.length > 0 && elc[0] != null && elc[0].getChildren().length > 0) { for (PsiElement element : elc[0].getChildren()) { if (p.accepts(element) && (renderMethod.accepts(el) || renderPartialMethod.accepts(el))) { return true; } } } } return false; }
Example #30
Source File: PhpElementsUtil.java From yiistorm with MIT License | 6 votes |
static public boolean isMethodWithFirstString(PsiElement psiElement, String... methodName) { // filter out method calls without parameter // $this->methodName('service_name') // withName is not working, so simulate it in a hack if (!PlatformPatterns .psiElement(PhpElementTypes.METHOD_REFERENCE) .withChild(PlatformPatterns .psiElement(PhpElementTypes.PARAMETER_LIST) .withFirstChild(PlatformPatterns .psiElement(PhpElementTypes.STRING) ) ).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); }