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

The following examples show how to use com.jetbrains.php.lang.psi.elements.Method. 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: XmlServiceInstanceInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void attachMethodInstances(@NotNull PsiElement target, @NotNull String serviceName, @NotNull Method method, int parameterIndex, @NotNull ProblemsHolder holder) {
    Parameter[] constructorParameter = method.getParameters();
    if(parameterIndex >= constructorParameter.length) {
        return;
    }

    String className = constructorParameter[parameterIndex].getDeclaredType().toString();
    PhpClass expectedClass = PhpElementsUtil.getClassInterface(method.getProject(), className);
    if(expectedClass == null) {
        return;
    }

    PhpClass serviceParameterClass = ServiceUtil.getResolvedClassDefinition(method.getProject(), serviceName);
    if(serviceParameterClass != null && !PhpElementsUtil.isInstanceOf(serviceParameterClass, expectedClass)) {
        holder.registerProblem(
            target,
            "Expect instance of: " + expectedClass.getPresentableFQN(),
            ProblemHighlightType.GENERIC_ERROR_OR_WARNING,
            new XmlServiceSuggestIntentionAction(expectedClass.getFQN(), target)
        );
    }
}
 
Example #2
Source File: TwigUtilTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void testGetControllerMethodShortcutForInvoke() {
    myFixture.copyFileToProject("controller_method.php");

    myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
        "namespace FooBundle\\Controller;\n" +
        "class FoobarController\n" +
        "{\n" +
        "   public function __in<caret>voke() {}\n" +
        "" +
        "}\n"
    );

    PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());

    List<String> strings = Arrays.asList(TwigUtil.getControllerMethodShortcut((Method) psiElement.getParent()));

    assertContainsElements(strings, "FooBundle::foobar.html.twig");
    assertContainsElements(strings, "FooBundle::foobar.json.twig");
    assertContainsElements(strings, "FooBundle::foobar.xml.twig");
}
 
Example #3
Source File: FormFieldResolver.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private static void attachFormFields(@Nullable MethodReference methodReference, @NotNull Collection<TwigTypeContainer> targets) {
    if(methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(
        methodReference,
        new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "createForm"),
        new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\ControllerTrait", "createForm"),
        new MethodMatcher.CallToSignature("\\Symfony\\Bundle\\FrameworkBundle\\Controller\\AbstractController", "createForm")
    )) {
        PsiElement formType = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, 0);
        if(formType != null) {
            PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(formType);

            if(phpClass == null) {
                return;
            }

            Method method = phpClass.findMethodByName("buildForm");
            if(method == null) {
                return;
            }

            targets.addAll(getTwigTypeContainer(method));
        }
    }
}
 
