Exemple #1
0
        public static bool IsContainerCall(this ITreeNode node, string containerClrTypeName)
        {
            var invocationExpression = node as IInvocationExpression;

            if (invocationExpression == null)
            {
                return(false);
            }

            var resolve = invocationExpression.InvocationExpressionReference.Resolve().Result;
            var method  = resolve.DeclaredElement as IMethod;

            if (method == null)
            {
                return(false);
            }
            ITypeElement containingType = method.GetContainingType();

            if (containingType == null)
            {
                return(false);
            }

            var containerClrType = TypeFactory.CreateTypeByCLRName(containerClrTypeName, node.GetPsiModule());

            return(containingType.IsDescendantOf(containerClrType.GetTypeElement()));
        }
        private bool ownsTypeMatch(IDeclaration declaration)
        {
            if (string.IsNullOrEmpty(_isOfType))
            {
                return(true);
            }

            if (_isOfTypeType == null)
            {
                return(false);
            }

            if (declaration is ITypeOwner)
            {
                IDeclaredType declaredType = ((ITypeOwner)declaration).Type as IDeclaredType;
                if (declaredType == null)
                {
                    return(false);
                }
                ITypeElement typeElement = declaredType.GetTypeElement();
                if (typeElement == null)
                {
                    return(false);
                }
                return(typeElement.IsDescendantOf(_isOfTypeType));
            }
            else
            {
                return(false);
            }
        }
Exemple #3
0
        private bool IsNinjectBindCall(ITreeNode element)
        {
            var invocationExpression = element as IInvocationExpression;

            if (invocationExpression == null)
            {
                return(false);
            }

            var resolve = invocationExpression.InvocationExpressionReference.Resolve().Result;
            var method  = resolve.DeclaredElement as IMethod;

            if (method == null)
            {
                return(false);
            }
            ITypeElement containingType = method.GetContainingType();

            if (containingType == null)
            {
                return(false);
            }

            if (bindingRootType == null)
            {
                bindingRootType = TypeFactory.CreateTypeByCLRName("Ninject.Syntax.IBindingRoot", element.GetPsiModule());
            }

            return(containingType.IsDescendantOf(bindingRootType.GetTypeElement()));
        }
Exemple #4
0
        public IEnumerable <UnityType> GetBaseUnityTypes([NotNull] ITypeElement type, Version unityVersion)
        {
            var types = myTypes.Value;

            unityVersion = types.NormaliseSupportedVersion(unityVersion);
            return(types.Types.Where(t => t.SupportsVersion(unityVersion) && type.IsDescendantOf(t.GetTypeElement(type.Module))));
        }
        public static bool IsMonoBehaviourType([NotNull] ITypeElement typeElement, [NotNull] IPsiModule module)
        {
            // TODO: Should the module + resolve context be for Unity.Engine.dll?
            // Then we could create a single type and reuse it
            var monoBehaviour = TypeFactory.CreateTypeByCLRName(MonoBehaviourName, module).GetTypeElement();

            return(typeElement.IsDescendantOf(monoBehaviour));
        }
Exemple #6
0
 private IEnumerable <UnityType> GetBaseUnityTypes(UnityTypes types, ITypeElement type, Version normalisedVersion)
 {
     return(types.Types.Where(t =>
     {
         using (CompilationContextCookie.GetExplicitUniversalContextIfNotSet())
             return t.SupportsVersion(normalisedVersion) && type.IsDescendantOf(t.GetTypeElement(type.Module));
     }));
 }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            if (!typeElement.IsDescendantOf(basedOnElement))
            {
                return false;
            }

            return base.IsSatisfiedBy(typeElement);;
        }
