CounterCollection.cs :  » Profilers » Prof-It » at » jku » ssw » ProfIt » Components » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Profilers » Prof It 
Prof It » at » jku » ssw » ProfIt » Components » CounterCollection.cs
/*----------------------------------------------------------------------
Prof-It for C#
Copyright (c) 2004 Klaus Lehner, University of Linz

This program is free software; you can redistribute it and/or modify it 
under the terms of the GNU General Public License as published by the 
Free Software Foundation; either version 2, or (at your option) any 
later version.

This program is distributed in the hope that it will be useful, but 
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
for more details.

You should have received a copy of the GNU General Public License along 
with this program; if not, write to the Free Software Foundation, Inc., 
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
----------------------------------------------------------------------*/

using System;
using System.Collections;

namespace at.jku.ssw.ProfIt.Components{

  /// <summary>
  /// A CounterCollection contains the blocks of a file. As an ID it holds
  /// the absolute path of the file
  /// </summary>
  [Serializable]
  public class CounterCollection {

    public ArrayList blocks = new ArrayList();
    internal ArrayList methods = new ArrayList();
    internal ArrayList classes = new ArrayList();
    private ArrayList braces = new ArrayList();
    private DateTime lastParseTime;

    /// <summary>
    /// This is the unique ID of the CounterCollection
    /// </summary>
    private string fileName;

    [NonSerialized]
    private int numberOfStatements = -1;
    [NonSerialized]
    private int maximumCounter = -1;
    [NonSerialized]
    private int numberOfExecutedStatements = -1;
    [NonSerialized]
    private float codeCoverage = -1;

    public CounterCollection(string fileName) {
      this.fileName = fileName;
    }

    public CounterCollection() {
    }

    public string FileName {
      get { return this.fileName; }
    }

    internal void SetFileName(string fileName) {
      this.fileName = fileName;
    }


    public DateTime LastParseTime {
      get { return lastParseTime; }
      set { this.lastParseTime = value; }
    }

    public void AddBlock (IBlock block) {
      blocks.Add(block);
    }

    public void AddMethod (MethodCounter block) {
      methods.Add(block);
    }

    public void AddClass (ClassCounter block) {
      classes.Add(block);
    }

    /// <summary>
    /// only show "positive" blocks (blocks where start is less than end position)
    /// </summary>
    public ArrayList VisibleBlocks {
      get { 
        ArrayList list = new ArrayList();
        foreach (IBlock block in blocks) {
          if (block.Start < block.End && block.Statements>0) list.Add(block);
        }
        return list; 
      }
    }

    public ArrayList MethodCounters {
      get {
        return this.methods;
      }
    }

    public ArrayList ClassCounters {
      get {
        return this.classes;
      }
    }

    /// <summary>
    /// Removes all basic blocks that don't contain any statements and
    /// are not refered by CalcBlocks
    /// </summary>
    public void RemoveEmptyBlocks() {
      int idCounter = 0;
      ArrayList negativeBlocks = new ArrayList();

      ArrayList refBlocks = new ArrayList();
      // first filter out all negative blocks and all refBlocks
      foreach (IBlock block in blocks) {
        if (block.Start >= block.End) {
          negativeBlocks.Add(block);
        }
        if (block is CalcBlock) {
          refBlocks.Add(((CalcBlock)block).Ref);
        }
      }
      // copy all delegates among the negative blocks to another list, remove all other ones
      foreach (IBlock block in negativeBlocks) {
        if (!refBlocks.Contains(block)) {
          int indexOfBlock = blocks.IndexOf(block);
          if (indexOfBlock < blocks.Count -1) {
            IBlock nextBlock = (IBlock)blocks[blocks.IndexOf(block)+1];
            foreach (MethodCounter method in methods) {
              if (method.Ref == block && method.blocks.Contains(nextBlock)) {
                method.Ref = nextBlock;
              }
            }
          }
          blocks.Remove(block);
        }
      }
      // set the id for all StatementBlocks to speed up the increment at runtime
      foreach (IBlock block in blocks) {
        if (block is StatementBlock) {
          ((StatementBlock)block).ID = idCounter;
        }
        idCounter++;
      }
    }

    /// <summary>
    /// Resets the counters of all blocks in the file
    /// </summary>
    public void ResetCounters() {
      foreach (IBlock block in blocks) {
        if (block is StatementBlock) {
          ((StatementBlock)block).Reset();
        }
      }
      CalculateStatisticalValues();
    }

    public void AddBrace(int position, Brace brace) {
      braces.Insert(0,new BracePosition(position, brace));
    }

    public ArrayList Braces { get { return this.braces; } }


    #region statistical functions
    public void CalculateStatisticalValues() {
      this.numberOfStatements = 0;
      this.maximumCounter = 0;
      this.numberOfExecutedStatements = 0;

      foreach (IBlock block in blocks) {
        this.numberOfStatements += block.Statements;
        if (block.Counter > maximumCounter) maximumCounter = block.Counter;
        if (block.Counter > 0) numberOfExecutedStatements += block.Statements;
      }
      this.codeCoverage = ((float)NumberOfExecutedStatements / (float)NumberOfStatements) * 100;
    }

    public int NumberOfBlocks     { get { return VisibleBlocks.Count; } }
    public int NumberOfStatements { get { return this.numberOfStatements; } }
    public int NumberOfMethods    { get { return methods.Count; } }
    public int NumberOfClasses    { get { return classes.Count; } }
    public int MaximumCounter     { get { return maximumCounter; } }
    public float CodeCoverage     { get { return this.codeCoverage; } }
    public int NumberOfExecutedStatements { get { return this.numberOfExecutedStatements; } }
    #endregion
  }

  public enum Brace { None=1, Left=2, Right=4 }

  [Serializable]
  public class BracePosition {
    private int pos;
    private Brace brace;
    public BracePosition(int pos, Brace brace) {
      this.pos = pos; this.brace = brace;
    }
    public string Value { 
      get { 
        if (brace==Brace.Left) return "{"; 
        if (brace==Brace.Right) return "}"; 
        return ""; 
      } 
    }
    public int Position { get { return this.pos; } }
  }

}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.