Click here to Skip to main content
15,881,559 members
Articles / Programming Languages / C#

Calculating Metrics and Searching with a CodeDOM (Part 8)

Rate me:
Please Sign up or sign in to vote.
5.00/5 (7 votes)
6 Mar 2013CDDL7 min read 21.9K   682   10  
Calculating metrics on and searching a CodeDOM.
// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

namespace Nova.CodeDOM
{
    /// <summary>
    /// This interface allows for use of the Visitor design pattern to traverse a tree of <see cref="CodeObject"/>s.
    /// </summary>
    /// <returns>
    /// Create a class that implements this interface, and visit all code objects in a tree by passing your visitor
    /// class to the Accept(IVisitor) method of the root object (such as a <see cref="Solution"/>).  You must implement
    /// all methods, but if you have no special logic for a type, you can leave the method body empty or call a default
    /// handling routine.  Because of the large number of types (over 300), some types (such as most operators) are
    /// represented only by a base type, so if you need to check for subclasses that don't have their own methods, you
    /// must use 'is' or 'as' operators to check the specific derived type.  Internally generated (hidden) code objects
    /// are not visited (such as default constructors, delegate constructors and begin/endinvoke methods,
    /// global extern alias of CodeUnits, etc).  Hidden symbolic references (<see cref="CodeObject.HiddenRef"/>) are
    /// optionally visited, depending upon <see cref="VisitHiddenRefs"/>.
    /// </returns>
    public interface IVisitor
    {
        /// <summary>
        /// True if 'hidden' references should be visited.
        /// </summary>
        bool VisitHiddenRefs { get; }

        /// <summary>Visit a <see cref="Project"/>.</summary>
        void Visit(Project project);

        /// <summary>Visit a <see cref="CodeUnit"/>.</summary>
        void Visit(CodeUnit codeUnit);

        /// <summary>Visit a <see cref="UsingDirective"/> statement.</summary>
        void Visit(UsingDirective usingDirective);

        /// <summary>Visit an <see cref="Alias"/> statement.</summary>
        void Visit(Alias alias);

        /// <summary>Visit an <see cref="ExternAlias"/> statement.</summary>
        void Visit(ExternAlias externAlias);

        /// <summary>Visit a <see cref="Break"/> statement.</summary>
        void Visit(Break @break);

        /// <summary>Visit a <see cref="Continue"/> statement.</summary>
        void Visit(Continue @continue);

        /// <summary>Visit a <see cref="Goto"/> statement.</summary>
        void Visit(Goto @goto);

        /// <summary>Visit a <see cref="Label"/> statement.</summary>
        void Visit(Label label);

        /// <summary>Visit a <see cref="Return"/> statement.</summary>
        void Visit(Return @return);

        /// <summary>Visit a <see cref="Throw"/> statement.</summary>
        void Visit(Throw @throw);

        /// <summary>Visit a <see cref="YieldStatement"/> statement.</summary>
        void Visit(YieldStatement yieldStatement);

        /// <summary>Visit a <see cref="FieldDecl"/> statement (also <see cref="MultiFieldDecl"/>).</summary>
        void Visit(FieldDecl fieldDecl);

        /// <summary>Visit a <see cref="LocalDecl"/> statement (also <see cref="MultiLocalDecl"/>).</summary>
        void Visit(LocalDecl localDecl);

        /// <summary>Visit a <see cref="ParameterDecl"/> statement (also <see cref="ValueParameterDecl"/>).</summary>
        void Visit(ParameterDecl parameterDecl);

        /// <summary>Visit an <see cref="EnumMemberDecl"/> statement.</summary>
        void Visit(EnumMemberDecl enumMemberDecl);

        /// <summary>Visit an <see cref="IfBase"/> statement (common base of <see cref="If"/>, <see cref="ElseIf"/>).</summary>
        void Visit(IfBase ifBase);

        /// <summary>Visit an <see cref="Else"/> statement.</summary>
        void Visit(Else @else);

        /// <summary>Visit a <see cref="Switch"/> statement.</summary>
        void Visit(Switch @switch);

        /// <summary>Visit a <see cref="SwitchItem"/> statement (common base of <see cref="Case"/>, <see cref="Default"/>).</summary>
        void Visit(SwitchItem switchItem);