Example #4
Source File: PhpMatcherTest.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
public void testVariadicSignatureRegistrarMatcher() {
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n _variadic('<caret>')", "foo");
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n _variadic(null, '<caret>')", "foo");
    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n _variadic('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format"));

    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n _variadic('<caret>')", "foo");
    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n _variadic('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format"));

    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n new \\Foo\\Variadic('<caret>')", "foo");
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n new \\Foo\\Variadic(null, '<caret>')", "foo");
    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n new \\Foo\\Variadic('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format"));

    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n /** @var $f \\Foo\\Variadic */\n $f->getFoo('<caret>')", "foo");
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n /** @var $f \\Foo\\Variadic */\n $f->getFoo(null, '<caret>')", "foo");
    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n /** @var $f \\Foo\\Variadic */\n $f->getFoo('foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format"));
}
 
Example #5
Source File: Symfony2InterfacesUtil.java    From Thinkphp5-Plugin with MIT License 6 votes vote down vote up
protected boolean isCallTo(Method e, Method[] expectedMethods) {

        PhpClass methodClass = e.getContainingClass();
        if (methodClass == null) {
            return false;
        }

        for (Method expectedMethod : expectedMethods) {

            // @TODO: its stuff from beginning times :)
            if (expectedMethod == null) {
                continue;
            }

            PhpClass containingClass = expectedMethod.getContainingClass();
            if (containingClass != null && expectedMethod.getName().equals(e.getName()) && isInstanceOf(methodClass, containingClass)) {
                return true;
            }
        }

        return false;
    }
 
Example #6
Source File: EelProvider.java    From intellij-neos with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) {
    Project project = parameters.getPosition().getProject();
    Collection<String> contexts = FileBasedIndex.getInstance().getAllKeys(DefaultContextFileIndex.KEY, project);

    for (String eelHelper : contexts) {
        List<String> helpers = FileBasedIndex.getInstance().getValues(DefaultContextFileIndex.KEY, eelHelper, GlobalSearchScope.allScope(project));
        if (!helpers.isEmpty()) {
            for (String helper : helpers) {
                Collection<PhpClass> classes = PhpIndex.getInstance(project).getClassesByFQN(helper);
                for (PhpClass phpClass : classes) {
                    for (Method method : phpClass.getMethods()) {
                        if (!method.getAccess().isPublic()) {
                            continue;
                        }
                        if (method.getName().equals("allowsCallOfMethod")) {
                            continue;
                        }
                        String completionText = eelHelper + "." + method.getName() + "()";
                        result.addElement(LookupElementBuilder.create(completionText).withIcon(PhpIcons.METHOD_ICON));
                    }
                }
            }
        }
    }
}
 
Example #7
Source File: PhpTypeProviderUtilTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @see PhpTypeProviderUtil#getResolvedParameter
 */
public void testGetTypeSignature() {
    Function<PhpNamedElement, String> func = phpNamedElement ->
        phpNamedElement instanceof Method ? ((Method) phpNamedElement).getContainingClass().getFQN() : null;

    ArrayList<? extends PhpNamedElement> typeSignature = new ArrayList<PhpNamedElement>(PhpTypeProviderUtil.getTypeSignature(
        PhpIndex.getInstance(getProject()),
        "#M#C\\Doctrine\\Common\\Persistence\\ObjectManager.getRepository|#M#C\\Doctrine\\Common\\Persistence\\ObjectFoo.getRepository"
    ));

    assertContainsElements(ContainerUtil.map(typeSignature, func), "\\Doctrine\\Common\\Persistence\\ObjectManager", "\\Doctrine\\Common\\Persistence\\ObjectFoo");

    typeSignature = new ArrayList<PhpNamedElement>(PhpTypeProviderUtil.getTypeSignature(
        PhpIndex.getInstance(getProject()),
        "#M#C\\Doctrine\\Common\\Persistence\\ObjectManager.getRepository"
    ));
    assertContainsElements(ContainerUtil.map(typeSignature, func), "\\Doctrine\\Common\\Persistence\\ObjectManager");
}
 
Example #8
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 6 votes vote down vote up
protected boolean isCallTo(Method e, Method[] expectedMethods) {

        PhpClass methodClass = e.getContainingClass();
        if(methodClass == null) {
            return false;
        }

        for (Method expectedMethod : expectedMethods) {

            // @TODO: its stuff from beginning times :)
            if(expectedMethod == null) {
                continue;
            }

            PhpClass containingClass = expectedMethod.getContainingClass();
            if (containingClass != null && expectedMethod.getName().equalsIgnoreCase(e.getName()) && isInstanceOf(methodClass, containingClass)) {
                return true;
            }
        }

        return false;
    }
 
Example #9
Source File: RouteHelperTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#convertMethodToRouteShortcutControllerName
 */
public void testConvertMethodToRouteShortcutControllerForInvoke()
{
    myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("GetRoutesOnControllerAction.php"));

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

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

    assertEquals("FooBar\\FooBundle\\Controller\\FooBarController", RouteHelper.convertMethodToRouteShortcutControllerName(fooAction));
}
 
Example #10
Source File: PhpEventDispatcherGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<PsiElement> getPsiTargets(PsiElement element) {

    PsiElement parent = element.getParent();
    if(!(parent instanceof StringLiteralExpression)) {
        return Collections.emptyList();
    }

    String contents = ((StringLiteralExpression) parent).getContents();
    if(StringUtils.isBlank(contents)) {
        return Collections.emptyList();
    }

    Method method = phpClass.findMethodByName(contents);
    if(method != null) {
        return new ArrayList<>(Collections.singletonList(method));
    }

    return Collections.emptyList();
}
 
Example #11
Source File: YamlXmlServiceInstanceInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
/**
 * class: FooClass
 * tags:
 *  - [ setFoo, [@args_bar] ]
 */
private void visitCall(PsiElement psiElement) {
    PsiElement yamlScalar = psiElement.getContext();
    if(!(yamlScalar instanceof YAMLScalar)) {
        return;
    }

    YamlHelper.visitServiceCallArgument((YAMLScalar) yamlScalar, visitor -> {
        PhpClass serviceClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), visitor.getClassName(), getLazyServiceCollector(psiElement.getProject()));
        if(serviceClass == null) {
            return;
        }

        Method method = serviceClass.findMethodByName(visitor.getMethod());
        if (method == null) {
            return;
        }

        YamlXmlServiceInstanceInspection.registerInstanceProblem(psiElement, holder, visitor.getParameterIndex(), method, getLazyServiceCollector(psiElement.getProject()));
    });
}
 
