示例#1
0
        private void VisitForStatement_Init(IForInitializer init, IKaVEList <IStatement> forInit, IList <IStatement> body)
        {
            if (init == null)
            {
                return;
            }

            // case 1: single declaration
            var isDeclaration = init.Declaration != null;

            if (isDeclaration)
            {
                var decl = init.Declaration.Declarators[0];
                decl.Accept(this, forInit);
            }

            // case 2: multiple statements
            var hasStatements = init.Expressions.Count > 0;

            if (hasStatements)
            {
                foreach (var expr in init.ExpressionsEnumerable)
                {
                    expr.Accept(this, forInit);
                }
            }
        }
示例#2
0
        public void Setup()
        {
            _actualProcessedZips = Sets.NewHashSet <string>();
            _actualGroupedIds    = null;
            _actualGroups        = Lists.NewList <IKaVESet <string> >();
            _actualCleanedZips   = Lists.NewList <string>();

            _io = Mock.Of <IPreprocessingIo>();
            Mock.Get(_io).Setup(io => io.FindRelativeZipPaths()).Returns(GetExpectedZips());
            Mock.Get(_io)
            .Setup(io => io.GetFullPath_In(It.IsAny <string>()))
            .Returns <string>(relZip => "<dirIn>\\" + relZip);
            Mock.Get(_io)
            .Setup(io => io.GetFullPath_Merged(It.IsAny <string>()))
            .Returns <string>(relZip => "<dirMerged>\\" + relZip);
            Mock.Get(_io)
            .Setup(io => io.GetFullPath_Out(It.IsAny <string>()))
            .Returns <string>(relZip => "<dirOut>\\" + relZip);

            _log = Mock.Of <IMultiThreadedPreprocessingLogger>();
            Mock.Get(_log)
            .Setup(l => l.Error(It.IsAny <int>(), It.IsAny <Exception>()))
            .Callback <int, Exception>((taskId, ex) => _lastLoggedException = ex);

            _sut = new MultiThreadedPreprocessing(
                _io,
                _log,
                NumWorker,
                IdReaderFactory,
                CreateGrouper(),
                GroupMergerFactory,
                CleanerFactory);
        }
        public void Run()
        {
            _upes = Lists.NewList <IUserProfileEvent>();
            var users = Sets.NewHashSet <string>();

            _keys = Sets.NewHashSet <string>();
            _assignableSubmissions = Sets.NewHashSet <string>();

            var zips = _io.FindCcZips().ToList();

            var cur   = 1;
            var total = zips.Count;

            foreach (var zipName in zips)
            {
                _printer.StartZip(zipName, cur++, total);

                var userKey = GetUserKey(zipName);
                users.Add(userKey);
                _printer.FoundUserKey(userKey);

                var zipKeys = GetKeysFrom(zipName);
                _printer.FoundKeysInZip(zipKeys);
                foreach (var key in zipKeys)
                {
                    var combKey = string.Format("{0}\t{1}", key, userKey);
                    _keys.Add(combKey);
                }
            }

            _printer.FoundUsers(users);
            _printer.FoundKeys(_keys);
            _printer.FoundUpes(_upes);
            _printer.FoundAssignableZips(_assignableSubmissions);
        }
示例#4
0
 public void Visit(IKaVEList <IStatement> stmts, TContext context)
 {
     foreach (var stmt in stmts)
     {
         stmt.Accept(this, context);
     }
 }
示例#5
0
        protected void AssertBody(IKaVEList <IStatement> body)
        {
            Assert.AreEqual(1, ResultSST.Methods.Count);
            var m = ResultSST.Methods.First();

            AssertBody(m, body);
        }
示例#6
0
        public void Export(string rootDir)
        {
            var exports = _io.FindExports();

            _profiles = Lists.NewList <UserProfileEvent>();
            _days     = new HashSet <string>();

            _helper.LogFoundExports(exports.Count);

            var fileCounter = 0;

            foreach (var exportZip in exports)
            {
                _helper.LogOpenExport(exportZip);

                var hasUserProfile = false;
                foreach (var up in _io.ReadEvents(exportZip))
                {
                    RegisterKey(fileCounter, up);

                    var userProfileEvent = up as UserProfileEvent;
                    if (userProfileEvent != null)
                    {
                        hasUserProfile = true;
                        _profiles.Add(userProfileEvent);
                    }
                }

                _helper.LogResult(hasUserProfile);
                fileCounter++;
            }

            _helper.LogNumberDays(fileCounter, _days.Count);
            _helper.LogUserProfiles(_profiles);
        }
 private static void AddCommaIfNotLast <T>(T node, IKaVEList <T> list, SSTPrintingContext c)
     where T : ISSTNode
 {
     if (!ReferenceEquals(node, list.Last()))
     {
         c.Text(", ");
     }
 }
