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

The following examples show how to use com.jetbrains.php.lang.psi.elements.MethodReference. 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: PhpTranslationDomainInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void invoke(@NotNull ProblemsHolder holder, @NotNull PsiElement psiElement) {
    if (!(psiElement instanceof StringLiteralExpression) || !(psiElement.getContext() instanceof ParameterList)) {
        return;
    }

    ParameterList parameterList = (ParameterList) psiElement.getContext();

    PsiElement methodReference = parameterList.getContext();
    if (!(methodReference instanceof MethodReference)) {
        return;
    }

    if (!PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, TranslationUtil.PHP_TRANSLATION_SIGNATURES)) {
        return;
    }

    int domainParameter = 2;
    if("transChoice".equals(((MethodReference) methodReference).getName())) {
        domainParameter = 3;
    }

    ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(psiElement);
    if(currentIndex != null && currentIndex.getIndex() == domainParameter) {
        annotateTranslationDomain((StringLiteralExpression) psiElement, holder);
    }
}
 
Example #2
Source File: BladePsiUtil.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
public static boolean isDirectiveWithInstance(@NotNull PsiElement psiElement, @NotNull String clazz, @NotNull String method) {
    PsiElement stringLiteral = psiElement.getParent();
    if(stringLiteral instanceof StringLiteralExpression) {
        PsiElement parameterList = stringLiteral.getParent();
        if(parameterList instanceof ParameterList) {
            PsiElement methodReference = parameterList.getParent();
            if(methodReference instanceof MethodReference && method.equals(((MethodReference) methodReference).getName())) {
                String text = methodReference.getText();
                int i = text.indexOf(":");
                // method resolve dont work; extract class name from text "Foo::method(..."
                return i > 0 && StringUtils.stripStart(text.substring(0, i), "\\").equals(clazz);
            }
        }
    }

    return false;
}
 
Example #3
Source File: RouteGroupUtil.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
@Override
public boolean value(PsiElement psiElement) {

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

    MethodReference methodReference = (MethodReference) psiElement;

    if (!"group".equals(methodReference.getName())) {
        return false;
    }

    if(methodReference.getClassReference() == null || methodReference.getClassReference().getName() == null) {
        return false;
    }

    return availableClasses.contains(PhpElementsUtil.getFullClassName(methodReference, methodReference.getClassReference().getName()));
}
 
Example #4
Source File: CaseSensitivityServiceInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private void phpVisitor(final @NotNull ProblemsHolder holder, @NotNull PsiFile psiFile) {

        psiFile.acceptChildren(new PsiRecursiveElementVisitor() {
            @Override
            public void visitElement(PsiElement element) {
                PsiElement parent = element.getParent();
                if(!(parent instanceof StringLiteralExpression)) {
                    super.visitElement(element);
                    return;
                }

                MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter(element);
                if (methodReference != null && PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) {
                    String serviceName = ((StringLiteralExpression) parent).getContents();
                    if(StringUtils.isNotBlank(serviceName) && !serviceName.equals(serviceName.toLowerCase())) {
                        holder.registerProblem(element, SYMFONY_LOWERCASE_LETTERS_FOR_SERVICE, ProblemHighlightType.WEAK_WARNING);
                    }
                }

                super.visitElement(element);
            }
        });
    }
 
Example #5
Source File: GeneralUtilityTypeProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb() || !TYPO3CMSProjectSettings.isEnabled(psiElement)) {
        return null;
    }

    if (!(psiElement instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "makeInstance")) {
        return null;
    }

    MethodReference methodReference = (MethodReference) psiElement;

    String signature = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter(methodReference, TRIM_KEY);
    return  signature == null ? null : new PhpType().add("#" + getKey() + signature);
}
 
Example #6
Source File: PsiElementUtils.java    From yiistorm with MIT License 6 votes vote down vote up
@Nullable
public static MethodReference getMethodReferenceWithFirstStringParameter(PsiElement psiElement) {
    if (!PlatformPatterns.psiElement()
            .withParent(StringLiteralExpression.class).inside(ParameterList.class)
            .withLanguage(PhpLanguage.INSTANCE).accepts(psiElement)) {

        return null;
    }

    ParameterList parameterList = PsiTreeUtil.getParentOfType(psiElement, ParameterList.class);
    if (parameterList == null) {
        return null;
    }

    if (!(parameterList.getContext() instanceof MethodReference)) {
        return null;
    }

    return (MethodReference) parameterList.getContext();
}
 
