Ejemplo n.º 1
0
 internal DiagnosticBuilder(Diagnostics otherDiagnostics)
 {
     Diagnostics = CreateDiagnostics();
     foreach (var otherGroup in otherDiagnostics.Groups)
     {
         Diagnostics.Group thisGroup = Diagnostics.Groups[otherGroup.Key];
         foreach (var occurrence in otherGroup.Value.Occurrences)
         {
             thisGroup.Occurrences.Add(occurrence);
         }
     }
 }
Ejemplo n.º 2
0
        private Diagnostics CreateDiagnosticsFromSchema(Stream diagnosticSchema)
        {
            Diagnostics diagnostics = new DiagnosticsImpl();
            XElement    groupx      = new XElement("no-group-detail-avaialable");

            try
            {
                XDocument schema = XDocument.Load(diagnosticSchema);
                IEnumerable <XElement> groups = schema.Element(Constants.DiagnosticSchemaRoot)
                                                .Elements("group");
                foreach (var group in groups)
                {
                    groupx = group;
                    string topic;
                    var    dg = new Diagnostics.Group(
                        topic = group.Element("topic").Value
                        , (Diagnostics.Severity)Enum.Parse(
                            typeof(Diagnostics.Severity), group.Element("severity").Value)
                        , group.Element("intro").Value
                        , group.Element("background").Value
                        , group.Element("template").Value
                        , group.Element("artefacts").Elements()
                        .ToHashSet(a => a.Name.ToString())
                        );
                    diagnostics.Groups[topic] = dg;
                }
            }
            catch (ArgumentNullException ane)
            {
                throw new IOException($"The diagnostic schema is not valid. See:{Environment.NewLine}"
                                      + groupx, ane);
            }
            catch (NullReferenceException nre)
            {
                throw new Exception($"The diagnostic schema is not valid. See:{Environment.NewLine}"
                                    + groupx, nre);
            }
            catch (XmlException xe)
            {
                throw new Exception($"The diagnostic schema not correct XML."
                                    , xe);
            }
            return(diagnostics);
        }
Ejemplo n.º 3
0
        private void DetectNonBeanWithFactoryInterface(IReadOnlyList <Assembly> assemblies, Diagnostics diagnostics)
        {
            var classesWithFactoryInterface
                = assemblies.SelectMany(a => a.GetTypes())
                  .Where(t => t.GetInterfaces()
                         .Any(i => i.FullName == typeof(IFactory).FullName));
            var nonBeanFactories
                = classesWithFactoryInterface.Where(c =>
                                                    !c.GetCustomAttributes <BeanBaseAttribute>().Any() &&
                                                    !c.GetCustomAttributes <IgnoreBaseAttribute>().Any());

            Diagnostics.Group group = diagnostics.Groups["NonBeanFactory"];
            foreach (var type in nonBeanFactories)
            {
                dynamic diag = group.CreateDiagnostic();
                diag.Type = type.FullName;
                group.Add(diag);
            }
        }
Ejemplo n.º 4
0
        public void DetectUnreachableConstructors(IReadOnlyList <Assembly> assemblies, Diagnostics diagnostics)
        {
            var typesAndConstructors = assemblies.SelectMany(a =>
                                                             a.GetTypes().SelectMany(
                                                                 t => t.GetConstructors(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)
                                                                 .Select(c => new { type = t, constructor = c })));
            var nonBeanAndConstructors =
                typesAndConstructors.Where(tm => tm.type.IsAbstract || !tm.type.GetCustomAttributes <BeanBaseAttribute>().Any());
            var nonBeanTypesWithBeanConstructors =
                nonBeanAndConstructors.Where(tm => tm.constructor.GetCustomAttributes <ConstructorBaseAttribute>().Any());

            Diagnostics.Group group = diagnostics.Groups["UnreachableConstructor"];
            foreach (var typeAndMember in nonBeanTypesWithBeanConstructors)
            {
                dynamic diag = group.CreateDiagnostic();
                diag.Type = typeAndMember.type;
                group.Add(diag);
            }
        }
Ejemplo n.º 5
0
        private void DetectUnreachableStructs(IReadOnlyList <Assembly> assemblies, Diagnostics diagnostics)
        {
            var nonBeanStructMembers
                = assemblies.SelectMany(a => a.GetTypes()).SelectMany(t => t.GetMembers().Select(m => new { type = t, member = m }))
                  .Where(tm => tm.member is FieldInfo || tm.member is PropertyInfo)
                  .Where(tm => tm.member.GetPropertyOrFieldType().IsStruct())
                  .Where(tm => !tm.member.GetCustomAttributes <BeanReferenceBaseAttribute>().Any())
                  .Select(tm => new { declaration = tm, structType = tm.member.GetPropertyOrFieldType() })
                  .Where(ds => ds.structType.GetCustomAttributes <BeanBaseAttribute>().Any());

            Diagnostics.Group group = diagnostics.Groups["UnreachableStruct"];
            foreach (var ds in nonBeanStructMembers)
            {
                dynamic diag = group.CreateDiagnostic();
                diag.DeclaringType = ds.declaration.type.FullName;
                diag.MemberType    = ds.structType.FullName;
                diag.MemberName    = ds.declaration.member.Name;
                group.Add(diag);
            }
        }
Ejemplo n.º 6
0
        public void DetectUnreachableMembers(IReadOnlyList <Assembly> assemblies, Diagnostics diagnostics)
        {
            var typesAndMembers = assemblies.SelectMany(a =>
                                                        a.GetTypes().SelectMany(
                                                            t => t.GetMembers(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance)
                                                            .Select(m => new { type = t, member = m }))).Where(tm => tm.member.IsPropertyOrField());
            var nonBeanMembers =
                typesAndMembers.Where(tm => tm.type.IsAbstract || !tm.type.GetCustomAttributes <BeanBaseAttribute>().Any());
            var nonBeanTypesWithBeanReferences =
                nonBeanMembers.Where(tm => tm.member.GetCustomAttributes <BeanReferenceBaseAttribute>().Any());

            Diagnostics.Group group = diagnostics.Groups["UnreachableReference"];
            foreach (var typeAndMember in nonBeanTypesWithBeanReferences)
            {
                dynamic diag = group.CreateDiagnostic();
                diag.Type       = typeAndMember.type;
                diag.MemberName = typeAndMember.member.Name;
                diag.MemberType = typeAndMember.member.GetPropertyOrFieldType();
                group.Add(diag);
            }
        }
Ejemplo n.º 7
0
 internal Diagnostic(Diagnostics.Group group)
 {
     this.group = group;
     Members    = CreateArtefactMap(group.ArtefactSchema);
 }