Java Code Examples for com.intellij.patterns.ElementPattern#accepts()
The following examples show how to use
com.intellij.patterns.ElementPattern#accepts() .
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: AnnotationLightCodeInsightFixtureTestCase.java From idea-php-generics-plugin with MIT License | 6 votes |
private void assertNavigationMatch(ElementPattern<?> pattern) { PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); Set<String> targetStrings = new HashSet<String>(); for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor()); if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) { continue; } for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) { targetStrings.add(gotoDeclarationTarget.toString()); if(pattern.accepts(gotoDeclarationTarget)) { return; } } } fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString())); }
Example 2
Source File: AnnotationLightCodeInsightFixtureTestCase.java From idea-php-annotation-plugin with MIT License | 6 votes |
private void assertNavigationMatch(ElementPattern<?> pattern) { PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); Set<String> targetStrings = new HashSet<String>(); for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor()); if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) { continue; } for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) { targetStrings.add(gotoDeclarationTarget.toString()); if(pattern.accepts(gotoDeclarationTarget)) { return; } } } fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString())); }
Example 3
Source File: SymfonyLightCodeInsightFixtureTestCase.java From idea-php-toolbox with MIT License | 6 votes |
public void assertNavigationMatch(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) { myFixture.configureByText(languageFileType, configureByText); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); Set<String> targetStrings = new HashSet<>(); for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor()); if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) { continue; } for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) { targetStrings.add(gotoDeclarationTarget.toString()); if(pattern.accepts(gotoDeclarationTarget)) { return; } } } fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString())); }
Example 4
Source File: SymfonyLightCodeInsightFixtureTestCase.java From idea-php-toolbox with MIT License | 6 votes |
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) { myFixture.configureByText(languageFileType, configureByText); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class); if (psiElement == null) { fail("Element is not PhpReference."); } PsiElement resolve = ((PhpReference) psiElement).resolve(); if(!pattern.accepts(resolve)) { fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString())); } assertTrue(pattern.accepts(resolve)); }
Example 5
Source File: LaravelLightCodeInsightFixtureTestCase.java From idea-php-laravel-plugin with MIT License | 6 votes |
private void assertNavigationMatch(ElementPattern<?> pattern) { PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); Set<String> targetStrings = new HashSet<String>(); for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor()); if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) { continue; } for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) { targetStrings.add(gotoDeclarationTarget.toString()); if(pattern.accepts(gotoDeclarationTarget)) { return; } } } fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString())); }
Example 6
Source File: ShopwareLightCodeInsightFixtureTestCase.java From idea-php-shopware-plugin with MIT License | 6 votes |
private void assertNavigationMatch(ElementPattern<?> pattern) { PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); Set<String> targetStrings = new HashSet<String>(); for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor()); if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) { continue; } for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) { targetStrings.add(gotoDeclarationTarget.toString()); if(pattern.accepts(gotoDeclarationTarget)) { return; } } } fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString())); }
Example 7
Source File: ShopwareLightCodeInsightFixtureTestCase.java From idea-php-shopware-plugin with MIT License | 6 votes |
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) { myFixture.configureByText(languageFileType, configureByText); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class); if (psiElement == null) { fail("Element is not PhpReference."); } PsiElement resolve = ((PhpReference) psiElement).resolve(); if(!pattern.accepts(resolve)) { fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString())); } assertTrue(pattern.accepts(resolve)); }
Example 8
Source File: DrupalLightCodeInsightFixtureTestCase.java From idea-php-drupal-symfony2-bridge with MIT License | 6 votes |
private void assertNavigationMatch(ElementPattern<?> pattern) { PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); Set<String> targetStrings = new HashSet<String>(); for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor()); if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) { continue; } for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) { targetStrings.add(gotoDeclarationTarget.toString()); if(pattern.accepts(gotoDeclarationTarget)) { return; } } } fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString())); }
Example 9
Source File: SymfonyLightCodeInsightFixtureTestCase.java From idea-php-symfony2-plugin with MIT License | 6 votes |
private void assertReferences(@NotNull ElementPattern<?> pattern, PsiElement psiElement) { for (PsiReference reference : psiElement.getReferences()) { // single resolve; should also match first multi by design PsiElement element = reference.resolve(); if (pattern.accepts(element)) { return; } // multiResolve support if(reference instanceof PsiPolyVariantReference) { for (ResolveResult resolveResult : ((PsiPolyVariantReference) reference).multiResolve(true)) { if (pattern.accepts(resolveResult.getElement())) { return; } } } } fail(String.format("Fail that '%s' match given pattern", psiElement.toString())); }
Example 10
Source File: SymfonyLightCodeInsightFixtureTestCase.java From idea-php-toolbox with MIT License | 6 votes |
public void assertNavigationMatch(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) { myFixture.configureByText(languageFileType, configureByText); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); Set<String> targetStrings = new HashSet<>(); for (GotoDeclarationHandler gotoDeclarationHandler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { PsiElement[] gotoDeclarationTargets = gotoDeclarationHandler.getGotoDeclarationTargets(psiElement, 0, myFixture.getEditor()); if(gotoDeclarationTargets == null || gotoDeclarationTargets.length == 0) { continue; } for (PsiElement gotoDeclarationTarget : gotoDeclarationTargets) { targetStrings.add(gotoDeclarationTarget.toString()); if(pattern.accepts(gotoDeclarationTarget)) { return; } } } fail(String.format("failed that PsiElement (%s) navigate matches one of %s", psiElement.toString(), targetStrings.toString())); }
Example 11
Source File: PsiElementUtils.java From idea-php-symfony2-plugin with MIT License | 6 votes |
@NotNull public static <T extends PsiElement> Collection<T> getChildrenOfTypeAsList(@Nullable PsiElement element, ElementPattern<T> pattern) { Collection<T> collection = new ArrayList<>(); if (element == null) { return collection; } for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) { if (pattern.accepts(child)) { //noinspection unchecked collection.add((T)child); } } return collection; }
Example 12
Source File: AnnotationLightCodeInsightFixtureTestCase.java From idea-php-annotation-plugin with MIT License | 6 votes |
private void assertReferences(@NotNull ElementPattern<?> pattern, PsiElement psiElement) { for (PsiReference reference : psiElement.getReferences()) { // single resolve; should also match first multi by design PsiElement element = reference.resolve(); if (pattern.accepts(element)) { return; } // multiResolve support if(element instanceof PsiPolyVariantReference) { for (ResolveResult resolveResult : ((PsiPolyVariantReference) element).multiResolve(true)) { if (pattern.accepts(resolveResult.getElement())) { return; } } } } fail(String.format("Fail that '%s' match given pattern", psiElement.toString())); }
Example 13
Source File: SymfonyLightCodeInsightFixtureTestCase.java From idea-php-symfony2-plugin with MIT License | 6 votes |
public void assertPhpReferenceResolveTo(LanguageFileType languageFileType, String configureByText, ElementPattern<?> pattern) { myFixture.configureByText(languageFileType, configureByText); PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset()); psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class); if (psiElement == null) { fail("Element is not PhpReference."); } PsiElement resolve = ((PhpReference) psiElement).resolve(); if(!pattern.accepts(resolve)) { fail(String.format("failed pattern matches element of '%s'", resolve == null ? "null" : resolve.toString())); } assertTrue(pattern.accepts(resolve)); }
Example 14
Source File: PhpElementsUtil.java From idea-php-annotation-plugin with MIT License | 5 votes |
@Nullable public static <T extends PsiElement> T getChildrenOnPatternMatch(@Nullable PsiElement element, ElementPattern<T> pattern) { if (element == null) return null; for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) { if (pattern.accepts(child)) { //noinspection unchecked return (T)child; } } return null; }
Example 15
Source File: PsiElementUtils.java From idea-php-symfony2-plugin with MIT License | 5 votes |
public static <T extends PsiElement> List<T> getPrevSiblingsOfType(@Nullable PsiElement sibling, ElementPattern<T> pattern) { List<T> elements = new ArrayList<>(); if (sibling == null) return null; for (PsiElement child = sibling.getPrevSibling(); child != null; child = child.getPrevSibling()) { if (pattern.accepts(child)) { // noinspection unchecked elements.add((T)child); } } return elements; }
Example 16
Source File: PhpElementsUtil.java From idea-php-annotation-plugin with MIT License | 5 votes |
@Nullable public static <T extends PsiElement> T getPrevSiblingOfPatternMatch(@Nullable PsiElement sibling, ElementPattern<T> pattern) { if (sibling == null) return null; for (PsiElement child = sibling.getPrevSibling(); child != null; child = child.getPrevSibling()) { if (pattern.accepts(child)) { //noinspection unchecked return (T)child; } } return null; }
Example 17
Source File: PsiElementUtils.java From idea-php-symfony2-plugin with MIT License | 5 votes |
@Nullable public static <T extends PsiElement> T getNextSiblingOfType(@Nullable PsiElement sibling, ElementPattern<PsiElement> pattern) { if (sibling == null) return null; for (PsiElement child = sibling.getNextSibling(); child != null; child = child.getNextSibling()) { if (pattern.accepts(child)) { //noinspection unchecked return (T)child; } } return null; }
Example 18
Source File: PsiElementUtils.java From yiistorm with MIT License | 5 votes |
@Nullable public static <T extends PsiElement> T getChildrenOfType(@Nullable PsiElement element, ElementPattern<T> pattern) { if (element == null) return null; for (PsiElement child = element.getFirstChild(); child != null; child = child.getNextSibling()) { if (pattern.accepts(child)) { //noinspection unchecked return (T) child; } } return null; }
Example 19
Source File: PsiElementUtils.java From yiistorm with MIT License | 5 votes |
@Nullable public static <T extends PsiElement> T getNextSiblingOfType(@Nullable PsiElement sibling, ElementPattern<PsiElement> pattern) { if (sibling == null) return null; for (PsiElement child = sibling.getNextSibling(); child != null; child = child.getNextSibling()) { if (pattern.accepts(child)) { //noinspection unchecked return (T) child; } } return null; }
Example 20
Source File: CompletionUtil.java From consulo with Apache License 2.0 | 5 votes |
@Nonnull private static String findInText(int offset, int startOffset, ElementPattern<Character> idPart, ElementPattern<Character> idStart, CharSequence text) { final int offsetInElement = offset - startOffset; int start = offsetInElement - 1; while (start >= 0) { if (!idPart.accepts(text.charAt(start))) break; --start; } while (start + 1 < offsetInElement && !idStart.accepts(text.charAt(start + 1))) { start++; } return text.subSequence(start + 1, offsetInElement).toString().trim(); }