com.intellij.patterns.PlatformPatterns Java Examples
The following examples show how to use
com.intellij.patterns.PlatformPatterns.
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: DustCompletionContributor.java From Intellij-Dust with MIT License | 6 votes |
public DustCompletionContributor() { extend(CompletionType.BASIC, PlatformPatterns.psiElement(DustTypes.IDENTIFIER).withLanguage(DustLanguage.INSTANCE), new CompletionProvider<CompletionParameters>() { public void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet resultSet) { resultSet.addElement(LookupElementBuilder.create("if")); resultSet.addElement(LookupElementBuilder.create("select")); resultSet.addElement(LookupElementBuilder.create("log")); resultSet.addElement(LookupElementBuilder.create("idx")); resultSet.addElement(LookupElementBuilder.create("jsControl")); resultSet.addElement(LookupElementBuilder.create("math")); resultSet.addElement(LookupElementBuilder.create("lt")); resultSet.addElement(LookupElementBuilder.create("gt")); resultSet.addElement(LookupElementBuilder.create("ne")); resultSet.addElement(LookupElementBuilder.create("eq")); resultSet.addElement(LookupElementBuilder.create("pre.scss")); resultSet.addElement(LookupElementBuilder.create("pre.layout")); resultSet.addElement(LookupElementBuilder.create("pre.js")); resultSet.addElement(LookupElementBuilder.create("pre.i18n")); // TODO add more keywords, think about writing a reference based autocompleter } } ); }
Example #2
Source File: ConsoleHelperGotoCompletionRegistrarTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * @see fr.adrienbrault.idea.symfony2plugin.completion.command.ConsoleHelperGotoCompletionRegistrar */ public void testHelperSet() { assertCompletionContains(PhpFileType.INSTANCE, "<?php" + "/** @var \\Symfony\\Component\\Console\\Helper\\HelperSet $foo */\n" + "$foo->has('<caret>');", "foo" ); assertNavigationMatch(PhpFileType.INSTANCE, "<?php" + "/** @var \\Symfony\\Component\\Console\\Helper\\HelperSet $foo */\n" + "$foo->has('fo<caret>o');", PlatformPatterns.psiElement(PhpClass.class) ); assertCompletionContains(PhpFileType.INSTANCE, "<?php" + "/** @var \\Symfony\\Component\\Console\\Helper\\HelperSet $foo */\n" + "$foo->get('<caret>');", "foo" ); assertNavigationMatch(PhpFileType.INSTANCE, "<?php" + "/** @var \\Symfony\\Component\\Console\\Helper\\HelperSet $foo */\n" + "$foo->get('fo<caret>o');", PlatformPatterns.psiElement(PhpClass.class) ); }
Example #3
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 #4
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Provide a workaround for getting a FUNCTION scope as it not consistent in all Twig elements * * {% if asset('') %} * {{ asset('') }} */ @NotNull private static ElementPattern<PsiElement> getFunctionCallScopePattern() { return PlatformPatterns.or( // old and inconsistently implementations of FUNCTION_CALL: // eg {% if asset('') %} does not provide a FUNCTION_CALL whereas a print block does PlatformPatterns.psiElement(TwigElementTypes.PRINT_BLOCK), PlatformPatterns.psiElement(TwigElementTypes.TAG), PlatformPatterns.psiElement(TwigElementTypes.IF_TAG), PlatformPatterns.psiElement(TwigElementTypes.SET_TAG), PlatformPatterns.psiElement(TwigElementTypes.ELSE_TAG), PlatformPatterns.psiElement(TwigElementTypes.ELSEIF_TAG), PlatformPatterns.psiElement(TwigElementTypes.FOR_TAG), // PhpStorm 2017.3.2: {{ asset('') }} PlatformPatterns.psiElement(TwigElementTypes.FUNCTION_CALL) ); }
Example #5
Source File: DoctrinePropertyOrmAnnotationGenerateAction.java From idea-php-annotation-plugin with MIT License | 6 votes |
@Override protected boolean isValidForFile(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) { if(!(file instanceof PhpFile) || !DoctrineUtil.isDoctrineOrmInVendor(project)) { return false; } int offset = editor.getCaretModel().getOffset(); if(offset <= 0) { return false; } PsiElement psiElement = file.findElementAt(offset); if(psiElement == null) { return false; } if(!PlatformPatterns.psiElement().inside(PhpClass.class).accepts(psiElement)) { return false; } return true; }
Example #6
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static ElementPattern<PsiElement> getTemplateFileReferenceTagPattern(String... tagNames) { // {% include '<xxx>' with {'foo' : bar, 'bar' : 'foo'} %} //noinspection unchecked return PlatformPatterns .psiElement(TwigTokenTypes.STRING_TEXT) .afterLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(TwigTokenTypes.LBRACE), PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE), PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE), PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE) ), PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText(PlatformPatterns.string().oneOf(tagNames)) ) .withLanguage(TwigLanguage.INSTANCE); }
Example #7
Source File: TemplateLineMarkerProvider.java From idea-php-typo3-plugin with MIT License | 6 votes |
@Override protected void collectNavigationMarkers(@NotNull PsiElement element, @NotNull Collection<? super RelatedItemLineMarkerInfo> result) { if (!PlatformPatterns.psiElement(FluidFile.class).accepts(element)) { return; } Collection<Method> possibleMethodTargetsForControllerAction = FluidUtil.findPossibleMethodTargetsForControllerAction( element.getProject(), FluidUtil.inferControllerNameFromTemplateFile((FluidFile) element), FluidUtil.inferActionNameFromTemplateFile((FluidFile) element) ); if (possibleMethodTargetsForControllerAction.size() > 0) { result.add( NavigationGutterIconBuilder .create(PhpIcons.METHOD) .setTargets(possibleMethodTargetsForControllerAction) .setTooltipText("Navigate to controller action") .createLineMarkerInfo(element) ); } }
Example #8
Source File: YamlGoToDeclarationHandlerTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void testNamedArgumentsNavigationForDefaultBinding() { assertNavigationMatch("services.yml", "" + "services:\n" + " _defaults:\n" + " bind:\n" + " $<caret>i: ~\n"+ " Foo\\Bar: ~" + PlatformPatterns.psiElement(Parameter.class) ); assertNavigationMatch("services.yml", "" + "services:\n" + " _defaults:\n" + " bind:\n" + " $<caret>i: ~\n"+ " foobar:\n" + " class: Foo\\Bar\n" + PlatformPatterns.psiElement(Parameter.class) ); }
Example #9
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static ElementPattern<PsiElement> getForTagInVariablePattern() { // {% for key, user in "users" %} // {% for user in "users" %} // {% for user in "users"|slice(0, 10) %} //noinspection unchecked return PlatformPatterns .psiElement(TwigTokenTypes.IDENTIFIER) .afterLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE) ), PlatformPatterns.psiElement(TwigTokenTypes.IN) ) .withLanguage(TwigLanguage.INSTANCE); }
Example #10
Source File: TwigUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static String getTwigMethodString(@Nullable PsiElement transPsiElement) { if (transPsiElement == null) return null; ElementPattern<PsiElement> pattern = PlatformPatterns.psiElement(TwigTokenTypes.RBRACE); String currentText = transPsiElement.getText(); for (PsiElement child = transPsiElement.getNextSibling(); child != null; child = child.getNextSibling()) { currentText = currentText + child.getText(); if (pattern.accepts(child)) { //noinspection unchecked return currentText; } } return null; }
Example #11
Source File: PsiElementUtils.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@Nullable public static MethodReference getMethodReferenceWithFirstStringParameter(PsiElement psiElement) { if(!PlatformPatterns.psiElement() .withParent(StringLiteralExpression.class).inside(ParameterList.class) .withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) { return null; } ParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, ParameterList.class); if (parameterList == null) { return null; } if (!(parameterList.getContext() instanceof MethodReference)) { return null; } return (MethodReference) parameterList.getContext(); }
Example #12
Source File: DoctrineUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Extract text: @Entity(repositoryClass="foo") */ @Nullable public static String getAnnotationRepositoryClass(@NotNull PhpDocTag phpDocTag, @NotNull PhpClass phpClass) { PsiElement phpDocAttributeList = PsiElementUtils.getChildrenOfType(phpDocTag, PlatformPatterns.psiElement(PhpDocElementTypes.phpDocAttributeList)); if(phpDocAttributeList == null) { return null; } // @TODO: use annotation plugin // repositoryClass="Foobar" String text = phpDocAttributeList.getText(); String repositoryClass = EntityHelper.resolveDoctrineLikePropertyClass( phpClass, text, "repositoryClass", aVoid -> AnnotationUtil.getUseImportMap(phpDocTag) ); if (repositoryClass == null) { return null; } return StringUtils.stripStart(repositoryClass, "\\"); }
Example #13
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 #14
Source File: TwigTypeResolveUtil.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Get items before foo.bar.car, foo.bar.car() * * ["foo", "bar"] */ @NotNull public static Collection<String> formatPsiTypeName(@NotNull PsiElement psiElement) { String typeNames = PhpElementsUtil.getPrevSiblingAsTextUntil(psiElement, PlatformPatterns.or( PlatformPatterns.psiElement(TwigTokenTypes.LBRACE), PlatformPatterns.psiElement(PsiWhiteSpace.class ))); if(typeNames.trim().length() == 0) { return Collections.emptyList(); } if(typeNames.endsWith(".")) { typeNames = typeNames.substring(0, typeNames.length() -1); } Collection<String> possibleTypes = new ArrayList<>(); if(typeNames.contains(".")) { possibleTypes.addAll(Arrays.asList(typeNames.split("\\."))); } else { possibleTypes.add(typeNames); } return possibleTypes; }
Example #15
Source File: BuckIdentifierReferenceContributor.java From buck with Apache License 2.0 | 6 votes |
@Override public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) { registrar.registerReferenceProvider( PlatformPatterns.psiElement(BuckIdentifier.class), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement( @NotNull PsiElement element, @NotNull ProcessingContext context) { if (element instanceof BuckIdentifier) { BuckIdentifier identifier = (BuckIdentifier) element; return new PsiReference[] {new BuckIdentifierReference(identifier)}; } else { return new PsiReference[0]; } } }); }
Example #16
Source File: PhpMatcherTest.java From idea-php-toolbox with MIT License | 6 votes |
public void testVariadicSignatureRegistrarMatcher() { assertCompletionContains(PhpFileType.INSTANCE, "<?php\n _variadic('<caret>')", "foo"); assertCompletionContains(PhpFileType.INSTANCE, "<?php\n _variadic(null, '<caret>')", "foo"); assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n _variadic('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format")); assertCompletionContains(PhpFileType.INSTANCE, "<?php\n _variadic('<caret>')", "foo"); assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n _variadic('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format")); assertCompletionContains(PhpFileType.INSTANCE, "<?php\n new \\Foo\\Variadic('<caret>')", "foo"); assertCompletionContains(PhpFileType.INSTANCE, "<?php\n new \\Foo\\Variadic(null, '<caret>')", "foo"); assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n new \\Foo\\Variadic('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format")); assertCompletionContains(PhpFileType.INSTANCE, "<?php\n /** @var $f \\Foo\\Variadic */\n $f->getFoo('<caret>')", "foo"); assertCompletionContains(PhpFileType.INSTANCE, "<?php\n /** @var $f \\Foo\\Variadic */\n $f->getFoo(null, '<caret>')", "foo"); assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n /** @var $f \\Foo\\Variadic */\n $f->getFoo('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format")); }
Example #17
Source File: GraphQLCompletionContributor.java From js-graphql-intellij-plugin with MIT License | 6 votes |
private void completeFieldArgumentTypeName() { CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() { @Override protected void addCompletions(@NotNull final CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { final PsiElement completionElement = parameters.getPosition(); final TypeDefinitionRegistry registry = GraphQLTypeDefinitionRegistryServiceImpl.getService(completionElement.getProject()).getRegistry(parameters.getOriginalFile()); addInputTypeCompletions(result, registry); } }; extend(CompletionType.BASIC, psiElement(GraphQLElementTypes.NAME).afterLeafSkipping( // skip PlatformPatterns.or(psiComment(), psiElement(TokenType.WHITE_SPACE), psiElement().withText("[")), // until argument type colon occurs psiElement().withText(":") ).inside(GraphQLInputValueDefinition.class), provider); }
Example #18
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public static ElementPattern<PsiElement> getAutocompletableRoutePattern() { //noinspection unchecked return PlatformPatterns .psiElement(TwigTokenTypes.STRING_TEXT) .afterLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(TwigTokenTypes.LBRACE), PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE), PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE), PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE) ), PlatformPatterns.or( PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText("path"), PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText("url") ) ) .withLanguage(TwigLanguage.INSTANCE) ; }
Example #19
Source File: FormTypeReferenceContributorTest.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void testFormDataFieldPropertyPathReferencesForMethod() { for (String s : new String[]{"foo_bar", "fooBar"}) { assertReferenceMatchOnParent(PhpFileType.INSTANCE, "<?php\n" + "\n" + "class FormType\n" + "{\n" + " protected $foo = 'DateTime';\n" + " public function buildForm(\\Symfony\\Component\\Form\\FormBuilderInterface $builder, array $options) {\n" + " $builder->add('" + s + "<caret>');\n" + " }\n" + " public function setDefaultOptions(OptionsResolverInterface $resolver)\n" + " {\n" + " $resolver->setDefaults(array(\n" + " 'data_class' => \\Form\\DataClass\\Model::class,\n" + " ));\n" + " }\n" + "}", PlatformPatterns.psiElement(Method.class) ); } }
Example #20
Source File: PhpGlobalsNamespaceProvider.java From idea-php-typo3-plugin with MIT License | 6 votes |
@NotNull private PsiElementPattern.Capture<ArrayIndex> getEmptyArrayKeyPattern() { return PlatformPatterns.psiElement(ArrayIndex.class).withParent( PlatformPatterns.psiElement(ArrayAccessExpression.class).withParent( PlatformPatterns.psiElement(ArrayAccessExpression.class).withParent( PlatformPatterns.psiElement(AssignmentExpression.class) ) ).withChild( PlatformPatterns.psiElement(ArrayAccessExpression.class) .withChild( PlatformPatterns.psiElement(ArrayIndex.class).withText(PlatformPatterns.string().oneOf("'namespaces'")) ) .withChild( PlatformPatterns.psiElement(ArrayAccessExpression.class).withChild(PlatformPatterns.psiElement(ArrayIndex.class).withText(PlatformPatterns.string().oneOf("'fluid'"))).withChild( PlatformPatterns.psiElement(ArrayAccessExpression.class).withChild(PlatformPatterns.psiElement(ArrayIndex.class).withText(PlatformPatterns.string().oneOf("'SYS'"))).withChild( PlatformPatterns.psiElement(ArrayAccessExpression.class).withChild(PlatformPatterns.psiElement(ArrayIndex.class).withText(PlatformPatterns.string().oneOf("'TYPO3_CONF_VARS'"))) ) ) ) ) ); }
Example #21
Source File: RouteReferenceContributor.java From idea-php-typo3-plugin with MIT License | 6 votes |
private boolean isGenerator(@NotNull PsiElement element) { if (!PlatformPatterns .psiElement(StringLiteralExpression.class).withParent( PlatformPatterns.psiElement(ParameterList.class).withParent( PlatformPatterns.psiElement(MethodReference.class)) ) .accepts(element)) { return false; } PsiElement methodRef = element.getParent().getParent(); if (methodRef instanceof MethodReference) { Method method = (Method) ((MethodReference) methodRef).resolve(); if (method != null) { return isClassMethodCombination(method, "\\TYPO3\\CMS\\Backend\\Routing\\UriBuilder", "buildUriFromRoutePath") || isClassMethodCombination(method, "\\TYPO3\\CMS\\Backend\\Routing\\UriBuilder", "buildUriFromRoute") || isClassMethodCombination(method, "\\TYPO3\\CMS\\Backend\\Routing\\UriBuilder", "buildUriFromAjaxId") || isClassMethodCombination(method, "\\TYPO3\\CMS\\Backend\\Utility\\BackendUtility", "getAjaxUrl"); } } return false; }
Example #22
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Check for {% if foo is "foo" %} */ public static ElementPattern<PsiElement> getAfterIsTokenPattern() { //noinspection unchecked return PlatformPatterns .psiElement() .afterLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE) ), PlatformPatterns.or( PlatformPatterns.psiElement(TwigTokenTypes.IS), PlatformPatterns.psiElement(TwigTokenTypes.NOT) ) ) .withLanguage(TwigLanguage.INSTANCE); }
Example #23
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 #24
Source File: RoutingGotoCompletionRegistrarTest.java From idea-php-laravel-plugin with MIT License | 6 votes |
public void testRouteNameReferencesAsMethod() { Collection<String[]> providers = new ArrayList<String[]>() {{ add(new String[] {"Illuminate\\Routing\\UrlGenerator", "route"}); add(new String[] {"Illuminate\\Contracts\\Routing\\UrlGenerator", "route"}); add(new String[] {"Collective\\Html\\HtmlBuilder", "linkRoute"}); add(new String[] {"Tests\\Feature\\ExampleTest", "visitRoute"}); }}; for (String[] provider : providers) { assertCompletionContains(PhpFileType.INSTANCE, String.format("<?php\n" + "/** @var $r \\%s */\n" + "$r->%s('<caret>')" , provider[0], provider[1]), "profile" ); assertNavigationMatch(PhpFileType.INSTANCE, String.format("<?php\n" + "/** @var $r \\%s */\n" + "$r->%s('profile<caret>')" , provider[0], provider[1]), PlatformPatterns.psiElement().inFile(PlatformPatterns.psiFile().withName("routes.php")) ); } }
Example #25
Source File: AnnotationPattern.java From idea-php-annotation-plugin with MIT License | 6 votes |
/** * matches "@Callback(property="<value>")" */ public static ElementPattern<PsiElement> getTextIdentifier() { return PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_STRING) .withParent(PlatformPatterns.psiElement(StringLiteralExpression.class) .afterLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT).withText(PlatformPatterns.string().containsChars("=")), PlatformPatterns.psiElement(PsiWhiteSpace.class) ), PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_IDENTIFIER) ) .withParent(PlatformPatterns .psiElement(PhpDocElementTypes.phpDocAttributeList) .withParent(PlatformPatterns .psiElement(PhpDocElementTypes.phpDocTag) ) ) ); }
Example #26
Source File: PhpElementsUtil.java From idea-php-typo3-plugin with MIT License | 6 votes |
public static 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 #27
Source File: TwigPattern.java From idea-php-symfony2-plugin with MIT License | 6 votes |
/** * Pattern to match given string before "filter" with given function name * * {{ 'foo<caret>bar'|trans }} * {{ 'foo<caret>bar'|trans() }} * {{ 'foo<caret>bar'|transchoice() }} */ @NotNull public static ElementPattern<PsiElement> getTranslationKeyPattern(@NotNull String... type) { //noinspection unchecked return PlatformPatterns .psiElement(TwigTokenTypes.STRING_TEXT) .beforeLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE), PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE), PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE) ), PlatformPatterns.psiElement(TwigTokenTypes.FILTER).beforeLeafSkipping( PlatformPatterns.or( PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE), PlatformPatterns.psiElement(PsiWhiteSpace.class) ), PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).withText( PlatformPatterns.string().oneOf(type) ) ) ) .withLanguage(TwigLanguage.INSTANCE); }
Example #28
Source File: ViewCompletionContributor.java From yiistorm with MIT License | 5 votes |
public static PsiElementPattern.Capture viewsPattern() { PsiElementPattern.Capture<PsiElement> $patterns = PlatformPatterns .psiElement(PsiElement.class) .withParent( PlatformPatterns.or( PlatformPatterns.psiElement(StringLiteralExpression.class) .withParent( PlatformPatterns.psiElement(PhpElementTypes.PARAMETER_LIST) .withParent( PlatformPatterns.psiElement(PhpElementTypes.METHOD_REFERENCE) .withText(StandardPatterns.string().contains("renderPartial(")) ) ), PlatformPatterns.psiElement(StringLiteralExpression.class) .withParent( PlatformPatterns.psiElement(PhpElementTypes.PARAMETER_LIST) .withParent( PlatformPatterns.psiElement(PhpElementTypes.METHOD_REFERENCE) .withText(StandardPatterns.string().contains("render(")) ) ) ) ) .withLanguage(PhpLanguage.INSTANCE); return $patterns; }
Example #29
Source File: SmartyFileGoToDeclarationHandlerTest.java From idea-php-shopware-plugin with MIT License | 5 votes |
public void testNavigationForActionController() { assertNavigationMatch( SmartyFileType.INSTANCE, "{action module=widgets controller=Lis<caret>ting action=shopMenu}", PlatformPatterns.psiElement(PhpClass.class) ); assertNavigationMatch( SmartyFileType.INSTANCE, "{action module=widgets controller=\"Lis<caret>ting\" action=shopMenu}", PlatformPatterns.psiElement(PhpClass.class) ); assertNavigationMatch( SmartyFileType.INSTANCE, "{action module=widgets controller='Lis<caret>ting' action=shopMenu}", PlatformPatterns.psiElement(PhpClass.class) ); assertNavigationMatch( SmartyFileType.INSTANCE, "{action module=frontend controller=Fronten<caret>dListing action=shopMenu}", PlatformPatterns.psiElement(PhpClass.class) ); assertNavigationMatch( SmartyFileType.INSTANCE, "{action module=\"frontend\" controller=Fronten<caret>dListing action=shopMenu}", PlatformPatterns.psiElement(PhpClass.class) ); assertNavigationMatch( SmartyFileType.INSTANCE, "{action module='frontend' controller=Fronten<caret>dListing action=shopMenu}", PlatformPatterns.psiElement(PhpClass.class) ); }
Example #30
Source File: TYPO3Patterns.java From idea-php-typo3-plugin with MIT License | 5 votes |
public static ElementPattern<? extends PsiElement> connectSignalMethodName() { return PlatformPatterns .psiElement().withParent( PlatformPatterns.psiElement(StringLiteralExpression.class) ) .withSuperParent(3, PlatformPatterns.psiElement(MethodReference.class)); }