public IEnumerable <IntentionAction> CreateBulbItems()
        {
            Assertion.AssertNotNull(myContainingBody, "create bulb invoked without checking is available");

            myContainingBody.GetPsiServices().Locks.AssertReadAccessAllowed();

            return(GetBulbItems(myContainingBody));
        }
        protected IAttribute FindPureAttribute([NotNull] IMethodDeclaration methodDeclaration)
        {
            var pureProvider = methodDeclaration.GetPsiServices().GetCodeAnnotationsCache().GetProvider <PureAnnotationProvider>();

            return(methodDeclaration
                   .AttributesEnumerable
                   .FirstOrDefault(attr => pureProvider.IsPureAttribute(attr.GetAttributeInstance().GetClrName())));
        }
        public IEnumerable <BulbMenuItem> GetMenuItems(IMethodDeclaration methodDeclaration, ITextControl textControl, IReadOnlyCallGraphContext context)
        {
            methodDeclaration.GetPsiServices().Locks.AssertReadAccessAllowed();

            if (!CheckCallGraph(methodDeclaration, context))
            {
                return(EmptyList <BulbMenuItem> .Enumerable);
            }

            var result = GetActions(methodDeclaration, textControl);

            return(result);
        }
Ejemplo n.º 4
0
        public void Execute(ISolution solution, ITextControl textControl)
        {
            // Physical tree modifications are allowed under transaction only!
            var transactions = myMethodDeclaration.GetPsiServices().Transactions;

            transactions.Execute(GetType().Name, () =>
            {
                using (WriteLockCookie.Create())
                {
                    AttributeUtil.AddAttributeToSingleDeclaration(myMethodDeclaration, KnownTypes.BurstDiscardAttribute,
                                                                  myMethodDeclaration.GetPsiModule(), CSharpElementFactory.GetInstance(myMethodDeclaration));
                }
            });
        }
        public static bool IsAvailable([CanBeNull] IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration == null)
            {
                return(false);
            }

            methodDeclaration.GetPsiServices().Locks.AssertReadAccessAllowed();

            var declaredElement = methodDeclaration.DeclaredElement;

            return(declaredElement != null && methodDeclaration.IsValid() &&
                   !PerformanceCriticalCodeStageUtil.IsPerformanceCriticalRootMethod(methodDeclaration));
        }
Ejemplo n.º 6
0
        public static bool IsAvailable([CanBeNull] IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration == null)
            {
                return(false);
            }

            methodDeclaration.GetPsiServices().Locks.AssertReadAccessAllowed();

            var declaredElement = methodDeclaration.DeclaredElement;

            return(declaredElement != null && methodDeclaration.IsValid() &&
                   !BurstCodeAnalysisUtil.IsBurstProhibitedFunction(declaredElement));
        }
Ejemplo n.º 7
0
        private void ReplaceMethodToAsync(IMethodDeclaration method)
        {
            if (!method.IsValid())
            {
                return;
            }

            var methodDeclaredElement = method.DeclaredElement;

            if (methodDeclaredElement == null)
            {
                return;
            }

            var finder = method.GetPsiServices().Finder;
            var usages = finder.FindAllReferences(methodDeclaredElement);

            foreach (var usage in usages)
            {
                var invocation = usage.GetTreeNode().Parent as IInvocationExpression;
                asyncInvocationReplacer.ReplaceInvocation(invocation, GenerateAsyncMethodName(method.DeclaredName), invocation?.IsUnderAsyncDeclaration() ?? false);
            }

            //TODO: ugly hack. think
            while (true)
            {
                var allInvocationReplaced = method
                                            .DescendantsInScope <IInvocationExpression>()
                                            .All(invocationExpression => !invocationConverter.TryReplaceInvocationToAsync(invocationExpression));
                if (allInvocationReplaced)
                {
                    break;
                }
            }

            foreach (var parametersOwnerDeclaration in method
                     .Descendants <IParametersOwnerDeclaration>()
                     .ToEnumerable()
                     .Where(awaitEliderChecker.CanElide))
            {
                awaitElider.Elide(parametersOwnerDeclaration);
            }

            ReplaceMethodSignatureToAsync(methodDeclaredElement, method);
        }
Ejemplo n.º 8
0
        private void ReplaceMethodToAsync(IMethodDeclaration method)
        {
            if (!method.IsValid())
            {
                return;
            }

            var methodDeclaredElement = method.DeclaredElement;

            if (methodDeclaredElement == null)
            {
                return;
            }

            var finder = method.GetPsiServices().Finder;
            var usages = finder.FindAllReferences(methodDeclaredElement);

            foreach (var usage in usages)
            {
                var invocation = usage.GetTreeNode().Parent as IInvocationExpression;
                asyncInvocationReplacer.ReplaceInvocation(invocation, GenerateAsyncMethodName(method.DeclaredName), invocation?.IsUnderAsyncDeclaration() ?? false);
            }
            while (true)
            {
                var allInvocationReplaced = method
                                            .Body
                                            .Descendants <IInvocationExpression>()
                                            .ToEnumerable()
                                            .All(invocationExpression => !TryReplaceInvocationToAsync(invocationExpression));
                if (allInvocationReplaced)
                {
                    break;
                }
            }

            ReplaceMethodSignatureToAsync(methodDeclaredElement, method);
        }