protected override void Run(IUserDeclaredTypeUsage typeUsage, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) { var iRequire = typeUsage.TypeName.Reference.Resolve().DeclaredElement as IInterface; if (iRequire == null) { return; } if (!ZoneConstants.IsIRequire(iRequire)) { return; } foreach (var typeArgument in typeUsage.TypeName.TypeArguments) { var declaredType = typeArgument as IDeclaredType; if (declaredType != null) { var typeElement = declaredType.GetTypeElement(); if (typeElement != null) { if (!ZoneConstants.IsZoneDefinitionClass(typeElement)) { consumer.AddHighlighting(new UndefinedAxisError(typeUsage, typeElement.GetClrName().FullName, ZoneConstants.ZoneDefinitionAttributeNameFull), typeUsage.GetContainingFile()); } } } } }
protected override void Run(IClassDeclaration classDeclaration, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) { if (!myIsEnabled.Value) { return; } var typeElement = classDeclaration.DeclaredElement; if (typeElement == null || !ZoneConstants.IsZoneClass(typeElement)) { return; } var mark = myMarks.GetMark(typeElement.GetContainingNamespace()); var classes = myMarks.EnumerateClasses(mark).ToList(); // find all base zones var baseZones = new HashSet <IClass>(); foreach (var cls in classes) { foreach (var baseZone in MarksService.EnumerableMarkClasses(cls, true)) { if (!baseZone.Equals(cls)) { baseZones.Add(baseZone); } } } foreach (var typeUsage in classDeclaration.SuperTypeUsageNodes.OfType <IUserDeclaredTypeUsage>()) { IDeclaredType superType = CSharpTypeFactory.CreateDeclaredType(typeUsage); var superTypeElement = superType.GetTypeElement(); if (superTypeElement != null) { if (ZoneConstants.IsIRequire(superTypeElement as IInterface)) { var substitution = superType.GetSubstitution(); foreach (var parameter in substitution.Domain) { var zoneType = substitution[parameter] as IDeclaredType; if (zoneType != null) { var zoneClass = zoneType.GetTypeElement() as IClass; if (zoneClass != null && baseZones.Contains(zoneClass)) { consumer.AddHighlighting(new RedundantDependencySpecificationError(typeUsage), classDeclaration.GetContainingNode <IFile>()); } } } } } } }
public static IEnumerable <IClass> EnumerableMarkClasses([NotNull] IClass annotationClass, bool recursive) { if (annotationClass == null) { throw new ArgumentNullException("annotationClass"); } var ret = new LocalHashSet <IClass>(); var queue = new Queue <IClass>(); queue.Enqueue(annotationClass); while (!queue.IsEmpty()) { var el = queue.Dequeue(); foreach (var superType in el.GetSuperTypes()) { var typeElement = superType.GetTypeElement(); if (typeElement != null) { if (ZoneConstants.IsIRequire(typeElement as IInterface)) { var substitution = superType.GetSubstitution(); foreach (var parameter in substitution.Domain) { var zoneType = substitution[parameter] as IDeclaredType; if (zoneType != null) { var zoneClass = zoneType.GetTypeElement() as IClass; if (zoneClass != null) { if (ret.Add(zoneClass)) { if (recursive) { queue.Enqueue(zoneClass); } } } } } } } } } return(ret); }