public SyntaxNodeOrTokenListItem(SyntaxNodeOrToken syntaxNodeOrToken)
        {
            _lineSpan = syntaxNodeOrToken.GetLocation().GetLineSpan();

            Content = $"{_lineSpan}: {syntaxNodeOrToken.Kind()} {Truncate(syntaxNodeOrToken.ToString())}";
            ToolTip = syntaxNodeOrToken.ToString();
        }
예제 #2
0
        internal static ObsoleteDiagnosticKind ReportDiagnosticsIfObsoleteInternal(DiagnosticBag diagnostics, Symbol symbol, SyntaxNodeOrToken node, Symbol containingMember, BinderFlags location)
        {
            Debug.Assert(diagnostics != null);

            var kind = ObsoleteAttributeHelpers.GetObsoleteDiagnosticKind(symbol, containingMember);

            DiagnosticInfo info = null;

            switch (kind)
            {
            case ObsoleteDiagnosticKind.Diagnostic:
                info = ObsoleteAttributeHelpers.CreateObsoleteDiagnostic(symbol, location);
                break;

            case ObsoleteDiagnosticKind.Lazy:
            case ObsoleteDiagnosticKind.LazyPotentiallySuppressed:
                info = new LazyObsoleteDiagnosticInfo(symbol, containingMember, location);
                break;
            }

            if (info != null)
            {
                diagnostics.Add(info, node.GetLocation());
            }

            return(kind);
        }
        public SyntaxNodeOrTokenListItem(SyntaxNodeOrToken syntaxNodeOrToken)
        {
            _lineSpan = syntaxNodeOrToken.GetLocation().GetLineSpan();

            Content = $"{_lineSpan}: {syntaxNodeOrToken.Kind()} {Truncate(syntaxNodeOrToken.ToString())}";
            ToolTip = syntaxNodeOrToken.ToString();
        }
예제 #4
0
 public static Diagnostic CreateDiagnostic(
     this SyntaxNodeOrToken nodeOrToken,
     DiagnosticDescriptor rule,
     params object[] args)
 {
     return(nodeOrToken.GetLocation().CreateDiagnostic(rule, args));
 }
예제 #5
0
 void IDisposable.Dispose()
 {
     if (position < instructions.Count)
     {
         instructions[position].SourceLocation = syntax.GetLocation();
     }
 }
예제 #6
0
        public void AddMapping(SyntaxNodeOrToken node, Position pos)
        {
            var srcPos = node.GetLocation().GetLineSpan().StartLinePosition;

            if (_line == pos.Line)
            {
                if (_mapping.Length > 0 && _mapping[_mapping.Length - 1] != ';')
                {
                    _mapping.Append(',');
                }
            }
            else
            {
                while (_line < pos.Line)
                {
                    _mapping.Append(';');
                    _line++;
                }
            }

            _mapping.Append(Base64VLQEncoding.Encode(pos.Column));
            _mapping.Append(Base64VLQEncoding.Encode(_srcIdx));
            _mapping.Append(Base64VLQEncoding.Encode(srcPos.Line));
            _mapping.Append(Base64VLQEncoding.Encode(srcPos.Character));
        }
예제 #7
0
        private static void CheckIfCommasAreAtTheSameLineAsThePreviousParameter(SyntaxNodeAnalysisContext context, SyntaxNodeOrTokenList nodeOrTokenList)
        {
            SyntaxNode previousNode = null;

            // If index is even we expecting parameter syntax node, otherwise we expecting comma token.
            for (int index = 0, count = nodeOrTokenList.Count; index < count; ++index)
            {
                SyntaxNodeOrToken nodeOrToken = nodeOrTokenList[index];
                if (index % 2 == 0)
                {
                    // We expecting node here
                    if (nodeOrToken.IsToken)
                    {
                        return;
                    }

                    previousNode = nodeOrToken.AsNode();
                }
                else
                {
                    // We expecting token here
                    if (nodeOrToken.IsNode)
                    {
                        return;
                    }

                    if (previousNode.GetEndLine() < nodeOrToken.GetLineSpan().StartLinePosition.Line)
                    {
                        var properties = TokenSpacingProperties.RemovePrecedingPreserveLayout;
                        context.ReportDiagnostic(Diagnostic.Create(Descriptor, nodeOrToken.GetLocation(), properties));
                    }
                }
            }
        }
