public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags)
        {
            ISolution         iSolution     = element.GetSolution();
            IList <IAssembly> allAssemblies = iSolution.GetAllAssemblies();
            bool referencesUnity            =
                allAssemblies.Any(
                    assembly => assembly.Name == "UnityEngine" || assembly.Name == "UnityEditor");

            if (!referencesUnity)
            {
                flags = ImplicitUseKindFlags.Default;
                return(false);
            }
            IClass cls = element as IClass;

            if (cls != null)
            {
                if (m_unitySolutionHelper.IsUnityImplicitType(cls, cls.Module))
                {
                    flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature;
                    return(true);
                }
            }

            IMethod method = element as IMethod;

            if (method != null && MonoBehaviourUtil.IsEventHandler(method.ShortName))
            {
                ITypeElement containingType = method.GetContainingType();
                if (containingType != null && m_unitySolutionHelper.IsUnityImplicitType(containingType, method.Module))
                {
                    flags = ImplicitUseKindFlags.Access;
                    return(true);
                }
            }

            IField field = element as IField;

            if (field != null)
            {
                if (m_unitySolutionHelper.CheckFieldForUnityImplicits(field, field.Module))
                {
                    // Public fields gets exposed to the Unity Editor and assigned from the UI. But it still should be checked if the field is ever accessed from the code.
                    flags = ImplicitUseKindFlags.Assign;
                    return(true);
                }
            }

            flags = ImplicitUseKindFlags.Default;
            return(false);
        }
Exemple #2
0
        public void Check(IDeclaration declaration, INamingPolicyProvider namingPolicyProvider, out bool isFinalResult, out NamingConsistencyCheckResult result)
        {
            var methodDeclaration = declaration as IMethodDeclaration;

            if (methodDeclaration != null && MonoBehaviourUtil.IsEventHandler(methodDeclaration.DeclaredName))
            {
                var containingTypeElement = methodDeclaration.GetContainingTypeDeclaration().DeclaredElement;
                if (containingTypeElement != null && MonoBehaviourUtil.IsMonoBehaviourType(containingTypeElement, methodDeclaration.GetPsiModule()))
                {
                    result        = NamingConsistencyCheckResult.OK;
                    isFinalResult = true;
                    return;
                }
            }

            result        = null;
            isFinalResult = false;
        }
Exemple #3
0
        public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags)
        {
            // TODO: Only do any work if the element belongs to a project that references Unity.Engine

            var cls = element as IClass;

            if (cls != null)
            {
                if (MonoBehaviourUtil.IsMonoBehaviourType(cls, cls.Module))
                {
                    flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature;
                    return(true);
                }
            }

            var method = element as IMethod;

            if (method != null && MonoBehaviourUtil.IsEventHandler(method.ShortName))
            {
                var containingType = method.GetContainingType();
                if (containingType != null && MonoBehaviourUtil.IsMonoBehaviourType(containingType, method.Module))
                {
                    flags = ImplicitUseKindFlags.Access;
                    return(true);
                }
            }

            var field = element as IField;

            if (field != null && field.GetAccessRights() == AccessRights.PUBLIC)
            {
                var containingType = field.GetContainingType();
                if (containingType != null && MonoBehaviourUtil.IsMonoBehaviourType(containingType, field.Module))
                {
                    // Public fields gets exposed to the Unity Editor and assigned from the UI. But it still should be checked if the field is ever accessed from the code.
                    flags = ImplicitUseKindFlags.Assign;
                    return(true);
                }
            }

            flags = ImplicitUseKindFlags.Default;
            return(false);
        }