Example #7
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 #8
Source File: Util.java    From Thinkphp5-Plugin with MIT License 6 votes vote down vote up
public static PhpClass getInstanseClass(Project project, MethodReference methodRef) {
    Set<String> types = methodRef.getDeclaredType().getTypes();
    if (types.size() == 0) return null;
    String classType = null;
    for (String type : types) {
        if (type.contains("\\model\\")) {
            classType = type;
            break;
        }
    }
    if (classType == null) return null;
    String classFQN = classType.substring(classType.indexOf("\\"), classType.indexOf("."));
    Collection<PhpClass> classesByFQN = PhpIndex.getInstance(project).getClassesByFQN(classFQN);
    if (classesByFQN.size() == 0) return null;
    else
        return classesByFQN.iterator().next();
}
 
Example #9
Source File: MethodArgumentDroppedMatcherInspection.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiElementVisitor buildRealVisitor(@NotNull ProblemsHolder problemsHolder, boolean b) {
    return new PhpElementVisitor() {
        @Override
        public void visitPhpMethodReference(MethodReference reference) {
            ParameterList parameterList = reference.getParameterList();
            PhpExpression classReference = reference.getClassReference();
            if (classReference != null) {
                PhpType inferredType = classReference.getInferredType();
                String compiledClassMethodKey = inferredType.toString() + "->" + reference.getName();
                if (ExtensionScannerUtil.classMethodHasDroppedArguments(reference.getProject(), compiledClassMethodKey)) {
                    int maximumNumberOfArguments = ExtensionScannerUtil.getMaximumNumberOfArguments(reference.getProject(), compiledClassMethodKey);

                    if (parameterList != null && maximumNumberOfArguments != -1 && parameterList.getParameters().length != maximumNumberOfArguments) {
                        problemsHolder.registerProblem(reference, "Number of arguments changes with upcoming TYPO3 version, consider refactoring");
                    }
                }
            }

            super.visitPhpMethodReference(reference);
        }
    };
}
 
Example #10
Source File: BladeDirectiveReferences.java    From idea-php-laravel-plugin with MIT License 6 votes vote down vote up
private boolean isDirectiveWithName(PsiElement psiElement, String directiveName) {
    PsiElement stringLiteral = psiElement.getParent();
    if(stringLiteral instanceof StringLiteralExpression) {
        PsiElement parameterList = stringLiteral.getParent();
        if(parameterList instanceof ParameterList) {
            PsiElement methodReference = parameterList.getParent();
            if(methodReference instanceof MethodReference) {
                String name = ((MethodReference) methodReference).getName();
                if(name != null && name.equalsIgnoreCase(directiveName)) {
                    return true;
                }
            }
        }
    }

    return false;
}
 
Example #11
Source File: IconAnnotator.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Override
public void annotate(@NotNull PsiElement psiElement, @NotNull AnnotationHolder annotationHolder) {
    if (!TYPO3CMSProjectSettings.getInstance(psiElement.getProject()).pluginEnabled) {
        return;
    }

    if (!TYPO3CMSProjectSettings.getInstance(psiElement.getProject()).iconAnnotatorEnabled) {
        return;
    }

    if (!stringParameterInMethodReference().accepts(psiElement)) {
        return;
    }

    StringLiteralExpression literalExpression = (StringLiteralExpression) psiElement;
    String value = literalExpression.getContents();

    if (value.isEmpty()) {
        return;
    }

    PsiElement methodReference = PsiTreeUtil.getParentOfType(psiElement, MethodReference.class);
    if (PhpElementsUtil.isMethodWithFirstStringOrFieldReference(methodReference, "getIcon")) {
        annotateIconUsage(psiElement, annotationHolder, value);
    }
}
 
Example #12
Source File: ContainerBuilderStubIndex.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public boolean processAccessVariableInstruction(PhpAccessVariableInstruction instruction) {
    if (instruction.getAccess().isWrite() || instruction.getAccess().isWriteRef() ||
            !containerParameters.contains(instruction.getVariableName())) return true;
    
    MethodReference methodReference = 
            ObjectUtils.tryCast(instruction.getAnchor().getParent(), MethodReference.class);
    if (methodReference == null || !METHODS.contains(methodReference.getName())) return true;
    
    String value = PhpElementsUtil.getFirstArgumentStringValue(methodReference);
    if (value == null) return true;
    
    String methodName = methodReference.getName();
    map.computeIfAbsent(methodName, name -> new ContainerBuilderCall());
    map.get(methodName).addParameter(value);
    
    return true;
}
 
