Search in sources :

Example 1 with AtUnqualifiedNoParenthesesCall

use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.

the class CallDefinition method getLineMarkerInfo.

@Nullable
private LineMarkerInfo getLineMarkerInfo(@NotNull Call call) {
    LineMarkerInfo lineMarkerInfo = null;
    if (daemonCodeAnalyzerSettings.SHOW_METHOD_SEPARATORS && CallDefinitionClause.is(call)) {
        Call previousCallDefinitionClause = siblingCallDefinitionClause(call, PREVIOUS_SIBLING);
        boolean firstClause;
        if (previousCallDefinitionClause == null) {
            firstClause = true;
        } else {
            Pair<String, IntRange> callNameArityRange = nameArityRange(call);
            if (callNameArityRange != null) {
                Pair<String, IntRange> previousNameArityRange = nameArityRange(previousCallDefinitionClause);
                firstClause = previousNameArityRange == null || !previousNameArityRange.equals(callNameArityRange);
            } else {
                firstClause = true;
            }
        }
        if (firstClause) {
            PsiElement previousExpression = previousSiblingExpression(call);
            if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
                AtUnqualifiedNoParenthesesCall previousModuleAttributeDefinition = (AtUnqualifiedNoParenthesesCall) previousExpression;
                String moduleAttributeName = moduleAttributeName(previousModuleAttributeDefinition);
                if (moduleAttributeName.equals("@doc")) {
                    firstClause = false;
                } else if (moduleAttributeName.equals("@spec")) {
                    Pair<String, IntRange> callNameArityRange = nameArityRange(call);
                    if (callNameArityRange != null) {
                        Pair<String, Integer> specNameArity = moduleAttributeNameArity(previousModuleAttributeDefinition);
                        if (specNameArity != null) {
                            Integer specArity = specNameArity.second;
                            IntRange callArityRange = callNameArityRange.second;
                            if (callArityRange.containsInteger(specArity)) {
                                firstClause = false;
                            }
                        }
                    }
                }
            }
        }
        if (firstClause) {
            lineMarkerInfo = callDefinitionSeparator(call);
        }
    }
    return lineMarkerInfo;
}
Also used : LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) IntRange(org.apache.commons.lang.math.IntRange) Pair(com.intellij.openapi.util.Pair) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AtUnqualifiedNoParenthesesCall

use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.

the class CallDefinition method getLineMarkerInfo.

