Package fr.adrienbrault.idea.symfony2plugin.util.completion

Source Code of fr.adrienbrault.idea.symfony2plugin.util.completion.PhpClassReferenceInsertHandler

package fr.adrienbrault.idea.symfony2plugin.util.completion;

import com.intellij.codeInsight.completion.InsertHandler;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.codeInsight.lookup.LookupElement;
import com.jetbrains.php.lang.psi.elements.PhpClass;
import org.jetbrains.annotations.NotNull;

/**
* simplified PhpReferenceInsertHandler which not use trailing quote
*/
public class PhpClassReferenceInsertHandler implements InsertHandler<LookupElement> {

    private static final PhpClassReferenceInsertHandler instance = new PhpClassReferenceInsertHandler();

    public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) {
        Object object = lookupElement.getObject();

        if (!(object instanceof PhpClass)) {
            return;
        }

        StringBuilder textToInsertBuilder = new StringBuilder();
        PhpClass aClass = (PhpClass)object;
        String fqn = aClass.getNamespaceName();

        if(fqn.startsWith("\\")) {
            fqn = fqn.substring(1);
        }

        textToInsertBuilder.append(fqn);
        context.getDocument().insertString(context.getStartOffset(), textToInsertBuilder);

    }

    public static PhpClassReferenceInsertHandler getInstance(){
        return instance;
    }

}
TOP

Related Classes of fr.adrienbrault.idea.symfony2plugin.util.completion.PhpClassReferenceInsertHandler

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.