Exemple #1
0
        public SourceCodeMutationResult PerformMutationAnalysisOnSourceCodeProject(
            EnvDTE.Project sourceCodeProject,
            List <string> options)
        {
            var workspace = _roslynSetupHelper.CreateWorkspace();
            var solution  = _roslynSetupHelper.GetSolutionToAnalyze(
                workspace, _currentSolution.FileName);
            var projectToAnalyze     = _roslynSetupHelper.GetProjectToAnalyze(solution, sourceCodeProject.Name);
            var projectAssembly      = _roslynSetupHelper.GetProjectAssembly(projectToAnalyze);
            var projectSemanticModel = _roslynSetupHelper.GetProjectSemanticModel(
                _roslynSetupHelper.GetProjectToAnalyze(solution, sourceCodeProject.Name));

            //get info about source code project's types
            var projectClasses = new List <Class>();

            foreach (var syntaxTree in projectAssembly.SyntaxTrees)
            {
                var classVisitor = new ClassVisitor();
                classVisitor.Visit(syntaxTree.GetRoot());
                projectClasses.AddRange(classVisitor.ProjectClasses);
            }

            var generatedMutants =
                GenerateMutantsForProject(projectAssembly, projectSemanticModel,
                                          options, workspace, projectClasses, solution, projectToAnalyze.OutputFilePath);

            return(new SourceCodeMutationResult()
            {
                GeneratedMutants = generatedMutants,
                OutputPath = projectToAnalyze.OutputFilePath,
                Usings = Usings
            });
        }
        protected override Func <PropertyInfo, Delegate> Call <TObj, TValue>()
        {
            ClassVisitor <DeserializeContext, TValue> elementVisitor = visitorFactory.GetClassVisitor <TValue>();

            return(property =>
            {
                ISetter <TObj, IList <TValue> > setter = Setter.Create <TObj, IList <TValue> >(property);
                return new ProcessField <DeserializeContext, TObj, IList <TValue> >(
                    (DeserializeContext context, TObj obj, ref IList <TValue> value) =>
                {
                    value = new List <TValue>();
                    setter.Apply(obj, value);
                    int length = PrimitiveDeserializer.Impl <int> .Instance(context.Stream);
                    for (int i = 0; i < length; i++)
                    {
                        TValue element = new TValue();
                        if (elementVisitor.Visit(context, element) == VisitStatus.Exit)
                        {
                            return VisitStatus.Exit;
                        }
                        value.Add(element);
                    }
                    return VisitStatus.SkipChildren;
                });
            });
        }
        protected override Delegate Call <TObj>()
        {
            ClassVisitor <Stream, TObj> elementVisitor = visitorFactory.GetClassVisitor <TObj>();

            return(new ProcessObject <Stream, IList <TObj> >(
                       (Stream stream, IList <TObj> value) =>
            {
                PrimitiveSerializer.Impl <int> .Instance(stream, value.Count());
                foreach (TObj element in value)
                {
                    elementVisitor.Visit(stream, element);
                }
                return VisitStatus.SkipChildren;
            }));
        }
 public virtual Accept(ClassVisitor visitor)
 {
     visitor.Visit(this);
 }
 public override Accept(ClassVisitor visitor)
 {
     visitor.Visit(this);
 }
Exemple #6
0
 public virtual string Accept(ClassVisitor visitor)
 {
     return(visitor.Visit(this));
 }
Exemple #7
0
 public override string Accept(ClassVisitor visitor)
 {
     return(visitor.Visit(this));
 }
Exemple #8
0
        /// <summary>Makes the given class visitor visit this class.</summary>
        /// <param name="classVisitor">a class visitor.</param>
        public virtual void Accept(ClassVisitor classVisitor)
        {
            // Visit the header.
            var interfacesArray = new string[interfaces.Count];

            Collections.ToArray(interfaces, interfacesArray);
            classVisitor.Visit(version, access, name, signature, superName, interfacesArray);
            // Visit the source.
            if (sourceFile != null || sourceDebug != null)
            {
                classVisitor.VisitSource(sourceFile, sourceDebug);
            }
            // Visit the module.
            if (module != null)
            {
                module.Accept(classVisitor);
            }
            // Visit the nest host class.
            if (nestHostClass != null)
            {
                classVisitor.VisitNestHost(nestHostClass);
            }
            // Visit the outer class.
            if (outerClass != null)
            {
                classVisitor.VisitOuterClass(outerClass, outerMethod, outerMethodDesc);
            }
            // Visit the annotations.
            if (visibleAnnotations != null)
            {
                for (int i = 0, n = visibleAnnotations.Count; i < n; ++i)
                {
                    var annotation = visibleAnnotations[i];
                    annotation.Accept(classVisitor.VisitAnnotation(annotation.desc, true));
                }
            }

            if (invisibleAnnotations != null)
            {
                for (int i = 0, n = invisibleAnnotations.Count; i < n; ++i)
                {
                    var annotation = invisibleAnnotations[i];
                    annotation.Accept(classVisitor.VisitAnnotation(annotation.desc, false));
                }
            }

            if (visibleTypeAnnotations != null)
            {
                for (int i = 0, n = visibleTypeAnnotations.Count; i < n; ++i)
                {
                    var typeAnnotation = visibleTypeAnnotations[i];
                    typeAnnotation.Accept(classVisitor.VisitTypeAnnotation(typeAnnotation.typeRef, typeAnnotation
                                                                           .typePath, typeAnnotation.desc, true));
                }
            }

            if (invisibleTypeAnnotations != null)
            {
                for (int i = 0, n = invisibleTypeAnnotations.Count; i < n; ++i)
                {
                    var typeAnnotation = invisibleTypeAnnotations[i];
                    typeAnnotation.Accept(classVisitor.VisitTypeAnnotation(typeAnnotation.typeRef, typeAnnotation
                                                                           .typePath, typeAnnotation.desc, false));
                }
            }

            // Visit the non standard attributes.
            if (attrs != null)
            {
                for (int i = 0, n = attrs.Count; i < n; ++i)
                {
                    classVisitor.VisitAttribute(attrs[i]);
                }
            }
            // Visit the nest members.
            if (nestMembers != null)
            {
                for (int i = 0, n = nestMembers.Count; i < n; ++i)
                {
                    classVisitor.VisitNestMember(nestMembers[i]);
                }
            }
            // Visit the permitted subtypes.
            if (permittedSubtypesExperimental != null)
            {
                for (int i = 0, n = permittedSubtypesExperimental.Count; i < n; ++i)
                {
                    classVisitor.VisitPermittedSubtypeExperimental(permittedSubtypesExperimental[i]);
                }
            }
            // Visit the inner classes.
            for (int i = 0, n = innerClasses.Count; i < n; ++i)
            {
                innerClasses[i].Accept(classVisitor);
            }
            // Visit the record components.
            if (recordComponentsExperimental != null)
            {
                for (int i = 0, n = recordComponentsExperimental.Count; i < n; ++i)
                {
                    recordComponentsExperimental[i].AcceptExperimental(classVisitor);
                }
            }
            // Visit the fields.
            for (int i = 0, n = fields.Count; i < n; ++i)
            {
                fields[i].Accept(classVisitor);
            }
            // Visit the methods.
            for (int i = 0, n = methods.Count; i < n; ++i)
            {
                methods[i].Accept(classVisitor);
            }
            classVisitor.VisitEnd();
        }