Example #13
Source File: FormFieldResolver.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
private static List<TwigTypeContainer> getTwigTypeContainer(Method method) {
    MethodReference[] formBuilderTypes = FormUtil.getFormBuilderTypes(method);
    List<TwigTypeContainer> twigTypeContainers = new ArrayList<>();

    for(MethodReference methodReference: formBuilderTypes) {

        String fieldName = PsiElementUtils.getMethodParameterAt(methodReference, 0);
        PsiElement psiElement = PsiElementUtils.getMethodParameterPsiElementAt(methodReference, 1);
        TwigTypeContainer twigTypeContainer = new TwigTypeContainer(fieldName);

        // find form field type
        if(psiElement != null) {
            PhpClass phpClass = FormUtil.getFormTypeClassOnParameter(psiElement);
            if(phpClass != null) {
                twigTypeContainer.withDataHolder(new FormDataHolder(phpClass));
            }
        }

        twigTypeContainers.add(twigTypeContainer);
    }

    return twigTypeContainers;
}
 
Example #14
Source File: ServiceDeprecatedClassesInspection.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@Override
public void visitElement(PsiElement element) {
    MethodReference methodReference = PsiElementUtils.getMethodReferenceWithFirstStringParameter(element);
    if (methodReference == null || !PhpElementsUtil.isMethodReferenceInstanceOf(methodReference, ServiceContainerUtil.SERVICE_GET_SIGNATURES)) {
        super.visitElement(element);
        return;
    }

    PsiElement psiElement = element.getParent();
    if(!(psiElement instanceof StringLiteralExpression)) {
        super.visitElement(element);
        return;
    }

    String contents = ((StringLiteralExpression) psiElement).getContents();
    if(StringUtils.isNotBlank(contents)) {
        this.problemRegistrar.attachDeprecatedProblem(element, contents, holder);
        this.problemRegistrar.attachServiceDeprecatedProblem(element, contents, holder);
    }

    super.visitElement(element);
}
 
Example #15
Source File: PhpStringLiteralExpressionReference.java    From idea-php-symfony2-plugin with MIT License 6 votes vote down vote up
@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
    if (!Symfony2ProjectComponent.isEnabled(psiElement) || !(psiElement.getContext() instanceof ParameterList)) {
        return new PsiReference[0];
    }

    ParameterList parameterList = (ParameterList) psiElement.getContext();
    PsiElement methodReference = parameterList.getContext();
    if (!(methodReference instanceof MethodReference)) {
        return new PsiReference[0];
    }

    for(Call call: this.oneOfCall) {
        if (PhpElementsUtil.isMethodReferenceInstanceOf((MethodReference) methodReference, call.getClassName(), call.getMethodName()) && PsiElementUtils.getParameterIndexValue(psiElement) == call.getIndex()) {
            return this.getPsiReferenceBase(psiElement);
        }
    }

    return new PsiReference[0];
}
 
Example #16
Source File: ContextTypeProvider.java    From idea-php-typo3-plugin with MIT License 6 votes vote down vote up
@Nullable
@Override
public PhpType getType(PsiElement psiElement) {
    if (DumbService.getInstance(psiElement.getProject()).isDumb() || !TYPO3CMSProjectSettings.isEnabled(psiElement)) {
        return null;
    }

    if (!(psiElement instanceof MethodReference) || !PhpElementsUtil.isMethodWithFirstStringOrFieldReference(psiElement, "getAspect")) {
        return null;
    }

    MethodReference methodReference = (MethodReference) psiElement;
    if (methodReference.getParameters().length == 0) {
        return null;
    }

    PsiElement firstParam = methodReference.getParameters()[0];
    if (firstParam instanceof StringLiteralExpression) {
        StringLiteralExpression contextAlias = (StringLiteralExpression) firstParam;
        if (!contextAlias.getContents().isEmpty()) {
            return new PhpType().add("#" + this.getKey() + contextAlias.getContents());
        }
    }

    return null;
}
 
