private void ProcessReferencedSymbol(
            Solution solution,
            ReferencedSymbol referencedSymbol,
            ArrayBuilder <DefinitionItem> definitions,
            ArrayBuilder <SourceReferenceItem> references,
            HashSet <DocumentSpan> uniqueSpans)
        {
            // See if this is a symbol we even want to present to the user.  If not,
            // ignore it entirely (including all its reference locations).
            if (!referencedSymbol.ShouldShow())
            {
                return;
            }

            var definitionItem = referencedSymbol.Definition.ToDefinitionItem(solution, uniqueSpans);

            definitions.Add(definitionItem);

            // Now, create the SourceReferenceItems for all the reference locations
            // for this definition.
            CreateReferences(referencedSymbol, references, definitionItem, uniqueSpans);

            // Finally, see if there are any third parties that want to add their
            // own result to our collection.
            var thirdPartyItem = GetThirdPartyDefinitionItem(solution, referencedSymbol.Definition);

            if (thirdPartyItem != null)
            {
                definitions.Add(thirdPartyItem);
            }
        }
示例#2
0
        private static void CreateReferences(
            ReferencedSymbol referencedSymbol,
            ImmutableArray <SourceReferenceItem> .Builder references,
            DefinitionItem definitionItem,
            HashSet <DocumentLocation> uniqueLocations)
        {
            foreach (var referenceLocation in referencedSymbol.Locations)
            {
                var location = referenceLocation.Location;
                Debug.Assert(location.IsInSource);

                var document   = referenceLocation.Document;
                var sourceSpan = location.SourceSpan;

                var documentLocation = new DocumentLocation(document, sourceSpan);
                if (!documentLocation.CanNavigateTo())
                {
                    continue;
                }

                if (uniqueLocations.Add(documentLocation))
                {
                    references.Add(new SourceReferenceItem(definitionItem, documentLocation));
                }
            }
        }
 public FieldParameterSyntax(TextSpan span, Name name, IExpressionSyntax?defaultValue)
     : base(span, name)
 {
     Name         = name;
     DefaultValue = defaultValue;
     DataType     = ReferencedSymbol.Select(s => s?.DataType ?? Types.DataType.Unknown);
 }
        /// <summary>
        /// Reference locations are de-duplicated across the entire find references result set
        /// Order the definitions so that references to multiple definitions appear under the
        /// desired definition (e.g. constructor references should prefer the constructor method
        /// over the type definition). Note that this does not change the order in which
        /// definitions are displayed in Find Symbol Results, it only changes which definition
        /// a given reference should appear under when its location is a reference to multiple
        /// definitions.
        /// </summary>
        private static int GetPrecedence(ReferencedSymbol referencedSymbol)
        {
            switch (referencedSymbol.Definition.Kind)
            {
            case SymbolKind.Event:
            case SymbolKind.Field:
            case SymbolKind.Label:
            case SymbolKind.Local:
            case SymbolKind.Method:
            case SymbolKind.Parameter:
            case SymbolKind.Property:
            case SymbolKind.RangeVariable:
                return(0);

            case SymbolKind.ArrayType:
            case SymbolKind.DynamicType:
            case SymbolKind.ErrorType:
            case SymbolKind.NamedType:
            case SymbolKind.PointerType:
                return(1);

            default:
                return(2);
            }
        }
        private AbstractTreeItem ConvertToDefinitionItem(
            Solution solution,
            ReferencedSymbol referencedSymbol,
            Location location,
            Glyph glyph)
        {
            if (!location.IsInSource)
            {
                return(referencedSymbol.Locations.Any()
                    ? new MetadataDefinitionTreeItem(
                           solution.Workspace,
                           referencedSymbol.Definition,
                           referencedSymbol.Locations.First().Document.Project.Id,
                           glyph.GetGlyphIndex())
                    : null);
            }

            var document   = solution.GetDocument(location.SourceTree);
            var sourceSpan = location.SourceSpan;

            if (!IsValidSourceLocation(document, sourceSpan))
            {
                return(null);
            }

            return(new SourceDefinitionTreeItem(document, sourceSpan, referencedSymbol.Definition, glyph.GetGlyphIndex()));
        }
        public static bool ShouldShow(this ReferencedSymbol referencedSymbol)
        {
            // If the reference has any locations then we will present it.
            if (referencedSymbol.Locations.Any())
            {
                return(true);
            }

            return(referencedSymbol.Definition.ShouldShowWithNoReferenceLocations());
        }
