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

The following examples show how to use fr.adrienbrault.idea.symfony2plugin.util.PhpElementsUtil#getClassMethod() . 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: CreateMethodQuickFix.java    From idea-php-shopware-plugin with MIT License 6 votes vote down vote up
private void attachVariablesInScope(@NotNull Project project, StringBuilder stringBuilder) {

        // Events
        if(HookSubscriberUtil.NOTIFY_EVENTS_MAP.containsKey(generatorContainer.getHookName())) {
            Collection<String> references = HookSubscriberUtil.NOTIFY_EVENTS_MAP.get(generatorContainer.getHookName());
            for (String value : references) {
                String[] split = value.split("\\.");
                Method classMethod = PhpElementsUtil.getClassMethod(project, split[0], split[1]);
                if(classMethod == null) {
                    continue;
                }

                buildEventVariables(project, stringBuilder, classMethod);
            }
        } else if(generatorContainer.getHookMethod() != null) {
            // add hook parameter
            Parameter[] hookMethodParameters = generatorContainer.getHookMethod().getParameters();
            if(hookMethodParameters.length > 0 ) {
                stringBuilder.append("\n");
                for(Parameter parameter : hookMethodParameters) {
                    String name = parameter.getName();
                    stringBuilder.append("$").append(name).append(" = ").append("$args->get('").append(name).append("');\n");
                }
            }
        }
    }
 
Example 2
Source File: YamlGoToDeclarationHandler.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
private Collection<PsiElement> classGoToDeclaration(@NotNull PsiElement psiElement, @NotNull String className) {

    Collection<PsiElement> psiElements = new HashSet<>();

    // Class::method
    // Class::FooAction
    // Class:Foo
    if(className.contains(":")) {
        String[] split = className.replaceAll("(:)\\1", "$1").split(":");
        if(split.length == 2) {
            for(String append: new String[] {"", "Action"}) {
                Method classMethod = PhpElementsUtil.getClassMethod(psiElement.getProject(), split[0], split[1] + append);
                if(classMethod != null) {
                    psiElements.add(classMethod);
                }
            }
        }

        return psiElements;
    }

    // ClassName
    psiElements.addAll(PhpElementsUtil.getClassesInterface(psiElement.getProject(), className));
    return psiElements;
}
 
Example 3
Source File: SubscriberIndexUtil.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Nullable
public static Method getMethodForResource(@NotNull Project project, @NotNull ServiceResource resource) {
    String signature = resource.getSignature();
    if(signature == null) {
        return null;
    }

    String[] split = signature.split("\\.");
    if(split.length < 2) {
        return null;
    }

    return PhpElementsUtil.getClassMethod(project, split[0], split[1]);
}
 
Example 4
Source File: CreateMethodQuickFix.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Nullable
public static PsiElement getSubjectTargetOnHook(Project project, final String contents) {

    for(PsiElement psiElement : LazySubscriberReferenceProvider.getHookTargets(project, contents)) {
        if(psiElement instanceof Method) {
            return psiElement;
        } else if(psiElement instanceof PhpClass) {
            return psiElement;
        }
    }

    if(HookSubscriberUtil.NOTIFY_EVENTS_MAP.containsKey(contents)) {
        Collection<String> references = HookSubscriberUtil.NOTIFY_EVENTS_MAP.get(contents);
        for (String value : references) {
            String[] split = value.split("\\.");
            Method classMethod = PhpElementsUtil.getClassMethod(project, split[0], split[1]);
            if(classMethod == null) {
                continue;
            }

            return classMethod;
        }
    }


    return null;
}
 
Example 5
Source File: XmlReferenceContributor.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
@Override
public ResolveResult[] multiResolve(boolean b) {
    Method classMethod = PhpElementsUtil.getClassMethod(getElement().getProject(), aClass, method);
    if(classMethod == null) {
        return new ResolveResult[0];
    }

    return PsiElementResolveResult.createResults(classMethod);
}
 
Example 6
Source File: RouteHelperTest.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
/**
 * @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#getRoutesOnControllerAction
 */
public void testGetRoutesOnControllerAction() {
    myFixture.copyFileToProject("GetRoutesOnControllerAction.php");
    myFixture.copyFileToProject("GetRoutesOnControllerAction.routing.xml");
    myFixture.copyFileToProject("GetRoutesOnControllerAction.services.xml");

    PhpClass phpClass = PhpPsiElementFactory.createPhpPsiFromText(getProject(), PhpClass.class, "<?php\n" +
        "namespace FooBar\\FooBundle\\Controller\\SubFolder" +
        "{\n" +
        "  class FooBarController\n" +
        "  {\n" +
        "     function fooAction() {}\n" +
        "  }\n" +
        "}"
    );

    Method fooAction = phpClass.findMethodByName("fooAction");
    assertNotNull(fooAction);

    List<Route> routesOnControllerAction = RouteHelper.getRoutesOnControllerAction(fooAction);

    assertNotNull(ContainerUtil.find(routesOnControllerAction, route ->
        "xml_route_subfolder_backslash".equals(route.getName())
    ));

    assertNotNull(ContainerUtil.find(routesOnControllerAction, route ->
        "xml_route_subfolder_slash".equals(route.getName())
    ));

    assertNotNull(ContainerUtil.find(routesOnControllerAction, route ->
        "xml_route_subfolder_class_syntax".equals(route.getName())
    ));

    // controller as service
    Method indexAction = PhpElementsUtil.getClassMethod(getProject(), "Service\\Controller\\FooController", "indexAction");
    assertNotNull(indexAction);

    assertNotNull(ContainerUtil.find(RouteHelper.getRoutesOnControllerAction(indexAction), route ->
        "xml_route_as_service".equals(route.getName())
    ));
}