Search in sources :

Example 1 with CfmlFunctionDescription

use of com.intellij.coldFusion.model.info.CfmlFunctionDescription in project intellij-plugins by JetBrains.

the class CfmlParameterInfoHandler method showParameterInfo.

public void showParameterInfo(@NotNull PsiElement element, @NotNull CreateParameterInfoContext context) {
    ResolveResult[] variants = ResolveResult.EMPTY_ARRAY;
    if (element instanceof PsiPolyVariantReference) {
        variants = ((PsiPolyVariantReference) element).multiResolve(true);
        if (variants.length != 0) {
            context.setItemsToShow(ContainerUtil.map2Array(variants, CfmlFunctionDescription.class, resolveResult -> {
                final PsiElement element1 = resolveResult.getElement();
                if (CfmlPsiUtil.isFunctionDefinition(element1)) {
                    CfmlFunction function = CfmlPsiUtil.getFunctionDefinition(element1);
                    if (function != null) {
                        return function.getFunctionInfo();
                    }
                } else if (element1 instanceof PsiMethod) {
                    PsiMethod function = (PsiMethod) element1;
                    CfmlFunctionDescription javaMethodDescr = new CfmlFunctionDescription(function.getName(), function.getReturnType().getPresentableText());
                    final PsiParameter[] psiParameters = function.getParameterList().getParameters();
                    final int paramsNum = psiParameters.length;
                    for (int i = 0; i < paramsNum; i++) {
                        PsiParameter psiParameter = psiParameters[i];
                        javaMethodDescr.addParameter(new CfmlFunctionDescription.CfmlParameterDescription(psiParameter.getName(), psiParameter.getType().getPresentableText(), true));
                    }
                    return javaMethodDescr;
                }
                return null;
            }));
            context.showHint(element, element.getTextRange().getStartOffset(), this);
            return;
        }
    }
    if (element instanceof CfmlReferenceExpression) {
        String functionName = element.getText().toLowerCase();
        if (ArrayUtil.find(CfmlLangInfo.getInstance(element.getProject()).getPredefinedFunctionsLowCase(), functionName) != -1) {
            context.setItemsToShow(new Object[] { CfmlLangInfo.getInstance(element.getProject()).getFunctionParameters().get(functionName) });
            context.showHint(element, element.getTextRange().getStartOffset(), this);
        }
    }
}
Also used : com.intellij.lang.parameterInfo(com.intellij.lang.parameterInfo) ArrayUtil(com.intellij.util.ArrayUtil) LookupElement(com.intellij.codeInsight.lookup.LookupElement) com.intellij.coldFusion.model.psi(com.intellij.coldFusion.model.psi) CfmlFunctionDescription(com.intellij.coldFusion.model.info.CfmlFunctionDescription) CfmlFile(com.intellij.coldFusion.model.files.CfmlFile) ContainerUtil(com.intellij.util.containers.ContainerUtil) CfscriptTokenTypes(com.intellij.coldFusion.model.lexer.CfscriptTokenTypes) CfmlLangInfo(com.intellij.coldFusion.model.info.CfmlLangInfo) ArrayList(java.util.ArrayList) ASTNode(com.intellij.lang.ASTNode) Nullable(org.jetbrains.annotations.Nullable) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) List(java.util.List) Function(com.intellij.util.Function) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) CfmlFunctionDescription(com.intellij.coldFusion.model.info.CfmlFunctionDescription)

Example 2 with CfmlFunctionDescription

use of com.intellij.coldFusion.model.info.CfmlFunctionDescription in project intellij-plugins by JetBrains.

