public bool CheckFieldForUnityImplicits([NotNull] IField field, [NotNull] IPsiModule module) { ITypeElement containingType = field.GetContainingType(); if (containingType == null) { return(false); } bool serializable = containingType.HasAttributeInstance(new ClrTypeName("System.SerializableAttribute"), true); bool unityObject = containingType.GetSuperTypes().Any(t => IsUnityImplicitType(t, module)); if (!serializable && !unityObject) { return(false); } if (field.GetAccessRights() == AccessRights.PUBLIC) { return(true); } foreach (KeyValuePair <string, string> pair in m_unitySettings.UnityUsageAttributes.EnumIndexedValues()) { bool hasAtttribute = field.HasAttributeInstance(new ClrTypeName(pair.Value), true); if (hasAtttribute) { return(true); } } return(false); }
private static TypeHierarchy CreateTypeHierarchy(ITypeElement type, ISubstitution substitution, IKaVEList <ITypeName> seenTypes, bool shouldIgnoreRootTypes) { if (shouldIgnoreRootTypes && (type == null || IsRootType(type))) { // ignore implicite extensions in type hierarchy return(null); } var typeName = type.GetName <ITypeName>(substitution); seenTypes.Add(typeName); var enclosingClassHierarchy = new TypeHierarchy(typeName.Identifier); foreach (var superType in type.GetSuperTypes()) { var resolveResult = superType.Resolve(); var declElem = resolveResult.DeclaredElement; var isUnresolvedAlias = declElem is IUsingAliasDirective; // TODO NameUpdate: "isUnknownOrUnResolvedUntested" required by one analyzed solution, still untested var isUnknownOrUnResolvedUntested = superType.IsUnknown || !superType.IsResolved; if (!resolveResult.IsValid() || declElem == null || isUnresolvedAlias || isUnknownOrUnResolvedUntested) { enclosingClassHierarchy.Implements.Add(new TypeHierarchy()); continue; } var superName = declElem.GetName <ITypeName>(substitution); if (seenTypes.Contains(superName)) { continue; } var superTypeElement = superType.GetTypeElement(); var superTypeSubstitution = superType.GetSubstitution(); var superHierarchy = CreateTypeHierarchy(superTypeElement, superTypeSubstitution, seenTypes, true); if (declElem is IClass || declElem is IStruct) { enclosingClassHierarchy.Extends = superHierarchy; } else if (declElem is IInterface) { enclosingClassHierarchy.Implements.Add(superHierarchy); } } return(enclosingClassHierarchy); }
/// <summary> /// It is possible for GetSuperTypes to return types that would form a cycle /// if the user typed in something like "class A : A" (even accidentally). /// This will cause big problems down the line so we drop supertypes with cycles. /// </summary> private static IEnumerable<IDeclaredType> SafeGetSuperTypes(ITypeElement typeElement) { if (!typeElement.IsValid()) yield break; IList<IDeclaredType> superTypes = typeElement.GetSuperTypes(); if (superTypes.Count == 0) yield break; foreach (IDeclaredType superType in typeElement.GetSuperTypes()) { #if RESHARPER_31 || RESHARPER_40 || RESHARPER_41 if (superType.IsValid) #else if (superType.IsValid()) #endif { ITypeElement superTypeElement = superType.GetTypeElement(); if (superTypeElement.IsValid()) { if (!HasSuperTypeCycle(superTypeElement)) yield return superType; } } } }