示例#1
0
 void GetSequencePointContent(CodeCoverageSequencePoint sp)
 {
     if (cacheFileName == sp.Document)
     {
         // check primary cache (this.Filename)
         sp.Content = cacheDocument == null? "" : cacheDocument.GetText(sp);
     }
     else
     {
         // check & update secondary cache
         if (cache2FileName == sp.Document)
         {
             sp.Content = cache2Document == null? "" : cache2Document.GetText(sp);
         }
         else
         {
             cache2FileName = sp.Document;
             cache2Document = GetSource(cache2FileName);
             sp.Content     = cache2Document == null? "" : cache2Document.GetText(sp);
         }
     }
     if (sp.Content != String.Empty)
     {
         if (sp.Line != sp.EndLine)
         {
             // merge multiple lines to single line
             sp.Content = Regex.Replace(sp.Content, @"\s+", " ");
         }
         // SequencePoint.Length counts all but whitespace
         sp.Length = Regex.Replace(sp.Content, @"\s", "").Length;
     }
 }
		void Init()
		{
			MethodName = GetMethodName();
			IsGetter = GetBooleanAttributeValue("isGetter");
			IsSetter = GetBooleanAttributeValue("isSetter");

			this.FileID = GetFileRef();
			this.FileName = String.Empty;
			if (!String.IsNullOrEmpty(this.FileID)) {
			    if (parent != null) {
    				this.FileName = parent.GetFileName(this.FileID);
    				if ( File.Exists(this.FileName) ) {
    					if (cacheFileName != this.FileName) {
    						cacheFileName = this.FileName;
    						cacheDocument = null;
    						try {
    							using (Stream stream = new FileStream(this.FileName, FileMode.Open, FileAccess.Read)) {
    								try {
    									stream.Position = 0;
    									string textSource = ICSharpCode.AvalonEdit.Utils.FileReader.ReadFileContent(stream, Encoding.Default);
    									cacheDocument = new CodeCoverageStringTextSource(textSource);
    								} catch {}
    							}
    						} catch {}
    					}
    				}
			    }
			}
			
			this.IsVisited = this.GetBooleanAttributeValue("visited");
			this.CyclomaticComplexity = (int)this.GetDecimalAttributeValue("cyclomaticComplexity");
			this.SequencePointsCount = this.GetSequencePointsCount();
			this.SequenceCoverage = (int)this.GetDecimalAttributeValue("sequenceCoverage");
			this.IsConstructor = this.GetBooleanAttributeValue("isConstructor");
			this.IsStatic = this.GetBooleanAttributeValue("isStatic");
			if ( !String.IsNullOrEmpty( this.FileID ) ) {
				this.SequencePoints = this.GetSequencePoints();
				this.BodyStartSP = getBodyStartSP(); // before OrderBy Line/Col
				// SP's are originaly ordered by CIL offset
				// but ccrewrite can move offset of
				//   Contract.Requires before method signature SP { and
				//   Contract.Ensures after method closing SP }
				// So sort SP's back by line/column
				this.SequencePoints.OrderBy(item => item.Line).OrderBy(item => item.Column);
				this.BodyFinalSP = getBodyFinalSP(); // after orderBy Line/Col
				this.SequencePoints = this.FilterSequencePoints(this.SequencePoints);
				this.BranchPoints = this.GetBranchPoints();
				this.BranchCoverageRatio = this.GetBranchRatio();
				this.BranchCoverage = this.GetBranchCoverage();
			}
		}
示例#3
0
        void Init()
        {
            MethodName = GetMethodName();
            IsGetter   = GetBooleanAttributeValue("isGetter");
            IsSetter   = GetBooleanAttributeValue("isSetter");

            this.FileID      = GetFileRef();
            this.FileName    = String.Empty;
            this.FileNameExt = String.Empty;
            if (!String.IsNullOrEmpty(this.FileID))
            {
                if (results != null)
                {
                    this.FileName = results.GetFileName(this.FileID);
                    try {
                        this.FileNameExt = Path.GetExtension(this.FileName).ToLowerInvariant();
                    }
                    catch {}
                    if (cacheFileName != this.FileName)
                    {
                        cacheFileName = this.FileName;
                        cacheDocument = GetSource(cacheFileName);
                    }
                }
            }

            this.IsVisited            = this.GetBooleanAttributeValue("visited");
            this.CyclomaticComplexity = (int)this.GetDecimalAttributeValue("cyclomaticComplexity");
            this.SequencePointsCount  = this.GetSequencePointsCount();
            this.SequenceCoverage     = (int)this.GetDecimalAttributeValue("sequenceCoverage");
            this.IsConstructor        = this.GetBooleanAttributeValue("isConstructor");
            this.IsStatic             = this.GetBooleanAttributeValue("isStatic");
            if (!String.IsNullOrEmpty(this.FileID))
            {
                this.GetSequencePoints();
                this.GetSequencePointsContent();
                this.getBodyStartSP();
                this.getBodyFinalSP();
                this.GetBranchRatio();
                this.GetBranchCoverage();

                // SP's are originaly ordered by CIL offset
                // because ccrewrite can move offset of
                //   Contract.Requires before method start ({) SP offset
                //   Contract.Ensures after method final (}) SP offset
                // So sort SP's back by line/column
                this.SequencePoints.OrderBy(item => item.Line).OrderBy(item => item.Column);
            }
        }