예제 #8
0
        public ShwingNode(SyntaxNodeOrToken node, int precedingId, int currentDepth, int maxDepth)
        {
            Id = S_UID++;

            Kind      = node.Kind();
            _filename = node.GetLocation().SourceSpan;

            Add(node, precedingId, currentDepth, maxDepth);
        }
        public SyntaxOrTokenItemViewModel(SyntaxNodeOrToken syntaxNodeOrToken, int?maxFilePathLength = null)
        {
            LineSpan = syntaxNodeOrToken.GetLocation().GetLineSpan();

            Class   = LineSpan.Path.Split('\\').Last();
            Content =
                $"{LineSpan.Path.PadRight(maxFilePathLength ?? 100)} {LineSpan.Span.ToString().PadLeft(20)}{"".PadLeft(5)}{syntaxNodeOrToken.ToString().Truncate()}";
            ToolTip = syntaxNodeOrToken.ToString();
        }
        private static void CheckIfCommasAreAtTheSameLineAsThePreviousParameter(SyntaxNodeAnalysisContext context, SyntaxNodeOrTokenList nodeOrTokenList)
        {
            SyntaxNode previousNode = null;

            // If index is even we expecting parameter syntax node, otherwise we expecting comma token.
            for (int index = 0, count = nodeOrTokenList.Count; index < count; ++index)
            {
                SyntaxNodeOrToken nodeOrToken = nodeOrTokenList[index];
                if (index % 2 == 0)
                {
                    // We expecting node here
                    if (nodeOrToken.IsToken)
                    {
                        return;
                    }

                    previousNode = nodeOrToken.AsNode();
                }
                else
                {
                    // We expecting token here
                    if (nodeOrToken.IsNode)
                    {
                        return;
                    }

                    if (previousNode.GetEndLine() < nodeOrToken.GetLineSpan().StartLinePosition.Line)
                    {
                        var properties = new Dictionary <string, string>
                        {
                            [OpenCloseSpacingCodeFixProvider.LocationKey] = OpenCloseSpacingCodeFixProvider.LocationPreceding,
                            [OpenCloseSpacingCodeFixProvider.ActionKey]   = OpenCloseSpacingCodeFixProvider.ActionRemove,
                            [OpenCloseSpacingCodeFixProvider.LayoutKey]   = OpenCloseSpacingCodeFixProvider.LayoutPreserve
                        };
                        context.ReportDiagnostic(Diagnostic.Create(Descriptor, nodeOrToken.GetLocation(), properties.ToImmutableDictionary()));
                    }
                }
            }
        }
예제 #11
0
        public void AddMapping(SyntaxNodeOrToken node, Position pos)
        {
            var srcPos = node.GetLocation().GetLineSpan().StartLinePosition;
            if (_line == pos.Line)
            {
                if (_mapping.Length > 0 && _mapping[_mapping.Length - 1] != ';')
                    _mapping.Append(',');
            }
            else
            {
                while (_line < pos.Line)
                {
                    _mapping.Append(';');
                    _line++;
                }
            }

            _mapping.Append(Base64VLQEncoding.Encode(pos.Column));
            _mapping.Append(Base64VLQEncoding.Encode(_srcIdx));
            _mapping.Append(Base64VLQEncoding.Encode(srcPos.Line));
            _mapping.Append(Base64VLQEncoding.Encode(srcPos.Character));
        }
예제 #12
0
 internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax, params object[] args)
 {
     Error(diagnostics, code, syntax.GetLocation(), args);
 }
예제 #13
0
 internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax)
 {
     Error(diagnostics, code, syntax.GetLocation());
 }