示例#8
0
 public virtual void LogUserProfiles(IKaVEList <UserProfileEvent> profiles)
 {
     foreach (var profile in profiles)
     {
         Console.WriteLine(@"----------------------------");
         Console.WriteLine(profile.ToFormattedJson());
     }
 }
        private void Fire(IKaVEList <IVersionControlAction> content, ISolutionName solutionName)
        {
            var gitEvent = Create <VersionControlEvent>();

            gitEvent.Solution = solutionName;
            gitEvent.Actions  = content;
            FireNow(gitEvent);
        }
 public TestGitEventGenerator([NotNull] IRSEnv env,
                              [NotNull] IMessageBus messageBus,
                              [NotNull] IDateUtils dateUtils,
                              [NotNull] IThreading threading)
     : base(env, messageBus, dateUtils, threading)
 {
     Content = Lists.NewList <string>();
 }
示例#11
0
 public GitEventGenerator([NotNull] IRSEnv env,
                          [NotNull] IMessageBus messageBus,
                          [NotNull] IDateUtils dateUtils,
                          [NotNull] IThreading threading)
     : base(env, messageBus, dateUtils, threading)
 {
     _oldActions = Lists.NewList <VersionControlAction>();
 }
示例#12
0
 protected void AssertStrings <T>(IKaVEList <string> parameters, IList <T> parameterNames) where T : IName
 {
     Assert.AreEqual(parameters.Count, parameterNames.Count);
     for (var i = 0; i < parameters.Count; i++)
     {
         Assert.AreEqual(parameters[i], parameterNames[i].Identifier);
     }
 }
示例#13
0
        private void WriteEvents(IKaVEList <Event> events)
        {
            var streamFileName = Path.Combine(_dirEvents, "eventstream.txt");
            var streamFile     = new StreamWriter(streamFileName, false);
            var setFileName    = Path.Combine(_dirEvents, "eventMapping.txt");
            var setFile        = new StreamWriter(setFileName, false);

            Console.WriteLine("stream contains {0} events", events.Count);
            var uniqueEvents = new HashSet <Event>();
            var eventList    = new List <Event>();

            var isFirstMethod = true;
            var time          = 0.000;

            foreach (var e in events)
            {
                if (!uniqueEvents.Contains(e))
                {
                    uniqueEvents.Add(e);
                    eventList.Add(e);
                }

                var idx = eventList.IndexOf(e);

                if (e.Kind == EventKind.MethodDeclaration && !isFirstMethod)
                {
                    time += EventStreamTimeout;
                }
                isFirstMethod = false;

                streamFile.Write("{0},{1:0.000}\n", idx, time);

                time += EventStreamDelta;
            }

            streamFile.Close();

            setFile.WriteLine('[');
            var isFirst = true;

            foreach (var e in eventList)
            {
                if (!isFirst)
                {
                    setFile.WriteLine(',');
                }
                setFile.Write(e.ToCompactJson());
                isFirst = false;
            }
            setFile.WriteLine();
            setFile.WriteLine(']');

            // -> write eventList

            setFile.Close();

            Console.WriteLine("finished");
        }
示例#14
0
 public void Setup()
 {
     _foundIds = Lists.NewList <IEnumerable <string> >();
     _log      = Mock.Of <IIdReaderLogger>();
     Mock.Get(_log)
     .Setup(l => l.FoundIds(It.IsAny <IEnumerable <string> >()))
     .Callback <IEnumerable <string> >(s => _foundIds.Add(s));
     _sut = new IdReader(_log);
 }
示例#15
0
        private int Visit(IKaVEList <IStatement> body, int context)
        {
            int size = 0;

            foreach (var stmt in body)
            {
                size += stmt.Accept(this, 0);
            }

            return(size);
        }
