Commits

roundcrisis committed d95e077

rename MethodCodeShape.cs to method shape
adding support for single method class

Comments (0)

Files changed (9)

src/CodeShapes/ClassAnalyzer.cs

 {
 	public class AnalizedClass
 	{
-		private IEnumerable<ICodeShape> _classShapes;
+		private IEnumerable<CodeShape> _classShapes;
 
-		public AnalizedClass(IEnumerable<ICodeShape> classShapes)
+		public AnalizedClass(IEnumerable<CodeShape> classShapes)
 		{
 			_classShapes = classShapes;
 		}
 	{
 		public IEnumerable<ICodeShape> Analyze<T>()
 		{
-			var shapes = FindAllPrivateMethods(typeof(T))
-				.Concat(FindMethods(typeof(T)))
+			var shapes = FindMethods(typeof(T))
+//				.Concat(FindMethods(typeof(T)))
 				.Concat(FindFields(typeof(T))).ToArray();
 
 			var methods = shapes.Where(s => s is MethodCodeShape).Cast<MethodCodeShape>();
 		public IEnumerable<FieldCodeShape> FindFields(Type type)
 		{
 			var fieldInfos = type.GetFields(BindingFlags.Public| BindingFlags.NonPublic| BindingFlags.Static| BindingFlags.Instance);
-			IList<FieldShape> fieldShapes = new List<FieldShape>();
+			IList<FieldCodeShape> fieldShapes = new List<FieldCodeShape>();
 			foreach (var fieldInfo in fieldInfos)
 			{
 				var visibility = fieldInfo.IsPublic ? Visibility.Public : Visibility.NonPublic;
-				fieldShapes.Add(new FieldShape(fieldInfo.Name, visibility));
+				fieldShapes.Add(new FieldCodeShape(fieldInfo.Name, visibility));
 			}
 			return fieldShapes.ToArray();
 		}
 		//todo: properties
-		private IEnumerable<IClassShape> FindMethods(Type type)
+		private IEnumerable<ICodeShape> FindMethods(Type type)
 		{
 			var privateProtectedInternalMethods = type.GetMethods( BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance);
 			var publicMethods = type.GetMethods();
 
-			List<MethodShape> result = privateProtectedInternalMethods.Select(methodInfo => new MethodShape(methodInfo, methodInfo.Name, Visibility.NonPublic)).ToList();
-			result.AddRange(publicMethods.Select(methodInfo => new MethodShape(methodInfo, methodInfo.Name, Visibility.Public)));
+			List<MethodCodeShape> result = privateProtectedInternalMethods.Select(methodInfo => new MethodCodeShape(methodInfo, methodInfo.Name, Visibility.NonPublic)).ToList();
+			result.AddRange(publicMethods.Select(methodInfo => new MethodCodeShape(methodInfo, methodInfo.Name, Visibility.Public)));
 			return result;
 		}
 	}

src/CodeShapes/CodeShapes.csproj

     <Compile Include="Shapes\FieldCodeShape.cs" />
     <Compile Include="Shapes\ICodeShape.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="Shapes\MethodShape.cs" />
+    <Compile Include="Shapes\MethodCodeShape.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
   <Target Name="AfterBuild">
   </Target>
   -->
-</Project>
+</Project>

src/CodeShapes/Shapes/CodeShape.cs

 		}
 		public string Name { get; protected set; }
 
-		public Visibility Visibility { get; private set; }
+		public Visibility Visibility { get; protected set; }
 
 		public IDictionary<int, ICodeShape> AdjacencyList { get; private set; }
 	}
 	public enum ShapeType
 	{
 		Method,
-		Property
+		Property,
+		Field
 	}
 }

src/CodeShapes/Shapes/MethodCodeShape.cs

 			MethodBase = methodBase;
 		}
 
-		public MethodCodeShape(string methodName, Visibility visibility)
-			: base(methodName, visibility)
-		{}
-
-		public MethodBase MethodBase { get; set; }
+		public MethodBase MethodBase { get; private set; }
 	}
 }

src/CodeShapes/Shapes/MethodShape.cs

-using System.Reflection;
-
-namespace CodeShapes.Shapes
-{
-	public class MethodShape : ClassShape
-	{
-		public MethodShape(MethodBase methodBase, string methodName, Visibility visibility)
-			: base(methodName)
-		{
-			MethodBase = methodBase;
-		}
-
-		public MethodShape(string methodName)
-			: base(methodName)
-		{}
-
-		public MethodBase MethodBase { get; private set; }
-
-		public Visibility Visibility { get; private set; }
-	}
-
-	public enum Visibility
-	{
-		Public,
-		NonPublic,
-		ProtectedMethod,
-		InternalMethod
-	}
-
-}

