コード例 #1
0
        private static SourceCodeEntitiesFile processSrcML(XmlDocument doc)
        {
            SourceCodeEntitiesFile scef      = new SourceCodeEntitiesFile();
            XPathNavigator         navigator = doc.CreateNavigator();

            collectEntitiesByType(scef, navigator, "class",
                                  SourceCodeEntityType.CLASS, "*[local-name() = 'name']",
                                  new Dictionary <string, string>());
            collectEntitiesByType(scef, navigator, "decl_stmt",
                                  SourceCodeEntityType.ATTRIBUTE,
                                  "*[local-name() = 'decl']/*[local-name() = 'name']",
                                  new Dictionary <string, string> {
                { "class", "*[local-name() = 'name']" },
                { "function", "*[local-name() = 'name']" },
            });
            collectEntitiesByType(scef, navigator, "function",
                                  SourceCodeEntityType.METHOD, "*[local-name() = 'name']",
                                  new Dictionary <string, string> {
                { "class", "*[local-name() = 'name']" }
            });
            collectEntitiesByType(scef, navigator, "comment",
                                  SourceCodeEntityType.COMMENT, ".", new Dictionary <string, string> {
                { "class", "*[local-name() = 'name']" },
                { "function", "*[local-name() = 'name']" },
            });

            return(scef);
        }
コード例 #2
0
        public static SourceCodeEntitiesFileCollection run(string src2srcml_path,
                                                           string input_directory)
        {
            if (!verifySrc2SrcMLExecutable(src2srcml_path))
            {
                Console.WriteLine("WARNING: src2srcml_path does not appear to be a " +
                                  "src2srcml executable");
            }

            List <FileInfo> files = SrcMLCodeReader.getFiles(
                new DirectoryInfo(input_directory), "*.java");
            SourceCodeEntitiesFileCollection collection =
                new SourceCodeEntitiesFileCollection();

            foreach (FileInfo file in files)
            {
                XmlDocument document = new XmlDocument();
                document.PreserveWhitespace = true;
                document.LoadXml(loadSourceInfo(file, src2srcml_path));
                SourceCodeEntitiesFile scef = processSrcML(document);
                scef.FileName = file.Name;
                collection.Add(scef);
            }

            return(collection);
        }
コード例 #3
0
        private static void collectEntitiesByType(SourceCodeEntitiesFile scef,
                                                  XPathNavigator navigator, string srcml_name, SourceCodeEntityType type,
                                                  string name_xpath, Dictionary <string, string> parent_names)
        {
            XPathNodeIterator iterator = (XPathNodeIterator)navigator.Evaluate(
                "//*[local-name() = '" + srcml_name + "']");

            while (iterator.MoveNext())
            {
                XPathNavigator     element  = iterator.Current;
                EntityPositionInfo position = getEntityPosition(element);

                string            name        = "";
                XPathNodeIterator search_name = (XPathNodeIterator)
                                                element.Evaluate(name_xpath);
                if (search_name.MoveNext())
                {
                    name = search_name.Current.Value;
                }

                Stack <string> fully_qualified_name = new Stack <string>();
                while (element.MoveToParent())
                {
                    if (parent_names.ContainsKey(element.Name))
                    {
                        search_name =
                            (XPathNodeIterator)element.Evaluate(parent_names[element.Name]);
                        if (search_name.MoveNext())
                        {
                            fully_qualified_name.Push(search_name.Current.Value);
                        }
                    }
                }

                SourceCodeEntity sce = new SourceCodeEntity();
                sce.LineStart   = position.line_start;
                sce.LineEnd     = position.line_end;
                sce.ColumnStart = position.col_start;
                sce.ColumnEnd   = position.col_end;
                sce.Type        = type;
                sce.Name        = name;
                while (fully_qualified_name.Count > 0)
                {
                    sce.FullyQualifiedName.Add(fully_qualified_name.Pop());
                }

                sce.parent_file = scef;
                scef.Add(sce);
            }
        }
コード例 #4
0
ファイル: GazeToSource.cs プロジェクト: jmeinken/itrace-pilot
        run(GazeResults gaze_results, SourceCodeEntitiesFileCollection scefc)
        {
            GazeSourceRelationship gsr = new GazeSourceRelationship();

            foreach (GazeData gd in gaze_results.gazes)
            {
                GazeSourceEntityRelationship gser = new GazeSourceEntityRelationship();

                SourceCodeEntitiesFile scef = getSourceFileByGaze(gd, scefc);
                if (scef != null)
                {
                    foreach (SourceCodeEntity sce in scef)
                    {
                        if (isInEntity(gd, sce))
                        {
                            gser.sc_file   = scef;
                            gser.sc_entity = sce;
                            gser.gaze_data = gd;

                            switch (sce.Type)
                            {
                            case SourceCodeEntityType.CLASS:
                                gser.class_ = sce.Name;
                                break;

                            case SourceCodeEntityType.ATTRIBUTE:
                                gser.attribute = sce.Name;
                                break;

                            case SourceCodeEntityType.METHOD:
                                gser.method = sce.Name;
                                break;

                            case SourceCodeEntityType.COMMENT:
                                gser.comment = sce.Name;
                                break;
                            }
                        }
                    }
                }
                else
                {
                    gser.gaze_data = gd;
                }

                gsr.Add(gser);
            }

            return(gsr);
        }
コード例 #5
0
ファイル: GazeToSource.cs プロジェクト: jmeinken/itrace-pilot
        private static SourceCodeEntitiesFile getSourceFileByGaze(GazeData gd,
                                                                  SourceCodeEntitiesFileCollection scefc)
        {
            SourceCodeEntitiesFile scef = null;

            foreach (SourceCodeEntitiesFile cur_scef in scefc)
            {
                if (gd.filename == cur_scef.FileName)
                {
                    scef = cur_scef;
                    break;
                }
            }
            return(scef);
        }