Esempio n. 1
0
        public void Constructor_SetsNameWithSignature(ReferenceKind type)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference);

            Assert.IsFalse(string.IsNullOrEmpty(viewModel.NameWithSignature));
        }
Esempio n. 2
0
 public Reference(MethodInfo p, int c)
 {
     kind  = ReferenceKind.methodInfo_;
     ptr   = (object)p;
     count = c;
     del   = null;
 }
Esempio n. 3
0
 public Reference(Delegate d, int c)
 {
     kind  = ReferenceKind.delegate_;
     del   = d;
     count = c;
     ptr   = null;
 }
Esempio n. 4
0
 public Reference(object p, int c)
 {
     kind  = ReferenceKind.object_;
     ptr   = p;
     count = c;
     del   = null;
 }
Esempio n. 5
0
        public void Constructor_SetsIsExpandedFalse(ReferenceKind type)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference);

            Assert.IsFalse(viewModel.IsExpanded);
        }
Esempio n. 6
0
        public void Constructor_SetsName(ReferenceKind type)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference);

            Assert.AreEqual(reference.Name, viewModel.Name);
        }
Esempio n. 7
0
        public void Constructor_ToolTip_IsDescription(ReferenceKind type)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference);

            Assert.AreEqual(reference.Description, viewModel.ToolTip);
        }
        public int CollectReference(int sourceSymbolId, int referenceSymbolId, ReferenceKind referenceKind)
        {
            if (sourceSymbolId <= 0 || referenceSymbolId <= 0)
            {
                throw new ArgumentException("A symbol-id must be greater than zero");
            }

            return(sourcetraildb.recordReference(sourceSymbolId, referenceSymbolId, referenceKind));
        }
Esempio n. 9
0
        public void ErrorStateCanNotBeSet(ReferenceKind type)
        {
            var folder = new CodeExplorerReferenceFolderViewModel(null, null, Enumerable.Empty <ReferenceModel>().ToList(), type)
            {
                IsErrorState = true
            };

            Assert.IsFalse(folder.IsErrorState);
        }
Esempio n. 10
0
        public void UnusedReferenceIsDimmed(ReferenceKind type)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference);

            reference.IsUsed = false;

            Assert.IsTrue(viewModel.IsDimmed);
        }
        public ReferenceEndpoint(ReferenceKind referenceKind, INamedTypeSymbol symbol)
        {
            if (symbol == null)
            {
                throw new ArgumentNullException("symbol");
            }

            ReferenceKind = referenceKind;
            Symbol        = symbol;
        }
Esempio n. 12
0
        public void ErrorStateCanNotBeSet(ReferenceKind type)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference)
            {
                IsErrorState = true
            };

            Assert.IsFalse(viewModel.IsErrorState);
        }
Esempio n. 13
0
 internal ReferenceArgs(Parser parser, ReferenceKind kind, string mimeType = null)
 {
     if (parser == null)
     {
         throw new ArgumentNullException("parser");
     }
     Parser   = parser;
     Kind     = kind;
     MimeType = !string.IsNullOrEmpty(mimeType) ? mimeType : null;
 }
Esempio n. 14
0
        public void ReferenceLockedStateMatchesIsBuiltIn(ReferenceKind type, bool builtIn)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;

            reference.IsBuiltIn = builtIn;

            var viewModel = new CodeExplorerReferenceViewModel(null, reference);

            Assert.AreEqual(builtIn, viewModel.Locked);
        }
Esempio n. 15
0
 public CodeExplorerReferenceFolderViewModel(
     ICodeExplorerNode parent,
     DeclarationFinder finder,
     List <ReferenceModel> references,
     ReferenceKind type)
     : base(parent, parent?.Declaration)
 {
     _finder       = finder;
     ReferenceKind = type;
     Synchronize(Declaration, references);
 }
Esempio n. 16
0
 public ReferenceModel(ReferenceInfo info, ReferenceKind type, bool recent = false, bool pinned = false) : this()
 {
     Guid        = info.Guid;
     Name        = info.Name;
     Description = Name;
     FullPath    = info.FullPath;
     Major       = info.Major;
     Minor       = info.Minor;
     IsRecent    = recent;
     IsPinned    = pinned;
     Type        = type;
 }
