コード例 #1
0
		public IEnumerable<IHalsteadMetrics> Calculate(SyntaxNode root)
		{
			var analyzer = new HalsteadAnalyzer();
			var childNodes = root.ChildNodes().AsArray();

			var types = childNodes.Where(n => n.IsKind(SyntaxKind.ClassDeclaration) || n.IsKind(SyntaxKind.StructDeclaration))
				.AsArray();
			var methods = types.SelectMany(n => n.ChildNodes().Where(_isMethod));
			var getProperties = types.SelectMany(n => n.ChildNodes().Where(IsGetProperty));
			var setProperties = types.SelectMany(n => n.ChildNodes().Where(IsSetProperty));
			var looseMethods = childNodes.Where(_isMethod);
			var looseGetProperties = childNodes.Where(IsGetProperty);
			var looseSetProperties = childNodes.Where(IsSetProperty);
			var members = methods.Concat(getProperties)
								 .Concat(setProperties)
								 .Concat(looseMethods)
								 .Concat(looseGetProperties)
								 .Concat(looseSetProperties)
								 .AsArray();
			if (members.Any())
			{
				return members.Select(analyzer.Calculate);
			}

			var statements = childNodes.Length == 0
				? root.DescendantNodesAndTokens().Select(x => SyntaxFactory.ParseStatement(x.ToFullString(), 0, new CSharpParseOptions(kind: SourceCodeKind.Script, preprocessorSymbols: new string[0])))
				: childNodes.Select(x => SyntaxFactory.ParseStatement(x.ToFullString(), 0, new CSharpParseOptions(kind: SourceCodeKind.Script, preprocessorSymbols: new string[0])));

			var fakeMethod = SyntaxFactory.MethodDeclaration(SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.VoidKeyword)), "fake")
				.WithBody(SyntaxFactory.Block(statements));
			return new[]
				   {
					   analyzer.Calculate(fakeMethod)
				   };
		}
コード例 #2
0
 /// <summary>
 /// Gets the list of the nodes that were annotated for a conflict check 
 /// </summary>
 private IEnumerable<ValueTuple<SyntaxNodeOrToken, RenameActionAnnotation>> GetNodesOrTokensToCheckForConflicts(
     DocumentId documentId,
     SyntaxNode syntaxRoot)
 {
     return syntaxRoot.DescendantNodesAndTokens(descendIntoTrivia: true)
         .Where(s => _renameAnnotations.HasAnnotations<RenameActionAnnotation>(s))
         .Select(s => ValueTuple.Create(s, _renameAnnotations.GetAnnotations<RenameActionAnnotation>(s).Single()));
 }