示例#7
0
        private async Task <IEnumerable <ArgumentResults> > ExtractArguments(ReferencedSymbol reference)
        {
            var result = new List <ArgumentResults>();

            foreach (var location in reference.Locations)
            {
                result.Add(await CalculateArgumentResults(location));
            }

            return(result);
        }
        public static bool ShouldShow(
            this ReferencedSymbol referencedSymbol, FindReferencesSearchOptions options)
        {
            // If the reference has any locations then we will present it.
            if (referencedSymbol.Locations.Any())
            {
                return(true);
            }

            return(referencedSymbol.Definition.ShouldShowWithNoReferenceLocations(
                       options, showMetadataSymbolsWithoutReferences: true));
        }
示例#9
0
        private static void Verify(ReferencedSymbol reference, HashSet <int> expectedMatchedLines)
        {
            System.Action <Location> verifier = (location) => Assert.True(expectedMatchedLines.Remove(location.GetLineSpan().StartLinePosition.Line));

            foreach (var location in reference.Locations)
            {
                verifier(location.Location);
            }

            foreach (var location in reference.Definition.Locations)
            {
                verifier(location);
            }
        }
        private bool IncludeDefinition(ReferencedSymbol reference)
        {
            var definition = reference.Definition;

            // Don't include parameters to property accessors
            if (definition is IParameterSymbol &&
                definition.ContainingSymbol is IMethodSymbol &&
                ((IMethodSymbol)definition.ContainingSymbol).AssociatedSymbol is IPropertySymbol)
            {
                return(false);
            }

            return(true);
        }
示例#11
0
        private static ReferencedSymbol CreateReferencedSymbol(string symbolName, int referenceCount)
        {
            var symbol = new StubSymbol(symbolName);

            var locations = new List <ReferenceLocation>(capacity: referenceCount);

            for (int i = 0; i < referenceCount; i++)
            {
                locations.Add(new ReferenceLocation());
            }

            var referencedSymbol = new ReferencedSymbol(symbol, locations);

            return(referencedSymbol);
        }
示例#12
0
        private static DefinitionItem CreateDefinitionItem(
            Solution solution,
            ReferencedSymbol referencedSymbol,
            HashSet <DocumentLocation> uniqueLocations)
        {
            var definition   = referencedSymbol.Definition;
            var displayParts = definition.ToDisplayParts(s_definitionDisplayFormat).ToTaggedText();

            return(CreateDefinitionItem(
                       GlyphTags.GetTags(definition.GetGlyph()),
                       displayParts,
                       definition.ShouldShowWithNoReferenceLocations(),
                       solution,
                       definition,
                       uniqueLocations));
        }
示例#13
0
        private static void Verify(ReferencedSymbol reference, HashSet <int> expectedMatchedLines)
        {
            void verifier(Location location)
            {
                var line = location.GetLineSpan().StartLinePosition.Line;

                Assert.True(expectedMatchedLines.Remove(line), $"An unexpected reference was found on line number {line}.");
            }

            foreach (var location in reference.Locations)
            {
                verifier(location.Location);
            }

            foreach (var location in reference.Definition.Locations)
            {
                verifier(location);
            }
        }
        private static bool ShouldKeep(ReferencedSymbol r)
        {
            if (r.Locations.Any())
            {
                return(true);
            }

            if (r.Definition.IsImplicitlyDeclared)
            {
                return(false);
            }

            if (r.Definition.IsPropertyAccessor())
            {
                return(false);
            }

            return(true);
        }
        private static void CreateReferences(
            ReferencedSymbol referencedSymbol,
            ArrayBuilder <SourceReferenceItem> references,
            DefinitionItem definitionItem,
            HashSet <DocumentSpan> uniqueSpans)
        {
            foreach (var referenceLocation in referencedSymbol.Locations)
            {
                var sourceReferenceItem = referenceLocation.TryCreateSourceReferenceItem(definitionItem);
                if (sourceReferenceItem == null)
                {
                    continue;
                }

                if (uniqueSpans.Add(sourceReferenceItem.SourceSpan))
                {
                    references.Add(sourceReferenceItem);
                }
            }
        }
        public void DebuggerDisplay_NoReferences()
        {
            ReferencedSymbol referencedSymbol = CreateReferencedSymbol("Foo", 0);

            Assert.Equal("Foo, 0 refs", referencedSymbol.DebuggerDisplay);
        }
