public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) { return(cachedGraph); } cachedGraph = new DependencyGraph(); foreach (var method in Methods) { cachedGraph.AddVertex(new DependencyVertex(method)); } foreach (var field in Fields) { cachedGraph.AddVertex(new DependencyVertex(field)); } foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); } foreach (var fieldUse in method.FieldUses) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } } return(cachedGraph); }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) { return(_graphCache); } var g = new DependencyGraph(); foreach (var method in Methods) { g.AddVertex(new DependencyVertex(method)); } foreach (var field in Fields) { g.AddVertex(new DependencyVertex(field)); } foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); } foreach (var fieldUse in method.FieldUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } } _graphCache = g; return(g); }
private void FilterByType(string typeName, DependencyGraph newGraph) { TypeInfo previousType = null; var thisType = _currentGraph.Edges.FirstOrDefault(x => string.Equals(x.Source.Name, typeName))?.Source ?? _currentGraph.Edges.FirstOrDefault(x => string.Equals(x.Target.Name, typeName))?.Target; while (thisType != null && !string.Equals(thisType.Type.FullName, _selectedType.FullName)) { var type = thisType; var parent = previousType; var edgesToUse = previousType == null ? _currentGraph.Edges.Where(x => string.Equals(x.Source.Name, type.Name)) : _currentGraph.Edges.Where(x => string.Equals(x.Target.Name, parent.Name) && string.Equals(x.Source.Name, type.Name)); foreach (var edge in edgesToUse) { if (!newGraph.Vertices.Contains(edge.Source)) { newGraph.AddVertex(edge.Source); } if (!newGraph.Vertices.Contains(edge.Target)) { newGraph.AddVertex(edge.Target); } newGraph.AddEdge(edge); } previousType = thisType; thisType = thisType.Parent; } }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) return _graphCache; var g = new DependencyGraph(); foreach (var ns in Namespaces) { g.AddVertex(new DependencyVertex(ns)); } foreach (var ns in Namespaces) { foreach (var type in ns.Types) { var types = type.GetUses(); foreach (var dependType in types) { if (dependType != type && dependType.Namespace.Module == type.Namespace.Module) g.AddEdge(new DependencyEdge(new DependencyVertex(type.Namespace), new DependencyVertex(dependType.Namespace))); } } } _graphCache = g; return g; }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) { return(cachedGraph); } this.cachedGraph = new DependencyGraph(); foreach (var t in types) { cachedGraph.AddVertex(new DependencyVertex(t)); } foreach (var t in types) { foreach (var dependType in t.GetUsedTypes()) { if (dependType != t && dependType.Namespace == t.Namespace) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(t), new DependencyVertex(dependType))); } } } return(cachedGraph); }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) { return(cachedGraph); } cachedGraph = new DependencyGraph(); foreach (var ns in Namespaces) { cachedGraph.AddVertex(new DependencyVertex(ns)); foreach (var type in ns.Types) { var types = type.GetUsedTypes(); foreach (var dependType in types) { if (dependType != type && dependType.Namespace.Assembly == type.Namespace.Assembly) { cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(type.Namespace), new DependencyVertex(dependType.Namespace))); } } } } return(cachedGraph); }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) { return(_graphCache); } var g = new DependencyGraph(); foreach (var type in Types) { g.AddVertex(new DependencyVertex(type)); } foreach (var type in Types) { var types = type.GetUses(); foreach (var dependType in types) { if (dependType != type && dependType.Namespace == type.Namespace) { g.AddEdge(new DependencyEdge(new DependencyVertex(type), new DependencyVertex(dependType))); } } } _graphCache = g; return(g); }
private void FilterByAssemblies(DependencyGraph newGraph) { var matchingEdges = _currentGraph.Edges.Where(x => ReferencedAssemblies.Any(y => y.ShouldShow && x.Source.Assembly == y.AssemblyName) && ReferencedAssemblies.Any(y => y.ShouldShow && x.Target.Assembly == y.AssemblyName)); foreach (var edge in matchingEdges) { if (!newGraph.Vertices.Contains(edge.Source)) { newGraph.AddVertex(edge.Source); } if (!newGraph.Vertices.Contains(edge.Target)) { newGraph.AddVertex(edge.Target); } newGraph.AddEdge(edge); } }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) return cachedGraph; cachedGraph = new DependencyGraph(); foreach (var method in Methods) cachedGraph.AddVertex(new DependencyVertex(method)); foreach (var field in Fields) cachedGraph.AddVertex(new DependencyVertex(field)); foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); foreach (var fieldUse in method.FieldUses) cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } return cachedGraph; }
public DependencyGraph BuildDependencyGraph() { if (_graphCache != null) return _graphCache; var g = new DependencyGraph(); foreach (var method in Methods) { g.AddVertex(new DependencyVertex(method)); } foreach (var field in Fields) { g.AddVertex(new DependencyVertex(field)); } foreach (var method in Methods) { foreach (var methodUse in method.MethodUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(methodUse))); } foreach (var fieldUse in method.FieldUses) { g.AddEdge(new DependencyEdge(new DependencyVertex(method), new DependencyVertex(fieldUse))); } } _graphCache = g; return g; }
private void FillTypeInfoGraph(MemberInfo type, DependencyGraph rootTypeInfo, TypeInfo parent = null) { var typeInfo = GenerateTypeInfo(type, parent); if (rootTypeInfo.Vertices.Any(x => x.Equals(typeInfo)) && parent != null) { var vert = rootTypeInfo.Vertices.First(x => x.Equals(typeInfo)); var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(vert)); if (matchingEdge == null && !parent.Equals(vert)) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, vert)); } } else { rootTypeInfo.AddVertex(typeInfo); if (parent != null) { var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(typeInfo)); if (matchingEdge == null) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, typeInfo)); } } switch (type.MemberType) { case MemberTypes.Property: FillTypeInfoGraph(((PropertyInfo)type).PropertyType, rootTypeInfo, typeInfo); break; case MemberTypes.Constructor: break; case MemberTypes.Event: FillTypeInfoGraph(((EventInfo)type).EventHandlerType, rootTypeInfo, typeInfo); break; case MemberTypes.Field: FillTypeInfoGraph(((FieldInfo)type).FieldType, rootTypeInfo, typeInfo); break; case MemberTypes.Method: var methodInfo = type as MethodInfo; FillTypeInfoGraph(methodInfo.ReturnType, rootTypeInfo, typeInfo); var methodParameters = methodInfo.GetParameters(); foreach (var parameter in methodParameters) { FillTypeInfoGraph(parameter.ParameterType, rootTypeInfo, typeInfo); } var methodBody = methodInfo.GetMethodBody(); if (methodBody == null) { break; } foreach (var localVariable in methodBody.LocalVariables) { FillTypeInfoGraph(localVariable.LocalType, rootTypeInfo, typeInfo); } break; case MemberTypes.TypeInfo: break; case MemberTypes.Custom: break; case MemberTypes.NestedType: break; case MemberTypes.All: break; default: throw new ArgumentOutOfRangeException(); } } }
private void FillTypeInfoGraph(Type type, DependencyGraph rootTypeInfo, TypeInfo parent = null) { try { var enumerableEntryType = IsTypeOfEnumerableKind(type) ? GetEnumerableEntryType(type) : null; if (!ShouldProcessType(type, enumerableEntryType)) { return; } var typeInfo = GenerateTypeInfo(type, parent, enumerableEntryType); if (rootTypeInfo.Vertices.Any(x => x.Equals(typeInfo)) && parent != null) { var vert = rootTypeInfo.Vertices.First(x => x.Equals(typeInfo)); var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(vert)); if (matchingEdge == null && !parent.Equals(vert)) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, vert)); } } else { rootTypeInfo.AddVertex(typeInfo); if (parent != null) { var matchingEdge = rootTypeInfo.Edges.FirstOrDefault(x => x.Source.Equals(parent) && x.Target.Equals(typeInfo)); if (matchingEdge == null) { rootTypeInfo.AddEdge(new Edge <TypeInfo>(parent, typeInfo)); } } if (typeInfo.DeepDigType) { ProcessBaseTypes(type, rootTypeInfo, typeInfo); ProcessInterfaces(type, rootTypeInfo, typeInfo); ProcessKnownTypeAttributes(type, rootTypeInfo, typeInfo); ProcessCustomAttributes(type, rootTypeInfo, typeInfo); ProcessConstructors(type, rootTypeInfo, typeInfo); ProcessFields(type, rootTypeInfo, typeInfo); ProcessMethods(type, rootTypeInfo, typeInfo); ProcessEvents(type, rootTypeInfo, typeInfo); ProcessGenericArguments(type, rootTypeInfo, typeInfo); ProcessNetstedTypes(type, rootTypeInfo, typeInfo); ProcessProperties(type, rootTypeInfo, typeInfo); ProcessMembersAttributes(type.GetMembers(), rootTypeInfo, typeInfo); //ProcessChilds(type, rootTypeInfo, typeInfo); } if (enumerableEntryType != null) { FillTypeInfoGraph(enumerableEntryType, rootTypeInfo, typeInfo); } } } catch { } }
public DependencyGraph BuildDependencyGraph() { if (cachedGraph != null) return cachedGraph; this.cachedGraph = new DependencyGraph(); foreach (var t in types) { cachedGraph.AddVertex(new DependencyVertex(t)); } foreach (var t in types) { foreach (var dependType in t.GetUsedTypes()) { if (dependType != t && dependType.Namespace == t.Namespace) cachedGraph.AddEdge(new DependencyEdge(new DependencyVertex(t), new DependencyVertex(dependType))); } } return cachedGraph; }
public DependencyGraph Build() { projs.Keys.ForEach(p => { p.Project = new Project(p.Name, p.LibraryName, p.Guid, p.Filename, p.Languages); p.Project.Names.AddRange(p.Names.Where(n => !p.Project.Names.Contains(n)) .OrderBy(n => n, StringComparer.CurrentCultureIgnoreCase)); p.Project.LibraryNames.AddRange(p.LibraryNames.Where(n => !p.Project.LibraryNames.Contains(n)) .OrderBy(n => n, StringComparer.CurrentCultureIgnoreCase)); p.Ignored = Ignore(p.Project); }); CreateInitialProjects(); // Create project references first so we can create the entries as Project if possible CreateProjectReferences(); CreateLibraryReferences(); var libraries = db.QueryAll(); libraries.Where(l => !l.Languages.Any()) .ForEach(l => l.Languages.Add("Unknown")); libraries.ForEach(UpdateIsLocal); libraries.Sort(Library.NaturalOrdering); dependencies.Sort(Dependency.NaturalOrdering); RuleUtils.ReportUnusedConfig(warnings, "ignore", config.Ignores.Select(i => i.Location), usedIgnores); var graph = new DependencyGraph(); libraries.ForEach(p => graph.AddVertex(p)); dependencies.ForEach(d => graph.AddEdge(d)); return graph; }