the class CfmlArgumentNameReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    Collection<LookupElement> result = new LinkedList<>();
    Object[] superResult = ArrayUtil.EMPTY_OBJECT_ARRAY;
    String functionName = getFunctionName();
    if (CfmlUtil.isPredefinedFunction(functionName, getProject())) {
        CfmlFunctionDescription cfmlFunctionDescription = CfmlLangInfo.getInstance(getProject()).getFunctionParameters().get(functionName.toLowerCase());
        for (CfmlFunctionDescription.CfmlParameterDescription param : cfmlFunctionDescription.getParameters()) {
            result.add(TailTypeDecorator.withTail(LookupElementBuilder.create(param.getName()).withCaseSensitivity(false), TailType.createSimpleTailType('=')));
        }
    } else {
        CfmlArgumentList parentArgumentsList = PsiTreeUtil.getParentOfType(this, CfmlArgumentList.class);
        if (parentArgumentsList != null) {
            CfmlExpression[] arguments = parentArgumentsList.getArguments();
            if (arguments.length == 1) {
                result.add(LookupElementBuilder.create("argumentCollection").withCaseSensitivity(false));
            }
        }
    }
    PsiElement nextSibling = getNextSibling();
    while (nextSibling instanceof PsiWhiteSpace) {
        nextSibling = nextSibling.getNextSibling();
    }
    if (nextSibling != null && nextSibling.getNode().getElementType() != CfmlTokenTypes.ASSIGN) {
        superResult = super.getVariants();
    }
    CfmlParameter[] functionParameters = getFunctionParameters();
    if (functionParameters != null) {
        for (CfmlParameter param : functionParameters) {
            result.add(CfmlLookUpItemUtil.namedElementToLookupItem(param, null));
        }
    }
    if (!result.isEmpty() || superResult.length > 0) {
        return ArrayUtil.mergeArrays(superResult, ContainerUtil.map2Array(result, Object.class, (Function<LookupElement, Object>) lookupElement -> lookupElement));
    }
    return ArrayUtil.EMPTY_OBJECT_ARRAY;
}
Also used : LookupElement(com.intellij.codeInsight.lookup.LookupElement) LinkedList(java.util.LinkedList) Function(com.intellij.util.Function) CfmlFunctionDescription(com.intellij.coldFusion.model.info.CfmlFunctionDescription) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CfmlFunctionDescription

use of com.intellij.coldFusion.model.info.CfmlFunctionDescription in project intellij-plugins by JetBrains.

the class CfmlLookUpItemUtil method getFunctionDescription.

public static CfmlFunctionDescription getFunctionDescription(CfmlFunction function) {
    PsiType returnType = function.getReturnType();
    CfmlFunctionDescription functionInfo = new CfmlFunctionDescription(function.getName(), returnType != null ? returnType.getCanonicalText() : null);
    CfmlParameter[] params = function.getParameters();
    for (CfmlParameter param : params) {
        functionInfo.addParameter(new CfmlFunctionDescription.CfmlParameterDescription(param.getName(), param.getType(), param.isRequired()));
    }
    return functionInfo;
}
Also used : CfmlFunctionDescription(com.intellij.coldFusion.model.info.CfmlFunctionDescription)

Aggregations

CfmlFunctionDescription (com.intellij.coldFusion.model.info.CfmlFunctionDescription)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Function (com.intellij.util.Function)2 NotNull (org.jetbrains.annotations.NotNull)2 CfmlFile (com.intellij.coldFusion.model.files.CfmlFile)1 CfmlLangInfo (com.intellij.coldFusion.model.info.CfmlLangInfo)1 CfscriptTokenTypes (com.intellij.coldFusion.model.lexer.CfscriptTokenTypes)1 com.intellij.coldFusion.model.psi (com.intellij.coldFusion.model.psi)1 ASTNode (com.intellij.lang.ASTNode)1 com.intellij.lang.parameterInfo (com.intellij.lang.parameterInfo)1 com.intellij.psi (com.intellij.psi)1 PsiElement (com.intellij.psi.PsiElement)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 PsiTreeUtil (com.intellij.psi.util.PsiTreeUtil)1 ArrayUtil (com.intellij.util.ArrayUtil)1 ContainerUtil (com.intellij.util.containers.ContainerUtil)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Nullable (org.jetbrains.annotations.Nullable)1