Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Static Code Analysis

, 15 Mar 2010
A static code analyzer building method call networks + sample applications.
CodeAnalyzerAndToDoSample.zip
Generator
bin
.noclean
Arebis.CodeAnalysis.Static.dll
Arebis.CodeGeneration.dll
Arebis.CodeGeneration.VisualStudio.dll
Arebis.CodeGenerator.dll
Arebis.Common.dll
CGen.exe
Content.cst
Content.cst.gen
COperation.cst
COperation.cst.gen
files
GeneratorMain.cst
GeneratorMain.cst.gen
Index.cst
Index.cst.gen
IndexTop.cst
IndexTop.cst.gen
SOperation.cst
SOperation.cst.gen
UIOperation.cst
UIOperation.cst.gen
Output
SampleApp
LocalTestRun.testrunconfig
ToDoApplication
Infrastructure
Properties
Service References
ToDoContract
Properties
ToDoSample.vsmdi
ToDoService
Entities.edmx
Infrastructure
Properties
ToDoSample.Service.csproj.user
ToDoSampleDb.mdf
ToDoSampleDb_log.ldf
ToDoUnitTests
Properties
Testing
ToDoSample.UnitTests.csproj.user
UnitTests
StaticCodeAnalyzer
Arebis.CodeAnalysis.Static
Arebis.CodeAnalysis.Static.csproj.user
CodeModel.cd
Processors
Rules
Properties
Arebis.Common
Arebis
Collections
Generic
Reflection
Properties
System
Collections
Generic
Net2
Threading
Net2
<?xml version="1.0" encoding="utf-8" ?>
<analyzer
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <assemblies>
    <!-- Include the mscorlib.dll to have access to the NotImplementedException constructor methods -->
    <assembly file="mscorlib.dll" />
    <!-- Include the client-tier assemblies -->
    <filepatterns path="..\SampleApp\ToDoApplication\bin\Debug">
      <add value="*.exe" />
      <add value="*.dll" />
    </filepatterns>
    <!-- Include the service-tier assemblies -->
    <filepatterns path="..\SampleApp\ToDoService\bin\Debug">
      <add value="*.dll" />
    </filepatterns>
    <!-- Include the unittest assemblies -->
    <filepatterns path="..\SampleApp\ToDoUnitTests\bin\Debug">
      <add value="*.dll" />
    </filepatterns>
  </assemblies>
  <!-- Set the language in which to express method signatures to C# and
       consider the given namespaces as imported -->
  <language code="C#">
    <import namespace="System" />
    <import namespace="System.Collections" />
    <import namespace="System.Collections.Generic" />
    <import namespace="ToDoSample.Contract" />
    <import namespace="ToDoSample.Service"/>
  </language>
  <processors>
    <!-- The specialmethodsprocessor adds tags "constructor" (and others) to methods to ease
         processing by the rule based processor -->
    <specialmethodsprocessor handler="Arebis.CodeAnalysis.Static.Processors.SpecialMethodsProcessor" />
    <!-- The rule based processor with its rules -->
    <rulesprocessor handler="Arebis.CodeAnalysis.Static.Processors.RulesProcessor">
      <definitions>
        <assembly path="bin\Arebis.CodeAnalysis.Static.dll" />
      </definitions>
      <rulesets>
        <ruleset name="_skip">
          <!-- the _skip tag has special meaning for the rule based processor: methods matching this rule are not processed further -->
          <namerule like="System.Windows.Markup.IComponentConnector.Connect" target="Method" />
        </ruleset>
        <ruleset name="uioperation">
          <basetyperule type="System.Windows.Controls.Control"/>
          <tagrule name="accessor" reverse="true"/>
          <tagrule name="constructor" reverse="true"/>
        </ruleset>
        <ruleset name="serviceoperationdefinition">
          <attributerule type="System.ServiceModel.ServiceContractAttribute" target="Type" />
          <modifierrule modifiers="Interface" target="Type" />
        </ruleset>
        <ruleset name="serviceoperationimplementation">
          <attributerule type="System.ServiceModel.ServiceBehaviorAttribute" target="Type" />
          <tagrule name="constructor" reverse="true"/>
        </ruleset>
        <ruleset name="explicitimplements">
          <!-- Explicit interface implementations have methodnames containing dots -->
          <namerule match=".*\..*" target="Method"/>
        </ruleset>
        <ruleset name="componentoperation">
          <modifierrule modifiers="FamANDAssem" target="Method"/>
          <modifierrule modifiers="Static" target="Method"/>
          <namerule target="Type" like="*ComponentManager"/>
          <tagrule name="constructor" reverse="true"/>
        </ruleset>
        <ruleset name="systemexception">
          <basetyperule type="System.Exception"/>
          <namerule target="Type" like="System.*"/>
        </ruleset>
        <ruleset name="applicationexception">
          <basetyperule type="System.Exception"/>
          <tagrule name="constructor"/>
          <tagrule name="systemexception" reverse="true"/>
        </ruleset>
        <ruleset name="missingimplementationexception">
          <basetyperule type="System.NotImplementedException"/>
          <tagrule name="constructor"/>
        </ruleset>
        <ruleset name="unittest">
          <attributerule type="Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute" target="Method"/>
        </ruleset>
        <ruleset name="defaultimplementation">
          <!-- Methods with the serviceoperationimplementation tag are connected to their interface definition -->
          <tagrule name="serviceoperationimplementation"/>
        </ruleset>
        <ruleset name="leafmethod">
          <!-- Exceptions are made leaf to break the link to the supertype constructor -->
          <tagrule name="applicationexception"/>
        </ruleset>
        <ruleset name="leafmethod">
          <!-- We are not interested in the methodcalls within the System namespace -->
          <namerule target="Type" like="System.*"/>
        </ruleset>
      </rulesets>
    </rulesprocessor>
    <!-- The defaultimplementationprocessor connects methods with the defaultimplementation tag to their interface definition -->
    <defaultimplementationprocessor handler="Arebis.CodeAnalysis.Static.Processors.DefaultImplementationProcessor" />
    <!-- The defaultmethodprocessor connects methods with the defaultmethod to their types constructor (not used here) -->
    <defaultmethodprocessor handler="Arebis.CodeAnalysis.Static.Processors.DefaultMethodProcessor" />
    <!-- The virtualmethodprocessor connects virtual methods to their base definition if it has the baseimplementation tag (not used here) -->
    <virtualmethodprocessor handler="Arebis.CodeAnalysis.Static.Processors.VirtualMethodProcessor" />
    <!-- The leafmethodprocessor disconnects methods with the leafmethod tag -->
    <leafmethodprocessor handler="Arebis.CodeAnalysis.Static.Processors.LeafMethodProcessor" />
  </processors>
</analyzer>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Rudi Breedenraedt
Architect Wolters Kluwer Belgium
Belgium Belgium
Rudi is a Software Architect at Wolters Kluwer Belgium.

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 15 Mar 2010
Article Copyright 2010 by Rudi Breedenraedt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid