Example #1
0
        private static ICollection <JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > > GetModulesNotCached([NotNull] IArgumentsOwner argumentsOwner)
        {
            argumentsOwner.AssertIsValid("argumentsOwner is invalid");
            IPsiModule psiModule = argumentsOwner.GetPsiModule();

            IProject project = argumentsOwner.GetProject();

            Assertion.AssertNotNull(project, "project == null");
            IProjectFile projectFile = argumentsOwner.GetSourceFile().ToProjectFile();

            Assertion.AssertNotNull(projectFile, "projectFile == null");

            IList <string> controllerNames = ProcessArgumentsExpression(argumentsOwner, MvcKind.Controller);

            ICollection <JetTuple <string, string, MvcUtil.DeterminationKind, bool> > moduleNames =
                new List <JetTuple <string, string, MvcUtil.DeterminationKind, bool> >();

            if (controllerNames.IsEmpty())
            {
                // first, try detect implicit controller type by view

                var    typeDeclaration = argumentsOwner.GetContainingNode <ITypeDeclaration>();
                IClass declaredElement = (typeDeclaration != null)
                    ? typeDeclaration.DeclaredElement as IClass
                    : null;

                if (declaredElement == null)
                {
                    return(EmptyList <JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > > .InstanceList);
                }

                JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > @default =
                    JetTuple.Of(GetControllerArea(declaredElement),
                                GetControllerName(declaredElement),
                                MvcUtil.DeterminationKind.ImplicitByContainingMember,
                                (ICollection <IClass>) new IClass[] { null });

                // with inheritors
                if (declaredElement.IsAbstract)
                {
                    // with inheritors
                    return(GetAvailableModules(psiModule, argumentsOwner.GetResolveContext(), baseClass: declaredElement)
                           .SelectMany(_ => _.Value)
                           .GroupBy(
                               @class => new { area = GetControllerArea(@class), controller = GetControllerName(@class) })
                           .Select(_ => JetTuple.Of(_.Key.area, _.Key.controller,
                                                    MvcUtil.DeterminationKind.ImplicitByContainingMember,
                                                    (ICollection <IClass>)_.ToList()))
                           .DefaultIfEmpty(@default)
                           .ToList());
                }

                moduleNames = new[]
                { JetTuple.Of(@default.A, @default.B, MvcUtil.DeterminationKind.ImplicitByContainingMember, true) };
            }

            return((from tuple in moduleNames
                    let availableModules = GetAvailableModules(psiModule, argumentsOwner.GetResolveContext(), includingIntermediateControllers: tuple.D)
                                           select JetTuple.Of(tuple.A, tuple.B, tuple.C, tuple.B == null
                    ? (ICollection <IClass>) new IClass[] { null }
                    : availableModules.GetValuesCollection(tuple.B)))
                   .ToList());
        }
