Java Code Examples for com.jetbrains.php.lang.psi.elements.StringLiteralExpression#getReferences()

The following examples show how to use com.jetbrains.php.lang.psi.elements.StringLiteralExpression#getReferences() . 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: RouteFoldingBuilder.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public FoldingDescriptor[] buildFoldRegions(@NotNull PsiElement root, @NotNull Document document, boolean quick) {
    FoldingGroup group = FoldingGroup.newGroup("TYPO3Route");

    List<FoldingDescriptor> descriptors = new ArrayList<>();
    Collection<StringLiteralExpression> literalExpressions = PsiTreeUtil.findChildrenOfType(root, StringLiteralExpression.class);

    for (final StringLiteralExpression literalExpression : literalExpressions) {
        for (PsiReference reference : literalExpression.getReferences()) {
            if (reference instanceof RouteReference) {
                String value = literalExpression.getContents();

                FoldingDescriptor descriptor = foldRouteReferenceString(reference, value, group);
                if (descriptor != null) {
                    descriptors.add(descriptor);
                }
            }
        }


    }

    return descriptors.toArray(new FoldingDescriptor[0]);
}
 
Example 2
Source File: ContextReferenceTest.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
public void testCanResolveToAspectClass() {
    myFixture.copyFileToProject("classes.php");

    PsiFile psiFile = myFixture.configureByText("foo.php",
        "<?php\n" +
            "/** @var \\TYPO3\\CMS\\Core\\Context\\Context $context */\n" +
            "$context->getAspect('frontend.u<caret>ser');"
    );

    PsiElement elementAtCaret = psiFile.findElementAt(myFixture.getCaretOffset());
    assertInstanceOf(elementAtCaret.getParent(), StringLiteralExpression.class);

    StringLiteralExpression literalExpression = (StringLiteralExpression) elementAtCaret.getParent();
    for (PsiReference reference : literalExpression.getReferences()) {
        if (reference instanceof ContextReference) {
            PsiElement resolve = reference.resolve();

            assertNotNull(resolve);
            assertInstanceOf(resolve, PhpClass.class);

            return;
        }
    }

    fail("No reference found.");
}
 
Example 3
Source File: RouteAnnotator.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (!TYPO3CMSProjectSettings.getInstance(psiElement.getProject()).pluginEnabled) {
        return;
    }

    if (!TYPO3CMSProjectSettings.getInstance(psiElement.getProject()).routeAnnotatorEnabled) {
        return;
    }

    if (!(psiElement instanceof StringLiteralExpression)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
    String value = literalExpression.getContents();

    if (value.isEmpty()) {
        return;
    }

    for (PsiReference psiReference : literalExpression.getReferences()) {
        if (psiReference instanceof RouteReference) {
            annotateRoute(psiElement, annotationHolder, value);
        }
    }
}