Esempio n. 1
0
        public NancyMvcViewReference([NotNull] IExpression owner,
                                     [NotNull] ICollection <JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > > names,
                                     MvcKind mvcKind, Version version)
            : base(owner, names, mvcKind, version)
        {
            this.names   = names;
            this.mvcKind = mvcKind;
            this.version = version;
            psiServices  = owner.GetPsiServices();
            mvcCache     = psiServices.GetComponent <MvcCache>();

            ResolveFilter = element =>
            {
                var pathDeclaredElement = element as IPathDeclaredElement;
                if (pathDeclaredElement == null || pathDeclaredElement.GetProjectItem() == null)
                {
                    return(false);
                }

                if (pathDeclaredElement.Path.ExistsDirectory)
                {
                    return(false);
                }
                return(true);
            };
        }
Esempio n. 2
0
        public static MvcViewLocationType GetViewLocationType(MvcKind mvcKind, string area)
        {
            switch (mvcKind)
            {
            case MvcKind.Master:
                return(area.IsEmpty() ? MvcViewLocationType.Master : MvcViewLocationType.AreaMaster);

            case MvcKind.PartialView:
            case MvcKind.DisplayTemplate:
            case MvcKind.EditorTemplate:
                return(area.IsEmpty() ? MvcViewLocationType.PartialView : MvcViewLocationType.AreaPartialView);

            case MvcKind.View:
                return(area.IsEmpty() ? MvcViewLocationType.View : MvcViewLocationType.AreaView);

            default:
                return(MvcViewLocationType.Unknown);
            }
        }
Esempio n. 3
0
        public static IResolveInfo CheckMvcResolveResult([NotNull] IResolveInfo result, MvcKind mvcKind)
        {
            if (result == ResolveErrorType.MULTIPLE_CANDIDATES)
            {
                result = ResolveErrorType.DYNAMIC;
            }

            return(result == ResolveErrorType.NOT_RESOLVED
                ? ourMvcResolveErrors.TryGetValue(mvcKind, MvcResolveErrorType.MVC_NOT_RESOLVED)
                : result);
        }
Esempio n. 4
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());
        }
Esempio n. 5
0
        public static FileSystemPath GetControllerFolder([CanBeNull] IProject project, [CanBeNull] string area, [CanBeNull] string controllerName, MvcKind mvcKind = MvcKind.View)
        {
            if ((project == null) || (controllerName == null))
            {
                return(FileSystemPath.Empty);
            }

            var mvcCache = project.GetSolution().GetComponent <MvcCache>();

            try
            {
                foreach (string locationFormat in mvcCache.GetLocations(project, GetViewLocationType(mvcKind, area)))
                {
                    string path = string.Format(locationFormat, null, controllerName, area);
                    return(new FileSystemPath(path).Directory);
                }
            }
            catch (InvalidPathException)
            {
            }

            return(FileSystemPath.Empty);
        }
Esempio n. 6
0
        private static IEnumerable <Pair <string, string> > ParseLocationFormatString(string locationFormat, MvcKind mvcKind, string controller, string area)
        {
            string text = string.Format(locationFormat, '', controller, area);

            string[] array = text.Split(new char[]
            {
                ''
            });
            Pair <string, string> pair = Pair.Of <string, string>(array[0], (array.Length > 1) ? array[1] : null);

            switch (mvcKind)
            {
            case MvcKind.DisplayTemplate:
                yield return(Pair.Of <string, string>(pair.First + "DisplayTemplates\\", pair.Second));

                break;

            case MvcKind.EditorTemplate:
                yield return(Pair.Of <string, string>(pair.First + "EditorTemplates\\", pair.Second));

                break;

            case MvcKind.Template:
                yield return(Pair.Of <string, string>(pair.First + "DisplayTemplates\\", pair.Second));

                yield return(Pair.Of <string, string>(pair.First + "EditorTemplates\\", pair.Second));

                break;

            default:
                yield return(pair);

                break;
            }
            yield break;
        }
