// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Media.Imaging;
using QuickGraph;
namespace ICSharpCode.CodeQualityAnalysis
{
public class Method : INode
{
///
/// Parameters which are used by method
///
public ISet Parameters { get; private set; }
///
/// Types which are used in body of method
///
public ISet TypeUses { get; private set; }
///
/// Methods which are called in body of method
///
public ISet MethodUses { get; private set; }
///
/// Fields which are accesed in body of method
///
public ISet FieldUses { get; private set; }
///
/// Instructions inside of the method
///
public ISet Instructions { get; private set; }
///
/// A name of method
///
public string Name { get; set; }
///
/// A return type of method
///
public Type ReturnType { get; set; }
///
/// Type which owns this method
///
public Type DeclaringType { get; set; }
///
/// Whether the method is constructor or not
///
public bool IsConstructor { get; set; }
///
/// Whether the method is public
///
public bool IsPublic { get; set; }
///
/// Whether the method is private
///
public bool IsPrivate { get; set; }
///
/// Whether the method is protected
///
public bool IsProtected { get; set; }
///
/// Whether the method is static
///
public bool IsStatic { get; set; }
///
/// Whether the method is sealed
///
public bool IsSealed { get; set; }
///
/// Whether the method is abstract
///
public bool IsAbstract { get; set; }
///
/// Whether the method is setter
///
public bool IsSetter { get; set; }
///
/// Whether the method is getter
///
public bool IsGetter { get; set; }
///
/// Whether the method is virtual
///
public bool IsVirtual { get; set; }
///
/// If the return type is generic instance so all types used in generic are presented in this set.
///
public ISet GenericReturnTypes { get; private set; }
///
/// Whether the return type is generic instance
///
public bool IsReturnTypeGenericInstance { get; set; }
///
/// Cyclomatic Complexity of the method
///
public int CyclomaticComplexity { get; set; }
///
/// The number of variables declared in the body of the method
///
public int Variables { get; set; }
public Method()
{
Parameters = new HashSet();
TypeUses = new HashSet();
MethodUses = new HashSet();
FieldUses = new HashSet();
Instructions = new HashSet();
GenericReturnTypes = new HashSet();
ReturnType = null;
DeclaringType = null;
IsReturnTypeGenericInstance = false;
Dependency = null;
CyclomaticComplexity = 0;
Variables = 0;
}
public Relationship GetRelationship(INode node)
{
Relationship relationship = new Relationship();
return relationship;
}
public override string ToString()
{
return Name;
}
public IDependency Dependency { get; set; }
public string GetInfo()
{
var builder = new StringBuilder();
builder.AppendLine("Method Summary");
builder.Append(Environment.NewLine);
builder.AppendLine(String.Format("Name: {0}", Name));
builder.AppendLine(String.Format("Parameters: {0}", Parameters.Count));
builder.AppendLine(String.Format("Cyclomatic Complexity: {0}", CyclomaticComplexity));
builder.AppendLine(String.Format("Variables: {0}", Variables));
// more to come
builder.Append(Environment.NewLine);
if (IsAbstract)
builder.AppendLine("IsAbstract");
if (IsConstructor)
builder.AppendLine("IsConstructor");
if (IsGetter)
builder.AppendLine("IsGetter");
if (IsSetter)
builder.AppendLine("IsSetter");
if (IsPrivate)
builder.AppendLine("IsPrivate");
if (IsProtected)
builder.AppendLine("IsProtected");
if (IsPublic)
builder.AppendLine("IsPublic");
if (IsSealed)
builder.AppendLine("IsSealed");
if (IsStatic)
builder.AppendLine("IsStatic");
if (IsVirtual)
builder.AppendLine("IsVirtual");
return builder.ToString();
}
public BitmapSource Icon { get { return NodeIconService.GetIcon(this); } }
}
public class MethodParameter
{
///
/// The type of the parameter
///
public Type ParameterType { get; set; }
///
/// Whether the parameter is generic instance
///
public bool IsGenericInstance { get; set; }
///
/// Whether the parameter is in
///
public bool IsIn { get; set; }
///
/// Whether the parameter is out
///
public bool IsOut { get; set; }
///
/// Whether the parameter is optional
///
public bool IsOptional { get; set; }
///
/// If the parameter is generic instance so all types used in generic are presented in this set.
///
public ISet GenericTypes { get; set; }
public MethodParameter()
{
GenericTypes = new HashSet();
IsGenericInstance = false;
}
}
}