        /// <summary>Visit a <see cref="For"/> statement.</summary>
        void Visit(For @for);

        /// <summary>Visit a <see cref="ForEach"/> statement.</summary>
        void Visit(ForEach forEach);

        /// <summary>Visit a <see cref="While"/> statement.</summary>
        void Visit(While @while);

        /// <summary>Visit a <see cref="Try"/> statement.</summary>
        void Visit(Try @try);

        /// <summary>Visit a <see cref="Catch"/> statement.</summary>
        void Visit(Catch @catch);

        /// <summary>Visit a <see cref="Finally"/> statement.</summary>
        void Visit(Finally @finally);

        /// <summary>Visit a <see cref="Using"/> statement.</summary>
        void Visit(Using @using);

        /// <summary>Visit a <see cref="Lock"/> statement.</summary>
        void Visit(Lock @lock);

        /// <summary>Visit a <see cref="BlockDecl"/> statement.</summary>
        void Visit(BlockDecl blockDecl);

        /// <summary>Visit a <see cref="CheckedBlock"/> statement.</summary>
        void Visit(CheckedBlock checkedBlock);

        /// <summary>Visit an <see cref="UncheckedBlock"/> statement.</summary>
        void Visit(UncheckedBlock uncheckedBlock);

        /// <summary>Visit a <see cref="NamespaceDecl"/> statement (does NOT include <see cref="CodeUnit"/>s).</summary>
        void Visit(NamespaceDecl namespaceDecl);

        /// <summary>
        /// Visit a <see cref="TypeDecl"/> statement (common base of <see cref="ClassDecl"/>, <see cref="StructDecl"/>,
        /// <see cref="InterfaceDecl"/>, <see cref="EnumDecl"/>, <see cref="DelegateDecl"/>).
        /// </summary>
        void Visit(TypeDecl typeDecl);

        /// <summary>
        /// Visit a <see cref="MethodDeclBase"/> statement (common base of <see cref="MethodDecl"/>, <see cref="GenericMethodDecl"/>,
        /// <see cref="ConstructorDecl"/>, <see cref="DestructorDecl"/>, <see cref="GetterDecl"/>, <see cref="SetterDecl"/>, <see cref="AdderDecl"/>,
        /// <see cref="RemoverDecl"/>, <see cref="OperatorDecl"/>, <see cref="ConversionOperatorDecl"/>).
        /// </summary>
        void Visit(MethodDeclBase methodDeclBase);

        /// <summary>Visit a <see cref="PropertyDeclBase"/> statement (common base of <see cref="PropertyDecl"/>, <see cref="IndexerDecl"/>, <see cref="EventDecl"/>).</summary>
        void Visit(PropertyDeclBase propertyDeclBase);

        /// <summary>Visit an <see cref="AnonymousMethod"/> expression.</summary>
        void Visit(AnonymousMethod anonymousMethod);

        /// <summary>Visit an <see cref="Initializer"/> expression.</summary>
        void Visit(Initializer initializer);

        /// <summary>Visit a <see cref="Literal"/> expression.</summary>
        void Visit(Literal literal);

        /// <summary>
        /// Visit a <see cref="SymbolicRef"/> expression (common base of <see cref="NamespaceRef"/>,
        /// <see cref="TypeRefBase"/> [common base of <see cref="TypeRef"/>, <see cref="MethodRef"/>, <see cref="UnresolvedRef"/>],
        /// <see cref="VariableRef"/>, <see cref="SelfRef"/>, <see cref="GotoTargetRef"/>, <see cref="ExternAliasRef"/>,
        /// and <see cref="DirectiveSymbolRef"/>).
        /// </summary>
        void Visit(SymbolicRef symbolicRef);

        /// <summary>Visit an <see cref="Unrecognized"/> expression.</summary>
        void Visit(Unrecognized unrecognized);

        /// <summary>Visit an <see cref="ArgumentsOperator"/> operator (common base of <see cref="Call"/>, <see cref="Index"/>, <see cref="NewOperator"/>).</summary>
        void Visit(ArgumentsOperator argumentsOperator);

        /// <summary>
        /// Visit a <see cref="SingleArgumentOperator"/> operator (common base of <see cref="Ref"/>, <see cref="Out"/>,
        /// <see cref="Checked"/>, <see cref="Unchecked"/>, <see cref="TypeOf"/>, <see cref="SizeOf"/>, <see cref="DefaultValue"/>).
        /// </summary>
        void Visit(SingleArgumentOperator singleArgumentOperator);

