com.jetbrains.php.lang.psi.elements.PhpReference Java Examples

The following examples show how to use com.jetbrains.php.lang.psi.elements.PhpReference. 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: AbstractTestCase.java    From idea-php-typo3-plugin 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 #2
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-toolbox 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 #3
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin 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 #4
Source File: CodeInsightFixtureTestCase.java    From silex-idea-plugin with MIT License 6 votes vote down vote up
protected void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, @NotNull Class aClass, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, aClass);

    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    PhpIndex phpIndex = PhpIndex.getInstance(myFixture.getProject());
    Collection<? extends PhpNamedElement> collection = phpIndex.getBySignature(((PhpReference)psiElement).getSignature(), null, 0);
    assertNotEmpty(collection);

    for (String type : collection.iterator().next().getType().getTypes()) {
        if (type.equals(typeSignature)) {
            return;
        }
    }

    fail("Can't find type: "+typeSignature+", found:"+collection.iterator().next().getType().toString());
}
 
Example #5
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-toolbox 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 #6
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin 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: 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 #8
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 #9
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-annotation-plugin with MIT License 5 votes vote down vote up
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
}
 
Example #10
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-annotation-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 #11
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-annotation-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 #12
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private PsiElement assertGetPhpReference(LanguageFileType languageFileType, String configureByText) {
    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.");
    }

    return psiElement;
}
 
Example #13
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-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 #14
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge with MIT License 5 votes vote down vote up
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
}
 
Example #15
Source File: DrupalLightCodeInsightFixtureTestCase.java    From idea-php-drupal-symfony2-bridge 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 #16
Source File: ShopwareLightCodeInsightFixtureTestCase.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
}
 
Example #17
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-generics-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 #18
Source File: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
}
 
Example #19
Source File: LaravelLightCodeInsightFixtureTestCase.java    From idea-php-laravel-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 #20
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 #21
Source File: CodeInsightFixtureTestCase.java    From silex-idea-plugin with MIT License 5 votes vote down vote up
protected void assertTypeEquals(LanguageFileType languageFileType, @NotNull Class aClass, String configureByText, String phpClassType) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, aClass);

    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    PhpIndex phpIndex = PhpIndex.getInstance(myFixture.getProject());
    Collection<? extends PhpNamedElement> collection = phpIndex.getBySignature(((PhpReference)psiElement).getSignature(), null, 0);
    assertNotEmpty(collection);

    String types = "";

    for (String type : collection.iterator().next().getType().getTypes()) {
        Collection<? extends PhpNamedElement> col = phpIndex.getBySignature(type, null, 0);
        if (col.size() == 0) {
            continue;
        }

        for (String classType : col.iterator().next().getType().getTypes()) {
            types = types + classType + '|';
            if (classType.equals(phpClassType)) {
                return;
            }
        }
    }

    fail("Can't find type: "+phpClassType+", found:"+types);
}
 
Example #22
Source File: PhpDiTypeProvider.java    From phpstorm-phpdi with MIT License 5 votes vote down vote up
@Nullable
@Override
public String getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb()) {
        return null;
    }

    if (!(psiElement instanceof MethodReference)) {
        return null;
    }

    MethodReference methodRef = ((MethodReference) psiElement);

    if (!("get".equals(methodRef.getName()) || "make".equals(methodRef.getName()))) {
        return null;
    }

    if (methodRef.getParameters().length == 0) {
        return null;
    }

    PsiElement firstParam = methodRef.getParameters()[0];

    if (firstParam instanceof PhpReference) {
        PhpReference ref = (PhpReference)firstParam;
        if (ref.getText().toLowerCase().contains("::class")) {
            return methodRef.getSignature() + "%" + ref.getSignature();
        }
    }

    return null;
}
 
Example #23
Source File: AbstractTestCase.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
@NotNull
private PsiElement assertGetPhpReference(LanguageFileType languageFileType, String configureByText) {
    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.");
    }

    return psiElement;
}
 
Example #24
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    myFixture.configureByText(languageFileType, configureByText);
    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    psiElement = PsiTreeUtil.getParentOfType(psiElement, PhpReference.class);
    if (!(psiElement instanceof PhpReference)) {
        fail("Element is not PhpReference.");
    }

    assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
}
 
Example #25
Source File: AnnotationLightCodeInsightFixtureTestCase.java    From idea-php-generics-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 #26
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public void assertPhpReferenceSignatureEquals(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    PsiElement psiElement = assertGetPhpReference(languageFileType, configureByText);
    assertEquals(typeSignature, ((PhpReference) psiElement).getSignature());
}
 
Example #27
Source File: SymfonyLightCodeInsightFixtureTestCase.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
public void assertPhpReferenceSignatureContains(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    PsiElement psiElement = assertGetPhpReference(languageFileType, configureByText);
    assertTrue(((PhpReference) psiElement).getSignature().contains(typeSignature));
}
 
Example #28
Source File: AbstractTestCase.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
public void assertPhpReferenceSignatureContains(LanguageFileType languageFileType, String configureByText, String typeSignature) {
    PsiElement psiElement = assertGetPhpReference(languageFileType, configureByText);
    assertTrue(((PhpReference) psiElement).getSignature().contains(typeSignature));
}