Browse Source

Implemented icons in tree. Added a lof of properties with information about fields, methods and so on.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@6036 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Tomáš Linhart 16 years ago
parent
commit
58f9e89c20
  1. 5
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj
  2. 8
      src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.sln
  3. 5
      src/AddIns/Analysis/CodeQuality/Src/Event.cs
  4. 40
      src/AddIns/Analysis/CodeQuality/Src/Field.cs
  5. 102
      src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs
  6. 52
      src/AddIns/Analysis/CodeQuality/Src/Method.cs
  7. 99
      src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs
  8. 183
      src/AddIns/Analysis/CodeQuality/Src/NodeIconService.cs
  9. 75
      src/AddIns/Analysis/CodeQuality/Src/Type.cs

5
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.csproj

@ -96,6 +96,7 @@ @@ -96,6 +96,7 @@
<Compile Include="Src\DependencyGraphCommand.cs" />
<Compile Include="Src\Event.cs" />
<Compile Include="Src\Field.cs" />
<Compile Include="Src\NodeIconService.cs" />
<Compile Include="Src\IDependency.cs" />
<Compile Include="Src\MetricsReader.cs" />
<Compile Include="Src\Method.cs" />
@ -172,6 +173,10 @@ @@ -172,6 +173,10 @@
<Name>ICSharpCode.Core</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj">
<Project>{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}</Project>
<Name>ICSharpCode.Core.Presentation</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="CodeQualityAnalysis.addin">

8
src/AddIns/Analysis/CodeQuality/CodeQualityAnalysis.sln

@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core", "..\..\. @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core", "..\..\.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.SharpDevelop", "..\..\..\Main\Base\Project\ICSharpCode.SharpDevelop.csproj", "{2748AD25-9C63-4E12-877B-4DCE96FBED54}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ICSharpCode.Core.Presentation", "..\..\..\Main\ICSharpCode.Core.Presentation\ICSharpCode.Core.Presentation.csproj", "{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -35,6 +37,12 @@ Global @@ -35,6 +37,12 @@ Global
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|Any CPU.Build.0 = Release|Any CPU
{2748AD25-9C63-4E12-877B-4DCE96FBED54}.Release|x86.ActiveCfg = Release|Any CPU
{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}.Debug|x86.ActiveCfg = Debug|Any CPU
{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}.Release|Any CPU.Build.0 = Release|Any CPU
{7E4A7172-7FF5-48D0-B719-7CD959DD1AC9}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

5
src/AddIns/Analysis/CodeQuality/Src/Event.cs

@ -27,5 +27,10 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -27,5 +27,10 @@ namespace ICSharpCode.CodeQualityAnalysis
{
return null;
}
public override string ToString()
{
return Name;
}
}
}

40
src/AddIns/Analysis/CodeQuality/Src/Field.cs

@ -24,9 +24,46 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -24,9 +24,46 @@ namespace ICSharpCode.CodeQualityAnalysis
public Type Owner { get; set; }
/// <summary>
/// Whether this field is event
/// Whether the field is event
/// </summary>
public bool IsEvent { get; set; }
/// <summary>
/// Whether the field is public
/// </summary>
public bool IsPublic { get; set; }
/// <summary>
/// Whether the field is private
/// </summary>
public bool IsPrivate { get; set; }
/// <summary>
/// Whether the field is protected
/// </summary>
public bool IsProtected { get; set; }
/// <summary>
/// Whether the field is static
/// </summary>
public bool IsStatic { get; set; }
/// <summary>
/// Whether the field is constant
/// </summary>
public bool IsConstant { get; set; }
/// <summary>
/// Whether the field is read only
/// </summary>
public bool IsReadOnly { get; set; }
public Field()
{
FieldType = null;
IsEvent = false;
Owner = null;
}
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()
{
@ -37,6 +74,5 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -37,6 +74,5 @@ namespace ICSharpCode.CodeQualityAnalysis
{
return Name;
}
}
}

102
src/AddIns/Analysis/CodeQuality/Src/MainWindow.xaml.cs

