Search in sources :

Example 1 with PsiPerlCommaSequenceExprImpl

use of com.perl5.lang.perl.psi.impl.PsiPerlCommaSequenceExprImpl in project Perl5-IDEA by Camelcade.

the class PerlParameterInfoHandler method markActiveparametersRecursively.

private static int markActiveparametersRecursively(PsiElement element, PerlParameterInfo[] parameterInfos, int currentIndex, int offset) {
    while (element != null) {
        if (parameterInfos.length <= currentIndex) {
            return currentIndex;
        }
        IElementType elementType = PsiUtilCore.getElementType(element);
        if (element instanceof PsiPerlParenthesisedExprImpl || element instanceof PsiPerlCommaSequenceExprImpl) {
            currentIndex = markActiveparametersRecursively(element.getFirstChild(), parameterInfos, currentIndex, offset);
        } else {
            if (isComma(elementType)) {
                if (parameterInfos[currentIndex].getArgument().getContextType() == PerlContextType.SCALAR) {
                    currentIndex++;
                }
            }
        }
        if (element.getTextRange().getEndOffset() >= offset) {
            if (element instanceof PerlCompositeElementImpl) {
                PerlContextType valueContextType = PerlContextType.from(element);
                if (valueContextType == PerlContextType.SCALAR) {
                    if (currentIndex < parameterInfos.length) {
                        parameterInfos[currentIndex].setSelected(true);
                    }
                    return parameterInfos.length;
                } else if (// consumes all arguments to the end
                valueContextType == PerlContextType.LIST) {
                    while (currentIndex < parameterInfos.length) {
                        parameterInfos[currentIndex++].setSelected(true);
                    }
                    return currentIndex;
                }
            }
            // space, comma or smth
            if (currentIndex < parameterInfos.length) {
                parameterInfos[currentIndex].setSelected(true);
            }
            return parameterInfos.length;
        } else if (elementType == SUB_EXPR && element.getFirstChild() instanceof PsiPerlBlock) {
            PsiElement nextSibling = PerlPsiUtil.getNextSignificantSibling(element);
            if (!isComma(PsiUtilCore.getElementType(nextSibling))) {
                currentIndex++;
            }
        } else if (isPrintHandleArgument(element)) {
            currentIndex++;
        }
        element = element.getNextSibling();
    }
    return currentIndex;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) PsiPerlCommaSequenceExprImpl(com.perl5.lang.perl.psi.impl.PsiPerlCommaSequenceExprImpl) PerlCompositeElementImpl(com.perl5.lang.perl.psi.impl.PerlCompositeElementImpl) PsiPerlParenthesisedExprImpl(com.perl5.lang.perl.psi.impl.PsiPerlParenthesisedExprImpl) PerlContextType(com.perl5.lang.perl.psi.utils.PerlContextType) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiElement (com.intellij.psi.PsiElement)1 IElementType (com.intellij.psi.tree.IElementType)1 PerlCompositeElementImpl (com.perl5.lang.perl.psi.impl.PerlCompositeElementImpl)1 PsiPerlCommaSequenceExprImpl (com.perl5.lang.perl.psi.impl.PsiPerlCommaSequenceExprImpl)1 PsiPerlParenthesisedExprImpl (com.perl5.lang.perl.psi.impl.PsiPerlParenthesisedExprImpl)1 PerlContextType (com.perl5.lang.perl.psi.utils.PerlContextType)1