示例#16
0
        public void FoundUpes(IKaVEList <IUserProfileEvent> upes)
        {
            var total = upes.Count;
            var i     = 1;

            Console.WriteLine(@"#### upes:");
            foreach (var key in upes)
            {
                Console.WriteLine(@"{0}/{1}: {2}", i++, total, key);
            }
            Console.WriteLine();
        }
示例#17
0
 protected void AssertBody(IMethodDeclaration method, IKaVEList <IStatement> body)
 {
     if (!body.Equals(method.Body))
     {
         Console.WriteLine("AssertBody failed!");
         Console.WriteLine("\n-- expected body --\n");
         Console.WriteLine(body.ToString());
         Console.WriteLine("\n-- actual body --\n");
         Console.WriteLine(method.Body.ToString());
         Assert.Fail();
     }
 }
示例#18
0
        private static Query Find(Tuple <CoReMethodName, CoReTypeName> key, IKaVEList <Query> usages)
        {
            foreach (var usage in usages)
            {
                var isMethod = usage.methodCtx.Equals(key.Item1);
                var isType   = usage.type.Equals(key.Item2);
                if (isMethod && isType)
                {
                    return(usage);
                }
            }

            return(null);
        }
        private void AppendPropertyAccessor(SSTPrintingContext c, IKaVEList <IStatement> body, string keyword)
        {
            if (body.Any())
            {
                c.Indentation().Text(keyword);
                c.StatementBlock(body, this);
            }
            else
            {
                c.Indentation().Text(keyword).Text(";");
            }

            c.NewLine();
        }
示例#20
0
        public override void VisitSwitchStatement(ISwitchStatement block, IList <IStatement> body)
        {
            AddIf(block, CompletionCase.EmptyCompletionBefore, body);

            var switchBlock = new SwitchBlock {
                Reference = _exprVisitor.ToVariableRef(block.Condition, body)
            };

            foreach (var section in block.Sections)
            {
                IKaVEList <IStatement> currentSection = null;

                foreach (var label in section.CaseLabels)
                {
                    currentSection = new KaVEList <IStatement>();
                    if (label.IsDefault)
                    {
                        switchBlock.DefaultSection = currentSection;
                    }
                    else
                    {
                        switchBlock.Sections.Add(
                            new CaseBlock
                        {
                            Label = _exprVisitor.ToSimpleExpression(label.ValueExpression, body),
                            Body  = currentSection
                        });
                    }
                    AddIf(label, CompletionCase.InBody, currentSection);
                }

                AddIf(section, CompletionCase.InBody, currentSection);
                foreach (var statement in section.Statements)
                {
                    statement.Accept(this, currentSection);
                }

                switch (1)
                {
                case 1 * 2:
                case 0:
                    break;
                }
            }

            body.Add(switchBlock);

            AddIf(block, CompletionCase.EmptyCompletionAfter, body);
        }
示例#21
0
        private static TypeHierarchy CreateTypeHierarchy(ITypeElement type,
                                                         ISubstitution substitution,
                                                         IKaVEList <ITypeName> seenTypes,
                                                         bool shouldIgnoreRootTypes)
        {
            if (shouldIgnoreRootTypes && (type == null || IsRootType(type)))
            {
                // ignore implicite extensions in type hierarchy
                return(null);
            }
            var typeName = type.GetName <ITypeName>(substitution);

            seenTypes.Add(typeName);
            var enclosingClassHierarchy = new TypeHierarchy(typeName.Identifier);

            foreach (var superType in type.GetSuperTypes())
            {
                var resolveResult     = superType.Resolve();
                var declElem          = resolveResult.DeclaredElement;
                var isUnresolvedAlias = declElem is IUsingAliasDirective;
                // TODO NameUpdate: "isUnknownOrUnResolvedUntested" required by one analyzed solution, still untested
                var isUnknownOrUnResolvedUntested = superType.IsUnknown || !superType.IsResolved;
                if (!resolveResult.IsValid() || declElem == null || isUnresolvedAlias || isUnknownOrUnResolvedUntested)
                {
                    enclosingClassHierarchy.Implements.Add(new TypeHierarchy());
                    continue;
                }

                var superName = declElem.GetName <ITypeName>(substitution);
                if (seenTypes.Contains(superName))
                {
                    continue;
                }

                var superTypeElement      = superType.GetTypeElement();
                var superTypeSubstitution = superType.GetSubstitution();
                var superHierarchy        = CreateTypeHierarchy(superTypeElement, superTypeSubstitution, seenTypes, true);

                if (declElem is IClass || declElem is IStruct)
                {
                    enclosingClassHierarchy.Extends = superHierarchy;
                }
                else if (declElem is IInterface)
                {
                    enclosingClassHierarchy.Implements.Add(superHierarchy);
                }
            }
            return(enclosingClassHierarchy);
        }
