Exemplo n.º 1
0
        protected Location GetLocation(ICSharpTreeNode expression)
        {
            var start = expression.GetDocumentStartOffset().Offset;
            var end   = expression.GetDocumentEndOffset().Offset;

            return(new Location(MyParams.GetPersistentFileId(), start, end));
        }
Exemplo n.º 2
0
 private void AddIf(ICSharpTreeNode node, CompletionCase completionCase, IList <IStatement> body)
 {
     if (IsTargetMatch(node, completionCase))
     {
         body.Add(EmptyCompletionExpression);
     }
 }
Exemplo n.º 3
0
        private bool IsTargetMatch(ICSharpTreeNode o, CompletionCase completionCase)
        {
            var isValid     = _marker.HandlingNode != null;
            var isMatch     = o == _marker.HandlingNode;
            var isRightCase = _marker.Case == completionCase;

            return(isValid && isMatch && isRightCase);
        }
Exemplo n.º 4
0
        private void AnalyzeStatements([NotNull] ICSharpTreeNode scope, [NotNull] PropertiesAccessContainer referencesContainer)
        {
            var visitor = new PropertiesAnalyzerVisitor(referencesContainer, scope,
                                                        new Dictionary <IReferenceExpression, IEnumerator <ITreeNode> >(ourComparer),
                                                        new HashSet <IReferenceExpression>(ourComparer));

            scope.ProcessThisAndDescendants(visitor);
        }
Exemplo n.º 5
0
 internal EmptyArrayInitializationHighlighting(
     [NotNull] string message,
     [NotNull] ICSharpTreeNode treeNode,
     [NotNull] IType arrayElementType) : base(message)
 {
     TreeNode         = treeNode;
     ArrayElementType = arrayElementType;
 }
 public CachePropertyValueQuickFix(InefficientPropertyAccessWarning warning)
 {
     myReferences           = warning.References;
     myHighlightedReference = warning.HighlightedReference;
     myInlineCache          = warning.InlineCacheValue;
     myInlineRestore        = warning.InlineRestoreValue;
     myCacheAnchor          = warning.CacheAnchor;
     myRestoreAnchor        = warning.RestoreAnchor;
 }
Exemplo n.º 7
0
        public SnapNode([NotNull] ICSharpTreeNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            Node             = node;
            Occurences       = new Dictionary <Guid, ExpressionKind>();
            InitialOccurence = Guid.Empty;
        }
Exemplo n.º 8
0
        protected override void Analyze(ITreeNode node, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            // container to collect groups of IReferenceExpressions which can be cached
            var container = new PropertiesAccessContainer(consumer);

            ICSharpTreeNode scope = null;

            switch (node)
            {
            case ICSharpParametersOwnerDeclaration parametersOwnerDeclaration:
                var codeBody = parametersOwnerDeclaration.GetCodeBody();
                scope = codeBody.BlockBody ?? (ICSharpTreeNode)codeBody.ExpressionBody;
                break;

            case ILambdaExpression lambdaExpression:
                codeBody = lambdaExpression.GetCodeBody();
                scope    = codeBody.BlockBody ?? (ICSharpTreeNode)codeBody.ExpressionBody;
                break;

            case IPropertyDeclaration propertyDeclaration:
                var initial = propertyDeclaration.Initial;
                if (initial != null)
                {
                    scope = initial;
                }
                else
                {
                    foreach (var accessorDeclaration in propertyDeclaration.AccessorDeclarationsEnumerable)
                    {
                        codeBody = accessorDeclaration.GetCodeBody();
                        var body = codeBody.BlockBody ?? (ICSharpTreeNode)codeBody.ExpressionBody;
                        if (body != null)
                        {
                            AnalyzeStatements(body, container);
                            container.InvalidateCachedValues();
                        }
                    }
                }
                break;

            default:
                return;
            }

            if (scope == null)
            {
                return;
            }

            AnalyzeStatements(scope, container);

            // cache all references which is not invalidated dut to no related expression was found
            container.InvalidateCachedValues();
        }
