Ejemplo n.º 1
0
        private UnitTestElementLocation GetUnitTestElementLocation(IInvocationExpression invocation)
        {
            var projectFile = invocation.GetSourceFile().ToProjectFile();
              var reference = (invocation.InvokedExpression as IReferenceExpression)
              .AssertNotNull("invocationExpression.InvokedExpression is not a IReferenceExpression");

              var startOffset = reference.NameIdentifier.GetDocumentStartOffset();
              var endOffset = invocation.GetDocumentRange().EndOffsetRange();
              var textRange = startOffset.JoinRight(endOffset).TextRange;

              return new UnitTestElementLocation(projectFile, textRange, textRange);
        }
Ejemplo n.º 2
0
        private static DisposeMethodStatus GetStatusForInvocationExpressionFromCache(
            IInvocationExpression invocationExpression)
        {
            var invokedDeclaredElement = invocationExpression.InvocationExpressionReference.Resolve().DeclaredElement;
            if (invokedDeclaredElement == null)
                return null;
            var invokedDeclaration = invokedDeclaredElement.GetDeclarations().FirstOrDefault();
            if (invokedDeclaration == null)
                return null;
            var invokedMethodDeclaration = invokedDeclaration as ICSharpFunctionDeclaration;
            if (invokedMethodDeclaration == null)
                return null;

            var offset = InvokedExpressionData.GetOffsetByNode(invokedMethodDeclaration);
            var cache = invokedMethodDeclaration.GetPsiServices().Solution.GetComponent<DisposeCache>();
            var invokedMethodSourceFile = invokedMethodDeclaration.GetSourceFile();
            if (invokedMethodSourceFile == null)
                return null;
            var methodStatus = cache.GetDisposeMethodStatusesForMethod(invokedMethodSourceFile, offset);
            if (methodStatus == null) // Принудительно пересчитываем кэш
            {
                var sourceFile = invocationExpression.GetSourceFile();
                if (DisposeCache.Accepts(invocationExpression.GetSourceFile()))
                {
                    var builtPart = cache.Build(sourceFile, false);
                    cache.Merge(sourceFile, builtPart);
                    methodStatus = cache.GetDisposeMethodStatusesForMethod(invokedMethodSourceFile, offset);
                }
            }
            return methodStatus;
        }