Exemplo n.º 1
0
        public static ulong Calculate(Lim.Asg.Nodes.Logical.Scope limScope, ref List <Interval> intervals)
        {
            ulong TLOC = 0;

            if (limScope.Factory.getFilterState(limScope.Id) == Lim.Asg.Filter.FilterState.Filtered)
            {
                return(0);
            }

            // The root package does not have all the isContainedIn edges
            // So we calculate its TLOC by the sum of its child package's TLOC

            // Subpackages are not physically inside their parent Packages
            // ( unlike e.g. local or anonym classes inside other classes )
            // So the TLOC of a Package is computed recursively
            if (Lim.Asg.Common.getIsPackage(limScope))
            {
                ListIterator <Lim.Asg.Nodes.Logical.Member> subPackageIt = limScope.HasMemberListIteratorBegin;
                while (subPackageIt.getValue() != null)
                {
                    Lim.Asg.Nodes.Logical.Member subPackage = subPackageIt.getValue();
                    if (!Lim.Asg.Common.getIsPackage(subPackage))
                    {
                        subPackageIt = subPackageIt.getNext();
                        continue;
                    }
                    Lim.Asg.Nodes.Logical.Package _subPackage = subPackage as Lim.Asg.Nodes.Logical.Package;
                    TLOC        += Calculate(_subPackage, ref intervals);
                    subPackageIt = subPackageIt.getNext();
                }
            }

            ListIteratorAssocSourcePosition <File> sourcePositionInFileBeginIt = limScope.IsContainedInListIteratorAssocBegin;

            for (var fileIt = sourcePositionInFileBeginIt.getValue(); fileIt != null; fileIt = sourcePositionInFileBeginIt.getNext().getValue())
            {
                var pos = sourcePositionInFileBeginIt.getAssocItem();
                var i   = new Interval
                {
                    Key  = limScope.Factory.StringTable.set(Lim.Asg.Common.GetFullPath(fileIt)),
                    From = pos.Line,
                    To   = pos.EndLine
                };
                intervals.Add(i);

                TLOC += i.To - i.From + 1;
            }

            return(TLOC);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create association edge for the File node
        /// </summary>
        /// <param name="limNode"></param>
        /// <param name="roslynNode"></param>
        public static void AddIsContainedInEdge(Member limNode, SyntaxNode roslynNode)
        {
            SourcePosition       limPos = new SourcePosition();
            FileLinePositionSpan flps   = roslynNode.GetLocation().GetLineSpan();

            limPos.Line             = (uint)flps.StartLinePosition.Line + 1;
            limPos.Column           = (uint)flps.StartLinePosition.Character + 1;
            limPos.EndLine          = (uint)flps.EndLinePosition.Line + 1;
            limPos.EndColumn        = (uint)flps.EndLinePosition.Character + 1;
            limPos.RealizationLevel = Types.RealizationLevel.relDefines;

            string filePath = Common.ProcessPath(roslynNode.GetLocation().SourceTree.FilePath);

            if (!string.IsNullOrEmpty(filePath))
            {
                File file = roslynNode.GetLocation().CreateFile();
                if (file == null)
                {
                    return;
                }
                bool found = false;
                ListIteratorAssocSourcePosition <File> sourcePositionInFileBeginIt = limNode.IsContainedInListIteratorAssocBegin;

                for (File fileIt = sourcePositionInFileBeginIt.getValue(); fileIt != null; fileIt = sourcePositionInFileBeginIt.getNext().getValue())
                {
                    SourcePosition oldSp = sourcePositionInFileBeginIt.getAssocItem();
                    if
                    (
                        fileIt.Id == file.Id &&
                        oldSp.Line == (uint)flps.StartLinePosition.Line + 1 &&
                        oldSp.Column == (uint)flps.StartLinePosition.Character + 1 &&
                        oldSp.EndLine == (uint)flps.EndLinePosition.Line + 1 &&
                        oldSp.EndColumn == (uint)flps.EndLinePosition.Character + 1
                    )
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    limNode.addIsContainedIn(file, limPos);
                }
            }
        }