com.intellij.patterns.ElementPattern Java Examples

The following examples show how to use com.intellij.patterns.ElementPattern. 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: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * {% filter foo %}
 */
public static ElementPattern<PsiElement> getFilterTagPattern() {
    //noinspection unchecked
    return
        PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME)
            )
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.FILTER_TAG)
            )
            .withLanguage(TwigLanguage.INSTANCE)
        ;
}
 
Example #2
Source File: TwigUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
/**
 * Check for {{ include('|')  }}
 *
 * @param functionName twig function name
 */
public static ElementPattern<PsiElement> getPrintBlockFunctionPattern(String... functionName) {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement(TwigTokenTypes.STRING_TEXT)
        .withParent(PlatformPatterns.or(
            PlatformPatterns.psiElement(TwigElementTypes.PRINT_BLOCK),
            PlatformPatterns.psiElement(TwigElementTypes.SET_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.IF_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.FUNCTION_CALL)
        ))
        .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.IDENTIFIER).withText(PlatformPatterns.string().oneOf(functionName))
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #3
Source File: SimpleProviderBinding.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void addAcceptableReferenceProviders(@Nonnull PsiElement position,
                                            @Nonnull List<ProviderInfo<Provider, ProcessingContext>> list,
                                            @Nonnull PsiReferenceService.Hints hints) {
  for (ProviderInfo<Provider, ElementPattern> trinity : myProviderPairs) {
    if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) {
      continue;
    }

    final ProcessingContext context = new ProcessingContext();
    if (hints != PsiReferenceService.Hints.NO_HINTS) {
      context.put(PsiReferenceService.HINTS, hints);
    }
    boolean suitable = false;
    try {
      suitable = trinity.processingContext.accepts(position, context);
    }
    catch (IndexNotReadyException ignored) {
    }
    if (suitable) {
      list.add(new ProviderInfo<Provider, ProcessingContext>(trinity.provider, context, trinity.priority));
    }
  }
}
 
Example #4
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
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 #5
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static ElementPattern<PsiElement> getTwigMacroNameKnownPattern(String macroName) {

        // {% macro <foo>(user) %}

        //noinspection unchecked
        return PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER).withText(macroName)
            .withParent(PlatformPatterns.psiElement(
                TwigElementTypes.MACRO_TAG
            ))
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText("macro")
            )
            .withLanguage(TwigLanguage.INSTANCE);
    }
 
Example #6
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
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 #7
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static ElementPattern<PsiElement> getIfVariablePattern() {

        // {% if "var" %}

        //noinspection unchecked
        return PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.TAG_NAME).withText(
                    PlatformPatterns.string().oneOfIgnoreCase("if")
                )
            )
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.IF_TAG)
            )
            .withLanguage(TwigLanguage.INSTANCE);
    }
 
Example #8
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-annotation-plugin with MIT License 6 votes vote down vote up
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 #9
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * {% include foo ? '' : '' %}
 * {% extends foo ? '' : '' %}
 */
public static ElementPattern<PsiElement> getTagTernaryPattern(@NotNull IElementType type) {
    //noinspection unchecked
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT)
            .withParent(
                PlatformPatterns.psiElement(type)
            )
            .afterLeafSkipping(
                STRING_WRAP_PATTERN,
                PlatformPatterns.psiElement(TwigTokenTypes.QUESTION)
            )
            .withLanguage(TwigLanguage.INSTANCE),
        PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT)
            .withParent(
                PlatformPatterns.psiElement(type)
            )
            .afterLeafSkipping(
                STRING_WRAP_PATTERN,
                PlatformPatterns.psiElement(TwigTokenTypes.COLON)
            )
            .withLanguage(TwigLanguage.INSTANCE)
    );
}
 
Example #10
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
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 #11
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * Check for {% if foo is "foo foo" %}
 */
