Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil#mergeSignatureResults()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.PhpTypeProviderUtil#mergeSignatureResults() . 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: PhpTypeProviderUtilTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @see PhpTypeProviderUtil#mergeSignatureResults
 */
public void testMergeSignatureResults() {

    Collection<PhpNamedElement> phpNamedElements = new ArrayList<>();
    phpNamedElements.add(PhpElementsUtil.getClassMethod(getProject(), "PhpType\\Bar", "foo"));
    phpNamedElements.add(PhpElementsUtil.getClassMethod(getProject(), "PhpType\\Bar", "bar"));
    phpNamedElements.add(PhpElementsUtil.getClassMethod(getProject(), "PhpType\\Bar", "car"));

    Collection<? extends PhpNamedElement> elements = PhpTypeProviderUtil.mergeSignatureResults(phpNamedElements, PhpElementsUtil.getClass(getProject(), "\\PhpType\\Foo"));
    assertEquals(2, elements.size());
}
 
Example 2
Source File: ObjectRepositoryTypeProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) {
    // get back our original call
    int endIndex = expression.lastIndexOf(TRIM_KEY);
    if(endIndex == -1) {
        return Collections.emptySet();
    }

    String originalSignature = expression.substring(0, endIndex);
    String parameter = expression.substring(endIndex + 1);

    // search for called method
    PhpIndex phpIndex = PhpIndex.getInstance(project);
    Collection<? extends PhpNamedElement> phpNamedElementCollections = PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature);
    if(phpNamedElementCollections.size() == 0) {
        return Collections.emptySet();
    }

    PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next();
    if(!(phpNamedElement instanceof Method)) {
        return phpNamedElementCollections;
    }

    if (!PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, GET_REPOSITORIES_SIGNATURES)) {
        return phpNamedElementCollections;
    }

    // we can also pipe php references signatures and resolve them here
    // overwrite parameter to get string value
    parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter);
    if(parameter == null) {
        return phpNamedElementCollections;
    }

    PhpClass phpClass = EntityHelper.getEntityRepositoryClass(project, parameter);
    if(phpClass == null) {
        // self add :)
        return phpNamedElementCollections;
    }

    return PhpTypeProviderUtil.mergeSignatureResults(phpNamedElementCollections, phpClass);
}
 
Example 3
Source File: ObjectManagerFindTypeProvider.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@Override
public Collection<? extends PhpNamedElement> getBySignature(String expression, Set<String> visited, int depth, Project project) {
    // get back our original call
    int endIndex = expression.lastIndexOf(TRIM_KEY);
    if(endIndex == -1) {
        return Collections.emptySet();
    }

    String originalSignature = expression.substring(0, endIndex);
    String parameter = expression.substring(endIndex + 1);

    // search for called method
    PhpIndex phpIndex = PhpIndex.getInstance(project);
    Collection<? extends PhpNamedElement> phpNamedElementCollections = PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature);
    if(phpNamedElementCollections.size() == 0) {
        return Collections.emptySet();
    }

    PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next();
    if(!(phpNamedElement instanceof Method)) {
        return Collections.emptySet();
    }

    if (!(
        PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Doctrine\\Common\\Persistence\\ObjectManager", "find") ||
        PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Doctrine\\Persistence\\ObjectManager", "find")
    )) {
        return Collections.emptySet();
    }

    parameter = PhpTypeProviderUtil.getResolvedParameter(phpIndex, parameter);
    if(parameter == null) {
        return Collections.emptySet();
    }

    PhpClass phpClass = EntityHelper.resolveShortcutName(project, parameter);
    if(phpClass == null) {
        return Collections.emptySet();
    }

    return PhpTypeProviderUtil.mergeSignatureResults(phpNamedElementCollections, phpClass);
}