Example #17
Source File: MethodMatcher.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
public MethodMatchParameter match() {
    if (!Symfony2ProjectComponent.isEnabled(psiElement)) {
        return null;
    }

    MethodReferenceBag bag = PhpElementsUtil.getMethodParameterReferenceBag(psiElement);
    if(bag == null) {
        return null;
    }

    // try on current method
    MethodMatcher.MethodMatchParameter methodMatchParameter = new StringParameterMatcher(psiElement, parameterIndex)
        .withSignature(this.signatures)
        .match();

    if(methodMatchParameter != null) {
        return methodMatchParameter;
    }

    // walk down next method
    MethodReference methodReference = bag.getMethodReference();
    for (Method method : PhpElementsUtil.getMultiResolvedMethod(methodReference)) {
        for(PsiElement var: PhpElementsUtil.getMethodParameterReferences(method, bag.getParameterBag().getIndex())) {

            MethodMatcher.MethodMatchParameter methodMatchParameterRef = new MethodMatcher.StringParameterMatcher(var, parameterIndex)
                .withSignature(this.signatures)
                .match();

            if(methodMatchParameterRef != null) {
                return methodMatchParameterRef;
            }
        }
    }

    return null;
}
 
Example #18
Source File: QueryBuilderRepositoryDetectorParameter.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
public MethodReference getMethodReferenceByName(@NotNull String methodName) {

    for (MethodReference methodReference : methodReferences) {
        if(methodName.equals(methodReference.getName())) {
            return methodReference;
        }
    }

    return null;
}
 
Example #19
Source File: MethodMatcher.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
public MethodMatchParameter match() {

    if (!Symfony2ProjectComponent.isEnabled(this.psiElement)) {
        return null;
    }

    ArrayCreationExpression arrayCreationExpression = PhpElementsUtil.getCompletableArrayCreationElement(this.psiElement);
    if (arrayCreationExpression == null) {
        return null;
    }

    PsiElement parameterList = arrayCreationExpression.getContext();
    if (!(parameterList instanceof ParameterList)) {
        return null;
    }

    PsiElement methodParameters[] = ((ParameterList) parameterList).getParameters();
    if (methodParameters.length < this.parameterIndex) {
        return null;
    }

    if (!(parameterList.getContext() instanceof MethodReference)) {
        return null;
    }
    MethodReference methodReference = (MethodReference) parameterList.getContext();

    ParameterBag currentIndex = PsiElementUtils.getCurrentParameterIndex(arrayCreationExpression);
    if (currentIndex == null || currentIndex.getIndex() != this.parameterIndex) {
        return null;
    }

    CallToSignature matchedMethodSignature = this.isCallTo(methodReference);
    if(matchedMethodSignature == null) {
        return null;
    }

    return new MethodMatchParameter(matchedMethodSignature, currentIndex, methodParameters, methodReference);
}
 
Example #20
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Deprecated
@Nullable
public static String getFirstArgumentStringValue(MethodReference e) {
    String stringValue = null;

    PsiElement[] parameters = e.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof StringLiteralExpression) {
        stringValue = ((StringLiteralExpression) parameters[0]).getContents();
    }

    return stringValue;
}
 
Example #21
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
protected boolean isMatchingMethodName(MethodReference methodRef, Method[] expectedMethods) {
    String methodRefName = methodRef.getName();
    for (Method expectedMethod : Arrays.asList(expectedMethods)) {
        if(expectedMethod == null) {
            continue;
        }

        if(expectedMethod.getName().equalsIgnoreCase(methodRefName)) {
            return true;
        }
    }

    return false;
}
 
Example #22
Source File: PsiParameterStorageRunnable.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(PsiElement element) {
    if (element instanceof MethodReference) {
        visitMethodReference((MethodReference) element);
    }
    super.visitElement(element);
}
 
Example #23
Source File: BladeCustomDirectivesVisitor.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(PsiElement element) {

    if (element instanceof MethodReference) {
        visitMethodReference((MethodReference) element);
    }

    super.visitElement(element);
}
 
Example #24
Source File: GenericsUtilTest.java    From idea-php-generics-plugin with MIT License 5 votes vote down vote up
public void testThatTypeTemplateIsExtracted() {
    MethodReference methodReference = PhpPsiElementFactory.createMethodReference(getProject(), "C::a('foo', 'foobar')");

    PsiElement[] parameters = methodReference.getParameterList().getParameters();

    assertEquals("Exception", GenericsUtil.getExpectedParameterInstanceOf(parameters[0]));
    assertNull(GenericsUtil.getExpectedParameterInstanceOf(parameters[1]));
}
 