public static ElementPattern<PsiElement> getAfterIsTokenWithOneIdentifierLeafPattern() {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement()
        .afterLeafSkipping(
            PlatformPatterns.or(
                PlatformPatterns.psiElement(PsiWhiteSpace.class),
                PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
            ),
            PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER).afterLeafSkipping(PlatformPatterns.psiElement(PsiWhiteSpace.class), PlatformPatterns.or(
                PlatformPatterns.psiElement(TwigTokenTypes.IS),
                PlatformPatterns.psiElement(TwigTokenTypes.NOT)
            ))
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #12
Source File: NamedObjectProviderBinding.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void addMatchingProviders(final PsiElement position,
                                  @Nullable final List<ProviderInfo<Provider, ElementPattern>> providerList,
                                  @Nonnull List<ProviderInfo<Provider, ProcessingContext>> ret,
                                  PsiReferenceService.Hints hints) {
  if (providerList == null) return;

  for (ProviderInfo<Provider, ElementPattern> trinity : providerList) {
    if (hints != PsiReferenceService.Hints.NO_HINTS && !((PsiReferenceProvider)trinity.provider).acceptsHints(position, hints)) {
      continue;
    }

    final ProcessingContext context = new ProcessingContext();
    if (hints != PsiReferenceService.Hints.NO_HINTS) {
      context.put(PsiReferenceService.HINTS, hints);
    }
    boolean suitable = false;
    try {
      suitable = trinity.processingContext.accepts(position, context);
    }
    catch (IndexNotReadyException ignored) {
    }
    if (suitable) {
      ret.add(new ProviderInfo<Provider, ProcessingContext>(trinity.provider, context, trinity.priority));
    }
  }
}
 
Example #13
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
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 #14
Source File: TwigUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
/**
 * Check for {{ include('|')  }}
 *
 * @param functionName twig function name
 */
public static ElementPattern<PsiElement> getPrintBlockFunctionPattern(String... functionName) {
    //noinspection unchecked
    return PlatformPatterns
        .psiElement(TwigTokenTypes.STRING_TEXT)
        .withParent(PlatformPatterns.or(
            PlatformPatterns.psiElement(TwigElementTypes.PRINT_BLOCK),
            PlatformPatterns.psiElement(TwigElementTypes.SET_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.IF_TAG),
            PlatformPatterns.psiElement(TwigElementTypes.FUNCTION_CALL)
        ))
        .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.IDENTIFIER).withText(PlatformPatterns.string().oneOf(functionName))
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #15
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public static ElementPattern<PsiElement> getSetVariablePattern() {

        // {% set count1 = "var" %}

        //noinspection unchecked
        return PlatformPatterns
            .psiElement(TwigTokenTypes.IDENTIFIER)
            .afterLeafSkipping(
                PlatformPatterns.or(
                    PlatformPatterns.psiElement(PsiWhiteSpace.class),
                    PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE)
                ),
                PlatformPatterns.psiElement(TwigTokenTypes.EQ)
            )
            .withParent(
                PlatformPatterns.psiElement(TwigElementTypes.SET_TAG)
            )
            .withLanguage(TwigLanguage.INSTANCE);
    }
 
Example #16
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * 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 #17
Source File: SemServiceImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
private MultiMap<SemKey, NullableFunction<PsiElement, ? extends SemElement>> collectProducers() {
  final MultiMap<SemKey, NullableFunction<PsiElement, ? extends SemElement>> map = MultiMap.createSmart();

  final SemRegistrar registrar = new SemRegistrar() {
    @Override
    public <T extends SemElement, V extends PsiElement> void registerSemElementProvider(SemKey<T> key,
                                                                                        final ElementPattern<? extends V> place,
                                                                                        final NullableFunction<V, T> provider) {
      map.putValue(key, element -> {
        if (place.accepts(element)) {
          return provider.fun((V)element);
        }
        return null;
      });
    }
  };

  for (SemContributorEP contributor : myProject.getExtensions(SemContributor.EP_NAME)) {
    contributor.registerSemProviders(myProject.getInjectingContainer(), registrar);
  }

  return map;
}
 
Example #18
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 6 votes vote down vote up
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 #19
Source File: FluidPatterns.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
public static ElementPattern<PsiElement> getAccessorInIdentifierPattern() {
    return PlatformPatterns.psiElement(FluidTypes.IDENTIFIER)
        .afterLeaf(
            PlatformPatterns.psiElement(FluidTypes.DOT)
        )
        .withParent(
            PlatformPatterns.psiElement(FluidFieldChain.class).afterSibling(PlatformPatterns.psiElement(FluidFieldExpr.class))
        )
        .withLanguage(FluidLanguage.INSTANCE);
}
 
