Ejemplo n.º 1
0
        private static bool TryAddRegressionAttributeViaPex <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Method method, string message, IOutput output, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder, System.Type attributeType)
        {
            IFeedbackManager feedbackManager = GetFeedbackConnection();
            bool             success         = false;

            if (feedbackManager != null)
            {
                ConstructorInfo attrCtor = attributeType.GetConstructor(new System.Type[1] {
                    typeof(string)
                });
                MethodDefinitionName target = Translate(method, output, mdDecoder);

                string           group = Guid.NewGuid().ToString();
                ICustomAttribute ca    = new CustomAttributeBuilder(MetadataFromReflection.GetMethod(attrCtor), MetadataExpression.String(message));

                CodeUpdate update = CodeUpdate.AddAttribute("Regression", target, ca);

                CodeFix fix = CodeFix.FromUpdate("ClousotRegression", "missing regression attribute", group, update, 100, CodeFixImage.Message);
                try
                {
                    feedbackManager.AddFix(fix);
                    success = true;
                }
                catch { }
            }
            return(success);
        }
Ejemplo n.º 2
0
        private static bool TryAddRegressionAttributeViaPex <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Method method, Enum outcome, string message, int primaryILOffset, int methodILOffset, IOutput output, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder, System.Type attributeType)
        {
            IFeedbackManager feedbackManager = GetFeedbackConnection();
            bool             success         = false;

            if (feedbackManager != null)
            {
                PropertyInfo    outcomeProp   = attributeType.GetProperty("Outcome");
                PropertyInfo    messageProp   = attributeType.GetProperty("Message");
                PropertyInfo    primaryILProp = attributeType.GetProperty("PrimaryILOffset");
                PropertyInfo    methodILProp  = attributeType.GetProperty("MethodILOffset");
                ConstructorInfo attrCtor      = attributeType.GetConstructor(new System.Type[0]);

                MethodDefinitionName target = Translate(method, output, mdDecoder);

                MethodName attributeCtorName = MetadataFromReflection.GetMethod(attrCtor).SerializableName;

#if DEBUG_PEX_BY_XML
                SafeSimpleXmlWriter writer = SafeSimpleXmlWriter.Create(new StreamWriter(@"C:\temp\" + mdDecoder.Name(method) + ".xml"), true);
                target.WriteXml(writer, "method");
                writer.Close();

                SafeSimpleXmlWriter writer2 = SafeSimpleXmlWriter.Create(new StreamWriter(@"C:\temp\" + mdDecoder.Name(method) + "2.xml"), true);
                attributeCtorName2.WriteXml(writer2, "method");
                writer2.Close();
#endif
                string group = Guid.NewGuid().ToString();

                var outcomeArg = AttributeArgument.Named(MetadataFromReflection.GetProperty(outcomeProp), MetadataExpression.EnumValue(outcome));
#if DEBUG_PEX_BY_XML
                SafeSimpleXmlWriter writer3 = SafeSimpleXmlWriter.Create(new StreamWriter(@"C:\temp\" + mdDecoder.Name(method) + "3.xml"), true);
                outcomeArg.WriteXml(writer3, "method");
                writer3.Close();
#endif
                CodeUpdate update =
                    CodeUpdate.AddAttribute("Regression", target, attributeCtorName,
                                            outcomeArg,
                                            AttributeArgument.Named(MetadataFromReflection.GetProperty(messageProp), MetadataExpression.String(message)),
                                            AttributeArgument.Named(MetadataFromReflection.GetProperty(primaryILProp), MetadataExpression.I4(MetadataFromReflection.GetType(typeof(int)), primaryILOffset)),
                                            AttributeArgument.Named(MetadataFromReflection.GetProperty(methodILProp), MetadataExpression.I4(MetadataFromReflection.GetType(typeof(int)), methodILOffset))
                                            );

                CodeFix fix = CodeFix.FromUpdate("ClousotRegression", "missing regression attribute", group, update, 100, CodeFixImage.Message);
                try
                {
                    feedbackManager.AddFix(fix);
                    success = true;
                }
                catch { }
            }
            return(success);
        }
Ejemplo n.º 3
0
        private static void SuggestPostConditionViaPex <Local, Parameter, Method, Field, Property, Event, Type, Expression, Variable, Attribute, Assembly>(IExpressionContext <Local, Parameter, Method, Field, Type, Expression, Variable> context, int rank, string symptom, IOutput output, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder, string post) where Type : IEquatable <Type>
        {
#if INCLUDE_PEXINTEGRATION
            IFeedbackManager feedbackManager = GetFeedbackConnection();
            if (feedbackManager != null)
            {
                MethodDefinitionName target = Translate(context.MethodContext.CurrentMethod, output, mdDecoder);

                string     group = Guid.NewGuid().ToString();
                var        microsoftContractsAssembly = ShortAssemblyName.FromName("Microsoft.Contracts");
                CodeUpdate update =
                    CodeUpdate.InsertCheck("Ensures", target, MakePostconditionString(post), new[] { "System.Diagnostics.Contracts" }, new[] { microsoftContractsAssembly }, "Clousot");

                CodeFix fix = CodeFix.FromUpdate("Clousot", symptom, group, update, rank, CodeFixImage.Message);
                try
                {
                    feedbackManager.AddFix(fix);
                }
                catch { }
            }
#endif
        }
Ejemplo n.º 4
0
        private static bool TryAddRegressionAttributeViaPex <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(Assembly assembly, string message, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder, System.Type attributeType)
        {
            IFeedbackManager feedbackManager = GetFeedbackConnection();
            bool             success         = true;

            if (feedbackManager != null)
            {
                ConstructorInfo attrCtor = attributeType.GetConstructor(new System.Type[1] {
                    typeof(string)
                });

#if DEBUG_PEX_BY_XML
                SafeSimpleXmlWriter writer = SafeSimpleXmlWriter.Create(new StreamWriter(@"C:\temp\" + mdDecoder.Name(method) + ".xml"), true);
                target.WriteXml(writer, "method");
                writer.Close();

                SafeSimpleXmlWriter writer2 = SafeSimpleXmlWriter.Create(new StreamWriter(@"C:\temp\" + mdDecoder.Name(method) + "2.xml"), true);
                attributeCtorName2.WriteXml(writer2, "method");
                writer2.Close();
#endif
                string           group = Guid.NewGuid().ToString();
                ICustomAttribute ca    = new CustomAttributeBuilder(MetadataFromReflection.GetMethod(attrCtor), MetadataExpression.String(message));

                CodeUpdate update =
                    CodeUpdate.AddAttribute("Regression",
                                            new Microsoft.ExtendedReflection.Metadata.Names.ShortAssemblyName(mdDecoder.Name(assembly), null),
                                            ca);

                CodeFix fix = CodeFix.FromUpdate("ClousotRegression", "missing regression attribute", group, update, 100, CodeFixImage.Message);
                try
                {
                    feedbackManager.AddFix(fix);
                    success = true;
                }
                catch { }
            }
            return(success);
        }