Example #25
Source File: ConfigIndex.java    From idea-php-shopware-plugin with MIT License 5 votes vote down vote up
@Override
public void visitElement(PsiElement element) {
    if(!(element instanceof MethodReference)) {
        super.visitElement(element);
        return;
    }

    MethodReference methodReference = (MethodReference) element;
    if (!METHODS.contains(methodReference.getName())) {
        super.visitElement(element);
        return;
    }

    String firstArgument = PhpElementsUtil.getFirstArgumentStringValue(methodReference);
    if (StringUtils.isBlank(firstArgument)) {
        super.visitElement(element);
        return;
    }

    if (!shouldIndex(element.getFirstChild())) {
        super.visitElement(element);
        return;
    }

    map.get("all").add(firstArgument);
    super.visitElement(element);
}
 
Example #26
Source File: RouteGroupUtil.java    From idea-php-laravel-plugin with MIT License 5 votes vote down vote up
/**
 * Analyzes Route::group elements and returns string values for specified property.
 * Route::group(['namespace' => 'Foo'], function() {
 *      Route::group(['namespace' => 'Bar'], function() {
 *          Route::get(...
 *      });
 * });
 *
 * getRouteGroupPropertiesCollection(Route::get element, "namespace") will return list with 'Foo', 'Bar'
 */
@NotNull
public static List<String> getRouteGroupPropertiesCollection(PsiElement element, String propertyName)
{
    List<String> values = new ArrayList<>();

    RouteGroupCondition routeGroupCondition = new RouteGroupCondition();

    PsiElement routeGroup = PsiTreeUtil.findFirstParent(element, true, routeGroupCondition);

    while (routeGroup != null) {
        ArrayCreationExpression arrayCreation = PsiTreeUtil.getChildOfType(((MethodReference)routeGroup).getParameterList(), ArrayCreationExpression.class);

        if (arrayCreation != null) {
            for (ArrayHashElement hashElement : arrayCreation.getHashElements()) {
                if (hashElement.getKey() instanceof StringLiteralExpression) {
                    if (propertyName.equals(((StringLiteralExpression) hashElement.getKey()).getContents())) {
                        if (hashElement.getValue() instanceof StringLiteralExpression) {
                            values.add(((StringLiteralExpression) hashElement.getValue()).getContents());
                        }
                        break;
                    }
                }
            }
        }

        routeGroup = PsiTreeUtil.findFirstParent(routeGroup, true, routeGroupCondition);
    }

    Collections.reverse(values);
    return values;
}
 
Example #27
Source File: FormFieldNameReference.java    From idea-php-symfony2-plugin with MIT License 5 votes vote down vote up
@Nullable
@Override
public PsiElement resolve() {

    MethodReference[] formBuilderTypes = FormUtil.getFormBuilderTypes(method);
    for(MethodReference methodReference: formBuilderTypes) {
        String fieldName = PsiElementUtils.getMethodParameterAt(methodReference, 0);
        if(fieldName != null && fieldName.equals(this.element.getContents())) {
            return methodReference;
        }
    }

    return null;
}
 
Example #28
Source File: Symfony2InterfacesUtil.java    From idea-php-toolbox with MIT License 5 votes vote down vote up
@Deprecated
@Nullable
public static String getFirstArgumentStringValue(MethodReference e) {
    String stringValue = null;

    PsiElement[] parameters = e.getParameters();
    if (parameters.length > 0 && parameters[0] instanceof StringLiteralExpression) {
        stringValue = ((StringLiteralExpression) parameters[0]).getContents();
    }

    return stringValue;
}
 
Example #29
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 #30
Source File: PhpTypeProviderUtilTest.java    From idea-php-typo3-plugin with MIT License 5 votes vote down vote up
public void testSignaturesAreProvided() {
    MethodReference methodReference = PhpPsiElementFactory.createMethodReference(
        getProject(),
        "<?php\n" +
            "use App\\Foo\\Bar\\Foo;\n" +
            "GeneralUtility::makeInstance(Foo::class);"
    );
    String referenceSignatureByFirstParameter = PhpTypeProviderUtil.getReferenceSignatureByFirstParameter(methodReference, '%');

    assertEquals("#M#C\\GeneralUtility.makeInstance%#K#C\\App\\Foo\\Bar\\Foo.class", referenceSignatureByFirstParameter);
}