Example #20
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public static ElementPattern<PsiElement> getDocBlockTag() {
    return
        PlatformPatterns.or(
            PlatformPatterns.psiElement()
                .withSuperParent(1, PhpDocPsiElement.class)
                     .withParent(PhpDocComment.class)
            .withLanguage(PhpLanguage.INSTANCE)
        ,
            // all "@<caret>"
            PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TAG_NAME)
                .withLanguage(PhpLanguage.INSTANCE)
        );
}
 
Example #21
Source File: PsiElementUtils.java    From yiistorm with MIT License 5 votes vote down vote up
@Nullable
public static <T extends PsiElement> T getPrevSiblingOfType(@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 #22
Source File: PsiElementUtils.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
public static <T extends PsiElement> T getPrevSiblingOfType(@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 #23
Source File: AnnotationPattern.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
/**
 * Pattern @Foo(Foo::<caret>), @Foo(name=Foo::<caret>)
 */
@NotNull
public static ElementPattern<PsiElement> getDocStaticPattern() {
    return PlatformPatterns.or(
        PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_STATIC),
        PlatformPatterns.psiElement(PhpDocTokenTypes.DOC_TEXT).withText("::") // array lexer workaround having text element in array; WI-32801
    );
}
 
Example #24
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * Only a parameter is valid ", 'foobar' [,)]"
 */
@NotNull
public static PsiElementPattern getParameterAsStringPattern() {
    // string wrapped elements
    ElementPattern[] elementPatterns = {
        PlatformPatterns.psiElement(TwigTokenTypes.WHITE_SPACE),
        PlatformPatterns.psiElement(PsiWhiteSpace.class),
        PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
        PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)
    };

    return PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT)
        .beforeLeafSkipping(PlatformPatterns.or(elementPatterns), PlatformPatterns.or(PlatformPatterns.psiElement(TwigTokenTypes.COMMA), PlatformPatterns.psiElement(TwigTokenTypes.RBRACE)))
        .afterLeafSkipping(PlatformPatterns.or(elementPatterns), PlatformPatterns.psiElement(TwigTokenTypes.COMMA));
}
 
Example #25
Source File: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
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.");
    }

    assertTrue(pattern.accepts(((PhpReference) psiElement).resolve()));
}
 
Example #26
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
public void assertPhpReferenceNotResolveTo(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.");
    }

    assertFalse(pattern.accepts(((PhpReference) psiElement).resolve()));
}
 
Example #27
Source File: CompletionUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #28
Source File: TwigPattern.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
public static ElementPattern<PsiElement> getParentFunctionPattern() {
    return PlatformPatterns
        .psiElement(TwigTokenTypes.IDENTIFIER)
        .withText("parent")
        .beforeLeaf(
            PlatformPatterns.psiElement(TwigTokenTypes.LBRACE)
        )
        .withLanguage(TwigLanguage.INSTANCE);
}
 
Example #29
Source File: FluidPatterns.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public static ElementPattern<? extends PsiElement> inlineArgumentNamePattern() {

        return PlatformPatterns.or(
            /*
             * "{ f:foo(<caret>) }"
             * "{ f:foo(u<caret>) }"
             */
            PlatformPatterns
                .psiElement(FluidTypes.IDENTIFIER)
                .withParent(
                    PlatformPatterns.psiElement(FluidFieldExpr.class).afterSibling(
                        PlatformPatterns.psiElement(FluidViewHelperExpr.class)
                    )
                ),
            /* 2018.1 fallback */
            PlatformPatterns
                .psiElement(FluidTypes.IDENTIFIER)
                .withParent(
                    PlatformPatterns.psiElement(FluidInlineChain.class).withFirstChild(
                        PlatformPatterns.psiElement(FluidViewHelperExpr.class)
                    )
                ),
            /*
             * "{ f:foo(u<caret>:) }"
             */
            PlatformPatterns
                .psiElement(FluidTypes.IDENTIFIER)
                .withParent(
                    PlatformPatterns.psiElement(FluidArgumentKey.class)
                )
        );
    }
 
Example #30
Source File: PsiElementUtils.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@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;
}