Exemple #8
0
        public static bool IsDescendantOf([NotNull] IClrTypeName unityTypeClrName, [CanBeNull] ITypeElement type)
        {
            if (type == null)
            {
                return(false);
            }
            var mb = TypeFactory.CreateTypeByCLRName(unityTypeClrName, type.Module);

            return(type.IsDescendantOf(mb.GetTypeElement()));
        }
        public static bool IsFluentValidationAbstractValidator(this ITypeElement element)
        {
            if (element == null)
            {
                return(false);
            }

            var type = element.Module.GetFluentValidationPredefinedType().AbstractValidator.GetTypeElement();

            return(element.IsDescendantOf(type));
        }
        public static bool DerivesFrom([CanBeNull] this ITypeElement candidate, IClrTypeName baseTypeName)
        {
            if (candidate == null)
            {
                return(false);
            }
            var knownTypesCache = candidate.GetSolution().GetComponent <KnownTypesCache>();
            var baseType        = GetTypeElement(baseTypeName, knownTypesCache, candidate.Module);

            return(candidate.IsDescendantOf(baseType));
        }
        public static bool IsNUnitAssert(this ITypeElement element)
        {
            if (element == null)
            {
                return(false);
            }

            var type = element.Module.GetFluentAssertionsPredefinedType().Assert.GetTypeElement();

            return(element.IsDescendantOf(type));
        }