Example #2
0
        private static IList <string> ProcessArgumentsExpression(IArgumentsOwner argumentsOwner, MvcKind kind)
        {
#if SDK80
            IDeclaredType stringType = TypeFactory.CreateTypeByCLRName(PredefinedType.STRING_FQN, argumentsOwner.GetPsiModule(), argumentsOwner.GetResolveContext());
#else
            IDeclaredType stringType = TypeFactory.CreateTypeByCLRName(PredefinedType.STRING_FQN, argumentsOwner.GetPsiModule());
#endif

            var enumerabe1 = from expression in RetrieveArgumentExpressions(argumentsOwner, kind)
                             let finder = new RecursiveElementCollector <IExpression>(
                literalExpression =>
            {
                if (!literalExpression.GetExpressionType().IsImplicitlyConvertibleTo(
                        stringType, IntentionLanguageSpecific.GetTypeConversion(literalExpression)))
                {
                    return(false);
                }

                string initializerName;
                IInvocationInfo invocationInfo;
                GetMvcLiteral(literalExpression, out invocationInfo, out initializerName);
                return((invocationInfo == argumentsOwner) &&
                       expression.Second.Any(_ => StringComparer.OrdinalIgnoreCase.Equals(_.B, initializerName)));
            })
                                          select new { finder, expression };
            return((from x in enumerabe1
                    from literal in x.finder.ProcessElement(x.expression.First).GetResults()
                    select literal.ConstantValue.Value as string).ToList());
        }
        public FormattingFunctionInvocationInfo TryGetByExpression(IArgumentsOwner argumentsOwner)
        {
            IFunctionInvocationClrWrapper functionInvocation = FunctionInvocationUtil.GetFunctionInvocationByArgumentsOwner(argumentsOwner);
            if (functionInvocation == null)
            {
                return null;
            }

            IList<IFunction> candidates = functionInvocation.InvokedFunction.IfNotNull(_ => new List<IFunction> { _ }) ?? functionInvocation.InvokedFunctionCandidates;
            if (candidates == null || candidates.IsEmpty())
            {
                return null;
            }

            IList<IExpression> arguments = functionInvocation.Arguments;
            List<IParameter> annotatedParameters = candidates.Select(_ => myCodeAnnotationsCache.GetStringFormatMethodParameter(_)).ToList();
            if (annotatedParameters.IsEmpty() || annotatedParameters.Contains(null))
            {
                return null;
            }

            IParameter parameter = annotatedParameters.First();
            var function = parameter.ContainingParametersOwner as IFunction;
            if (function == null)
            {
                return null;
            }

            int index1 = function.Parameters.IndexOf(parameter);
            if (index1 < 0 || index1 >= arguments.Count)
            {
                return null;
            }
            int num = index1 + 1;
            IList<IParameter> parameters = function.Parameters;
            IDeclaredType typeByClrName = TypeFactory.CreateTypeByCLRName("System.IFormatProvider",
                argumentsOwner.GetPsiModule(), argumentsOwner.GetResolveContext());
            ITypeConversionRule typeConversion = IntentionLanguageSpecific.GetTypeConversion(argumentsOwner);
            bool flag1 = false;
            for (int index2 = 0; index2 < index1; ++index2)
            {
                IExpression expression = index2 < arguments.Count ? arguments[index2] : null;
                if (expression != null &&
                    expression.GetExpressionType().IsImplicitlyConvertibleTo(typeByClrName, typeConversion))
                {
                    flag1 = true;
                    break;
                }
            }
            if (!flag1 && index1 + 1 < parameters.Count &&
                (index1 + 1 < arguments.Count && arguments[index1 + 1] != null) &&
                (parameters[index1 + 1] != null && parameters[index1 + 1].Type.Equals(typeByClrName)))
            {
                flag1 = true;
                ++num;
            }
            if (num > arguments.Count)
            {
                return null;
            }
            IExpression expression1 = arguments[index1];
            if (expression1 == null)
            {
                return null;
            }
            var list3 = new List<IExpression>();
            bool flag2 = false;
            for (int index2 = num; index2 < arguments.Count; ++index2)
            {
                if (index2 == parameters.Count - 1 && parameters.Count == arguments.Count &&
                    parameters.Last().IsParameterArray &&
                    (arguments.Last() == null || arguments.Last().ConstantValue.IsPureNull(argumentsOwner.Language) ||
                     arguments.Last().GetExpressionType().ToIType() is IArrayType))
                {
                    flag2 = true;
                    break;
                }
                list3.Add(arguments[index2]);
            }
            IStringConcatenationClrWrapper stringConcatenation =
                StringConcatenationClrWrapperUtil.CreateStringConcatenation(expression1);
            if (stringConcatenation == null)
            {
                return null;
            }
            return new FormattingFunctionInvocationInfo
            {
                Invocation = functionInvocation,
                FormatStringConcatenation = stringConcatenation,
                FormattingArguments = list3,
                HasCustomFormatProvider = flag1,
                HasExplicitParamArrayArgument = flag2
            };
        }