예제 #14
0
파일: Binder.cs 프로젝트: Rickinio/roslyn
        /// <returns>
        /// True if the symbol is definitely obsolete.
        /// False if the symbol is definitely not obsolete.
        /// Unknown if the symbol may be obsolete.
        /// 
        /// NOTE: The return value reflects obsolete-ness, not whether or not the diagnostic was reported.
        /// </returns>
        private static ThreeState ReportDiagnosticsIfObsoleteInternal(DiagnosticBag diagnostics, Symbol symbol, SyntaxNodeOrToken node, Symbol containingMember, BinderFlags location)
        {
            Debug.Assert(diagnostics != null);

            if (symbol.ObsoleteState == ThreeState.False)
            {
                return ThreeState.False;
            }

            var data = symbol.ObsoleteAttributeData;
            if (data == null)
            {
                // Obsolete attribute has errors.
                return ThreeState.False;
            }

            // If we haven't cracked attributes on the symbol at all or we haven't
            // cracked attribute arguments enough to be able to report diagnostics for
            // ObsoleteAttribute, store the symbol so that we can report diagnostics at a 
            // later stage.
            if (symbol.ObsoleteState == ThreeState.Unknown)
            {
                diagnostics.Add(new LazyObsoleteDiagnosticInfo(symbol, containingMember, location), node.GetLocation());
                return ThreeState.Unknown;
            }

            // After this point, always return True.

            var inObsoleteContext = ObsoleteAttributeHelpers.GetObsoleteContextState(containingMember);

            // If we are in a context that is already obsolete, there is no point reporting
            // more obsolete diagnostics.
            if (inObsoleteContext == ThreeState.True)
            {
                return ThreeState.True;
            }
            // If the context is unknown, then store the symbol so that we can do this check at a
            // later stage
            else if (inObsoleteContext == ThreeState.Unknown)
            {
                diagnostics.Add(new LazyObsoleteDiagnosticInfo(symbol, containingMember, location), node.GetLocation());
                return ThreeState.True;
            }

            // We have all the information we need to report diagnostics right now. So do it.
            var diagInfo = ObsoleteAttributeHelpers.CreateObsoleteDiagnostic(symbol, location);
            if (diagInfo != null)
            {
                diagnostics.Add(diagInfo, node.GetLocation());
                return ThreeState.True;
            }

            return ThreeState.True;
        }
예제 #15
0
파일: Binder.cs 프로젝트: Rickinio/roslyn
 internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax, params object[] args)
 {
     Error(diagnostics, code, syntax.GetLocation(), args);
 }
예제 #16
0
파일: Binder.cs 프로젝트: Rickinio/roslyn
 internal static void Error(DiagnosticBag diagnostics, ErrorCode code, SyntaxNodeOrToken syntax)
 {
     Error(diagnostics, code, syntax.GetLocation());
 }
예제 #17
0
 public static TextSpan GetTextSpan(this SyntaxNodeOrToken node)
 {
     return(ToTextSpan(node.GetLocation()));
 }
예제 #18
0
        ///// <summary>
        ///// Find the node in the AST where the method was declared
        ///// We use that to visit a callee method.
        ///// </summary>
        ///// <param name="solution"></param>
        ///// <param name="roslynMethod"></param>
        ///// <returns></returns>
        //internal static SyntaxReference FindMethodDeclaration(IMethodSymbol roslynMethod)
        //{
        //	var nodes = roslynMethod.DeclaringSyntaxReferences;
        //	if (nodes.Count() > 0)
        //	{
        //		return nodes[0].GetSyntax();
        //	}
        //	else
        //	{
        //		return null;
        //	}

        //	//var position = roslynMethod.Locations.First().SourceSpan.Start;
        //	//var st = roslynMethod.Locations.First().SourceTree;
        //	//if (st != null)
        //	//{
        //	//    var node = st.GetRoot().FindToken(position).Parent.FirstAncestorOrSelf<BaseMethodDeclarationSyntax>();
        //	//    return node;
        //	//}
        //	//else return null;
        //}

        internal static int GetInvocationNumber(IMethodSymbol roslynMethod, SyntaxNodeOrToken invocation)
        {
            // var roslynMethod = RoslynSymbolFactory.FindMethodSymbolInSolution(this.solution, locMethod.Value);
            var methodDeclarationSyntax = roslynMethod.DeclaringSyntaxReferences.First();
            //var syntaxTree = methodDeclarationSyntax.SyntaxTree;
            var invocations = methodDeclarationSyntax.GetSyntax().DescendantNodesAndSelf().OfType <InvocationExpressionSyntax>().ToArray();
            int count       = 0;

            for (int i = 0; i < invocations.Length && !invocations[i].GetLocation().Equals(invocation.GetLocation()); i++)
            {
                count++;
            }

            return(count);
        }
예제 #19
0
        internal static int GetStatementNumber(SyntaxNodeOrToken expression)
        {
            //var methodDeclarationSyntax = expression.AsNode().Ancestors().OfType<BaseMethodDeclarationSyntax>().First();
            var methodDeclarationSyntax = expression.AsNode().Ancestors().OfType <MemberDeclarationSyntax>().First();
            //var syntaxTree = methodDeclarationSyntax.SyntaxTree;
            var invocations = methodDeclarationSyntax.DescendantNodesAndSelf().OfType <InvocationExpressionSyntax>().ToArray();
            int count       = 0;

            for (int i = 0; i < invocations.Length && !invocations[i].GetLocation().Equals(expression.GetLocation()); i++)
            {
                count++;
            }

            return(count);
        }
 public CompilationException(SyntaxNodeOrToken syntax, string id, string message)
     : this(syntax.GetLocation(), id, message)
 {
 }