Beispiel #1
0
        private void ChangeReference(IArgumentsOwner reference, string recommendedName, IType type)
        {
            var csharpOwner = reference as ICSharpArgumentsOwner;

            if (csharpOwner == null)
            {
                return;
            }
            var factory = CSharpElementFactory.GetInstance(type.Module);
            var inField = false;

            if (csharpOwner.GetContainingNode <IFieldDeclaration>() != null)
            {
                inField = true;
            }
            var expression     = factory.CreateExpression(inField ? "TODO" : recommendedName);
            var cSharpArgument = factory.CreateArgument(ParameterKind.VALUE, null, expression);

            csharpOwner.AddArgumentAfter(
                cSharpArgument,
                csharpOwner.Arguments.LastOrDefault());

            if (!inField)
            {
                AddStub(cSharpArgument, reference, recommendedName);
            }
        }
Beispiel #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());
        }
 protected override void AddStub(ICSharpArgument cSharpArgument, IArgumentsOwner reference, string recommendedName)
 {
     var referenceExpression = cSharpArgument.Value as IReferenceExpression;
     var anchor = reference.GetContainingNode<IBlock>();
     var containingMethod = anchor.Parent as IMethodDeclaration;
     if (containingMethod == null)
         return;
     if (!containingMethod.Attributes.Select(x => x.Name.QualifiedName).Any(x => x == "SetUp" || x == "Test" || x == "TestCase"))
         return;
     var addStub = new AddRhinoStub(recommendedName, referenceExpression, anchor);
     addStub.Execute();
 }
Beispiel #4
0
        public static IEnumerable <JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > > GetModules(
            [CanBeNull] IArgumentsOwner argumentsOwner)
        {
            if ((argumentsOwner == null) || !argumentsOwner.IsValid())
            {
                return(EmptyList <JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > > .InstanceList);
            }

            CachedPsiValue <ICollection <JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > > >
            cachedData = argumentsOwner.UserData.GetOrCreateData(ourCachedControllersKey,
                                                                 () => argumentsOwner.CreateCachedValue(GetModulesNotCached(argumentsOwner)));

            return(cachedData.GetValue(argumentsOwner, () => GetModulesNotCached(argumentsOwner)));
        }
Beispiel #5
0
        protected override void AddStub(ICSharpArgument cSharpArgument, IArgumentsOwner reference, string recommendedName)
        {
            var referenceExpression = cSharpArgument.Value as IReferenceExpression;
            var anchor           = reference.GetContainingNode <IBlock>();
            var containingMethod = anchor.Parent as IMethodDeclaration;

            if (containingMethod == null)
            {
                return;
            }
            if (!containingMethod.Attributes.Select(x => x.Name.QualifiedName).Any(x => x == "SetUp" || x == "Test" || x == "TestCase"))
            {
                return;
            }
            var addStub = new AddRhinoStub(recommendedName, referenceExpression, anchor);

            addStub.Execute();
        }
Beispiel #6
0
        RetrieveArgumentExpressions([CanBeNull] IArgumentsOwner argumentsOwner, MvcKind?kind = null,
                                    bool returnAllKinds = false)
        {
            if (argumentsOwner == null)
            {
                return
                    (EmptyList <Pair <IExpression, ICollection <JetTuple <MvcKind, string, IAttributeInstance> > > >
                     .InstanceList);
            }

            return
                (from argument in argumentsOwner.Arguments
                 where argument != null
                 // just for case
                 let expression = argument.Expression
                                  where expression != null
                                  let matchingParameter = argument.MatchingParameter
                                                          where matchingParameter != null
                                                          let parameter = matchingParameter.Element
                                                                          let mvcKinds = parameter.GetMvcKinds()
                                                                                         let allowedMvcKinds = kind.HasValue ? mvcKinds.Where(_ => _.A == kind).ToList() : mvcKinds
                                                                                                               where allowedMvcKinds.Any()
                                                                                                               select Pair.Of(expression, returnAllKinds?mvcKinds : allowedMvcKinds));
        }
Beispiel #7
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());
        }
Beispiel #8
0
 protected virtual void AddStub(ICSharpArgument cSharpArgument, IArgumentsOwner reference, string recommendedName)
 {
 }
 private static void ChangeReference(IArgumentsOwner reference, string recommendedName, IType type)
 {
     var csharpOwner = reference as ICSharpArgumentsOwner;
     if (csharpOwner == null || type.Module == null)
         return;
     var factory = CSharpElementFactory.GetInstance(type.Module);
     var inField = false;
     if (csharpOwner.GetContainingElement<IFieldDeclaration>(false) != null)
         inField = true;
     var expression = factory.CreateExpression(inField ? "TODO" : recommendedName);
     csharpOwner.AddArgumentAfter(
         factory.CreateArgument(ParameterKind.VALUE, null, expression),
         csharpOwner.Arguments.LastOrDefault());
 }
 protected virtual void AddStub(ICSharpArgument cSharpArgument, IArgumentsOwner reference, string recommendedName)
 {
 }
        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
            };
        }
Beispiel #12
0
 public NancyMvcActionReference([NotNull] IExpression owner, IArgumentsOwner argumentsExpression)
     : base(owner, argumentsExpression)
 {
 }