示例#1
0
		public void Analyze(MethodBody body, NodeBase analyzedNode)
		{
			if (analyzedNode is MethodNode)
				((MethodNode)analyzedNode).CyclomaticComplexity = 0;
			
			if (body == null)
				return;
			
			foreach (var instruction in body.Instructions) {
				// IL cyclomatic complexity
				if (instruction.OpCode.FlowControl == FlowControl.Cond_Branch && analyzedNode is MethodNode)
					((MethodNode)analyzedNode).CyclomaticComplexity++;

				var operand = ReadOperand(instruction);
				
				if (operand is MethodReference) {
					var md = ((MethodReference)operand).Resolve();
					if (md != null && assemblies.Contains(md.DeclaringType.Module.Assembly) && mappings.cecilMappings.ContainsKey(md)) {
						if (md.IsGetter || md.IsSetter) {
							var propertyNode = mappings.propertyMappings[(IProperty)mappings.cecilMappings[md]];
							analyzedNode.AddRelationship(propertyNode);
						} else {
							var methodNode = mappings.methodMappings[(IMethod)mappings.cecilMappings[md]];
							analyzedNode.AddRelationship(methodNode);
						}
					}
				} else if (operand is FieldReference) {
					var fd = ((FieldReference)operand).Resolve();
					if (fd != null && assemblies.Contains(fd.DeclaringType.Module.Assembly) && mappings.cecilMappings.ContainsKey(fd)) {
						var fieldNode = mappings.fieldMappings[(IField)mappings.cecilMappings[fd]];
						analyzedNode.AddRelationship(fieldNode);
					}
				}
			}
		}
示例#2
0
		public static string GetInfoText(this NodeBase left, NodeBase top)
		{
			int item1 = left.GetUses(top);
			int item2 = top.GetUses(left);
			
			string text = GetText(item1, item2);
			
			return string.Format("{0} {1} {2}", left.Name, text, top.Name);
		}
示例#3
0
		public int GetUses(NodeBase value)
		{
			if (this == value)
				return -1;
			int uses;
			if (relationships.TryGetValue(value, out uses))
				return uses;
			return 0;
		}
示例#4
0
		public void AddRelationship(NodeBase reference)
		{
			foreach (NodeBase pa in AncestorsAndSelf) {
				if (reference.AncestorsAndSelf.Contains(pa)) break;
				foreach (NodeBase pb in reference.AncestorsAndSelf) {
					if (AncestorsAndSelf.Contains(pb)) break;
					pa.AddRelationshipInternal(pb);
				}
			}
		}
示例#5
0
		public void AddEdge(NodeBase target)
		{
			// copies all ancestors of target into a hashset
			// duplicates are removed
			while (target != null) {
				if (!outgoingEdges.Add(target))
					break;
				target = target.Parent;
			}
		}
示例#6
0
		void CreateEdges(NodeBase source)
		{
			// add edges to source
			while (source != null) {
				foreach (NodeBase n in outgoingEdges) {
					source.AddRelationship(n);
				}
				source = source.Parent;
			}
			outgoingEdges.Clear();
		}
示例#7
0
		public static BitmapSource GetIcon(NodeBase node)
		{
			if (node is AssemblyNode) 
				return GetIcon((AssemblyNode)node);
			if (node is NamespaceNode)
				return GetIcon((NamespaceNode)node);
			if (node is TypeNode)
				return GetIcon((TypeNode)node);
			if (node is MethodNode)
				return GetIcon((MethodNode)node);
			if (node is FieldNode)
				return GetIcon((FieldNode)node);
			if (node is PropertyNode)
				return GetIcon((PropertyNode)node);
			if (node is EventNode)
				return GetIcon((EventNode)node);
			
			return null;
		}