@ -11,6 +11,7 @@ using System.Windows.Media; @@ -11,6 +11,7 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.Core.Presentation;
using Microsoft.Win32;
using Mono.Cecil;
using Mono.Cecil.Cil;
@ -51,32 +52,62 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -51,32 +52,62 @@ namespace ICSharpCode.CodeQualityAnalysis
}
/// <summary>
/// Fill tree with module, types and methods and TODO: fields
/// Fill tree with module, types and methods and fields
/// </summary>
private void FillTree()
{
var itemModule = new MetricTreeViewItem() { Header = _metricsReader.MainModule.Name, Dependency = _metricsReader.MainModule };
definitionTree.Items.Add(itemModule);
var itemModule = new MetricTreeViewItem
{
Text = _metricsReader.MainModule.Name,
Dependency = _metricsReader.MainModule,
Icon = NodeIconService.GetIcon(_metricsReader.MainModule)
};
definitionTree.Items.Add(itemModule);
foreach (var ns in _metricsReader.MainModule.Namespaces)
{
var nsType = new MetricTreeViewItem() { Header = ns.Name, Dependency = ns };
var nsType = new MetricTreeViewItem
{
Text = ns.Name,
Dependency = ns,
Icon = NodeIconService.GetIcon(ns)
};
itemModule.Items.Add(nsType);
foreach (var type in ns.Types)
{
var itemType = new MetricTreeViewItem() { Header = type.Name, Dependency = type };
var itemType = new MetricTreeViewItem
{
Text = type.Name,
Dependency = type,
Icon = NodeIconService.GetIcon(type)
};
nsType.Items.Add(itemType);
foreach (var method in type.Methods)
{
var itemMethod = new MetricTreeViewItem() { Header = method.Name, Dependency = method };
var itemMethod = new MetricTreeViewItem
{
Text = method.Name,
Dependency = method,
Icon = NodeIconService.GetIcon(method)
};
itemType.Items.Add(itemMethod);
}
foreach (var field in type.Fields)
{
var itemField = new MetricTreeViewItem() { Header = field.Name, Dependency = field };
var itemField = new MetricTreeViewItem
{
Text = field.Name,
Dependency = field,
Icon = NodeIconService.GetIcon(field)
};
itemType.Items.Add(itemField);
}
}
@ -109,7 +140,64 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -109,7 +140,64 @@ namespace ICSharpCode.CodeQualityAnalysis
private class MetricTreeViewItem : TreeViewItem
{
private readonly Image _iconControl;
private readonly TextBlock _textControl;
private BitmapSource _bitmap;
public IDependency Dependency { get; set; }
/// <summary>
/// Gets or sets the text content for the item
/// </summary>
public string Text
{
get
{
return _textControl.Text;
}
set
{
_textControl.Text = value;
}
}
/// <summary>
/// Gets or sets the icon for the item
/// </summary>
public BitmapSource Icon
{
get
{
return _bitmap;
}
set
{
_iconControl.Source = _bitmap = value;
}
}
public MetricTreeViewItem()
{
var stack = new StackPanel
{
Orientation = Orientation.Horizontal
};
Header = stack;
_iconControl = new Image
{
Margin = new Thickness(0, 0, 5, 0)
};
_textControl = new TextBlock()
{
VerticalAlignment = VerticalAlignment.Center
};
stack.Children.Add(_iconControl);
stack.Children.Add(_textControl);
}
}
}
}

52
src/AddIns/Analysis/CodeQuality/Src/Method.cs

@ -31,7 +31,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -31,7 +31,7 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <summary>
/// A return type of method
/// </summary>
public Type MethodType { get; set; }
public Type ReturnType { get; set; }
/// <summary>
/// Type which owns this method
@ -39,15 +39,63 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -39,15 +39,63 @@ namespace ICSharpCode.CodeQualityAnalysis
public Type Owner { get; set; }
/// <summary>
/// Whether a method is constructor or not
/// Whether the method is constructor or not
/// </summary>
public bool IsConstructor { get; set; }
/// <summary>
/// Whether the method is public
/// </summary>
public bool IsPublic { get; set; }
/// <summary>
/// Whether the method is private
/// </summary>
public bool IsPrivate { get; set; }
/// <summary>
/// Whether the method is protected
/// </summary>
public bool IsProtected { get; set; }
/// <summary>
/// Whether the method is static
/// </summary>
public bool IsStatic { get; set; }
/// <summary>
/// Whether the method is sealed
/// </summary>
public bool IsSealed { get; set; }
/// <summary>
/// Whether the method is abstract
/// </summary>
public bool IsAbstract { get; set; }
/// <summary>
/// Whether the method is setter
/// </summary>
public bool IsSetter { get; set; }
/// <summary>
/// Whether the method is getter
/// </summary>
public bool IsGetter { get; set; }
/// <summary>
/// Whether the method is virtual
/// </summary>
public bool IsVirtual { get; set; }
public Method()
{
TypeUses = new HashSet<Type>();
MethodUses = new HashSet<Method>();
FieldUses = new HashSet<Field>();
ReturnType = null;
Owner = null;
}
public BidirectionalGraph<object, IEdge<object>> BuildDependencyGraph()

