Exemplo n.º 1
0
        private void ReplaceMethodSignatureToAsync([NotNull] IParametersOwner parametersOwner, [NotNull] IMethodDeclaration methodDeclaration)
        {
            var returnType = parametersOwner.ReturnType;

            var           psiModule = methodDeclaration.GetPsiModule();
            IDeclaredType newReturnValue;

            if (returnType.IsVoid())
            {
                newReturnValue = TypeFactory.CreateTypeByCLRName("System.Threading.Tasks.Task", psiModule);
            }
            else
            {
                var task = TypeFactory.CreateTypeByCLRName("System.Threading.Tasks.Task`1", psiModule).GetTypeElement();
                if (task == null)
                {
                    return;
                }
                newReturnValue = TypeFactory.CreateType(task, returnType);
            }

            var name = GenerateAsyncMethodName(methodDeclaration.DeclaredName);

            SetSignature(methodDeclaration, newReturnValue, name);

            if (awaitEliderChecker.CanElide(methodDeclaration))
            {
                awaitElider.Elide(methodDeclaration);
            }
        }
        static bool IsTestMethodOfOldMsTest([CanBeNull] IMethodDeclaration methodDeclaration)
        {
            if (methodDeclaration == null || !methodDeclaration.IsDeclaredInOldMsTestProject())
            {
                return(false);
            }

            var testMethodAttributeTypes = null as IDeclaredType[];

            return(methodDeclaration.Attributes.Any(
                       attribute =>
            {
                if (attribute == null)
                {
                    return false;
                }

                if (testMethodAttributeTypes == null)
                {
                    testMethodAttributeTypes = new IDeclaredType[testMethodAttributes.Length];
                    for (var i = 0; i < testMethodAttributes.Length; i++)
                    {
                        testMethodAttributeTypes[i] = TypeFactory.CreateTypeByCLRName(
                            testMethodAttributes[i],
                            NullableAnnotation.Unknown,
                            methodDeclaration.GetPsiModule());
                    }
                }

                var attributeType = attribute.GetAttributeInstance().GetAttributeType();

                return testMethodAttributeTypes.Any(
                    type => attributeType.Equals(type, TypeEqualityComparer.Default) || attributeType.IsSubtypeOf(type));
            }));
        }
Exemplo n.º 3
0
        private void GetTestScope(IMethodDeclaration unitTest)
        {
            var module  = unitTest.GetPsiModule();
            var project = module.ContainingProjectModule as ProjectImpl;

            TestProjectName    = project.Name;
            TestedProjectNames = project.GetProjectReferences().Select(t => t.Name);
        }
Exemplo n.º 4
0
        private IType CreateParameterType(UnityEventFunctionParameter parameter)
        {
            var type = TypeFactory.CreateTypeByCLRName(parameter.ClrTypeName, myMethodDeclaration.GetPsiModule());

            if (parameter.IsArray)
            {
                return(TypeFactory.CreateArrayType(type, 1));
            }
            return(type);
        }
Exemplo n.º 5
0
        public InvalidReturnTypeFix(InvalidReturnTypeWarning warning)
        {
            var eventFunction = warning.Function;

            myMethodDeclaration = warning.MethodDeclaration;

            myReturnType = TypeFactory.CreateTypeByCLRName(eventFunction.ReturnType, myMethodDeclaration.GetPsiModule());
            if (eventFunction.ReturnTypeIsArray)
            {
                myReturnType = TypeFactory.CreateArrayType(myReturnType, 1);
            }
        }
Exemplo n.º 6
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));
                }
            });
        }
Exemplo n.º 7
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var element = myMethodDeclaration.DeclaredElement;

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

            var predefinedTypeCache = solution.GetComponent <IPredefinedTypeCache>();
            var predefinedType      = predefinedTypeCache.GetOrCreatePredefinedType(myMethodDeclaration.GetPsiModule());

            var language         = myMethodDeclaration.Language;
            var changeTypeHelper = LanguageManager.Instance.GetService <IChangeTypeHelper>(language);

            changeTypeHelper.ChangeType(predefinedType.IEnumerator, element);

            return(null);
        }
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var element = myMethodDeclaration.DeclaredElement;

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

            var unityApi        = solution.GetComponent <UnityApi>();
            var knownTypesCache = solution.GetComponent <KnownTypesCache>();
            var eventFunction   = unityApi.GetUnityEventFunction(element);

            var returnType = eventFunction.ReturnType.AsIType(knownTypesCache, myMethodDeclaration.GetPsiModule());

            var changeTypeHelper = LanguageManager.Instance.GetService <IChangeTypeHelper>(myMethodDeclaration.Language);

            changeTypeHelper.ChangeType(returnType, element);

            return(null);
        }
Exemplo n.º 9
0
        protected override Action <ITextControl> ExecutePsiTransaction(ISolution solution, IProgressIndicator progress)
        {
            var element = myMethodDeclaration.DeclaredElement;

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

            var unityApi      = solution.GetComponent <UnityApi>();
            var eventFunction = unityApi.GetUnityEventFunction(element);

            IType returnType = TypeFactory.CreateTypeByCLRName(eventFunction.ReturnType, myMethodDeclaration.GetPsiModule());

            if (eventFunction.ReturnTypeIsArray)
            {
                returnType = TypeFactory.CreateArrayType(returnType, 1);
            }

            var language         = myMethodDeclaration.Language;
            var changeTypeHelper = LanguageManager.Instance.GetService <IChangeTypeHelper>(language);

            changeTypeHelper.ChangeType(returnType, element);

            return(null);
        }
Exemplo n.º 10
0
 private void GetTestScope(IMethodDeclaration unitTest)
 {
     var module = unitTest.GetPsiModule();
     var project = module.ContainingProjectModule as ProjectImpl;
     TestProjectName = project.Name;
     TestedProjectNames = project.GetProjectReferences().Select(t => t.Name);
 }