@Nullable
private LineMarkerInfo getLineMarkerInfo(@NotNull AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
    LineMarkerInfo lineMarkerInfo = null;
    String moduleAttributeName = moduleAttributeName(atUnqualifiedNoParenthesesCall);
    if (moduleAttributeName.equals("@doc")) {
        PsiElement previousExpression = siblingExpression(atUnqualifiedNoParenthesesCall, PREVIOUS_SIBLING);
        boolean firstInGroup = true;
        if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
            AtUnqualifiedNoParenthesesCall previousModuleAttribute = (AtUnqualifiedNoParenthesesCall) previousExpression;
            String previousModuleAttributeName = moduleAttributeName(previousModuleAttribute);
            if (previousModuleAttributeName.equals("@spec")) {
                Pair<String, Integer> moduleAttributeNameArity = moduleAttributeNameArity(previousModuleAttribute);
                if (moduleAttributeNameArity != null) {
                    Call nextSiblingCallDefinitionClause = siblingCallDefinitionClause(atUnqualifiedNoParenthesesCall, NEXT_SIBLING);
                    if (nextSiblingCallDefinitionClause != null) {
                        Pair<String, IntRange> nameArityRange = nameArityRange(nextSiblingCallDefinitionClause);
                        if (nameArityRange != null) {
                            IntRange arityRange = nameArityRange.second;
                            if (arityRange.containsInteger(moduleAttributeNameArity.second)) {
                                // the previous spec is part of the group
                                firstInGroup = false;
                            }
                        }
                    }
                }
            }
        }
        if (firstInGroup) {
            lineMarkerInfo = callDefinitionSeparator(atUnqualifiedNoParenthesesCall);
        }
    } else if (moduleAttributeName.equals("@spec")) {
        PsiElement previousExpression = siblingExpression(atUnqualifiedNoParenthesesCall, PREVIOUS_SIBLING);
        boolean firstInGroup = true;
        if (previousExpression instanceof AtUnqualifiedNoParenthesesCall) {
            AtUnqualifiedNoParenthesesCall previousModuleAttribute = (AtUnqualifiedNoParenthesesCall) previousExpression;
            String previousModuleAttributeName = moduleAttributeName(previousModuleAttribute);
            if (previousModuleAttributeName.equals("@doc")) {
                firstInGroup = false;
            } else if (previousModuleAttributeName.equals("@spec")) {
                Pair<String, Integer> moduleAttributeNameArity = moduleAttributeNameArity(atUnqualifiedNoParenthesesCall);
                if (moduleAttributeNameArity != null) {
                    Pair<String, Integer> previousModuleAttributeNameArity = moduleAttributeNameArity(previousModuleAttribute);
                    if (previousModuleAttributeNameArity != null) {
                        // name match, now check if the arities match.
                        if (moduleAttributeNameArity.first.equals(previousModuleAttributeNameArity.first)) {
                            Integer moduleAttributeArity = moduleAttributeNameArity.second;
                            Integer previousModuleAttributeArity = previousModuleAttributeNameArity.second;
                            if (moduleAttributeArity.equals(previousModuleAttributeArity)) {
                                /* same arity with different pattern is same function, so the previous @spec should
                                       check if it is first because this one isn't */
                                firstInGroup = false;
                            } else {
                                /* same name, but different arity needs to determine if the call definition has an
                                       arity range. */
                                Call specification = specification(atUnqualifiedNoParenthesesCall);
                                if (specification != null) {
                                    Call type = specificationType(specification);
                                    if (type != null) {
                                        PsiReference reference = type.getReference();
                                        if (reference != null) {
                                            List<PsiElement> resolvedList = null;
                                            if (reference instanceof PsiPolyVariantReference) {
                                                PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
                                                ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
                                                if (resolveResults.length > 0) {
                                                    resolvedList = new ArrayList<PsiElement>();
                                                    for (ResolveResult resolveResult : resolveResults) {
                                                        resolvedList.add(resolveResult.getElement());
                                                    }
                                                }
                                            } else {
                                                PsiElement resolved = reference.resolve();
                                                if (resolved != null) {
                                                    resolvedList = Collections.singletonList(resolved);
                                                }
                                            }
                                            if (resolvedList != null && resolvedList.size() > 0) {
                                                for (PsiElement resolved : resolvedList) {
                                                    if (resolved instanceof Call) {
                                                        Pair<String, IntRange> resolvedNameArityRange = nameArityRange((Call) resolved);
                                                        if (resolvedNameArityRange != null) {
                                                            IntRange resolvedArityRange = resolvedNameArityRange.second;
                                                            if (resolvedArityRange.containsInteger(moduleAttributeArity) && resolvedArityRange.containsInteger(previousModuleAttributeArity)) {
                                                                // the current @spec and the previous @spec apply to the same call definition clause
                                                                firstInGroup = false;
                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } else {
            Call specification = specification(atUnqualifiedNoParenthesesCall);
            if (specification != null) {
                Call type = specificationType(specification);
                if (type != null) {
                    PsiReference reference = type.getReference();
                    if (reference != null) {
                        if (reference instanceof PsiPolyVariantReference) {
                            PsiPolyVariantReference polyVariantReference = (PsiPolyVariantReference) reference;
                            ResolveResult[] resolveResults = polyVariantReference.multiResolve(false);
                            PsiFile containingFile = type.getContainingFile();
                            for (ResolveResult resolveResult : resolveResults) {
                                PsiElement element = resolveResult.getElement();
                                if (element != null) {
                                    if (element.getContainingFile().equals(containingFile) && element.getTextOffset() < type.getTextOffset()) {
                                        firstInGroup = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (firstInGroup) {
            lineMarkerInfo = callDefinitionSeparator(atUnqualifiedNoParenthesesCall);
        }
    }
    return lineMarkerInfo;
}
Also used : Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) IntRange(org.apache.commons.lang.math.IntRange) LineMarkerInfo(com.intellij.codeInsight.daemon.LineMarkerInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with AtUnqualifiedNoParenthesesCall

use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.

the class CallDefinitionSpecification method moduleAttributeNameArity.

@Nullable
public static Pair<String, Integer> moduleAttributeNameArity(AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
    Call specification = specification(atUnqualifiedNoParenthesesCall);
    Pair<String, Integer> nameArity = null;
    if (specification != null) {
        Call type = specificationType(specification);
        if (type != null) {
            nameArity = typeNameArity(type);
        }
    }
    return nameArity;
}
Also used : Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with AtUnqualifiedNoParenthesesCall

use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.

the class CallDefinitionSpecification method is.

@Contract(pure = true)
public static boolean is(@NotNull final Call call) {
    boolean is = false;
    if (call instanceof AtUnqualifiedNoParenthesesCall) {
        AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall = (AtUnqualifiedNoParenthesesCall) call;
        String moduleAttributeName = ElixirPsiImplUtil.moduleAttributeName(atUnqualifiedNoParenthesesCall);
        if (moduleAttributeName.equals("@spec")) {
            is = true;
        }
    }
    return is;
}
Also used : AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) Contract(org.jetbrains.annotations.Contract)

Example 5 with AtUnqualifiedNoParenthesesCall

use of org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall in project intellij-elixir by KronicDeth.

the class CallDefinitionSpecification method specification.

@Nullable
public static Call specification(AtUnqualifiedNoParenthesesCall atUnqualifiedNoParenthesesCall) {
    PsiElement[] arguments = atUnqualifiedNoParenthesesCall.getNoParenthesesOneArgument().arguments();
    Call specification = null;
    if (arguments.length == 1) {
        PsiElement argument = arguments[0];
        if (argument instanceof Call) {
            specification = (Call) argument;
        }
    }
    return specification;
}
Also used : Call(org.elixir_lang.psi.call.Call) AtUnqualifiedNoParenthesesCall(org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

AtUnqualifiedNoParenthesesCall (org.elixir_lang.psi.AtUnqualifiedNoParenthesesCall)8 Call (org.elixir_lang.psi.call.Call)6 Nullable (org.jetbrains.annotations.Nullable)6 PsiElement (com.intellij.psi.PsiElement)3 LineMarkerInfo (com.intellij.codeInsight.daemon.LineMarkerInfo)2 IntRange (org.apache.commons.lang.math.IntRange)2 Pair (com.intellij.openapi.util.Pair)1 Contract (org.jetbrains.annotations.Contract)1