Exemplo n.º 9
0
        private IInvocationExpression FindInvocationChain([NotNull] ICSharpTreeNode topLevelNode)
        {
            foreach (var invocation in topLevelNode.Descendants().OfType <IInvocationExpression>())
            {
                if (MatchChain(invocation))
                {
                    return(invocation);
                }
            }

            return(null);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Handles the removal of an import directive.
        /// </summary>
        /// <param name="psiServices">The PSI services.</param>
        /// <param name="scope">The namespace scope.</param>
        /// <param name="usingDirective">The using directive to remove.</param>
        /// <param name="action">The action to perform to remove the directive.</param>
        public void HandleRemoveImport(IPsiServices psiServices, ICSharpTypeAndNamespaceHolderDeclaration scope, IUsingDirective usingDirective, Action action)
        {
            ICSharpTreeNode namespaceNode = usingDirective.GetUsedNamespaceNode();

            if (namespaceNode == null)
            {
                Assertion.Fail("Only a namespace using can be removed.");
            }
            else
            {
                TreeTextRange range = namespaceNode.GetTreeTextRange();
                HandleRemoveImportInternal(psiServices, scope, usingDirective, action, CSharpLanguage.Instance, range);
            }
        }
Exemplo n.º 11
0
        public static HashSet <Assertion> CollectAssertions(
            [NotNull] AssertionMethodAnnotationProvider assertionMethodAnnotationProvider,
            [NotNull] AssertionConditionAnnotationProvider assertionConditionAnnotationProvider,
            [NotNull] ICSharpTreeNode rootNode)
        {
            var forTypeLevelInitializersOnly = rootNode is IClassLikeDeclaration;

            var assertions = new HashSet <Assertion>();

            foreach (var expression in rootNode.Descendants <ICSharpExpression>())
            {
                Debug.Assert(expression != null);

                var isInTypeLevelInitializer = expression.PathToRoot()
                                               .Any(node => node is IExpressionInitializer && (node.Parent is IFieldDeclaration || node.Parent is IPropertyDeclaration));

                if (forTypeLevelInitializersOnly != isInTypeLevelInitializer)
                {
                    continue;
                }

                switch (expression)
                {
                case IInvocationExpression invocationExpression:
                    var assertionStatement = AssertionStatement.TryFromInvocationExpression(
                        invocationExpression,
                        assertionMethodAnnotationProvider,
                        assertionConditionAnnotationProvider);
                    if (assertionStatement != null)
                    {
                        assertions.Add(assertionStatement);
                    }

                    var inlineAssertion = InlineAssertion.TryFromInvocationExpression(invocationExpression);
                    if (inlineAssertion != null)
                    {
                        assertions.Add(inlineAssertion);
                    }
                    break;

                case ISuppressNullableWarningExpression suppressNullableWarningExpression:
                    assertions.Add(new NullForgivingOperation(suppressNullableWarningExpression));
                    break;
                }
            }

            return(assertions);
        }
Exemplo n.º 12
0
        private void AddAny(ExpressionKind expressionKind, ICSharpTreeNode sharpTreeNode)
        {
            if (expressionKind == ExpressionKind.None || expressionKind == ExpressionKind.StubCandidate)
            {
                return;
            }

            var node = SnapNodes.SingleOrDefault(t => t.Node == sharpTreeNode);

            if (node == null)
            {
                SnapNodes.Add(new SnapNode(sharpTreeNode, expressionKind));
            }
            else
            {
                node.AddKind(expressionKind);
            }
        }
        public bool IsUnder(ICSharpTreeNode node)
        {
            var store       = node.GetSettingsStore();
            var customTypes = store.EnumIndexedValues(AsyncConverterSettingsAccessor.ConfigureAwaitIgnoreAttributeTypes).ToArray();

            if (customTypes.IsNullOrEmpty())
            {
                return(false);
            }

            var containingFunctionLikeDeclarationOrClosure = node.GetContainingFunctionDeclarationIgnoringClosures();

            if (containingFunctionLikeDeclarationOrClosure?.ContainsAttribute(customTypes) == true)
            {
                return(true);
            }

            return(false);
        }
 public UnexpectedReferenceTypeException(IDeclaredElement declaredElement, ReferenceExpressionEater eater, ICSharpTreeNode node)
     : base(string.Format("Unexpected reference declared type. Expected field, property, event, constant, variable or class, but was [{0}]", declaredElement.GetType()), eater, node)
 {
     DeclaredElement = declaredElement;
 }
 public MoqStubOptionWrongTypeException(ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(string.Format("Moq-stub options has wrong type. Expected conditional-and, equility, invocation, reference expressions. But was [{0}]", node.GetType()), eater, node)
 {
 }
 public MoqStubWrongSyntaxException(string message, ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(message, eater, node)
 {
 }
 public EatingException(string message, Exception exception, ICSharpNodeEater eater, ICSharpTreeNode node)
     : this(message, eater, node)
 {
     Exception = exception;
 }
 public UnexpectedReferenceTypeException(IDeclaredElement declaredElement, ReferenceExpressionEater eater, ICSharpTreeNode node)
     : base(string.Format("Unexpected reference declared type. Expected field, property, event, constant, variable or class, but was [{0}]", declaredElement.GetType()), eater, node)
 {
     DeclaredElement = declaredElement;
 }
Exemplo n.º 19
0
 public EatingException(string message, Exception exception, ICSharpNodeEater eater, ICSharpTreeNode node)
     : this(message, eater, node)
 {
     Exception = exception;
 }
Exemplo n.º 20
0
        private static IType GetQualifierExpressionType([CanBeNull] ICSharpExpression qualifierExpression, [NotNull] ICSharpTreeNode context)
        {
            if (qualifierExpression.IsThisOrBaseOrNull())
            {
                var structDeclaration = context.GetContainingTypeDeclaration() as IStructDeclaration;

                var structTypeElement = structDeclaration?.DeclaredElement;
                if (structTypeElement == null)
                {
                    return(null);
                }

                return(TypeFactory.CreateType(structTypeElement));
            }

            var expressionType = qualifierExpression.GetExpressionType();

            return(expressionType.ToIType());
        }
Exemplo n.º 21
0
 public EatingException(Exception exception, ICSharpNodeEater eater, ICSharpTreeNode node)
     : this(exception.Message, exception, eater, node)
 {
 }
 public UnexpectedAssignDestinationException(ICSharpExpression destination, AssignmentExpressionEater eater, ICSharpTreeNode node)
     : base(string.Format("Unexpected assign destination. Expected IReferenceExpression, but was [{0}]", destination.GetType()), eater, node)
 {
     Destination = destination;
 }
 public UnexpectedAssignDestinationException(ICSharpExpression destination, AssignmentExpressionEater eater, ICSharpTreeNode node)
     : base(string.Format("Unexpected assign destination. Expected IReferenceExpression, but was [{0}]", destination.GetType()), eater, node)
 {
     Destination = destination;
 }
Exemplo n.º 24
0
 public EatingException(string message, ICSharpNodeEater eater, ICSharpTreeNode node)
 {
     Message = message;
     Eater   = eater;
     Node    = node;
 }
Exemplo n.º 25
0
 public SnapNode(ICSharpTreeNode node, ExpressionKind kind)
     : this(node)
 {
     AddKind(kind);
 }
Exemplo n.º 26
0
            public void InvalidateCachedValues(IReferenceExpression key)
            {
                if (!myPropertiesMap.ContainsKey(key))
                {
                    return;
                }

                var highlighitingElements = myPropertiesMap[key];

                Assertion.Assert(highlighitingElements.Count > 0, "highlighitingElements.Length > 0");

                // calculate read/write operations for property
                int write = 0;
                int read  = 0;
                int startHighlightIndex = -1;

                ICSharpTreeNode      readAnchor          = null;
                bool                 inlineCacheValue    = false;
                ICSharpTreeNode      writeAnchor         = null;
                IReferenceExpression lastWriteExpression = null;
                bool                 inlineRestoreValue  = false;

                for (int i = 0; i < highlighitingElements.Count; i++)
                {
                    var referenceExpression = highlighitingElements[i];

                    var accessType = referenceExpression.GetAccessType();

                    if (read == 0 && write == 0)
                    {
                        readAnchor = referenceExpression.GetContainingStatementLike().NotNull("readAnchor != null");
                        var previousRelatedExpression = GetPreviousRelatedExpression(referenceExpression, readAnchor);
                        // if we have related expression before considered reference expression, we can only inline reading into statement
                        // Example:
                        // transform.Position = (transform.localPosition = Vector3.Up) + transform.position + transform.position;
                        //                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                        // transform.localPosition is related to transform.position, but we need cache our variable
                        // The result is:
                        // var cache = transform.position;
                        // transform.position = (transform.localPosition = Vector3.Up) + (cache = transform.position) + cache;

                        inlineCacheValue = previousRelatedExpression != null;
                    }

                    if (accessType.HasFlag(ExpressionAccessType.Write))
                    {
                        write++;
                        lastWriteExpression = referenceExpression;
                    }
                    if (accessType.HasFlag(ExpressionAccessType.Read))
                    {
                        read++;
                    }

                    if (startHighlightIndex == -1 && (read == 2 || write == 2 | read + write == 3))
                    {
                        startHighlightIndex = i;
                    }
                }

                if (lastWriteExpression != null)
                {
                    writeAnchor = lastWriteExpression.GetContainingStatementLike().NotNull("writeAnchor != null");
                    if (writeAnchor is IReturnStatement ||
                        writeAnchor is IYieldStatement yieldStatement && yieldStatement.StatementType == YieldStatementType.YIELD_RETURN)
                    {
                        inlineRestoreValue = true;
                    }
                    else
                    {
                        var relatedExpressions = GetFinder(lastWriteExpression).GetRelatedExpressions(writeAnchor, lastWriteExpression);
                        inlineRestoreValue = relatedExpressions.Any();
                    }
                }
Exemplo n.º 27
0
 public SnapNode(ICSharpTreeNode node, ExpressionKind kind)
     : this(node)
 {
     AddKind(kind);
 }
 public UnexpectedTypeOfNodeToEatException(Type expectedType, ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(string.Format("Unexpected type of tree node no eat. Expected [{0}], but was [{1}]", expectedType, node.GetType()), eater, node)
 {
 }
Exemplo n.º 29
0
 public MoqStubOptionTargetWrongTypeException(ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(string.Format("Moq-stub option target has wrong type. Expected invocation or reference expression. But was [{0}]", node.GetType()), eater, node)
 {
 }
 public EatingException(string message, ICSharpNodeEater eater, ICSharpTreeNode node)
 {
     Message = message;
     Eater = eater;
     Node = node;
 }
Exemplo n.º 31
0
 public MoqStubOptionWrongTypeException(ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(string.Format("Moq-stub options has wrong type. Expected conditional-and, equility, invocation, reference expressions. But was [{0}]", node.GetType()), eater, node)
 {
 }
 public EatingException(Exception exception, ICSharpNodeEater eater, ICSharpTreeNode node)
     : this(exception.Message, exception, eater, node)
 {
 }
 public UnexpectedTypeOfNodeToEatException(Type expectedType, ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(string.Format("Unexpected type of tree node no eat. Expected [{0}], but was [{1}]", expectedType, node.GetType()), eater, node)
 {
 }
 public MoqStubOptionTargetWrongTypeException(ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(string.Format("Moq-stub option target has wrong type. Expected invocation or reference expression. But was [{0}]", node.GetType()), eater, node)
 {
 }
Exemplo n.º 35
0
 private static bool HasError(ICSharpTreeNode prev)
 {
     return(prev.LastChild is IErrorElement);
 }
Exemplo n.º 36
0
 protected TreeNodeBase(ICSharpTreeNode treeNode)
 {
     _treeNode = treeNode;
 }
Exemplo n.º 37
0
 internal ThrowExceptionInUnexpectedLocationWarning([NotNull] string message, [NotNull] ICSharpTreeNode thrownStatementOrExpression) :
     base(message)
     => this.thrownStatementOrExpression = thrownStatementOrExpression;
Exemplo n.º 38
0
        private void AddAny(ExpressionKind expressionKind, ICSharpTreeNode sharpTreeNode)
        {
            if (expressionKind == ExpressionKind.None || expressionKind == ExpressionKind.StubCandidate)
            {
                return;
            }

            var node = SnapNodes.SingleOrDefault(t => t.Node == sharpTreeNode);
            if (node == null)
            {
                SnapNodes.Add(new SnapNode(sharpTreeNode, expressionKind));
            }
            else
            {
                node.AddKind(expressionKind);
            }
        }
 public MoqStubWrongSyntaxException(string message, ICSharpNodeEater eater, ICSharpTreeNode node)
     : base(message, eater, node)
 {
 }