Example #12
Source File: Symfony2InterfacesUtil.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
/**
 * Single resolve doesnt work if we have non unique class names in project context,
 * so try a multiResolve and use first matched method
 */
@Nullable
public static Method getMultiResolvedMethod(PsiReference psiReference) {

    // class be unique in normal case, so try this first
    PsiElement resolvedReference = psiReference.resolve();
    if (resolvedReference instanceof Method) {
        return (Method) resolvedReference;
    }

    // try multiResolve if class exists twice in project
    if(psiReference instanceof PsiPolyVariantReference) {
        for(ResolveResult resolveResult : ((PsiPolyVariantReference) psiReference).multiResolve(false)) {
            PsiElement element = resolveResult.getElement();
            if(element instanceof Method) {
                return (Method) element;
            }
        }
    }

    return null;
}
 
Example #13
Source File: YamlGoToDeclarationHandlerTest.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
public void testThatNavigationForControllerInvokeMethodIsAvailable() {
    myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
        "class Foobar\n" +
        "{\n" +
        "   public function __invoke() {}\n" +
        "}\n"
    );

    assertNavigationMatch("routing.yml", "" +
            "foobar:\n" +
            "    defaults:\n" +
            "       _controller: Foo<caret>bar\n",
        PlatformPatterns.psiElement(Method.class)
    );

    assertNavigationMatch("routing.yml", "" +
        "foobar:\n" +
        "    controller: Foo<caret>bar\n" +
        PlatformPatterns.psiElement(Method.class)
    );
}
 
Example #14
Source File: PhpEventDispatcherGotoCompletionRegistrar.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public Collection<LookupElement> getLookupElements() {

    Collection<LookupElement> elements = new ArrayList<>();

    for(Method method: phpClass.getMethods()) {
        if(method.getAccess().isPublic()) {
            String name = method.getName();
            if(!"getSubscribedEvents".equals(name) && !name.startsWith("__") && !name.startsWith("set")) {
                elements.add(LookupElementBuilder.create(name).withIcon(method.getIcon()));
            }
        }
    }

    return elements;
}
 
Example #15
Source File: YamlGoToDeclarationHandler.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
private Collection<PsiElement> getTagMethodGoto(@NotNull PsiElement psiElement) {
    String methodName = PsiElementUtils.trimQuote(psiElement.getText());
    if(StringUtils.isBlank(methodName)) {
        return Collections.emptyList();
    }

    String classValue = YamlHelper.getServiceDefinitionClassFromTagMethod(psiElement);
    if(classValue == null) {
        return Collections.emptyList();
    }

    PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(psiElement.getProject(), classValue);
    if(phpClass == null) {
        return Collections.emptyList();
    }

    Method method = phpClass.findMethodByName(methodName);
    if(method != null) {
        return Collections.singletonList(method);
    }

    return Collections.emptyList();
}
 
Example #16
Source File: ControllerReferencesTest.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
public void testRouteGroupsStartsWithBackslashRemovesFirstChar() {
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n" +
            "Route::group(['namespace' => '\\Foo\\Controllers'], function() {\n" +
            "    Route::get('/', '<caret>');\n" +
            "});",
        "BarController@foo"
    );

    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n" +
            "Route::group(['namespace' => '\\Foo\\Controllers'], function() {\n" +
            "    Route::get('/', 'BarController@foo<caret>');\n" +
            "});",
        PlatformPatterns.psiElement(Method.class).withParent(
            PlatformPatterns.psiElement(PhpClass.class).withName("BarController")
        )
    );
}
 
Example #17
Source File: TemplateAnnotationTypeProviderTest.java    From idea-php-generics-plugin with MIT License 6 votes vote down vote up
public void testTypesForFunctionWithClassString() {
    assertPhpReferenceResolveTo(PhpFileType.INSTANCE,
        "<?php\n instantiator(\\Foobar\\Foobar::class)->get<caret>Foo();\n",
        PlatformPatterns.psiElement(Method.class).withName("getFoo")
    );

    assertPhpReferenceResolveTo(PhpFileType.INSTANCE,
        "<?php\n instantiator2('', \\Foobar\\Foobar::class, '')->get<caret>Foo();\n",
        PlatformPatterns.psiElement(Method.class).withName("getFoo")
    );

    assertPhpReferenceNotResolveTo(PhpFileType.INSTANCE,
        "<?php\n instantiator2('', '', \\Foobar\\Foobar::class)->get<caret>Foo();\n",
        PlatformPatterns.psiElement(Method.class).withName("getFoo")
    );
}
 
