public override void ProcessType(TypeDefinition type)
        {
            if (!type.Inherits ("Android.App.Application"))
                return;

            ProcessAttributeProvider (type);
        }
		private void CheckCallingBaseMethod (TypeDefinition type, MethodSignature methodSignature)
		{
			MethodDefinition method = type.GetMethod (methodSignature);
			if (method == null)
				return; // Perhaps should report that doesn't exist the method (only with ctor).

			foreach (Instruction instruction in method.Body.Instructions) {
				if (instruction.OpCode.FlowControl == FlowControl.Call) {
					MethodReference operand = (MethodReference) instruction.Operand;
					if (methodSignature.Matches (operand) && type.Inherits (operand.DeclaringType.ToString ()))
						return;
				}
			}

			Runner.Report (method, Severity.High, Confidence.High, String.Format ("The method {0} isn't calling its base method.", method));
		}
Ejemplo n.º 3
0
 static bool IsImplementor(TypeDefinition type)
 {
     return type.Name.EndsWith ("Implementor") && type.Inherits ("Java.Lang.Object");
 }
 static bool IsTypeConverter(TypeDefinition type)
 {
     return type.Inherits ("System.ComponentModel", "TypeConverter");
 }
Ejemplo n.º 5
0
		static bool IsWebServiceClient (TypeDefinition type)
		{
			return type.Inherits ("System.Web.Services.Protocols", "SoapHttpClientProtocol");
		}
        public RuleResult CheckType(TypeDefinition type)
        {
            if (type.IsEnum || type.IsInterface || !type.HasFields)
                return RuleResult.DoesNotApply;

            Log.WriteLine (this);
            Log.WriteLine (this, "----------------------------------");

            bool isWinFormControl = usesWinForms && type.Inherits ("System.Windows.Forms", "Control");

            // All fields start out as always null and unused.
            foreach (FieldDefinition field in type.Fields) {
                if (field.IsPrivate && !field.FieldType.IsValueType)
                    if (!isWinFormControl || field.Name != "components")	// the winforms designer seems to like to leave this null
                        nullFields.Add (field);
            }

            CheckMethods (type);
            if (type.HasNestedTypes) {
                foreach (TypeDefinition nested in type.NestedTypes)
                    CheckMethods (nested);
            }

            // Report a defect if:
            // 1) The field is explicitly set to null and not used (if
            // if is implicitly set to null and not used AvoidUnusedPrivateFieldsRule
            // will catch it).
            setFields.IntersectWith (nullFields);
            setFields.ExceptWith (usedFields);
            if (setFields.Count > 0) {
                foreach (FieldDefinition field in setFields) {
                    Log.WriteLine (this, "{0} is always null", field.Name);
                    Runner.Report (field, Severity.Medium, Confidence.High);
                }
            }

            // 2) The field is always null and used somewhere.
            nullFields.IntersectWith (usedFields);
            if (nullFields.Count > 0) {
                foreach (FieldDefinition field in nullFields) {
                    Log.WriteLine (this, "{0} is always null", field.Name);
                    Runner.Report (field, Severity.Medium, Confidence.High);
                }
            }

            nullFields.Clear ();
            setFields.Clear ();
            usedFields.Clear ();

            return Runner.CurrentRuleResult;
        }
		public RuleResult CheckType (TypeDefinition type)
		{
			// rule apply only to type that inherits from System.Exception
			if (!type.Inherits (Exception))
				return RuleResult.DoesNotApply;

			// rule applies, only Success or Failure from the point on

			// check if the type implements all the needed exception constructors

			bool empty_ctor = false;		// MyException ()
			bool string_ctor = false;		// MyException (string message)
			bool inner_exception_ctor = false;	// MyException (string message, Exception innerException)
			bool serialization_ctor = false;	// MyException (SerializationInfo info, StreamingContext context)

			foreach (MethodDefinition ctor in type.GetConstructors ()) {
				// skip cctor
				if (ctor.IsStatic)
					continue;

				if (!ctor.HasParameters) {
					// there can be only one so only it's visibility matters
					empty_ctor = ctor.IsPublic;
					continue;
				}

				switch (ctor.Parameters.Count) {
				case 1:
					string_ctor |= CheckForStringConstructor (ctor);
					break;
				case 2:
					if (ctor.IsPublic) {
						if (!inner_exception_ctor) {
							inner_exception_ctor = CheckForInnerExceptionConstructor (ctor);
							if (inner_exception_ctor)
								break;
						}

						string_ctor |= CheckForStringConstructor (ctor);
					} else {
						serialization_ctor |= CheckForSerializationConstructor (ctor);
					}
					break;
				default:
					inner_exception_ctor |= CheckForInnerExceptionConstructor (ctor);
					break;
				}
			}

			if (!empty_ctor) {
				string s = String.Format (MissingConstructor, "public", type.Name, "()");
				Runner.Report (type, Severity.High, Confidence.Total, s);
			}
			if (!string_ctor) {
				string s = String.Format (MissingConstructor, "public", type.Name, "(string message)");
				Runner.Report (type, Severity.High, Confidence.Total, s);
			}
			if (!inner_exception_ctor) {
				string s = String.Format (MissingConstructor, "public", type.Name,
					"(string message, Exception innerException)");
				Runner.Report (type, Severity.High, Confidence.Total, s);
			}
			if (!serialization_ctor) {
				string s = String.Format (MissingConstructor, (type.IsSealed) ? "private" : "protected",
					type.Name, "(SerializationInfo info, StreamingContext context)");
				Runner.Report (type, Severity.High, Confidence.Total, s);
			}

			return Runner.CurrentRuleResult;
		}
		public RuleResult CheckType (TypeDefinition type)
		{
			if (!type.IsClass || !type.HasMethods || !type.Inherits ("System.Windows.FrameworkElement"))
				return RuleResult.DoesNotApply;
			var arrangeOverride = type.GetMethod (arrangeSignature);
			var measureOverride = type.GetMethod (measureSignature);
			// The class doesn't have either method.
			if (arrangeOverride == null && measureOverride == null)
				return RuleResult.DoesNotApply;
			// Only ArrangeOverride provided.
			if (arrangeOverride != null && measureOverride == null)
				Runner.Report (arrangeOverride, Severity.High, Confidence.Total);
			// Only MeasureOverride provided.
			if (measureOverride != null && arrangeOverride == null)
				Runner.Report (measureOverride, Severity.High, Confidence.Total);

			return Runner.CurrentRuleResult;
		}