Search in sources :

Example 1 with JsMacroParamDescriptor

use of ool.intellij.plugin.psi.macro.param.descriptor.JsMacroParamDescriptor in project oxy-template-support-plugin by mutant-industries.

the class JsMacroParamSuggestionProvider method getMacroParamSuggestions.

@NotNull
@Override
protected MacroParamSuggestionSet getMacroParamSuggestions() {
    JSParameter[] params;
    if ((params = functionExpression.getParameterVariables()).length == 0) {
        return MacroParamSuggestionSet.empty();
    }
    final MacroParamSuggestionSet result = new MacroParamSuggestionSet();
    submergedCalls = new LinkedList<>();
    String paramsObjectName = params[0].getText();
    /**
     * !! cannot be done via {@link com.intellij.psi.search.searches.ReferencesSearch.search}, which would in some
     * special cases (foreach in foreach) end up in infinite loop - reference search calls type resolver, which makes use of this method
     */
    for (PsiElement elementLocal : getParamReferencesLocal(params[0])) {
        PsiElement element = elementLocal;
        if (!(elementLocal instanceof JSReferenceExpression)) {
            continue;
        }
        if ((elementLocal = elementLocal.getNextSibling()) != null) {
            if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
                elementLocal = elementLocal.getNextSibling();
            }
            if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.DOT) {
                if ((elementLocal = elementLocal.getNextSibling()) != null) {
                    if (elementLocal.getNode().getElementType() == TokenType.WHITE_SPACE) {
                        elementLocal = elementLocal.getNextSibling();
                    }
                    if (elementLocal != null && elementLocal.getNode().getElementType() == JSTokenTypes.IDENTIFIER) {
                        result.add(new JsMacroParamDescriptor(elementLocal.getText(), macro, getJsParamDoc(elementLocal.getText(), macro), true));
                    }
                }
                continue;
            }
        }
        JSCallExpression macroCall = getMacroCall(element);
        JSReferenceExpression callReference;
        if (macroCall == null || (callReference = PsiTreeUtil.getChildOfType(macroCall, JSReferenceExpression.class)) == null || (element = callReference.resolve()) == null) {
            continue;
        }
        submergedCalls.add(element);
    }
    if (macro.getFirstChild() instanceof JSDocComment) {
        String paramName;
        PsiReference reference;
        PsiElement resolve;
        for (JSDocTag docTag : ((JSDocComment) macro.getFirstChild()).getTags()) {
            if ((reference = docTag.getReference()) != null && (resolve = reference.resolve()) != null && !params[0].isEquivalentTo(resolve) || (paramName = getCommentParameterName(docTag)) == null) {
                continue;
            }
            paramName = paramName.replaceFirst("^" + paramsObjectName + "\\.", "");
            if (result.getByName(paramName) != null) {
                continue;
            }
            result.add(new JsMacroParamDescriptor(paramName, macro, docTag, false));
        }
    }
    return result;
}
Also used : JSDocComment(com.intellij.lang.javascript.psi.jsdoc.JSDocComment) MacroParamSuggestionSet(ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet) JSReferenceExpression(com.intellij.lang.javascript.psi.JSReferenceExpression) JSCallExpression(com.intellij.lang.javascript.psi.JSCallExpression) PsiReference(com.intellij.psi.PsiReference) JsMacroParamDescriptor(ool.intellij.plugin.psi.macro.param.descriptor.JsMacroParamDescriptor) JSDocTag(com.intellij.lang.javascript.psi.jsdoc.JSDocTag) JSParameter(com.intellij.lang.javascript.psi.JSParameter) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JSCallExpression (com.intellij.lang.javascript.psi.JSCallExpression)1 JSParameter (com.intellij.lang.javascript.psi.JSParameter)1 JSReferenceExpression (com.intellij.lang.javascript.psi.JSReferenceExpression)1 JSDocComment (com.intellij.lang.javascript.psi.jsdoc.JSDocComment)1 JSDocTag (com.intellij.lang.javascript.psi.jsdoc.JSDocTag)1 PsiElement (com.intellij.psi.PsiElement)1 PsiReference (com.intellij.psi.PsiReference)1 MacroParamSuggestionSet (ool.intellij.plugin.psi.macro.param.MacroParamSuggestionSet)1 JsMacroParamDescriptor (ool.intellij.plugin.psi.macro.param.descriptor.JsMacroParamDescriptor)1 NotNull (org.jetbrains.annotations.NotNull)1