src/CodeShapesTests/ClassAnalyzerTests.cs

 		{
 			var classShapes = _classAnalyzer.Analyze<SampleClassWithProperty>();
 
-			IEnumerable<ICodeShape> fields = classShapes.Where(x => x.GetType().Equals(typeof(FieldCodeShape)));
+			var fields = classShapes.Where(x => x.GetType().Equals(typeof(FieldCodeShape)));
 
 			Assert.Contains(typeof(SampleClassWithProperty).GetFields().First().Name, fields.Select(x => x.Name));
 		}
 		{
 			var classShapes = _classAnalyzer.Analyze<SampleClass>();
 
-			var collection = classShapes.Where(x => x.GetType().Name == "PublicMethodCodeShape");
-			Assert.Equal("SampleMethod", collection.First().Name);
+			var collection = classShapes.Where(x => x.GetType().Name == typeof(MethodCodeShape).Name);
+			Assert.True(collection.Any(x => x.Name == "SampleMethod"));
 		}
 
 		[Fact]
 		{
 			var classShapes = _classAnalyzer.Analyze<SampleClass>();
 
-			Assert.True(classShapes.Any(x => x.GetType().Equals(typeof(PublicMethodCodeShape))));
+			Assert.True(classShapes.Any(x => x.GetType().Equals(typeof(MethodCodeShape))));
 		}
 
 		[Fact]
 		{
 			var classShapes = _classAnalyzer.Analyze<SampleClass>();
 
-			Assert.True(classShapes.Any(x => x.GetType().Equals(typeof(PublicMethodCodeShape))));
+			Assert.True(classShapes.Any(x => x.GetType().Equals(typeof(MethodCodeShape))));
 		}
 
 		[Fact]
 
 	public class SampleClassWithProperty
 	{
-		public string SampleProperty { get; set; }
+		public string SampleProperty;
 
 		public void SampleMethod()
 		{

src/CodeShapesTests/CodeShapeAcceptanceTests.cs

 using System;
+using CodeShapes;
 using StoryQ;
 using Xunit;
 
 	public class CodeShapeAcceptanceTests
 	{
 		private Feature _feature;
+		private Type _aClass;
+		private ClassAnalyzer _classAnalyzer;
 
 		public CodeShapeAcceptanceTests()
 		{
 			 var story = new Story("");
 			_feature = story.InOrderTo("Create a graph")
 				.AsA("developer")
-				.IWant("to enter a class collection and get a collection of images"); 
-			
+				.IWant("to enter a class collection and get a collection of images");
+			_classAnalyzer = new ClassAnalyzer();
 		}
 
 		[Fact]
 
 		private void IRunTheAnalizeMethod()
 		{
-			throw new NotImplementedException();
+			var codeShapes = _classAnalyzer.Analyze<MyClass>();
+			_classAnalyzer.TransformToGraph(codeShapes);
 		}
 
 		private void AClass()
 		{
-			throw new NotImplementedException();
+			_aClass = typeof (MyClass);
+		}
+	}
+
+	public class MyClass
+	{
+		public string MyString { get; private set; }
+
+		public void MyMethod(string someString)
+		{
+			MyPrivateMethod(someString);
+		}
+
+		private void MyPrivateMethod(string someString)
+		{
+			MyString = someString;
 		}
 	}
 }

src/CodeShapesTests/InstructionTests.cs

 		{
 			var methodInfo = typeof (SampleClass).GetMethod(name);
 			var fieldCodeShape = new FieldCodeShape("PublicField", Visibility.Public);
-			var publicMethodCodeShape = new PublicMethodCodeShape(methodInfo, name);
+			var publicMethodCodeShape = new MethodCodeShape(methodInfo, name, Visibility.Public);
 			publicMethodCodeShape.AdjacencyList.Add(1, fieldCodeShape);
 			return new List<ICodeShape>
 			       	{

src/CodeShapesTests/SampleClass.cs

 			PublicField = "Blah";
 			return _privateField;
 		}
+
+		protected void MyProtectedMethod()
+		{
+			PublicField = MyPrivateMethod();
+		}
+
+		private string MyPrivateMethod()
+		{
+			return _privateField;
+		}
 	}
 
 	public class SomeOtherClass
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.