Exemple #12
0
 public bool IsUnityImplicitType([NotNull] ITypeElement typeElement, [NotNull] IPsiModule module)
 {
     foreach (KeyValuePair <string, string> pair in m_unitySettings.UnityClasses.EnumIndexedValues())
     {
         IDeclaredType typeByClrName = TypeFactory.CreateTypeByCLRName(pair.Value, module);
         ITypeElement  unityClass    = typeByClrName.GetTypeElement();
         if (typeElement.IsDescendantOf(unityClass))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #13
0
        public bool IsUnityECSType([CanBeNull] ITypeElement type)
        {
            if (type == null)
            {
                return(false);
            }

            var jobComponentSystem = TypeFactory.CreateTypeByCLRName(KnownTypes.JobComponentSystem, type.Module);

            if (type.IsDescendantOf(jobComponentSystem.GetTypeElement()))
            {
                return(true);
            }

            var componentSystem = TypeFactory.CreateTypeByCLRName(KnownTypes.ComponentSystem, type.Module);

            if (type.IsDescendantOf(componentSystem.GetTypeElement()))
            {
                return(true);
            }

            return(false);
        }
Exemple #14
0
        public static OneToListMap <string, IClass> GetAvailableModules([NotNull] IPsiModule module,
                                                                        [NotNull] ISearchDomain searchDomain,
                                                                        IModuleReferenceResolveContext contex,
                                                                        bool includingIntermediateControllers = false,
                                                                        ITypeElement baseClass = null)
        {
            ITypeElement[] typeElements;

            ITypeElement nancyModuleInterface = GetNancyModuleInterface(module, contex);

            if (baseClass != null)
            {
                if (baseClass.IsDescendantOf(nancyModuleInterface))
                {
                    typeElements = new[] { baseClass };
                }
                else
                {
                    return(new OneToListMap <string, IClass>(0));
                }
            }
            else
            {
                typeElements = new[] { nancyModuleInterface };
            }

            var found = new List <IClass>();

            foreach (ITypeElement typeElement in typeElements.WhereNotNull())
            {
                module.GetPsiServices()
                .Finder.FindInheritors(typeElement, searchDomain, found.ConsumeDeclaredElements(),
                                       NullProgressIndicator.Instance);
            }

            IEnumerable <IClass> classes = found.Where(@class => @class.GetAccessRights() == AccessRights.PUBLIC);

            if (!includingIntermediateControllers)
            {
                classes = classes.Where(@class => [email protected] &&
                                        @class.ShortName.EndsWith(ModuleClassSuffix,
                                                                  StringComparison.OrdinalIgnoreCase));
            }

            return(new OneToListMap <string, IClass>(
                       classes.GroupBy(GetControllerName,
                                       (name, enumerable) => new KeyValuePair <string, IList <IClass> >(name, enumerable.ToList())),
                       StringComparer.OrdinalIgnoreCase));
        }
        private bool inheritsMatch(IDeclaration declaration)
        {
            if (string.IsNullOrEmpty(_inheritedFrom))
            {
                return(true);
            }

            if (_inheritedFromType == null)
            {
                return(false);
            }

            ITypeElement typeElement = declaration.DeclaredElement as ITypeElement;

            if (typeElement == null)
            {
                return(false);
            }
            return(typeElement.IsDescendantOf(_inheritedFromType));
        }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            // todo for now assume that interfaces are not supported
            if (typeElement is IInterface)
            {
                return false;
            }

            if (Implementation != null)
            {
                if (Implementation.IsGenericInterface())
                {
                    return typeElement.IsDescendantOf(Implementation);
                }

                return Implementation.Equals(typeElement);
            }

            return serviceType.Equals(typeElement);
        }
        public override bool IsSatisfiedBy(ITypeElement typeElement)
        {
            // todo for now assume that interfaces are not supported
            if (typeElement is IInterface)
            {
                return(false);
            }

            if (Implementation != null)
            {
                if (Implementation.IsGenericInterface())
                {
                    return(typeElement.IsDescendantOf(Implementation));
                }

                return(Implementation.Equals(typeElement));
            }

            return(serviceType.Equals(typeElement));
        }
        /// <summary>
        ///   Check if the member is visible as C# type member I.e. it skips accessors except to properties with parameters
        /// </summary>
        public static bool IsCollectionInitializerAddMethod(IDeclaredElement declaredElement)
        {
            var method = declaredElement as IMethod;

            if (method == null)
            {
                return(false);
            }
            if (method.IsStatic)
            {
                return(false);
            }
            if (method.ShortName != "Add")
            {
                return(false);
            }

            ITypeElement containingType = method.GetContainingType();

            if (containingType == null)
            {
                return(false);
            }

            if (method.Parameters.Any(parameter => parameter.Kind != ParameterKind.VALUE))
            {
                return(false);
            }

            if (!containingType.IsDescendantOf(method.Module.GetPredefinedType().IEnumerable.GetTypeElement()))
            {
                return(false);
            }

            return(true);
        }
Exemple #19
0
 private IEnumerable <UnityType> GetBaseUnityTypes(UnityTypes types, ITypeElement type, Version normalisedVersion)
 {
     return(types.Types.Where(t => t.SupportsVersion(normalisedVersion) && type.IsDescendantOf(t.GetTypeElement(type.Module))));
 }
        /// <summary>
        /// Checks if the given type element is a Nuke build class definition.
        /// </summary>
        /// <param name="typeElement">The type element to test.</param>
        /// <returns>True if the type element is a Nuke build class definition.</returns>
        public static bool IsNukeBuildClass(this ITypeElement typeElement)
        {
            var nukeBuildTypeElement = TypeFactory.CreateTypeByCLRName("Nuke.Common.NukeBuild", typeElement.Module).GetTypeElement();

            return(typeElement.IsDescendantOf(nukeBuildTypeElement));
        }
 private bool IsAssignableFrom(ITypeElement typeElement, ITypeElement implementedBy)
 {
     return implementedBy.IsDescendantOf(implementedBy);
 }
Exemple #22
0
 public IEnumerable <UnityType> GetBaseUnityTypes([NotNull] ITypeElement type)
 {
     return(myTypes.Value.Where(t => t.SupportsVersion(myUnityVersion.Version) && type.IsDescendantOf(t.GetType(type.Module))));
 }
 public IEnumerable <UnityType> GetBaseUnityTypes([NotNull] ITypeElement type)
 {
     return(myTypes.Value.Where(c => type.IsDescendantOf(c.GetType(type.Module))));
 }
 public static bool ClosesOver(this ITypeElement typeElement, ITypeElement openGenericType)
 {
     // todo this is probably wrong
     return(typeElement.IsDescendantOf(openGenericType));
 }