Example #18
Source File: ClassPublicMethodReference.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
@Deprecated
public Object[] getVariants() {

    PhpClass phpClass = ServiceUtil.getResolvedClassDefinition(getElement().getProject(), this.className);
    if(phpClass == null) {
        return new Object[0];
    }

    List<LookupElement> lookupElements = new ArrayList<>();
    for(Method publicMethod: PhpElementsUtil.getClassPublicMethod(phpClass)) {
        lookupElements.add(new PhpLookupElement(publicMethod));
    }

    return lookupElements.toArray();
}
 
Example #19
Source File: PhpMatcherTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
public void testThatParameterIndexStartsByZero() {
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n parameter('', '<caret>')", "bar", "car");
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n parameter(null, '<caret>')", "bar", "foo");

    assertCompletionNotContains(PhpFileType.INSTANCE, "<?php\n parameter('', '', '<caret>')", "bar", "car");
    assertCompletionNotContains(PhpFileType.INSTANCE, "<?php\n parameter('<caret>'', '')", "bar", "car");

    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n parameter('', 'foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format"));
    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n parameter(null, 'foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format"));

    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n/** @var $f \\Foo\\Parameter */\n$f->getFoo('', '<caret>')", "bar", "foo");
    assertCompletionContains(PhpFileType.INSTANCE, "<?php\n/** @var $f \\Foo\\Parameter */\n$f->getFoo(null, '<caret>')", "bar", "foo");

    assertNavigationMatch(PhpFileType.INSTANCE, "<?php\n/** @var $f \\Foo\\Parameter */\n$f->getFoo(null, 'foo<caret>')", PlatformPatterns.psiElement(Method.class).withName("format"));
}
 
Example #20
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
public boolean isTemplatingRenderCall(PsiElement e) {
    return isCallTo(e, new Method[] {
        getInterfaceMethod(e.getProject(), "\\Symfony\\Component\\Templating\\EngineInterface", "render"),
        getInterfaceMethod(e.getProject(), "\\Symfony\\Component\\Templating\\StreamingEngineInterface", "stream"),
        getInterfaceMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface", "renderResponse"),
        getClassMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "render"),
        getClassMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "renderView"),
        getClassMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "stream"),
    });
}
 
Example #21
Source File: ServiceBuilderTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@NotNull
private List<MethodParameter.MethodModelParameter> getMethodModelParameters() {
    PhpClass anyByFQN = PhpIndex.getInstance(getProject()).getAnyByFQN("\\Foo\\Bar").iterator().next();

    Method constructor = anyByFQN.getConstructor();
    assertNotNull(constructor);

    Parameter parameter = constructor.getParameters()[0];

    return Collections.singletonList(
        new MethodParameter.MethodModelParameter(constructor, parameter, 0, new HashSet<>(Collections.singletonList("foobar")), "foobar")
    );
}
 
Example #22
Source File: RouteHelperTest.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
/**
 * @see fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper#convertMethodToRouteShortcutControllerName
 */
public void testConvertMethodToRouteShortcutControllerName() {
    myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("GetRoutesOnControllerAction.php"));

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

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

    assertEquals("FooBarFooBundle:FooBar:foo", RouteHelper.convertMethodToRouteShortcutControllerName(fooAction));

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

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

    assertEquals("FooBarFooBundle:SubFolder\\Sub:foo", RouteHelper.convertMethodToRouteShortcutControllerName(fooAction));
}
 
Example #23
Source File: ExtbaseModelCollectionReturnTypeProviderTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testResolvesObjectStoragePropertiesToObjectTypes() {
    myFixture.copyFileToProject("PersistenceMocks.php");
    myFixture.configureByFile("FieldTypeProvider.php");

    int caretOffset = myFixture.getCaretOffset();
    PsiElement elementAtCaret = myFixture.getFile().findElementAt(caretOffset).getParent();

    assertInstanceOf(elementAtCaret, MethodReference.class);

    MethodReference methodReference = (MethodReference) elementAtCaret;
    Method m = (Method) methodReference.resolve();

    String fqn = m.getContainingClass().getFQN();
    assertTrue(fqn.equals("\\My\\Extension\\Domain\\Model\\Book"));
}
 
Example #24
Source File: Symfony2InterfacesUtil.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
public boolean isTemplatingRenderCall(PsiElement e) {
    return isCallTo(e, new Method[] {
        getInterfaceMethod(e.getProject(), "\\Symfony\\Component\\Templating\\EngineInterface", "render"),
        getInterfaceMethod(e.getProject(), "\\Symfony\\Component\\Templating\\StreamingEngineInterface", "stream"),
        getInterfaceMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Templating\\EngineInterface", "renderResponse"),
        getClassMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "render"),
        getClassMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "renderView"),
        getClassMethod(e.getProject(), "\\Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller", "stream"),
    });
}
 
