Search in sources :

Example 1 with ParameterInfoHandler

use of com.intellij.lang.parameterInfo.ParameterInfoHandler in project intellij-community by JetBrains.

the class ParameterInfoController method findArgumentList.

@Nullable
public static <E extends PsiElement> E findArgumentList(PsiFile file, int offset, int lbraceOffset) {
    if (file == null)
        return null;
    ParameterInfoHandler[] handlers = ShowParameterInfoHandler.getHandlers(file.getProject(), PsiUtilCore.getLanguageAtOffset(file, offset), file.getViewProvider().getBaseLanguage());
    if (handlers != null) {
        for (ParameterInfoHandler handler : handlers) {
            if (handler instanceof ParameterInfoHandlerWithTabActionSupport) {
                final ParameterInfoHandlerWithTabActionSupport parameterInfoHandler2 = (ParameterInfoHandlerWithTabActionSupport) handler;
                // please don't remove typecast in the following line; it's required to compile the code under old JDK 6 versions
                final E e = (E) ParameterInfoUtils.findArgumentList(file, offset, lbraceOffset, parameterInfoHandler2);
                if (e != null)
                    return e;
            }
        }
    }
    return null;
}
Also used : ParameterInfoHandlerWithTabActionSupport(com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport) ParameterInfoHandler(com.intellij.lang.parameterInfo.ParameterInfoHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ParameterInfoHandler

use of com.intellij.lang.parameterInfo.ParameterInfoHandler in project intellij-community by JetBrains.

the class ShowParameterInfoHandler method invoke.

public static void invoke(final Project project, final Editor editor, PsiFile file, int lbraceOffset, PsiElement highlightedElement, boolean requestFocus) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    PsiDocumentManager.getInstance(project).commitAllDocuments();
    final int offset = editor.getCaretModel().getOffset();
    final PsiElement psiElement = findAnyElementAt(file, offset);
    if (psiElement == null)
        return;
    final ShowParameterInfoContext context = new ShowParameterInfoContext(editor, project, file, offset, lbraceOffset, requestFocus);
    context.setHighlightedElement(highlightedElement);
    context.setRequestFocus(requestFocus);
    final Language language = psiElement.getLanguage();
    ParameterInfoHandler[] handlers = getHandlers(project, language, file.getViewProvider().getBaseLanguage());
    if (handlers == null)
        handlers = new ParameterInfoHandler[0];
    Lookup lookup = LookupManager.getInstance(project).getActiveLookup();
    if (lookup != null) {
        LookupElement item = lookup.getCurrentItem();
        if (item != null) {
            for (ParameterInfoHandler handler : handlers) {
                if (handler.couldShowInLookup()) {
                    final Object[] items = handler.getParametersForLookup(item, context);
                    if (items != null && items.length > 0) {
                        showLookupEditorHint(items, editor, project, handler, requestFocus);
                    }
                    return;
                }
            }
        }
        return;
    }
    DumbService.getInstance(project).setAlternativeResolveEnabled(true);
    try {
        for (ParameterInfoHandler<Object, ?> handler : handlers) {
            Object element = handler.findElementForParameterInfo(context);
            if (element != null) {
                handler.showParameterInfo(element, context);
            }
        }
    } finally {
        DumbService.getInstance(project).setAlternativeResolveEnabled(false);
    }
}
Also used : Language(com.intellij.lang.Language) Lookup(com.intellij.codeInsight.lookup.Lookup) LookupElement(com.intellij.codeInsight.lookup.LookupElement) ParameterInfoHandler(com.intellij.lang.parameterInfo.ParameterInfoHandler) LightweightHint(com.intellij.ui.LightweightHint) PsiElement(com.intellij.psi.PsiElement)

Aggregations

ParameterInfoHandler (com.intellij.lang.parameterInfo.ParameterInfoHandler)2 Lookup (com.intellij.codeInsight.lookup.Lookup)1 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 Language (com.intellij.lang.Language)1 ParameterInfoHandlerWithTabActionSupport (com.intellij.lang.parameterInfo.ParameterInfoHandlerWithTabActionSupport)1 PsiElement (com.intellij.psi.PsiElement)1 LightweightHint (com.intellij.ui.LightweightHint)1 Nullable (org.jetbrains.annotations.Nullable)1