99
src/AddIns/Analysis/CodeQuality/Src/MetricsReader.cs

@ -107,10 +107,23 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -107,10 +107,23 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <returns>A new type</returns>
private Type CreateType(Module module, TypeDefinition typeDefinition)
{
var type = new Type()
var type = new Type
{
Name = FormatTypeName(typeDefinition),
Owner = null
IsInterface = typeDefinition.IsInterface,
IsEnum = typeDefinition.IsEnum,
IsClass = typeDefinition.IsClass,
IsSealed = typeDefinition.IsSealed,
IsAbstract = typeDefinition.IsAbstract,
IsPublic = typeDefinition.IsPublic,
IsStruct = typeDefinition.IsValueType && !typeDefinition.IsEnum && typeDefinition.IsSealed,
IsInternal = typeDefinition.IsNotPublic,
IsDelegate = (typeDefinition.BaseType != null ?
typeDefinition.BaseType.FullName == "System.MulticastDelegate" : false),
IsNestedPrivate = typeDefinition.IsNestedPrivate,
IsNestedPublic = typeDefinition.IsNestedPublic,
IsNestedProtected = (!typeDefinition.IsNestedPrivate && !typeDefinition.IsNestedPublic &&
typeDefinition.IsNestedFamily)
};
// try find namespace
@ -122,7 +135,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -122,7 +135,7 @@ namespace ICSharpCode.CodeQualityAnalysis
if (ns == null)
{
ns = new Namespace()
ns = new Namespace
{
Name = nsName,
Module = module
@ -154,6 +167,30 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -154,6 +167,30 @@ namespace ICSharpCode.CodeQualityAnalysis
where (t.Name == FormatTypeName(typeDefinition))
select t).SingleOrDefault();
if (typeDefinition.BaseType != null)
{
var baseType = (from n in module.Namespaces
from t in n.Types
where (t.Name == FormatTypeName(typeDefinition.BaseType))
select t).SingleOrDefault();
type.BaseType = baseType; // if baseType is null so propably inherits from another assembly
}
// looks for implemented interfaces
if (typeDefinition.HasInterfaces)
{
foreach (var ic in typeDefinition.Interfaces)
{
var implementedIc = (from n in module.Namespaces
from t in n.Types
where (t.Name == FormatTypeName(ic))
select t).SingleOrDefault();
if (implementedIc != null)
type.ImplementedInterfaces.Add(implementedIc);
}
}
if (typeDefinition.HasFields)
ReadFields(type, typeDefinition.Fields);
@ -179,7 +216,7 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -179,7 +216,7 @@ namespace ICSharpCode.CodeQualityAnalysis
{
foreach (var eventDefinition in events)
{
var e = new Event()
var e = new Event
{
Name = eventDefinition.Name,
Owner = type
@ -219,11 +256,16 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -219,11 +256,16 @@ namespace ICSharpCode.CodeQualityAnalysis
{
foreach (FieldDefinition fieldDefinition in fields)
{
var field = new Field()
var field = new Field
{
Name = fieldDefinition.Name,
IsEvent = false,
Owner = type
Owner = type,
IsPublic = fieldDefinition.IsPublic,
IsPrivate = fieldDefinition.IsPrivate,
IsProtected = !fieldDefinition.IsPublic && !fieldDefinition.IsPrivate,
IsStatic = fieldDefinition.IsStatic,
IsConstant = fieldDefinition.HasConstant,
IsReadOnly = fieldDefinition.IsInitOnly
};
type.Fields.Add(field);
@ -251,16 +293,25 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -251,16 +293,25 @@ namespace ICSharpCode.CodeQualityAnalysis
{
Name = FormatMethodName(methodDefinition),
Owner = type,
IsConstructor = methodDefinition.IsConstructor
IsConstructor = methodDefinition.IsConstructor,
IsPublic = methodDefinition.IsPublic,
IsPrivate = methodDefinition.IsPrivate,
IsProtected = !methodDefinition.IsPublic && !methodDefinition.IsPrivate,
IsStatic = methodDefinition.IsStatic,
IsSealed = methodDefinition.IsFinal, // not sure if final is sealed
IsAbstract = methodDefinition.IsAbstract,
IsSetter = methodDefinition.IsSetter,
IsGetter = methodDefinition.IsGetter,
IsVirtual = methodDefinition.IsVirtual
};
var declaringType =
var returnType =
(from n in type.Namespace.Module.Namespaces
from t in n.Types
where t.Name == FormatTypeName(methodDefinition.DeclaringType)
where t.Name == FormatTypeName(methodDefinition.ReturnType)
select t).SingleOrDefault();
method.MethodType = declaringType;
method.ReturnType = returnType; // if null so return type is outside of assembly
type.Methods.Add(method);
}
@ -290,11 +341,11 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -290,11 +341,11 @@ namespace ICSharpCode.CodeQualityAnalysis
foreach (Instruction instruction in instructions)
{
var instr = ReadInstruction(instruction);
if (instr is MethodDefinition)
if (instr is MethodDefinition && method.ReturnType != null) // null means outside assembly
{
var md = instr as MethodDefinition;
var type = (from n in method.MethodType.Namespace.Module.Namespaces
var type = (from n in method.ReturnType.Namespace.Module.Namespaces
from t in n.Types
where t.Name == FormatTypeName(md.DeclaringType) &&
n.Name == t.Namespace.Name
@ -306,14 +357,14 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -306,14 +357,14 @@ namespace ICSharpCode.CodeQualityAnalysis
where m.Name == FormatMethodName(md)
select m).SingleOrDefault();
if (findTargetMethod != null && type == method.MethodType)
if (findTargetMethod != null && type == method.ReturnType)
method.MethodUses.Add(findTargetMethod);
}
if (instr is FieldDefinition)
{
var fd = instr as FieldDefinition;
var field = (from f in method.MethodType.Fields
var field = (from f in method.ReturnType.Fields
where f.Name == fd.Name
select f).SingleOrDefault();
@ -372,19 +423,19 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -372,19 +423,19 @@ namespace ICSharpCode.CodeQualityAnalysis
/// <summary>
/// Formats a specific type name. If type is generic. Brackets <> will be added with proper names of parameters.
/// </summary>
/// <param name="typeDefinition">A type definition with declaring type and name</param>
/// <param name="type">A type definition with declaring type and name</param>
/// <returns>A type name</returns>
public string FormatTypeName(TypeDefinition typeDefinition)
public string FormatTypeName(TypeReference type)
{
if (typeDefinition.IsNested && typeDefinition.DeclaringType != null)
if (type.IsNested && type.DeclaringType != null)
{
return FormatTypeName(typeDefinition.DeclaringType) + "+" + typeDefinition.Name;
return FormatTypeName(type.DeclaringType) + "+" + type.Name;
}
if (typeDefinition.HasGenericParameters)
if (type.HasGenericParameters)
{
var builder = new StringBuilder();
var enumerator = typeDefinition.GenericParameters.GetEnumerator();
var enumerator = type.GenericParameters.GetEnumerator();
bool hasNext = enumerator.MoveNext();
while (hasNext)
{
@ -394,10 +445,10 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -394,10 +445,10 @@ namespace ICSharpCode.CodeQualityAnalysis
builder.Append(",");
}
return StripGenericName(typeDefinition.Name) + "<" + builder + ">";
return StripGenericName(type.Name) + "<" + builder + ">";
}
return typeDefinition.Name;
return type.Name;
}
/// <summary>

183
src/AddIns/Analysis/CodeQuality/Src/NodeIconService.cs

@ -0,0 +1,183 @@ @@ -0,0 +1,183 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using ICSharpCode.Core.Presentation;
namespace ICSharpCode.CodeQualityAnalysis
{
public static class NodeIconService
{
private static readonly BitmapSource Namespace = GetImage("Icons.16x16.NameSpace");
private static readonly BitmapSource Assembly = GetImage("Icons.16x16.Assembly");
private static readonly BitmapSource Class = GetImage("Icons.16x16.Class");
private static readonly BitmapSource InternalClass = GetImage("Icons.16x16.InternalClass");
private static readonly BitmapSource ProtectedClass = GetImage("Icons.16x16.ProtectedClass");
private static readonly BitmapSource PrivateClass = GetImage("Icons.16x16.PrivateClass");
private static readonly BitmapSource Struct = GetImage("Icons.16x16.Struct");
private static readonly BitmapSource InternalStruct = GetImage("Icons.16x16.InternalStruct");
private static readonly BitmapSource ProtectedStruct = GetImage("Icons.16x16.ProtectedStruct");
private static readonly BitmapSource PrivateStruct = GetImage("Icons.16x16.PrivateStruct");
private static readonly BitmapSource Interface = GetImage("Icons.16x16.Interface");
private static readonly BitmapSource InternalInterface = GetImage("Icons.16x16.InternalInterface");
private static readonly BitmapSource ProtectedInterface = GetImage("Icons.16x16.ProtectedInterface");
private static readonly BitmapSource PrivateInterface = GetImage("Icons.16x16.PrivateInterface");
private static readonly BitmapSource Enum = GetImage("Icons.16x16.Enum");
private static readonly BitmapSource InternalEnum = GetImage("Icons.16x16.InternalEnum");
private static readonly BitmapSource ProtectedEnum = GetImage("Icons.16x16.ProtectedEnum");
private static readonly BitmapSource PrivateEnum = GetImage("Icons.16x16.PrivateEnum");
private static readonly BitmapSource Delegate = GetImage("Icons.16x16.Delegate");
private static readonly BitmapSource InternalDelegate = GetImage("Icons.16x16.InternalDelegate");
private static readonly BitmapSource ProtectedDelegate = GetImage("Icons.16x16.ProtectedDelegate");
private static readonly BitmapSource PrivateDelegate = GetImage("Icons.16x16.PrivateDelegate");
private static readonly BitmapSource Method = GetImage("Icons.16x16.Method");
private static readonly BitmapSource ProtectedMethod = GetImage("Icons.16x16.ProtectedMethod");
private static readonly BitmapSource PrivateMethod = GetImage("Icons.16x16.PrivateMethod");
private static readonly BitmapSource PropertyMethod = GetImage("Icons.16x16.Property");
private static readonly BitmapSource ProtectedPropertyMethod = GetImage("Icons.16x16.ProtectedProperty");
private static readonly BitmapSource PrivatePropertyMethod = GetImage("Icons.16x16.PrivateProperty");
private static readonly BitmapSource Field = GetImage("Icons.16x16.Field");
private static readonly BitmapSource ProtectedField = GetImage("Icons.16x16.ProtectedField");
private static readonly BitmapSource PrivateField = GetImage("Icons.16x16.PrivateField");
private static readonly BitmapSource EventField = GetImage("Icons.16x16.Event");
private static readonly BitmapSource ProtectedEventField = GetImage("Icons.16x16.ProtectedEvent");
private static readonly BitmapSource PrivateEventField = GetImage("Icons.16x16.PrivateEvent");
private static readonly BitmapSource ConstantField = GetImage("Icons.16x16.Literal");
private static BitmapSource GetImage(string name)
{
try
{
return PresentationResourceService.GetBitmapSource(name);
}
catch (Exception)
{
return null; // image isnt needed neccessery
}
}
public static BitmapSource GetIcon(Field field)
{
if (field.IsPublic)
return Field;
if (field.IsPrivate)
return PrivateField;
if (field.IsProtected)
return ProtectedField;
if (field.IsConstant)
return ConstantField;
if (field.IsEvent)
{
if (field.IsPublic)
return EventField;
if (field.IsPrivate)
return PrivateEventField;
if (field.IsProtected)
return ProtectedEventField;
}
return Field;
}
public static BitmapSource GetIcon(Method method)
{
if (method.IsPublic)
return Method;
if (method.IsPrivate)
return PrivateMethod;
if (method.IsProtected)
return ProtectedMethod;
if (method.IsGetter || method.IsSetter)
{
if (method.IsPublic)
return PropertyMethod;
if (method.IsPrivate)
return PrivatePropertyMethod;
if (method.IsProtected)
return ProtectedPropertyMethod;
}
return Method;
}
public static BitmapSource GetIcon(Module module)
{
return Assembly;
}
public static BitmapSource GetIcon(Namespace ns)
{
return Namespace;
}
public static BitmapSource GetIcon(Type type)
{
if (type.IsEnum)
{
if (type.IsPublic)
return Enum;
if (type.IsNestedPrivate)
return PrivateEnum;
if (type.IsNestedProtected)
return ProtectedEnum;
if (type.IsInternal)
return InternalEnum;
}
else if (type.IsStruct)
{
if (type.IsPublic)
return Struct;
if (type.IsNestedPrivate)
return PrivateStruct;
if (type.IsNestedProtected)
return ProtectedStruct;
if (type.IsInternal)
return InternalStruct;
}
else if (type.IsInterface)
{
if (type.IsPublic)
return Interface;
if (type.IsNestedPrivate)
return PrivateInterface;
if (type.IsNestedProtected)
return ProtectedInterface;
if (type.IsInternal)
return InternalInterface;
}
else if (type.IsDelegate)
{
if (type.IsPublic)
return Delegate;
if (type.IsNestedPrivate)
return PrivateDelegate;
if (type.IsNestedProtected)
return ProtectedDelegate;
if (type.IsInternal)
return InternalDelegate;
}
if (type.IsPublic)
return Class;
if (type.IsNestedPrivate)
return PrivateClass;
if (type.IsNestedProtected)
return ProtectedClass;
if (type.IsInternal)
return InternalClass;
return Class;
}
}
}

75
src/AddIns/Analysis/CodeQuality/Src/Type.cs

@ -18,6 +18,16 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -18,6 +18,16 @@ namespace ICSharpCode.CodeQualityAnalysis
/// </summary>
public Type Owner { get; set; }
/// <summary>
/// Inherited type. If there is no inheritance so it is null.
/// </summary>
public Type BaseType { get; set; }
/// <summary>
/// Interfaces which are implemented by this type
/// </summary>
public ISet<Type> ImplementedInterfaces { get; set; }
/// <summary>
/// Methods within type
/// </summary>
@ -54,12 +64,77 @@ namespace ICSharpCode.CodeQualityAnalysis @@ -54,12 +64,77 @@ namespace ICSharpCode.CodeQualityAnalysis
/// </summary>
public Namespace Namespace { get; set; }
/// <summary>
/// Whether the type is interface
/// </summary>
public bool IsInterface { get; set; }
/// <summary>
/// Whether the type is enum
/// </summary>
public bool IsEnum { get; set; }
/// <summary>
/// Whether the type is class
/// </summary>
public bool IsClass { get; set; }
/// <summary>
/// Whether the type is sealed
/// </summary>
public bool IsSealed { get; set; }
/// <summary>
/// Whether the type is abstract
/// </summary>
public bool IsAbstract { get; set; }
/// <summary>
/// Whether the type is public
/// </summary>
public bool IsPublic { get; set; }
/// <summary>
/// Whether the type is struct
/// </summary>
public bool IsStruct { get; set; }
/// <summary>
/// Whether the type is internal
/// </summary>
public bool IsInternal { get; set; }
/// <summary>
/// Whether the type is delagate
/// </summary>
public bool IsDelegate { get; set; }
/// <summary>
/// If it is nested type whether is private
/// </summary>
public bool IsNestedPrivate { get; set; }
/// <summary>
/// If it is nested type whether is public
/// </summary>
public bool IsNestedPublic { get; set; }
/// <summary>
/// If it is nested type whether is protected
/// </summary>
public bool IsNestedProtected { get; set; }
public Type()
{
Methods = new HashSet<Method>();
Fields = new HashSet<Field>();
Events = new HashSet<Event>();
NestedTypes = new HashSet<Type>();
ImplementedInterfaces = new HashSet<Type>();
Owner = null;
BaseType = null;
}
/// <summary>

Loading…
Cancel
Save