public static MethodSignatureMatch Match(this UnityEventFunction eventFunction, [NotNull] IMethod method)
        {
            if (method.ShortName != eventFunction.Name)
            {
                return(MethodSignatureMatch.NoMatch);
            }

            var match = MethodSignatureMatch.ExactMatch;

            if (method.IsStatic != eventFunction.IsStatic)
            {
                match |= MethodSignatureMatch.IncorrectStaticModifier;
            }
            if (!HasMatchingParameters(eventFunction, method))
            {
                match |= MethodSignatureMatch.IncorrectParameters;
            }
            if (!HasMatchingReturnType(eventFunction, method))
            {
                match |= MethodSignatureMatch.IncorrectReturnType;
            }
            if (!HasMatchingTypeParameters(method))
            {
                match |= MethodSignatureMatch.IncorrectTypeParameters;
            }
            return(match);
        }
Example #2
0
        public static MethodSignature AsMethodSignature(this UnityEventFunction eventFunction, IPsiModule module)
        {
            IType returnType = TypeFactory.CreateTypeByCLRName(eventFunction.ReturnType, module);

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

            if (eventFunction.Parameters.Length == 0)
            {
                return(new MethodSignature(returnType, eventFunction.IsStatic));
            }

            var parameterTypes = new IType[eventFunction.Parameters.Length];
            var parameterNames = new string[eventFunction.Parameters.Length];

            for (var i = 0; i < eventFunction.Parameters.Length; i++)
            {
                var   parameter = eventFunction.Parameters[i];
                IType paramType = TypeFactory.CreateTypeByCLRName(parameter.ClrTypeName, module);
                if (parameter.IsArray)
                {
                    paramType = TypeFactory.CreateArrayType(paramType, 1);
                }
                parameterTypes[i] = paramType;
                parameterNames[i] = parameter.Name;
            }

            return(new MethodSignature(returnType, eventFunction.IsStatic, parameterTypes, parameterNames));
        }
Example #3
0
        private static bool HasMatchingParameters(UnityEventFunction eventFunction, IMethod method)
        {
            var matchingParameters = false;

            if (method.Parameters.Count == eventFunction.Parameters.Length)
            {
                matchingParameters = true;
                for (var i = 0; i < eventFunction.Parameters.Length && matchingParameters; i++)
                {
                    if (!DoTypesMatch(method.Parameters[i].Type, eventFunction.Parameters[i].ClrTypeName,
                                      eventFunction.Parameters[i].IsArray))
                    {
                        matchingParameters = false;
                    }
                }
            }
            else
            {
                // TODO: This doesn't really handle optional parameters very well
                // It's fine for the current usage (a single parameter, either there or not)
                // but won't work for anything more interesting. Perhaps optional parameters
                // should be modeled as overloads?
                var optionalParameters = 0;
                foreach (var parameter in eventFunction.Parameters)
                {
                    if (parameter.IsOptional)
                    {
                        optionalParameters++;
                    }
                }
                if (method.Parameters.Count + optionalParameters == eventFunction.Parameters.Length)
                {
                    matchingParameters = true;
                }
            }

            return(matchingParameters);
        }
        public static MethodSignature AsMethodSignature(this UnityEventFunction eventFunction,
                                                        KnownTypesCache knownTypesCache, IPsiModule module)
        {
            var returnType = eventFunction.ReturnType.AsIType(knownTypesCache, module);

            if (eventFunction.Parameters.Length == 0)
            {
                return(new MethodSignature(returnType, eventFunction.IsStatic));
            }

            var parameterTypes = new IType[eventFunction.Parameters.Length];
            var parameterNames = new string[eventFunction.Parameters.Length];

            for (var i = 0; i < eventFunction.Parameters.Length; i++)
            {
                var parameter = eventFunction.Parameters[i];
                var paramType = parameter.TypeSpec.AsIType(knownTypesCache, module);
                parameterTypes[i] = paramType;
                parameterNames[i] = parameter.Name;
            }

            return(new MethodSignature(returnType, eventFunction.IsStatic, parameterTypes, parameterNames));
        }
 private static bool HasMatchingReturnType(UnityEventFunction eventFunction, IMethod method)
 {
     return(DoTypesMatch(method.ReturnType, eventFunction.ReturnType) ||
            (eventFunction.CanBeCoroutine && IsEnumerator(method.ReturnType)));
 }
Example #6
0
 private static bool HasMatchingReturnType(UnityEventFunction eventFunction, IMethod method)
 {
     return(DoTypesMatch(method.ReturnType, eventFunction.ReturnType, eventFunction.ReturnTypeIsArray) ||
            (eventFunction.Coroutine && DoTypesMatch(method.ReturnType, ourEnumeratorType, false)));
 }