public static IDeclaredElement GetActivePatternCaseElement([NotNull] FSharpActivePatternCase activePatternCase,
                                                                   [NotNull] IPsiModule psiModule, [CanBeNull] IFSharpReferenceOwner referenceOwnerToken)
        {
            var declaration = GetActivePatternDeclaration(activePatternCase, psiModule, referenceOwnerToken);

            return(declaration?.GetActivePatternByIndex(activePatternCase.Index));
        }
        private static IFSharpDeclaration GetActivePatternDeclaration([NotNull] FSharpActivePatternCase activePatternCase,
                                                                      [NotNull] IPsiModule psiModule, IFSharpReferenceOwner referenceOwnerToken)
        {
            var activePattern   = activePatternCase.Group;
            var declaringEntity = activePattern.DeclaringEntity?.Value;

            if (declaringEntity != null)
            {
                var patternName    = activePattern.PatternName();
                var typeElement    = GetTypeElement(declaringEntity, psiModule);
                var patternElement = typeElement.EnumerateMembers(patternName, true).FirstOrDefault();
                return(patternElement?.GetDeclarations().FirstOrDefault() as IFSharpDeclaration);
            }

            var patternId = FindNode <IActivePatternId>(activePatternCase.DeclarationLocation, referenceOwnerToken);

            return(patternId?.GetContainingNode <IFSharpDeclaration>());
        }
        private static IDeclaredElement GetActivePatternCaseElement(IPsiModule psiModule,
                                                                    IFSharpReferenceOwner referenceExpression, FSharpActivePatternCase patternCase)
        {
            var pattern = patternCase.Group;
            var entity  = pattern.DeclaringEntity?.Value;

            if (entity == null)
            {
                return(GetActivePatternCaseElement(patternCase, psiModule, referenceExpression));
            }

            var typeElement = GetTypeElement(entity, psiModule);
            var patternName = pattern.Name?.Value;

            if (typeElement == null || patternName == null)
            {
                return(null);
            }

            if (typeElement.Module.ContainingProjectModule is IProject)
            {
                return(GetActivePatternCaseElement(patternCase, psiModule, referenceExpression));
            }

            var patternMfv          = entity.MembersFunctionsAndValues.FirstOrDefault(mfv => mfv.LogicalName == patternName);
            var patternCompiledName = patternMfv?.CompiledName ?? patternCase.Name;

            if (typeElement.EnumerateMembers(patternCompiledName, true).FirstOrDefault() is IMethod method)
            {
                return(new CompiledActivePatternCase(method, patternCase.Name, patternCase.Index));
            }

            return(null);
        }
示例#4
0
 public ActivePatternCase(IFSharpDeclaration declaration, FSharpActivePatternCase activePatternCase)
     : base(declaration)
 {
     myActivePatternCase = activePatternCase;
 }