Esempio n. 17
0
        public void FilteredIsFalseForAnyCharacter(ReferenceKind type)
        {
            const string testCharacters = "abcdefghijklmnopqrstuwxyz";

            var folder = new CodeExplorerReferenceFolderViewModel(null, null, Enumerable.Empty <ReferenceModel>().ToList(), type);

            foreach (var character in testCharacters.ToCharArray().Select(letter => letter.ToString()))
            {
                folder.Filter = character;
                Assert.IsFalse(folder.Filtered);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReferenceSearchValue"/> class.
        /// </summary>
        /// <param name="referenceKind">The kind of reference.</param>
        /// <param name="baseUri">The base URI of the resource.</param>
        /// <param name="resourceType">The resource type.</param>
        /// <param name="resourceId">The resource id.</param>
        public ReferenceSearchValue(ReferenceKind referenceKind, Uri baseUri, ResourceType?resourceType, string resourceId)
        {
            if (baseUri != null)
            {
                EnsureArg.IsNotNull(resourceType, nameof(resourceType));
            }

            EnsureArg.IsNotNullOrWhiteSpace(resourceId, nameof(resourceId));

            Kind         = referenceKind;
            BaseUri      = baseUri;
            ResourceType = resourceType;
            ResourceId   = resourceId;
        }
Esempio n. 19
0
        public void Synchronize_RemovesReferenceFromList(ReferenceKind type)
        {
            var references = type == ReferenceKind.TypeLibrary
                ? AddRemoveReferencesSetup.DummyReferencesList
                : AddRemoveReferencesSetup.DummyProjectsList;

            var synching = references.First();

            var viewModel = new CodeExplorerReferenceViewModel(null, synching);

            viewModel.Synchronize(null, references);

            Assert.IsFalse(references.Contains(synching));
        }
Esempio n. 20
0
        public static FunctionPointerType FromSignature(MethodSignature <IType> signature, MetadataModule module)
        {
            IType returnType          = signature.ReturnType;
            bool  returnIsRefReadOnly = false;

            if (returnType is ModifiedType modReturn && modReturn.Modifier.IsKnownType(KnownAttribute.In))
            {
                returnType          = modReturn.ElementType;
                returnIsRefReadOnly = true;
            }
            var parameterTypes          = ImmutableArray.CreateBuilder <IType>(signature.ParameterTypes.Length);
            var parameterReferenceKinds = ImmutableArray.CreateBuilder <ReferenceKind>(signature.ParameterTypes.Length);

            foreach (var p in signature.ParameterTypes)
            {
                IType         paramType = p;
                ReferenceKind kind      = ReferenceKind.None;
                if (p is ModifiedType modreq)
                {
                    if (modreq.Modifier.IsKnownType(KnownAttribute.In))
                    {
                        kind      = ReferenceKind.In;
                        paramType = modreq.ElementType;
                    }
                    else if (modreq.Modifier.IsKnownType(KnownAttribute.Out))
                    {
                        kind      = ReferenceKind.Out;
                        paramType = modreq.ElementType;
                    }
                }
                if (paramType.Kind == TypeKind.ByReference)
                {
                    if (kind == ReferenceKind.None)
                    {
                        kind = ReferenceKind.Ref;
                    }
                }
                else
                {
                    kind = ReferenceKind.None;
                }
                parameterTypes.Add(paramType);
                parameterReferenceKinds.Add(kind);
            }
            return(new FunctionPointerType(
                       module, signature.Header.CallingConvention,
                       returnType, returnIsRefReadOnly,
                       parameterTypes.MoveToImmutable(), parameterReferenceKinds.MoveToImmutable()));
        }
Esempio n. 21
0
        public void Synchronize_Unmatched_SetsReferenceNull(ReferenceKind type)
        {
            var references = type == ReferenceKind.TypeLibrary
                ? AddRemoveReferencesSetup.DummyReferencesList
                : AddRemoveReferencesSetup.DummyProjectsList;

            var removing = references.First();

            var viewModel = new CodeExplorerReferenceViewModel(null, removing);

            references.Remove(removing);
            viewModel.Synchronize(null, references);

            Assert.IsNull(viewModel.Reference);
        }
Esempio n. 22
0
        public void FilteredIsTrueForCharactersNotInName(ReferenceKind type)
        {
            const string testCharacters = "abcdefghijklmnopqrstuwxyz";

            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference);
            var name      = viewModel.Name;

            var nonMatching = testCharacters.ToCharArray().Except(name.ToLowerInvariant().ToCharArray());

            foreach (var character in nonMatching.Select(letter => letter.ToString()))
            {
                viewModel.Filter = character;
                Assert.IsTrue(viewModel.Filtered);
            }
        }
Esempio n. 23
0
        public static ReferenceSpec GetEmitter(MemberSpec ms, int idx, ReferenceKind k, bool reference = false)
        {
            ReferenceSpec Emitter = null;


            if (reference)
            {
                Emitter             = new ReferenceEmitter(ms, 4, ReferenceKind.Parameter);
                Emitter.BaseEmitter = GetEmitter(new ParameterSpec(ms.Name, (ms as ParameterSpec).MethodHost, ms.Signature.Location, idx), idx, ReferenceKind.Parameter);
            }
            else
            {
                Emitter = new WordEmitter(ms, idx, k);
            }


            return(Emitter);
        }
        public Reference(string separatedLine, string sourceLine)
        {
            var parts = separatedLine.Split(';');

            FromAssemblyId       = string.Intern(parts[0]);
            Url                  = parts[1];
            FromLocalPath        = parts[2];
            ReferenceLineNumber  = int.Parse(parts[3]);
            ReferenceColumnStart = int.Parse(parts[4]);
            ReferenceColumnEnd   = int.Parse(parts[5]);
            if (parts.Length >= 7)
            {
                Kind = (ReferenceKind)int.Parse(parts[6]);
            }

            ReferenceLineText = sourceLine;
            ToSymbolName      = ReferenceLineText.Substring(ReferenceColumnStart, ReferenceColumnEnd - ReferenceColumnStart);
        }
Esempio n. 25
0
        public void FilteredIsFalseForSubsetsOfName(ReferenceKind type)
        {
            var reference = type == ReferenceKind.TypeLibrary ? LibraryReference : ProjectReference;
            var viewModel = new CodeExplorerReferenceViewModel(null, reference);
            var name      = viewModel.Name;

            for (var characters = 1; characters <= name.Length; characters++)
            {
                viewModel.Filter = name.Substring(0, characters);
                Assert.IsFalse(viewModel.Filtered);
            }

            for (var position = name.Length - 2; position > 0; position--)
            {
                viewModel.Filter = name.Substring(position);
                Assert.IsFalse(viewModel.Filtered);
            }
        }
Esempio n. 26
0
        private ReferenceSymbol GetReferenceSymbol(ISymbol symbol, ReferenceKind referenceKind, string id = null)
        {
            // Use unspecialized generic
            // TODO: Consider adding reference symbol for specialized generic as well so one can find all references
            // to List<string>.Add rather than just List<T>.Add
            symbol = symbol.OriginalDefinition;

            var boundSymbol = new ReferenceSymbol()
            {
                ProjectId            = symbol.ContainingAssembly.Name,
                Id                   = CreateSymbolId(id ?? GetDocumentationCommentId(symbol)),
                Kind                 = GetSymbolKind(symbol),
                ReferenceKind        = referenceKind.GetString(),
                IsImplicitlyDeclared = symbol.IsImplicitlyDeclared
            };

            if (!string.IsNullOrEmpty(symbol.Name))
            {
                DefinitionSymbol definition;
                if (!context.ReferenceDefinitionMap.TryGetValue(boundSymbol.Id.Value, out definition))
                {
                    var createdDefinition = GetDefinitionSymbol(symbol);
                    definition = context.ReferenceDefinitionMap.GetOrAdd(boundSymbol.Id.Value, createdDefinition);
                    if (createdDefinition == definition)
                    {
                        if (symbol.Kind != SymbolKind.Namespace &&
                            symbol.ContainingNamespace != null &&
                            !symbol.ContainingNamespace.IsGlobalNamespace)
                        {
                            var namespaceSymbol = GetReferenceSymbol(symbol.ContainingNamespace, ReferenceKind.Reference);
                            var extData         = context.GetReferenceNamespaceData(namespaceSymbol.Id.Value);
                            definition.ExtData = extData;
                        }
                    }
                }

                if (referenceKind != ReferenceKind.Definition)
                {
                    definition.IncrementReferenceCount();
                }
            }

            return(boundSymbol);
        }
Esempio n. 27
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Reference{TName,TSymbol}"/> class.
        /// </summary>
        /// <param name="symbol">The symbol being referenced; or <see langword="null"/>.</param>
        /// <param name="document">The document with the reference.</param>
        /// <param name="name">The range of the name of the reference.</param>
        /// <param name="range">The range of the whole reference.</param>
        /// <param name="kind">The kind of reference.</param>
        public Reference([CanBeNull] Symbol <TName, TSymbol> symbol, Uri document, Range name, Range range, ReferenceKind kind)
        {
            #region Contract
            if (document == null)
            {
                throw new ArgumentNullException(nameof(document));
            }
            if (Enum.IsDefined(typeof(ReferenceKind), kind))
            {
                throw new ArgumentException("Value is not a member of the enum.", nameof(kind));
            }
            #endregion

            this.Symbol   = symbol;
            this.Document = document;
            this.Name     = name;
            this.Range    = range;
            this.Kind     = kind;
        }
Esempio n. 28
0
 public DefaultParameter(IType type, string name, IParameterizedMember owner = null, IReadOnlyList <IAttribute> attributes = null,
                         ReferenceKind referenceKind = ReferenceKind.None, bool isParams = false, bool isOptional = false, object defaultValue = null)
 {
     if (type == null)
     {
         throw new ArgumentNullException(nameof(type));
     }
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     this.type          = type;
     this.name          = name;
     this.owner         = owner;
     this.attributes    = attributes ?? EmptyList <IAttribute> .Instance;
     this.referenceKind = referenceKind;
     this.isParams      = isParams;
     this.isOptional    = isOptional;
     this.defaultValue  = defaultValue;
 }
Esempio n. 29
0
            static ReferenceKind GetKind(HtmlNode element, ReferenceKind defaultKind)
            {
                var relationshipAttribute = element.Attributes["rel"];

                if (relationshipAttribute == null || string.IsNullOrEmpty(relationshipAttribute.Value))
                {
                    return(defaultKind);
                }
                var relationships = Helper.SplitSpaceSeparatedTokens(relationshipAttribute.Value);

                if (relationships.Any(relationship => _externalResourceRelationships.Any(type => string.Equals(relationship, type, StringComparison.OrdinalIgnoreCase))))
                {
                    return(ReferenceKind.ExternalResource);
                }
                if (relationships.Any(relationship => _skipRelationships.Any(type => string.Equals(relationship, type, StringComparison.OrdinalIgnoreCase))))
                {
                    return(ReferenceKind.Skip);
                }
                return(defaultKind);
            }
Esempio n. 30
0
 public VirtualParameter(IType type, string name, IParameterizedMember owner = null, IEnumerable <IAttribute> attributes = null,
                         ReferenceKind referenceKind = ReferenceKind.None, bool isRef = false, bool isOut = false, bool isIn = false, bool isParams = false, bool isOptional = false, object defaultValue = null)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.type          = type;
     this.name          = name;
     this.owner         = owner;
     this.Attributes    = attributes?.ToList() ?? new List <IAttribute>();
     this.ReferenceKind = referenceKind;
     this.isRef         = isRef;
     this.isOut         = isOut;
     this.isIn          = isIn;
     this.isParams      = isParams;
     this.isOptional    = isOptional;
     this.defaultValue  = defaultValue;
 }
        public void AddReference(
            string documentDestinationPath,
            SourceText referenceText,
            string destinationAssemblyName,
            ISymbol symbol,
            string symbolId,
            int startPosition,
            int endPosition,
            ReferenceKind kind)
        {
            string referenceString = referenceText.ToString(TextSpan.FromBounds(startPosition, endPosition));
            if (symbol is INamedTypeSymbol && (referenceString == "this" || referenceString == "base"))
            {
                // Don't count "this" or "base" expressions that bind to this type as references
                return;
            }

            var line = referenceText.Lines.GetLineFromPosition(startPosition);
            int start = referenceText.Lines.GetLinePosition(startPosition).Character;
            int end = start + endPosition - startPosition;
            int lineNumber = line.LineNumber + 1;
            string lineText = line.ToString();

            AddReference(
                documentDestinationPath,
                lineText,
                start,
                referenceString.Length,
                lineNumber,
                AssemblyName,
                destinationAssemblyName,
                symbol,
                symbolId,
                kind);
        }
        public void AddReference(
            string documentDestinationPath,
            string lineText,
            int referenceStartOnLine,
            int referenceLength,
            int lineNumber,
            string fromAssemblyName,
            string toAssemblyName,
            ISymbol symbol,
            string symbolId,
            ReferenceKind kind)
        {
            string localPath = Paths.MakeRelativeToFolder(
                documentDestinationPath,
                Path.Combine(SolutionGenerator.SolutionDestinationFolder, fromAssemblyName));
            localPath = Path.ChangeExtension(localPath, null);

            int referenceEndOnLine = referenceStartOnLine + referenceLength;

            lineText = Markup.HtmlEscape(lineText, ref referenceStartOnLine, ref referenceEndOnLine);

            string symbolName = GetSymbolName(symbol, symbolId);

            var reference = new Reference()
            {
                ToAssemblyId = toAssemblyName,
                ToSymbolId = symbolId,
                ToSymbolName = symbolName,
                FromAssemblyId = fromAssemblyName,
                FromLocalPath = localPath,
                ReferenceLineText = lineText,
                ReferenceLineNumber = lineNumber,
                ReferenceColumnStart = referenceStartOnLine,
                ReferenceColumnEnd = referenceEndOnLine,
                Kind = kind
            };

            if (referenceStartOnLine < 0 ||
                referenceStartOnLine >= referenceEndOnLine ||
                referenceEndOnLine > lineText.Length)
            {
                Log.Exception(
                    string.Format("AddReference: start = {0}, end = {1}, lineText = {2}, documentDestinationPath = {3}",
                    referenceStartOnLine,
                    referenceEndOnLine,
                    lineText,
                    documentDestinationPath));
            }

            string linkRelativePath = GetLinkRelativePath(reference);

            reference.Url = linkRelativePath;

            Dictionary<string, List<Reference>> referencesToAssembly = GetReferencesToAssembly(reference.ToAssemblyId);
            List<Reference> referencesToSymbol = GetReferencesToSymbol(reference, referencesToAssembly);
            lock (referencesToSymbol)
            {
                referencesToSymbol.Add(reference);
            }
        }
        private HtmlElementInfo ProcessReference(Classification.Range range, ISymbol symbol, ReferenceKind kind, bool isLargeFile = false)
        {
            ClassifiedSpan classifiedSpan = range.ClassifiedSpan;
            var methodSymbol = symbol as IMethodSymbol;
            if (methodSymbol != null && methodSymbol.ReducedFrom != null)
            {
                symbol = methodSymbol.ReducedFrom;
            }

            HtmlElementInfo result = null;

            if (symbol.IsImplicitlyDeclared)
            {
                if (methodSymbol != null &&
                    methodSymbol.MethodKind == MethodKind.Constructor &&
                    symbol.ContainingSymbol != null)
                {
                    return ProcessReference(range, symbol.ContainingSymbol, ReferenceKind.Instantiation);
                }
            }

            if (symbol.Kind == SymbolKind.Local ||
                symbol.Kind == SymbolKind.Parameter ||
                symbol.Kind == SymbolKind.TypeParameter)
            {
                if (isLargeFile)
                {
                    return null;
                }

                return HighlightReference(symbol);
            }

            if (methodSymbol != null &&
                methodSymbol.MethodKind == MethodKind.Constructor &&
                methodSymbol.ContainingType != null)
            {
                ProcessReference(range, methodSymbol.ContainingType, ReferenceKind.Instantiation);
            }

            if ((symbol.Kind == SymbolKind.Event ||
                 symbol.Kind == SymbolKind.Field ||
                 symbol.Kind == SymbolKind.Method ||
                 symbol.Kind == SymbolKind.NamedType ||
                 symbol.Kind == SymbolKind.Property) &&
                 symbol.Locations.Length >= 1)
            {
                var typeSymbol = symbol as ITypeSymbol;
                string symbolId = SymbolIdService.GetId(symbol);
                var location = symbol.Locations[0];
                string destinationAssemblyName = null;
                if (location.IsInSource)
                {
                    result = GenerateHyperlink(symbol, symbolId, location.SourceTree, out destinationAssemblyName);
                }
                else if (location.IsInMetadata && location.MetadataModule != null)
                {
                    var metadataModule = location.MetadataModule;
                    result = GenerateHyperlink(symbolId, symbol, metadataModule, isLargeFile, out destinationAssemblyName);
                }

                if (result == null)
                {
                    return result;
                }

                string target;
                if (result.Attributes == null ||
                    !result.Attributes.TryGetValue("href", out target) ||
                    !target.Contains("@"))
                {
                    // only register a reference to the symbol if it's not a symbol from an external assembly.
                    // if this links to a symbol in a different index, link target contain @.
                    projectGenerator.AddReference(
                        this.documentDestinationFilePath,
                        Text,
                        destinationAssemblyName,
                        symbol,
                        symbolId,
                        classifiedSpan.TextSpan.Start,
                        classifiedSpan.TextSpan.End,
                        kind);
                }
            }

            // don't make this and var into hyperlinks in large files to save space
            if (isLargeFile && (range.Text == "this" || range.Text == "var"))
            {
                result = null;
            }

            return result;
        }