private static bool IsTestFixture(ITypeElement typeElement) { if (!(typeElement is IClass) && !(typeElement is IStruct)) { return(false); } if (typeElement.GetAllTypeParameters().Any()) { return(false); // type should be concrete } var modifiersOwner = (IModifiersOwner)typeElement; if (modifiersOwner.IsAbstract || modifiersOwner.GetAccessRights() == AccessRights.INTERNAL) { return(false); } if (typeElement.HasAttributeInstance(TestFixtureAttribute, false)) { return(true); } var @class = typeElement as IClass; if (@class != null) { var visited = new HashSet <IClass>(); while ((@class = @class.GetSuperClass()) != null) { if (visited.Contains(@class)) { break; } visited.Add(@class); if (@class.HasAttributeInstance(TestFixtureAttribute, false)) { return(true); } } } return(false); }
private static IEnumerable <IType> GetGenericUnderlyingTypes([NotNull] IType type) { if (!(type is IDeclaredType declaredType)) { yield break; } ITypeElement typeElement = type.GetTypeElement(); if (typeElement == null) { yield break; } ISubstitution substitution = declaredType.GetSubstitution(); foreach (ITypeParameter typeParameter in typeElement.GetAllTypeParameters()) { yield return(substitution[typeParameter]); } }
private static IDeclaredType GetTypeWithSubstitution([NotNull] ITypeElement typeElement, IList <FSharpType> fsTypes, [CanBeNull] IList <ITypeParameter> typeParamsFromContext, [NotNull] IPsiModule psiModule, bool isFromMethodSig) { var typeParams = typeElement.GetAllTypeParameters().Reverse().ToIList(); var typeArgs = new IType[typeParams.Count]; for (var i = 0; i < typeParams.Count; i++) { var typeArg = GetTypeArgumentType(fsTypes[i], typeParams[i]?.Type(), typeParamsFromContext, psiModule, isFromMethodSig); if (typeArg == null) { return(TypeFactory.CreateUnknownType(psiModule)); } typeArgs[i] = typeArg; } return(TypeFactory.CreateType(typeElement, typeArgs)); }
private StaticDeclaredTypeWrapper MakeDeclaredType(ITypeElement typeElementHandle, ISubstitution substitutionHandle) { if (typeElementHandle is ITypeParameter) throw new ArgumentException("This method should never be called with a generic parameter as input.", "typeElementHandle"); ITypeElement declaringTypeElementHandle = typeElementHandle.GetContainingType(); StaticDeclaredTypeWrapper type; if (declaringTypeElementHandle != null) { StaticDeclaredTypeWrapper declaringType = MakeDeclaredType(declaringTypeElementHandle, substitutionHandle); type = new StaticDeclaredTypeWrapper(this, typeElementHandle, declaringType, declaringType.Substitution); } else { type = new StaticDeclaredTypeWrapper(this, typeElementHandle, null, StaticTypeSubstitution.Empty); } #if ! RESHARPER_50_OR_NEWER var typeParameterHandles = new List<ITypeParameter>(typeElementHandle.AllTypeParameters); #else var typeParameterHandles = new List<ITypeParameter>(typeElementHandle.GetAllTypeParameters()); #endif #if RESHARPER_31 || RESHARPER_40 || RESHARPER_41 if (substitutionHandle.IsIdempotent(typeParameterHandles)) #else if (substitutionHandle.IsIdempotentAll(typeParameterHandles)) #endif { return type; } ITypeInfo[] genericArguments = GenericCollectionUtils.ConvertAllToArray<ITypeParameter, ITypeInfo>(typeParameterHandles, delegate(ITypeParameter typeParameterHandle) { IType substitutedType = substitutionHandle.Apply(typeParameterHandle); if (substitutedType.IsUnknown) return MakeGenericParameterType(typeParameterHandle); return MakeType(substitutedType); }); return type.MakeGenericType(genericArguments); }