示例#22
0
        public void Setup()
        {
            _reportedCounts    = new List <IDictionary <string, int> >();
            _registeredFilters = Lists.NewList <string>();
            _registeredFixers  = Lists.NewList <string>();

            _log = Mock.Of <ICleanerLogger>();
            Mock.Get(_log)
            .Setup(l => l.FinishedWriting(It.IsAny <IDictionary <string, int> >()))
            .Callback <IDictionary <string, int> >(d => _reportedCounts.Add(d));
            Mock.Get(_log)
            .Setup(l => l.RegisteredConfig(It.IsAny <IEnumerable <string> >(), It.IsAny <IEnumerable <string> >()))
            .Callback <IEnumerable <string>, IEnumerable <string> >(
                (filters, fixers) =>
            {
                _registeredFilters.AddAll(filters);
                _registeredFixers.AddAll(fixers);
            });

            _sut = new Cleaner(Io, _log);
        }
示例#23
0
        private void ExtractEvents(IKaVEList <Event> events)
        {
            var logs      = FindSSTLogs(_dirCtxs);
            var generator = new EventStreamGenerator();

            foreach (var log in logs)
            {
                Console.WriteLine("##################################################");
                Console.WriteLine("reading {0}...", Path.GetFileName(log));
                using (var ra = new ReadingArchive(log))
                {
                    var ctxs = ra.GetAll <Context>();
                    Console.WriteLine("\tFound {0} contexts", ctxs.Count);
                    Console.Write("\tExtracting events... ");
                    foreach (var ctx in ctxs)
                    {
                        ctx.SST.Accept(generator, events);
                        Console.Write('.');
                    }
                    Console.WriteLine(" done");
                }
            }
        }
示例#24
0
        /// <summary>
        ///     Appends a statement block to the context with correct indentation.
        /// </summary>
        /// <param name="block">The block to append.</param>
        /// <param name="visitor">The visitor to use for printing each statement.</param>
        /// <param name="withBrackets">If false, opening and closing brackets will be omitted.</param>
        public SSTPrintingContext StatementBlock(IKaVEList <IStatement> block,
                                                 ISSTNodeVisitor <SSTPrintingContext> visitor,
                                                 bool withBrackets = true)
        {
            if (!block.Any())
            {
                if (withBrackets)
                {
                    Text(" { }");
                }

                return(this);
            }

            if (withBrackets)
            {
                NewLine().Indentation().Text("{");
            }

            IndentationLevel++;

            foreach (var statement in block)
            {
                NewLine();
                statement.Accept(visitor, this);
            }

            IndentationLevel--;

            if (withBrackets)
            {
                NewLine().Indentation().Text("}");
            }

            return(this);
        }
 public TestClassResult()
 {
     TestMethods = Lists.NewList <TestMethodResult>();
 }
示例#26
0
 public CatchBlock()
 {
     Parameter = Names.UnknownParameter;
     Body      = Lists.NewList <IStatement>();
 }
示例#27
0
 public CaseBlock()
 {
     Label = new UnknownExpression();
     Body  = Lists.NewList <IStatement>();
 }
 public TestRunInterval()
 {
     TestClasses = Lists.NewList <TestClassResult>();
 }
示例#29
0
        private static ISet <Tuple <CoReMethodName, CoReTypeName> > GetLocationIndices(IKaVEList <Query> aqs,
                                                                                       IKaVEList <Query> bqs)
        {
            var keys = new HashSet <Tuple <CoReMethodName, CoReTypeName> >();

            foreach (var qs in new[] { aqs, bqs })
            {
                foreach (var q in qs)
                {
                    keys.Add(Tuple.Create(q.methodCtx, q.type));
                }
            }

            return(keys);
        }
示例#30
0
 public IndexAccessExpression()
 {
     Reference = new VariableReference();
     Indices   = new KaVEList <ISimpleExpression>();
 }