Strange behavior in code completion by using PhpTypeProvider2

Hi, i try to create a plugin to simplify my working process.

I implement the interface "PhpTypeProvider2". The method "getType" return the signature of every "MethodReferenceImpl" instance. In the method "getBySignature" i try to resolve the return classes. If the return class cannot resolve the method return the "Method" instance of the method to fall back to the phpstorm default behavior. But this only works with methods that are not return "$this". If the return type of an method is defined as "@return $this" i get the following exception.

Someone knows what's wrong?
Thanks!

Exception:

[  24828]  ERROR - n.impl.GeneralHighlightingPass - Invalid Signature #M#C\FooBar
java.lang.RuntimeException: Invalid Signature #M#C\FooBar
at com.jetbrains.php.PhpIndexImpl.getBySignatureInternal(PhpIndexImpl.java:367)
at com.jetbrains.php.PhpIndexImpl.getBySignature(PhpIndexImpl.java:284)
at com.jetbrains.php.PhpIndexImpl.getClasses(PhpIndexImpl.java:429)
at com.jetbrains.php.lang.psi.resolve.types.PhpType.globalLocationAware(PhpType.java:408)
at com.jetbrains.php.lang.psi.elements.impl.MemberReferenceImpl.resolveGlobal(MemberReferenceImpl.java:149)
at com.jetbrains.php.lang.psi.elements.impl.PhpReferenceImpl$1.resolve(PhpReferenceImpl.java:106)
at com.jetbrains.php.lang.psi.elements.impl.PhpReferenceImpl$1.resolve(PhpReferenceImpl.java:103)
at com.intellij.psi.impl.source.resolve.ResolveCache$3.compute(ResolveCache.java:144)
at com.intellij.openapi.util.RecursionManager$2.doPreventingRecursion(RecursionManager.java:112)
at com.intellij.psi.impl.source.resolve.ResolveCache.a(ResolveCache.java:141)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:169)
at com.intellij.psi.impl.source.resolve.ResolveCache.resolveWithCaching(ResolveCache.java:161)
at com.jetbrains.php.lang.psi.elements.impl.PhpReferenceImpl.multiResolve(PhpReferenceImpl.java:98)
at com.jetbrains.php.lang.psi.elements.impl.PhpReferenceImpl.resolve(PhpReferenceImpl.java:85)
at com.jetbrains.php.lang.annotator.PhpAnnotatorVisitor.checkAccessModifiers(PhpAnnotatorVisitor.java:340)
at com.jetbrains.php.lang.annotator.PhpAnnotatorVisitor.visitPhpMethodReference(PhpAnnotatorVisitor.java:322)
at com.jetbrains.php.lang.psi.elements.impl.MethodReferenceImpl.accept(MethodReferenceImpl.java:31)
at com.jetbrains.php.lang.annotator.PhpAnnotator.annotate(PhpAnnotator.java:17)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.a(DefaultHighlightVisitor.java:160)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.visit(DefaultHighlightVisitor.java:103)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$5.run(GeneralHighlightingPass.java:312)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(GeneralHighlightingPass.java:397)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.access$300(GeneralHighlightingPass.java:64)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$6.run(GeneralHighlightingPass.java:403)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.analyze(DefaultHighlightVisitor.java:87)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(GeneralHighlightingPass.java:400)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.access$300(GeneralHighlightingPass.java:64)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass$6.run(GeneralHighlightingPass.java:403)
at com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightVisitor.analyze(XmlHighlightVisitor.java:746)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(GeneralHighlightingPass.java:400)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.a(GeneralHighlightingPass.java:388)
at com.intellij.codeInsight.daemon.impl.GeneralHighlightingPass.collectInformationWithProgress(GeneralHighlightingPass.java:230)
at com.intellij.codeInsight.daemon.impl.ProgressableTextEditorHighlightingPass.doCollectInformation(ProgressableTextEditorHighlightingPass.java:91)
at com.intellij.codeHighlighting.TextEditorHighlightingPass.collectInformation(TextEditorHighlightingPass.java:62)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1$1.run(PassExecutorService.java:427)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1180)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass$1.run(PassExecutorService.java:418)
at com.intellij.openapi.progress.ProgressManager.executeProcessUnderProgress(ProgressManager.java:193)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:211)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.a(PassExecutorService.java:415)
at com.intellij.codeInsight.daemon.impl.PassExecutorService$ScheduledPass.run(PassExecutorService.java:391)
at com.intellij.concurrency.JobLauncherImpl$VoidForkJoinTask.exec(JobLauncherImpl.java:193)
at jsr166e.ForkJoinTask.doExec(ForkJoinTask.java:260)
at jsr166e.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:858)
at jsr166e.ForkJoinPool.scan(ForkJoinPool.java:1687)
at jsr166e.ForkJoinPool.runWorker(ForkJoinPool.java:1642)
at jsr166e.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:109)
[  24834]  ERROR - n.impl.GeneralHighlightingPass - PhpStorm 8.0  Build #PS-138.2000.2262
[  24839]  ERROR - n.impl.GeneralHighlightingPass - JDK: 1.7.0_67
[  24839]  ERROR - n.impl.GeneralHighlightingPass - VM: Java HotSpot(TM) 64-Bit Server VM
[  24839]  ERROR - n.impl.GeneralHighlightingPass - Vendor: Oracle Corporation
[  24839]  ERROR - n.impl.GeneralHighlightingPass - OS: Linux
[  24840]  ERROR - n.impl.GeneralHighlightingPass - Last Action:
[  24839]  ERROR - aemon.impl.PassExecutorService - Invalid Signature #M#C\FooBar


test.php:

 
class FooBar {

    /**
     * @return $this
     */
    public function setDataset1() { }

    /**
     * @return FooBar
     */
    public function setDataset2() { }
}

$a = new FooBar();
$a->setDataset1()-> //code completion not work and throws an exception
$a->setDataset2()-> //code completion works like a charm


Temp.java:

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.php.PhpIndex;
import com.jetbrains.php.lang.psi.elements.Method;
import com.jetbrains.php.lang.psi.elements.MethodReference;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import com.jetbrains.php.lang.psi.elements.PhpNamedElement;
import com.jetbrains.php.lang.psi.elements.impl.MethodReferenceImpl;
import com.jetbrains.php.lang.psi.resolve.types.PhpTypeProvider2;
import org.jetbrains.annotations.Nullable;


import java.util.ArrayList;
import java.util.Collection;


public class Temp
    implements PhpTypeProvider2 {


    @Override
    public char getKey() {
        return 'Q';
    }


    @Nullable
    @Override
    public String getType(PsiElement psiElement) {
        if (psiElement instanceof MethodReferenceImpl) {
            return ((MethodReference) psiElement).getSignature();
        }


        return null;
    }


    @Override
    public Collection<? extends PhpNamedElement> getBySignature(String s, Project project) {
        String methodName = s.substring(s.lastIndexOf('.') + 1);
        Collection<Method> result = new ArrayList<>();
        PhpClass classObject = PhpIndex.getInstance(project).getClassByName("FooBar");
        if (null != classObject) {
            for (Method method : classObject.getMethods()) {
                if (method.getName().equalsIgnoreCase(methodName)) {
                    result.add(method);
                    break;
                }
            }
        }


        return result;
    }
}

1 comment
Comment actions Permalink

Hi, the exception is fixed in PhpStorm 9 EAP but the code completion dose not work. Is there any way to fall back to the default logic in PhpStorm 9 EAP for my usecase?

0

Please sign in to leave a comment.