示例#8
0
		public void Analyze(MethodBody body, NodeBase analyzedNode)
		{
			if (analyzedNode is MethodNode)
				((MethodNode)analyzedNode).CyclomaticComplexity = 0;
			
			if (body == null)
				return;
			
			foreach (var instruction in body.Instructions) {
				// IL cyclomatic complexity
				if (instruction.OpCode.FlowControl == FlowControl.Cond_Branch && analyzedNode is MethodNode)
					((MethodNode)analyzedNode).CyclomaticComplexity++;

				var operand = ReadOperand(instruction);
				
				try {
					if (operand is MethodReference) {
						var md = ((MethodReference)operand).Resolve();
						if (md != null && assemblies.Contains(md.DeclaringType.Module.Assembly) && mappings.cecilMappings.ContainsKey(md)) {
							if (md.IsGetter || md.IsSetter) {
								var propertyNode = mappings.propertyMappings[(IProperty)mappings.cecilMappings[md]];
								mappings.AddEdge(propertyNode);
							} else if (md.IsAddOn || md.IsRemoveOn || md.IsFire || md.IsOther) {
								var eventNode = mappings.eventMappings[(IEvent)mappings.cecilMappings[md]];
								mappings.AddEdge(eventNode);
							} else {
								var methodNode = mappings.methodMappings[(IMethod)mappings.cecilMappings[md]];
								mappings.AddEdge(methodNode);
							}
						}
					} else if (operand is FieldReference) {
						var fd = ((FieldReference)operand).Resolve();
						if (fd != null && assemblies.Contains(fd.DeclaringType.Module.Assembly) && mappings.cecilMappings.ContainsKey(fd)) {
							var fieldNode = mappings.fieldMappings[(IField)mappings.cecilMappings[fd]];
							mappings.AddEdge(fieldNode);
						}
					}
				} catch (AssemblyResolutionException are) {
					LoggingService.InfoFormatted("CQA: Skipping operand reference: {0}\r\nException:\r\n{1}", operand, are);
				}
			}
		}
示例#9
0
		public static object GetInfoText(this NodeBase left, NodeBase top)
		{
			int item1 = left.GetUses(top);
			int item2 = top.GetUses(left);
			var uses = Tuple.Create(item1, item2);
			
			string text = colorizer.GetDescription(uses);
			
			return new TextBlock {
				Inlines = {
					left.Name,
					new Bold {
						Inlines = {
							" " + text + " "
						},
						Foreground = colorizer.GetColorBrush(uses)
					},
					top.Name
				}
			};
		}
示例#10
0
		public MatrixTreeNode(NodeBase node)
		{
			this.node = node;
		}
示例#11
0
			public AnalysisTypeVisitor(AssemblyAnalyzer context, NodeBase node)
			{
				this.context = context;
				this.node = node;
			}
示例#12
0
		void AddRelationshipsForType(NodeBase node, IType type)
		{
			type.AcceptVisitor(new AnalysisTypeVisitor(this, node));
		}
示例#13
0
		void AddRelationshipsForAttributes(IList<IAttribute> attributes, NodeBase node)
		{
			try {
				foreach (var attr in attributes) {
					if (attr.Constructor != null)
						AddEdge(methodMappings[attr.Constructor]);
				}
			} catch (NotSupportedException nse) {
				// HACK : workaround for bug in NR5's attribute blob parser.
				LoggingService.DebugFormatted("CQA: Skipping attributes of: {0}\r\nException:\r\n{1}", node.Name, nse);
			}
		}
示例#14
0
		void AddRelationshipsForTypes(IEnumerable<IType> directBaseTypes, NodeBase node)
		{
			foreach (var baseType in directBaseTypes) {
				AddRelationshipsForType(node, baseType);
			}
		}
示例#15
0
		void AddRelationshipsForTypeParameters(IList<ITypeParameter> typeParameters, NodeBase node)
		{
			foreach (var param in typeParameters) {
				AddRelationshipsForAttributes(param.Attributes, node);
				AddRelationshipsForType(node, param.EffectiveBaseClass);
			}
		}
示例#16
0
 public void AddChild(NodeBase child)
 {
     child.Parent = this;
     Children.Add(child);
 }
示例#17
0
		public void AddChild(NodeBase child)
		{
			child.Parent = this;
			Children.Add(child);
		}
示例#18
0
		public void AddRelationship(NodeBase reference)
		{
			if (!relationships.ContainsKey(reference))
				relationships[reference] = 0;
			relationships[reference]++;
		}
示例#19
0
		void AddRelationshipsForAttributes(IList<IAttribute> attributes, NodeBase node)
		{
			foreach (var attr in attributes) {
				node.AddRelationship(methodMappings[attr.Constructor]);
			}
		}