/// <summary>
        /// Create panel showing information about changes to the selected node on both a type- and method- level.
        /// Also includes buttons to allow quick navigation to types/methods, and the diff patch (if applicable)
        /// </summary>
        void CreateDetailsPanel()
        {
            // Display limited info if no node selected
            if (selectedNode == null)
            {
                detailsScrollPosition = GUILayout.BeginScrollView(detailsScrollPosition);
                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();
                GUILayout.Label("-- Selected Node Details --", labelStyle);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                GUILayout.EndScrollView();
                return;
            }

            CustomType selectedType = selectedNode.type;

            GUILayout.BeginVertical();

            ShowTypeDetails(selectedType);
            ShowMethodDetails(selectedType);

            GUILayout.EndVertical();
        }
 public CustomTypeNode(CustomType type, CustomTypeNode parent, int level)
 {
     this.type   = type;
     this.level  = level;
     this.parent = parent;
 }
Exemple #3
0
        public List <CustomType> MatchTypesInFile(CustomFile file)
        {
            List <CustomType> typesInFile = new List <CustomType>();

            // Remove comments and strings to ensure no false positive matches
            string text = RemoveCommentsAndStrings(file);

            int        currentLineNum = 1;
            int        currentIndex   = 0;    // Index of text string where current match begins
            CustomType previousType   = null; // Keep track of the previous match's type

            // Iterate through all class declarations found in the file code
            foreach (Match typeMatch in typeRegex.Matches(text))
            {
                //Keep track of current line number by counting newlines since the last match
                currentLineNum += text.Substring(currentIndex, typeMatch.Index - currentIndex).Count(x => x == '\n');
                currentIndex    = typeMatch.Index;

                // Find the start and end lines of the matched type
                int startLineNum = currentLineNum;
                int endLineNum   = FindEndLineNum(typeMatch.Index, currentLineNum, text);

                // Get the name of the type as it appears in the text
                System.Text.StringBuilder typeString = new System.Text.StringBuilder("");
                typeString.Append(typeMatch.Groups["type"].Captures[0].Value);

                // Prepend type string with any of its parents (e.g. if B is nested in A, then string becomes "A+B")
                typeString.Insert(0, FindParentTypesInText(previousType, startLineNum, endLineNum));

                // Get the CustomType associated with the string found in text (modified if type was nested to match desired format of key)
                CustomType currentType = DependencyAnalyzer.GetCustomTypeFromString(typeString.ToString());
                if (currentType == null)
                {
                    Debug.LogError("Could not find " + typeString + " in customTypeLookup");
                }

                // Record the file, start, end line nums in the CustomType
                currentType.file         = file;
                currentType.startLineNum = startLineNum;
                currentType.endLineNum   = endLineNum;

                // Attempt to match all methods of the current type within the text, simularly recording start and end line nums
                ParseMethodsInFile(currentType, text, typeMatch.Index, currentLineNum);

                // Reset linenum/index back to the currentType before moving onto next type
                currentLineNum = currentType.startLineNum;
                currentIndex   = typeMatch.Index;
                previousType   = currentType;

                typesInFile.Add(currentType);

                // Debugging to ensure all methods found in text, compared to what is contained in the assembly
                //Debug.LogError("Class matched: " + classString + ", StartLineNum = " + currentType.startLineNum + ", EndLineNum = " + currentType.endLineNum);
                //if (numMatchesFound == currentType.methods.Count) {
                //    Debug.LogError("**FOUND ALL METHODS IN " + currentType + ": " + numMatchesFound + " out of " + currentType.methods.Count);
                //}
                //else {
                //    Debug.LogError("!!DID NOT FIND ALL METHODS IN " + currentType + ": " + numMatchesFound + " out of " + currentType.methods.Count);
                //}
            } // end type match iteration

            return(typesInFile);
        }
        /// <summary>
        /// Match each hunk in the diff patch, then localize each change in the hunk to the appropriate CustomMethod
        /// and/or CustomType.  Returns the total number of changes detected in the file
        /// </summary>
        private int ParseDiffPatch(string patchText, CustomFile file)
        {
            int totalFileChanges = 0;

            foreach (Match m in hunkRegex.Matches(patchText))
            {
                string hunk    = m.Groups["changes"].Captures[0].Value;
                int    lineNum = Int32.Parse(m.Groups["start"].Captures[0].Value);

                // Read the patch line-by-line
                System.Text.StringBuilder fileString = new System.Text.StringBuilder("");
                StringReader reader = new StringReader(hunk);
                string       line;
                while ((line = reader.ReadLine()) != null)
                {
                    // Determine what method and/or type is at the matched line number
                    CustomType   typeAtLine   = file.GetTypeByLineNumber(lineNum);
                    CustomMethod methodAtLine = null;
                    if (typeAtLine != null)
                    {
                        methodAtLine = typeAtLine.GetMethodAtLineNum(lineNum);
                    }

                    // Update additions and deletions for the determined CustomMethod and/or CustomType
                    //Note: changes outside the bounds of any type are not recorded
                    switch (line[0])
                    {
                    case '+':
                        if (typeAtLine != null)
                        {
                            if (methodAtLine != null)
                            {
                                typeAtLine.additionsInMethods++;
                                methodAtLine.additions++;
                            }
                            else
                            {
                                typeAtLine.additionsOutsideMethods++;
                            }
                            totalFileChanges++;
                        }
                        lineNum++;
                        break;

                    case '-':
                        if (typeAtLine != null)
                        {
                            if (methodAtLine != null)
                            {
                                typeAtLine.deletionsInMethods++;
                                methodAtLine.deletions++;
                            }
                            else
                            {
                                typeAtLine.deletionsOutsideMethods++;
                            }
                            totalFileChanges++;
                        }
                        break;

                    default:
                        Debug.LogError("Unknown hunk format for: " + hunk);
                        break;
                    }
                }

                //Debugging output for checking hunk matches
                //Debug.LogError("Found match: " + m);
                //Debug.LogError("   Hunk is:-" + m.Groups["changes"].Captures[0].Value + "-");
                //Debug.LogError("     LineNum is: " + m.Groups["start"].Captures[0].Value);
            }

            return(totalFileChanges);
        }