title: How do I determine if a file contains a specific class in SrcML.Net
body: <p>I want to display if the Android "ServiceTestCase" Class is being used in any of the Directories. </p>
  
  <p>The Program currently</p>
  
  <p>1) Displays the Sensor Types the File uses</p>
  
  <p>2) Displays the number of Implementations of the "onSensorChanged" Method</p>
  
  <p>3) Displays the other functions that call the "onSensorChange" Implementation.</p>
  
  <p>How do I display Classes?</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Diagnostics;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using ABB.SrcML;
  using ABB.SrcML.Data;
  using NUnit.Framework;
  using System.Collections;
  
  namespace CodeAnalysisToolkit
  {
  [TestFixture]
  public class SimpleAnalyticsCalculator_Thesis
  {
      //------Test Case Class------------------------------------------------------------------------
  
      [TestCase]
      public void CalculateSimpleProjectStats()
      {
          int NumOfApps = 5;
  
  
          //-----------Current Working Method to Get sub directories -------------------------
  
          // Get list of files in the specific directory.
          string[] TopDirectories = Directory.GetDirectories(@"C:\School\Grad School (Comp Sci)\Thesis\Apps\",
              "*.*",
              SearchOption.TopDirectoryOnly);
  
          // Display all the files.
          //for (int i = 0; i &lt;= NumOfApps; i++)
          //{
          //    Console.WriteLine(TopDirectories[i]);
          //}
  
          //Print out all Top Sub Directoies for Specified Path 
          //foreach (string file in TopDirectories)
          //{
          //    Console.WriteLine(file);
          //}
  
          //----------End of Print Sub directory Method----------------------------------------
  
  
          for (int i = 0; i &lt; NumOfApps; i++)
          {
              var dataProject = new DataProject&lt;CompleteWorkingSet&gt;(TopDirectories[i],
                  Path.GetFullPath(TopDirectories[i]),
                  "..//..//..//SrcML");
  
              Console.WriteLine();
              Debug.WriteLine("#############################################");
              Debug.WriteLine("Parsing " + TopDirectories[i]);
  
              dataProject.UpdateAsync().Wait();
  
              NamespaceDefinition globalNamespace;
              Assert.That(dataProject.WorkingSet.TryObtainReadLock(5000, out globalNamespace));
  
              DisplaySensorTypes(globalNamespace);
              //DisplayWhetherAppIsUnitTested();           
              DisplayCallsToOnSensorChanged(globalNamespace);
          }
      }
  
  
      //-------Display Sensor Type Class--------------------------------------------------------------
  
      private void DisplaySensorTypes(NamespaceDefinition globalNamespace)
      {
          var getDefaultSensorCalls = from statement in globalNamespace.GetDescendantsAndSelf()
                                      from expression in statement.GetExpressions()
                                      from call in expression.GetDescendantsAndSelf&lt;MethodCall&gt;()                                     
                                      where call.Name == "getDefaultSensor"
                                      select call;
  
          foreach (var call in getDefaultSensorCalls)
          {
              if (call.Arguments.Any())
              {
                  var firstArg = call.Arguments.First();
                  var components = firstArg.Components;
                  if (components.Count() == 3 &amp;&amp;
                      components.ElementAt(0).ToString() == "Sensor" &amp;&amp;
                      components.ElementAt(1).ToString() == ".")
                  {
                      Debug.WriteLine("sensor " + components.ElementAt(2).ToString() + " found");
                  }
              }
          }
      }
  
  
      private void DisplayWhetherAppIsUnitTested()
      {
          throw new NotImplementedException();
      }
  
  
  
  
      //-------Display Calls to OnSensorChanged Class------------------------------------------------
  
      private void DisplayCallsToOnSensorChanged(NamespaceDefinition globalNamespace)
      {
          var senChangedMethods = from method in globalNamespace.GetDescendants&lt;MethodDefinition&gt;()
              where method.Name == "onSensorChanged"
              select method;
  
          if (senChangedMethods.Count() == 0)
          {
              Debug.WriteLine("This File Does not contain any Sensor Change Mehtods");
          }
  
          else
          {
  
              Debug.WriteLine("----- ");
              Debug.WriteLine("\r\n");
              Debug.WriteLine(senChangedMethods.Count() + " Implementations of " + senChangedMethods.First().GetFullName());
              Debug.WriteLine("----- ");
  
              int n = senChangedMethods.Count();
              for (int i = 0; i &lt; n; i++)
              {
                  var senChangedMethod = senChangedMethods.ElementAt(i);
                  Debug.WriteLine("Implementations of onSensorChaged # " + (i + 1) + ": " + senChangedMethod.GetFullName());
  
                  //"GetCallsToSelf" returns the number of times the number is called
                  var callsToSenChanged = senChangedMethod.GetCallsToSelf();
                  for (int j = 0; j &lt; callsToSenChanged.Count(); j++)
                  {
                      var callerMethod = callsToSenChanged.ElementAt(j).ParentStatement.GetAncestorsAndSelf&lt;MethodDefinition&gt;();
                      if (callerMethod.Any())
                      {
                          Debug.WriteLine("   Called by --&gt; " + callerMethod.ElementAt(0).GetFullName());
                      }
                  }
                  //Debug.WriteLine("----- ");
              }
          }  //End of Else does not Equal 0 Check
      }
  
  
  
      //-------Display Test Class--------------------------------------------------------------
  
  
  
  }
  </code></pre>
  
  <p>}</p>