Example #25
Source File: ObjectManagerTypeProviderTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testIssue305() {
    myFixture.copyFileToProject("classes.php");

    assertPhpReferenceResolveTo(PhpFileType.INSTANCE,
        "<?php\n" +
            "/** @var $objectManager \\TYPO3\\CMS\\Extbase\\Object\\ObjectManagerInterface */\n" +
            "$dataMapper = $objectManager->get(\\TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Mapper\\DataMapper::class);\n" +
            "$dataMapper->ma<caret>p();",
        PlatformPatterns.psiElement(Method.class).withName("map")
    );
}
 
Example #26
Source File: GeneralUtilityServiceTypeProviderTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testCanResolveTypeFromMakeInstanceCall() {
    myFixture.copyFileToProject("classes.php");
    myFixture.addFileToProject("foo/ext_emconf.php", "");
    myFixture.copyFileToProject("ext_localconf_add_service.php", "foo/ext_localconf.php");

    assertPhpReferenceResolveTo(PhpFileType.INSTANCE,
        "<?php\n" +
            "$instance = \\TYPO3\\CMS\\Core\\Utility\\GeneralUtility::makeInstanceService(\"translator\");\n" +
            "$tree = $instance->tre<caret>e();",
        PlatformPatterns.psiElement(Method.class).withName("tree")
    );
}
 
Example #27
Source File: UserFuncReferenceTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testReferenceCanResolveDefinition() {
    myFixture.copyFileToProject("classes.php");

    assertResolvesTo(
            "bar.php",
            "<?php \n['userFunc' => 'Foo\\Bar->q<caret>ux'];",
            UserFuncReference.class,
            Method.class,
            "A class method can be resolved"
    );

    assertResolvesTo(
            "bar.php",
            "<?php \n['userFunc' => 'coun<caret>t'];",
            UserFuncReference.class,
            Function.class,
            "A global function can be resolved"
    );

    assertResolvesTo(
            "bar.php",
            "<?php \n['userFunc' => 'user_calc_my_stuf<caret>f'];",
            UserFuncReference.class,
            Function.class,
            "A global function can be resolved"
    );

    assertResolvesTo(
            "bar.php",
            "<?php \n['userFunc' => Foo\\Bar::class . '->q<caret>ux'];",
            UserFuncReference.class,
            Method.class,
            "A class method can be resolved through concatenation"
    );
}
 
Example #28
Source File: SignalDispatcherReferenceContributorTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testReferenceCanBeResolvedWithStringClassReference() {
    myFixture.copyFileToProject("classes.php");

    configureSignalSlotConnect(
        "'\\TYPO3\\CMS\\Core\\Core\\ClassLoadingInformation'",
        "'dumpClassLoadingInformat<caret>ion'"
    );

    PsiElement elementAtCaret = myFixture.getElementAtCaret();
    assertNotNull(elementAtCaret);
    assertInstanceOf(elementAtCaret, Method.class);
    assertEquals("dumpClassLoadingInformation", ((Method) elementAtCaret).getName());
}
 
Example #29
Source File: SignalDispatcherReferenceContributorTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testReferenceCanBeResolvedWithClassConstantReference() {
    myFixture.copyFileToProject("classes.php");

    configureSignalSlotConnect(
        "\\TYPO3\\CMS\\Core\\Core\\ClassLoadingInformation::class",
        "'dumpClassLoadingInformat<caret>ion'"
    );

    PsiElement elementAtCaret = myFixture.getElementAtCaret();
    assertNotNull(elementAtCaret);
    assertInstanceOf(elementAtCaret, Method.class);
    assertEquals("dumpClassLoadingInformation", ((Method) elementAtCaret).getName());
}
 
Example #30
Source File: PhpToolboxTypeProviderTest.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
public void testPhpTypeForFunctions() {
    assertPhpReferenceResolveTo(PhpFileType.INSTANCE, "<?php\n" +
        "car('', 'datetime')->for<caret>mat()",
        PlatformPatterns.psiElement(Method.class).withName("format")
    );

    assertPhpReferenceResolveTo(PhpFileType.INSTANCE, "<?php\n" +
        "car('', \\Foo\\Bar::DATETIME)->for<caret>mat()",
        PlatformPatterns.psiElement(Method.class).withName("format")
    );
}