Esempio n. 7
0
        private static ISymbolTable GetReferenceSymbolTable(IPsiServices psiServices, [CanBeNull] string area,
                                                            [CanBeNull] string controller, [CanBeNull] string view, MvcKind mvcKind, [CanBeNull] IProject project, Version version)
        {
            if (project == null)
            {
                return(EmptySymbolTable.INSTANCE);
            }
            ISolution solution  = project.GetSolution();
            var       component = solution.GetComponent <MvcCache>();
            IEnumerable <IProject> searcheableProjects = GetSearcheableProjects(project);
            bool hasExtension = false;

            if (view != null)
            {
                if (view.IndexOfAny(FileSystemDefinition.InvalidPathChars) != -1)
                {
                    return(EmptySymbolTable.INSTANCE);
                }
                if (view == "???")
                {
                    return(EmptySymbolTable.INSTANCE);
                }
                hasExtension = Path.HasExtension(view);
            }
            ISymbolTable symbolTable = EmptySymbolTable.INSTANCE;

            foreach (IProject current in searcheableProjects)
            {
                ISymbolTable symbolTable2 = EmptySymbolTable.INSTANCE;
                string       text         = null;
                if (view != null)
                {
                    string text2 = Path.IsPathRooted(view) ? ("~" + view) : view;
                    text = HtmlPathReferenceUtil.ExpandRootName(text2.Replace('/', '\\'), current);
                    if (Path.IsPathRooted(text))
                    {
                        FileSystemPath fileSystemPath = FileSystemPath.Parse(text);
                        if (!fileSystemPath.IsAbsolute)
                        {
                            fileSystemPath = WebPathReferenceUtil.GetRootPath(project).Combine(fileSystemPath);
                        }
                        symbolTable2 = symbolTable2.Merge(new DeclaredElementsSymbolTable <PathDeclaredElement>(psiServices, new[]
                        {
                            new PathDeclaredElement(psiServices, fileSystemPath)
                        }, 0, null));
                    }
                }
                List <string> list = null;
                if (hasExtension)
                {
                    list = component.GetDisplayModes(current).ToList();
                }
                string[] arg_152_0;
                if (!area.IsEmpty())
                {
                    var array = new string[2];
                    array[0]  = area;
                    arg_152_0 = array;
                }
                else
                {
                    arg_152_0 = new[]
                    {
                        area
                    };
                }
                string[] array2 = arg_152_0;
                for (int i = 0; i < array2.Length; i++)
                {
                    string area2 = array2[i];
                    foreach (
                        string current2 in
                        component.GetLocations(current, MvcUtil.GetViewLocationType(mvcKind, area2), true))
                    {
                        using (
                            IEnumerator <Pair <string, string> > enumerator3 =
                                ParseLocationFormatString(current2, mvcKind, controller, area2).GetEnumerator())
                        {
                            while (enumerator3.MoveNext())
                            {
                                Pair <string, string> location        = enumerator3.Current;
                                FileSystemPath        fileSystemPath2 = FileSystemPath.TryParse(location.First);
                                FileSystemPath        location2       = (location.First.LastIndexOf('\\') ==
                                                                         location.First.Length - 1)
                                    ? fileSystemPath2
                                    : fileSystemPath2.Directory;
                                var projectFolder = current.FindProjectItemByLocation(location2) as IProjectFolder;
                                if (projectFolder != null)
                                {
                                    Func <IProjectItem, bool> extensionFilter = item => item.Location.FullPath.EndsWith(location.Second, StringComparison.OrdinalIgnoreCase);
                                    Func <IProjectItem, bool> preFilter       = extensionFilter;
                                    if (view != null)
                                    {
                                        string text3 = Path.IsPathRooted(text)
                                            ? text
                                            : (location.First + text + location.Second);
                                        string extension     = Path.GetExtension(text3);
                                        var    possibleNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase)
                                        {
                                            text3
                                        };
                                        if (list != null)
                                        {
                                            foreach (string current3 in list)
                                            {
                                                possibleNames.Add(Path.ChangeExtension(text3, current3 + extension));
                                            }
                                        }
                                        preFilter = item => extensionFilter(item) && possibleNames.Contains(item.Location.FullPath);
                                    }
                                    // todo tmp
                                    var referenceContext = new PathReferenceContext(psiServices, projectFolder.Location);
                                    symbolTable2 = symbolTable2.Merge(PathReferenceUtil.GetSymbolTableByPath(referenceContext, false, true, projectItem => GetViewName(projectItem.Location, location), preFilter));
                                }
                            }
                        }
                    }
                }
                symbolTable = symbolTable.Merge(symbolTable2.Filter(new[]
                {
                    FileFilters.FileExists,
                    new FileFilters.ItemInProjectFilter(current)
                }));
            }
            return(symbolTable.Distinct(PathInfoComparer.Instance));
        }
Esempio n. 8
0
 protected virtual MvcViewReference <ICSharpLiteralExpression, IMethodDeclaration> GetMvcViewReference(IExpression literal, ICollection <JetTuple <string, string, MvcUtil.DeterminationKind, ICollection <IClass> > > names, MvcKind mvcKind, Version version)
 {
     return(new MvcViewReference <ICSharpLiteralExpression, IMethodDeclaration>(literal, names, mvcKind, version));
 }