示例#4
0
        static CodeCoverageStringTextSource GetSource(string filename)
        {
            if (filename == cacheGetSource_LastFileName)
            {
                return(cacheGetSource_LastSource);
            }

            var retSource = (CodeCoverageStringTextSource)null;

            try {
                using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
                    try {
                        stream.Position = 0;
                        string textSource = ICSharpCode.AvalonEdit.Utils.FileReader.ReadFileContent(stream, Encoding.Default);
                        retSource = new CodeCoverageStringTextSource(textSource);
                    } catch (Exception) {}
                }
            } catch (Exception) {}

            cacheGetSource_LastFileName = filename;
            cacheGetSource_LastSource   = retSource;
            return(retSource);
        }
		void Init()
		{
			MethodName = GetMethodName();
			IsGetter = GetBooleanAttributeValue("isGetter");
			IsSetter = GetBooleanAttributeValue("isSetter");

			this.FileID = GetFileRef();
			this.FileName = String.Empty;
			if (!String.IsNullOrEmpty(this.FileID)) {
				if (results != null) {
					this.FileName = results.GetFileName(this.FileID);
					if (cacheFileName != this.FileName) {
						cacheFileName = this.FileName;
						cacheDocument = GetSource (cacheFileName);
					}
				}
			}
			
			this.IsVisited = this.GetBooleanAttributeValue("visited");
			this.CyclomaticComplexity = (int)this.GetDecimalAttributeValue("cyclomaticComplexity");
			this.SequencePointsCount = this.GetSequencePointsCount();
			this.SequenceCoverage = (int)this.GetDecimalAttributeValue("sequenceCoverage");
			this.IsConstructor = this.GetBooleanAttributeValue("isConstructor");
			this.IsStatic = this.GetBooleanAttributeValue("isStatic");
			if ( !String.IsNullOrEmpty( this.FileID ) ) {
				this.GetSequencePoints();
				this.GetSequencePointsContent();
				this.getBodyStartSP();
				this.getBodyFinalSP();
				this.GetBranchRatio();
				this.GetBranchCoverage();

				// SP's are originaly ordered by CIL offset
				// because ccrewrite can move offset of
				//   Contract.Requires before method start ({) SP offset
				//   Contract.Ensures after method final (}) SP offset
				// So sort SP's back by line/column
				this.SequencePoints.OrderBy(item => item.Line).OrderBy(item => item.Column);
			}
		}
		void GetSequencePointContent(CodeCoverageSequencePoint sp)
		{
			if (cacheFileName == sp.Document) {
				// check primary cache (this.Filename)
				sp.Content = cacheDocument == null? "" : cacheDocument.GetText(sp);
			}
			else {
				// check & update secondary cache
				if (cache2FileName == sp.Document) {
					sp.Content = cache2Document == null? "" : cache2Document.GetText(sp);
				}
				else {
					cache2FileName = sp.Document;
					cache2Document = GetSource (cache2FileName);
					sp.Content = cache2Document == null? "" : cache2Document.GetText(sp);
				}
			}
			if (sp.Content != String.Empty) {
				if (sp.Line != sp.EndLine) {
					// merge multiple lines to single line
					sp.Content = Regex.Replace(sp.Content, @"\s+", " ");
				}
				// SequencePoint.Length counts all but whitespace
				sp.Length = Regex.Replace(sp.Content, @"\s", "").Length;
			}
		}
		static CodeCoverageStringTextSource GetSource(string filename) {

			if (filename == cacheGetSource_LastFileName) return cacheGetSource_LastSource;

			var retSource = (CodeCoverageStringTextSource)null;
			try {
				using (Stream stream = new FileStream(filename, FileMode.Open, FileAccess.Read)) {
					try {
						stream.Position = 0;
						string textSource = ICSharpCode.AvalonEdit.Utils.FileReader.ReadFileContent(stream, Encoding.Default);
						retSource = new CodeCoverageStringTextSource(textSource);
					} catch (Exception) {}
				}
			} catch (Exception) {}

			cacheGetSource_LastFileName = filename;
			cacheGetSource_LastSource = retSource;
			return retSource;
		}