Java Code Examples for fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#isMethodInstanceOf()

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#isMethodInstanceOf() . 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: ObjectRepositoryResultTypeProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private Collection<Method> getObjectRepositoryCall(Collection<? extends PhpNamedElement> phpNamedElements) {
    Collection<Method> methods = new HashSet<>();
    for (PhpNamedElement phpNamedElement: phpNamedElements) {
        if(phpNamedElement instanceof Method && PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, FIND_SIGNATURES)) {
            methods.add((Method) phpNamedElement);
        }
    }

    return methods;
}
 
Example 2
Source File: ServiceLineMarkerProvider.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
private void formNameMarker(PsiElement psiElement, Collection<? super RelatedItemLineMarkerInfo> result) {

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

        Method method = PsiTreeUtil.getParentOfType(psiElement, Method.class);
        if(method == null) {
            return;
        }

        if(PhpElementsUtil.isMethodInstanceOf(method, "\\Symfony\\Component\\Form\\FormTypeInterface", "getParent")) {
            // get form string; on blank string we dont need any further action

            String contents = ((StringLiteralExpression) psiElement).getContents();
            if(StringUtils.isBlank(contents)) {
                return;
            }

            PsiElement formPsiTarget = FormUtil.getFormTypeToClass(psiElement.getProject(), contents);
            if(formPsiTarget != null) {
                NavigationGutterIconBuilder<PsiElement> builder = NavigationGutterIconBuilder.create(Symfony2Icons.FORM_TYPE_LINE_MARKER).
                    setTargets(formPsiTarget).
                    setTooltipText("Navigate to form type");

                result.add(builder.createLineMarkerInfo(psiElement));
            }

        }

    }
 
Example 3
Source File: ShopwareApiResourcesTypeProvider.java    From idea-php-shopware-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
    // since phpstorm 7.1.2 we need to validate this
    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 = phpIndex.getBySignature(originalSignature, null, 0);
    if(phpNamedElementCollections.size() == 0) {
        return Collections.emptySet();
    }

    // get first matched item
    PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next();
    if(!(phpNamedElement instanceof Method)) {
        return Collections.emptySet();
    }

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

    // finally search the classes
    if(PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, "\\Shopware\\Components\\Api\\Manager", "getResource")) {
        PhpClass phpClass = ShopwareUtil.getResourceClass(project, parameter);
        if(phpClass != null) {
            return Collections.singletonList(phpClass);
        }
    }

    return phpNamedElementCollections;
}
 
Example 4
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 5
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);
}
 
Example 6
Source File: MethodSignatureTypeProvider.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 null;
    }

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

    PhpIndex phpIndex = PhpIndex.getInstance(project);
    Collection<? extends PhpNamedElement> phpNamedElementCollections = PhpTypeProviderUtil.getTypeSignature(phpIndex, originalSignature);
    if(phpNamedElementCollections.size() == 0) {
        return null;
    }

    // get first matched item
    PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next();
    if(!(phpNamedElement instanceof Method)) {
        return null;
    }

    Collection<MethodSignatureSetting> signatures = getSignatureSettings(phpNamedElement);
    if(signatures.size() == 0) {
        return null;
    }

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

    Collection<PhpNamedElement> phpNamedElements = new ArrayList<>();

    for(MethodSignatureSetting matchedSignature: signatures) {
        for(PhpTypeSignatureInterface signatureTypeProvider: PhpTypeSignatureTypes.DEFAULT_PROVIDER) {
            if( signatureTypeProvider.getName().equals(matchedSignature.getReferenceProviderName()) && PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, matchedSignature.getCallTo(), matchedSignature.getMethodName())) {
                Collection<? extends PhpNamedElement> namedElements = signatureTypeProvider.getByParameter(project, parameter);
                if(namedElements != null) {
                    phpNamedElements.addAll(namedElements);
                }
            }
        }
    }

    // not good but we need return any previous types: null clears all types
    return new ArrayList<>(phpNamedElements);
}
 
Example 7
Source File: SymfonyContainerTypeProvider.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
    // since phpstorm 7.1.2 we need to validate this
    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();
    }

    // get first matched item
    PhpNamedElement phpNamedElement = phpNamedElementCollections.iterator().next();
    if(!(phpNamedElement instanceof Method)) {
        return phpNamedElementCollections;
    }

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

    // finally search the classes
    if(PhpElementsUtil.isMethodInstanceOf((Method) phpNamedElement, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) {
        ContainerService containerService = ContainerCollectionResolver.getService(project, parameter);

        if(containerService != null) {
            Collection<PhpNamedElement> phpClasses = new HashSet<>();

            for (String s : containerService.getClassNames()) {
                phpClasses.addAll(PhpIndex.getInstance(project).getAnyByFQN(s));
            }

            return phpClasses;
        }
    }

    return phpNamedElementCollections;
}