示例#17
0
        public void DebuggerDisplay_TwoReferences()
        {
            ReferencedSymbol referencedSymbol = CreateReferencedSymbol("Foo", 2);

            Assert.Equal("Foo, 2 refs", referencedSymbol.GetDebuggerDisplay());
        }
示例#18
0
        public void DebuggerDisplay_OneReference()
        {
            ReferencedSymbol referencedSymbol = CreateReferencedSymbol("Foo", 1);

            Assert.Equal("Foo, 1 ref", referencedSymbol.GetDebuggerDisplay());
        }
示例#19
0
        public void DebuggerDisplay_NoReferences()
        {
            ReferencedSymbol referencedSymbol = CreateReferencedSymbol("Goo", 0);

            Assert.Equal("Goo, 0 refs", referencedSymbol.GetTestAccessor().GetDebuggerDisplay());
        }
示例#20
0
            async Task <PropertyDeclarationSyntax> FindFullPropertyForConvertingAutoPropertyAsync(PropertyDeclarationSyntax propertyDeclaration)
            {
                if (propertyDeclaration.AccessorList == null)
                {
                    return(null);
                }
                if (propertyDeclaration.AccessorList.Accessors.Count != 2)
                {
                    return(null);
                }

                var getNode = propertyDeclaration.AccessorList.Accessors.FirstOrDefault(x => x.Keyword.IsKind(SyntaxKind.GetKeyword));
                var setNode = propertyDeclaration.AccessorList.Accessors.FirstOrDefault(x => x.Keyword.IsKind(SyntaxKind.SetKeyword));

                if (setNode == null || getNode == null)
                {
                    return(null);
                }

                var getIdentifier = HasJustReturnValue(getNode);

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

                var setIdentifier = HasJustSetValue(setNode);

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

                var setIdentifierSymbol = projectItemDetails.SemanticModel.GetSymbolInfo(setIdentifier).Symbol;
                var getIdentifierSymbol = projectItemDetails.SemanticModel.GetSymbolInfo(getIdentifier).Symbol;

                if (SymbolEqualityComparer.Default.Equals(setIdentifierSymbol, getIdentifierSymbol) == false)
                {
                    return(null);
                }
                //if (setIdentifierSymbol != getIdentifierSymbol) return null;

                var baseFieldSymbol = projectItemDetails.SemanticModel.GetSymbolInfo(setIdentifier).Symbol;

                if (baseFieldSymbol is IFieldSymbol == false)
                {
                    return(null);
                }

                var propertyDelarationSymbol = projectItemDetails.SemanticModel.GetDeclaredSymbol(propertyDeclaration);

                if (SymbolEqualityComparer.Default.Equals(baseFieldSymbol.ContainingType, propertyDelarationSymbol.ContainingType) == false)
                {
                    return(null);
                }
                //if (baseFieldSymbol.ContainingType != propertyDelarationSymbol.ContainingType) return null;

                var baseFieldVariableDeclaration = await baseFieldSymbol.DeclaringSyntaxReferences[0].GetSyntaxAsync() as VariableDeclaratorSyntax;
                var baseFieldFieldDeclaration    = baseFieldVariableDeclaration.Parent.Parent as FieldDeclarationSyntax;

                if (CheckVisibility(baseFieldFieldDeclaration, getNode, setNode, propertyDeclaration) == false)
                {
                    return(null);
                }

                var refrences = await Microsoft.CodeAnalysis.FindSymbols.SymbolFinder.FindReferencesAsync(baseFieldSymbol, TidyCSharpPackage.Instance.CleanupWorkingSolution);

                ReferencedSymbol references = null;

                references = refrences.FirstOrDefault();

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

                if (baseFieldFieldDeclaration.HasNoneWhiteSpaceTrivia(new SyntaxKind[] { SyntaxKind.SingleLineCommentTrivia, SyntaxKind.MultiLineCommentTrivia }))
                {
                    return(null);
                }

                VariablesToRemove.Add(
                    new Tuple <VariableDeclaratorSyntax, PropertyDeclarationSyntax, bool>
                    (
                        baseFieldVariableDeclaration,
                        propertyDeclaration,
                        references.Locations.Count() > 2
                    )
                    );

                return(propertyDeclaration);
            }