        /// <summary>
        /// Visit a <see cref="BinaryOperator"/> operator (common base of <see cref="BinaryArithmeticOperator"/>, <see cref="BinaryBitwiseOperator"/>,
        /// <see cref="BinaryBooleanOperator"/>, <see cref="BinaryShiftOperator"/>, <see cref="Assignment"/>, <see cref="As"/>, <see cref="Dot"/>,
        /// <see cref="IfNullThen"/>, <see cref="Lookup"/>).
        /// </summary>
        void Visit(BinaryOperator binaryOperator);

        /// <summary>
        /// Visit an <see cref="UnaryOperator"/> operator (common base of <see cref="Cast"/>, <see cref="Complement"/>,
        /// <see cref="Decrement"/>, <see cref="Increment"/>, <see cref="Negative"/>, <see cref="Not"/>,
        /// <see cref="Positive"/>, <see cref="PostIncrement"/>, <see cref="PostDecrement"/>).
        /// </summary>
        void Visit(UnaryOperator unaryOperator);

        /// <summary>Visit a <see cref="Conditional"/> operator.</summary>
        void Visit(Conditional conditional);

        /// <summary>Visit an <see cref="Attribute"/> annotation.</summary>
        void Visit(Attribute attribute);

        /// <summary>Visit a <see cref="Comment"/> annotation.</summary>
        void Visit(Comment comment);

        /// <summary>
        /// Visit a <see cref="DocComment"/> annotation (also <see cref="DocText"/>, <see cref="DocCodeRefBase"/>, <see cref="DocNameBase"/>,
        /// <see cref="DocB"/>, <see cref="DocC"/>, <see cref="DocCode"/>, <see cref="DocCDATA"/>, <see cref="DocExample"/>, <see cref="DocI"/>,
        /// <see cref="DocInclude"/>, <see cref="DocPara"/>, <see cref="DocRemarks"/>, <see cref="DocSummary"/>, <see cref="DocTag"/>,
        /// <see cref="DocValue"/>, <see cref="DocList"/>, <see cref="DocListHeader"/>, <see cref="DocListItem"/>, <see cref="DocListDescription"/>,
        /// <see cref="DocListTerm"/>).
        /// </summary>
        void Visit(DocComment docComment);

        /// <summary>
        /// Visit a <see cref="CompilerDirective"/> annotation (common base of <see cref="ConditionalDirective"/>, <see cref="MessageDirective"/>,
        /// <see cref="SymbolDirective"/>, <see cref="PragmaDirective"/>, <see cref="LineDirective"/>).
        /// </summary>
        void Visit(CompilerDirective compilerDirective);

        /// <summary>Visit a <see cref="Message"/> annotation.</summary>
        void Visit(Message message);

        /// <summary>Visit a <see cref="TypeParameter"/>.</summary>
        void Visit(TypeParameter typeParameter);

        /// <summary>Visit a <see cref="ConstraintClause"/>.</summary>
        void Visit(ConstraintClause constraintClause);

        /// <summary>
        /// Visit a <see cref="TypeParameterConstraint"/> (common base of <see cref="ClassConstraint"/>, <see cref="StructConstraint"/>,
        /// <see cref="NewConstraint"/>, <see cref="TypeConstraint"/>).
        /// </summary>
        void Visit(TypeParameterConstraint typeParameterConstraint);

        /// <summary>
        /// Visit a <see cref="Block"/> body of a <see cref="BlockStatement"/> - this should rarely be used, since
        /// all members of the Block will be visited separately.
        /// </summary>
        void Visit(Block block);

        /// <summary>
        /// Visit a <see cref="ChildList{T}"/> collection - this should rarely be used, since all members of the list
        /// will be visited separately.
        /// </summary>
        void Visit<T>(ChildList<T> childList) where T : CodeObject;
    }
}

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 Common Development and Distribution License (CDDL)


Written By
Software Developer (Senior)
United States United States
I've been writing software since the late 70's, currently focusing mainly on C#.NET. I also like to travel around the world, and I own a Chocolate Factory (sadly, none of my employees are oompa loompas).

Comments and Discussions