Example #1
0
 protected virtual void ValidateConstraintModel(CompositeValidationResult result, CompositeModel model, ConstraintModel constraint)
 {
     if (constraint.ConstraintType == null)
     {
         result.InternalValidationErrors.Add(ValidationErrorFactory.NewInternalError("Constraint model had null as constraint type", constraint));
     }
 }
Example #2
0
        protected virtual void ValidateFragmentMethod(CompositeValidationResult result, CompositeModel compositeModel, CompositeMethodModel compositeMethod, AbstractFragmentMethodModel methodModel)
        {
            if (compositeMethod == null)
            {
                result.InternalValidationErrors.Add(ValidationErrorFactory.NewInternalError("Composite method model may not be null.", compositeModel));
            }
            if (methodModel != null)
            {
                var declType = methodModel.NativeInfo.DeclaringType;
                if (!declType
#if WINDOWS_PHONE_APP
                    .GetTypeInfo()
#endif
                    .IsClass)
                {
                    result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("The declaring type of fragment method " + methodModel.NativeInfo + " must be a class, however " + declType + " is not a class.", compositeModel, compositeMethod));
                }
                if (!methodModel.IsGeneric && (!methodModel.NativeInfo.IsVirtual || methodModel.NativeInfo.IsFinal))
                {
                    result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("The method " + methodModel.NativeInfo + " in " + declType + " is not virtual, however, all composite methods must be virtual.", compositeModel, methodModel));
                }
                if (declType
#if WINDOWS_PHONE_APP
                    .GetTypeInfo()
#endif
                    .IsSealed)
                {
                    result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("The type " + declType + " is sealed, however, all fragment types must be non-sealed.", compositeModel, methodModel));
                }
                //if ( !declType.IsPublic && !declType.IsNestedPublic )
                //{
                //   String msg = null;
                //   if ( methodModel.NativeInfo.IsAssembly || methodModel.NativeInfo.IsFamilyOrAssembly )
                //   {
                //      if ( !declType.Assembly.GetCustomAttributes( true ).OfType<InternalsVisibleToAttribute>().Any( attr => Qi4CSGeneratedAssemblyAttribute.ASSEMBLY_NAME.Equals( attr.AssemblyName ) ) )
                //      {
                //         msg = "The type " + declType + " is marked as internal, however, the " + typeof( InternalsVisibleToAttribute ) + " with argument " + typeof( Qi4CSGeneratedAssemblyAttribute ) + ".ASSEMBLY_NAME is not applied to the assembly";
                //      }
                //   }
                //   else
                //   {
                //      msg = "The type " + declType + " is not visible to the generated assembly.";
                //   }
                //   if ( msg != null )
                //   {
                //      result.AddStructureError( new StructureValidationErrorImpl( compositeModel, methodModel, msg ) );
                //   }
                //}
                var genName = Qi4CSGeneratedAssemblyAttribute.GetGeneratedAssemblyName(declType.GetAssembly());
                if (!IsTypeVisible(declType, genName))
                {
                    result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("The type " + declType + " is not visible. Consider either making it public, or internal with combination of applying " + typeof(InternalsVisibleToAttribute) + " with argument " + typeof(Qi4CSGeneratedAssemblyAttribute) + ".ASSEMBLY_NAME to the assembly.", compositeModel, methodModel));
                }
            }
        }
Example #3
0
 protected virtual void ValidateField(CompositeValidationResult result, CompositeModel compositeModel, FieldModel fieldModel)
 {
     if (fieldModel == null)
     {
         result.InternalValidationErrors.Add(ValidationErrorFactory.NewInternalError("Field model may not be null.", compositeModel));
     }
     else
     {
         this.ValidateInjectableModel(result, compositeModel, fieldModel);
     }
 }
Example #4
0
        public override void ValidateModelsInApplication(ApplicationModel <ApplicationSPI> appModel, ApplicationValidationResultMutable appValidation)
        {
            var sModels = appModel.CompositeModels.Values.OfType <ServiceCompositeModel>().ToArray();

            if (sModels.Any(sModel => sModel.ServiceID == null))
            {
                appValidation.InternalValidationErrors.Add(ValidationErrorFactory.NewInternalError("The following service composite models had their service ID as null: " + String.Join(", ", sModels.Where(sModel => sModel.ServiceID == null)), null));
            }
            else
            {
                var grouping = sModels.GroupBy(sModel => sModel.ServiceID).Where(g => g.Count() > 1).ToArray();
                if (grouping.Length > 0)
                {
                    appValidation.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("The following services have same service ID: " + String.Join("; ", grouping.Select(g => String.Join(", ", g))), appModel));
                }
            }
        }
Example #5
0
        protected virtual void ValidateInjectableModel(CompositeValidationResult result, CompositeModel compositeModel, AbstractInjectableModel model)
        {
            Int32 amount = model.GetAttributesMarkedWith(typeof(InjectionScopeAttribute)).Count;

            if (amount > 1)
            {
                result.InjectionValidationErrors.Add(ValidationErrorFactory.NewInjectionError("Only one injection permitted for field or parameter.", model));
            }
            else
            {
                Attribute attr = model.InjectionScope;
                if (attr != null)
                {
                    InjectionService injectionService = compositeModel.ApplicationModel.InjectionService;
                    if (injectionService.HasFunctionalityFor(attr))
                    {
                        if (!model.IsOptional)
                        {
                            var validationResult = injectionService.InjectionPossible(model);
                            if (validationResult == null || !validationResult.InjectionPossible)
                            {
                                result.InjectionValidationErrors.Add(ValidationErrorFactory.NewInjectionError("Injection was not possible" + (validationResult == null ? "." : (": " + validationResult.AdditionalMessage)), model));
                            }
                        }
                    }
                    else if (!model.IsOptional)
                    {
                        result.InjectionValidationErrors.Add(ValidationErrorFactory.NewInjectionError("Could not find injection functionality for attribute " + attr + ".", model));
                    }
                }
                else if (model is FieldModel)
                {
                    result.InternalValidationErrors.Add(ValidationErrorFactory.NewInternalError("Injection attribute was null", model));
                }
            }
        }
Example #6
0
        public virtual void ValidateComposite(CompositeValidationResultMutable result, CompositeModel compositeModel)
        {
            // TODO check that all keys of the type model CompositeTypeInformations and FragmentTypeInformations are assignable from all methods of the composite model.
            this.ValidateCompositeTypeModel(result, compositeModel);

            if (compositeModel.MainCodeGenerationType == null)
            {
                result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("Composite model main code generation type was null", compositeModel));
            }
            else if (!compositeModel.PublicTypes.Contains(compositeModel.MainCodeGenerationType))
            {
                result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("Composite model main code generation type " + compositeModel.MainCodeGenerationType + " was not contained in its public types (" + String.Join(", ", compositeModel.PublicTypes) + ").", compositeModel));
            }
            else
            {
                CompositeMethodModel[] unimplementedMethods = compositeModel.Methods
                                                              .Where(methodModel => methodModel.Mixin == null)
                                                              .ToArray();
                if (unimplementedMethods.Any())
                {
                    foreach (CompositeMethodModel unimplementedMethod in unimplementedMethods)
                    {
                        result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("No implementation found for " + unimplementedMethod.NativeInfo + ".", compositeModel, unimplementedMethod));
                    }
                }
                else
                {
                    foreach (FieldModel fieldModel in compositeModel.Fields)
                    {
                        this.ValidateField(result, compositeModel, fieldModel);
                    }

                    foreach (ConstructorModel constructorModel in compositeModel.Constructors)
                    {
                        foreach (ParameterModel parameterModel in constructorModel.Parameters)
                        {
                            this.ValidateParameter(result, compositeModel, parameterModel);
                        }
                    }

                    foreach (CompositeMethodModel compositeMethod in compositeModel.Methods)
                    {
                        if (compositeMethod == null)
                        {
                            result.InternalValidationErrors.Add(ValidationErrorFactory.NewInternalError("Composite method model may not be null.", compositeModel));
                        }
                        else
                        {
                            this.ValidateParameter(result, compositeModel, compositeMethod.Result);
                            foreach (ParameterModel parameterModel in compositeMethod.Parameters)
                            {
                                this.ValidateParameter(result, compositeModel, parameterModel);
                            }
                            foreach (AbstractFragmentMethodModel fragmentMethod in compositeMethod.GetAllMethodModels().OfType <AbstractFragmentMethodModel>())
                            {
                                this.ValidateFragmentMethod(result, compositeModel, compositeMethod, fragmentMethod);
                            }
                            foreach (ConstraintModel constraintModel in compositeMethod.Parameters.SelectMany(param => param.Constraints).Concat(compositeMethod.Result.Constraints))
                            {
                                if (constraintModel.ConstraintType == null)
                                {
                                    result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("Could not bind parameter constraint " + constraintModel.ConstraintAttribute + ".", compositeModel, compositeMethod));
                                }
                                else if (constraintModel.ConstraintType.GetConstructor(Empty <Type> .Array) == null)
                                {
                                    result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("Constraints must have constructor without parameters, but constraint of type " + constraintModel.ConstraintType + " does not.", compositeModel, compositeMethod));
                                }
                                else if (constraintModel.ConstraintType.ContainsGenericParameters() && !constraintModel.ConstraintType.IsGenericTypeDefinition())
                                {
                                    result.StructureValidationErrors.Add(ValidationErrorFactory.NewStructureError("Constraint type " + constraintModel.ConstraintType + " contains non-closed generic parameters but is not generic type definition.", compositeModel, compositeMethod));
                                }
                            }
                        }
                    }
                    foreach (var pModel in compositeModel.GetAllPropertyModels())
                    {
                        this.ValidatePropertyModel(result, compositeModel, pModel);
                    }
                    foreach (SpecialMethodModel specialMethod in compositeModel.SpecialMethods)
                    {
                        this.ValidateSpecialMethodModel(result, compositeModel, specialMethod);
                    }

                    foreach (var constraintModel in compositeModel.GetAllConstraints())
                    {
                        this.ValidateConstraintModel(result, compositeModel, constraintModel);
                    }

                    if (!result.IQ.HasAnyErrors())
                    {
                        result.TypeModel = new CompositeTypeModelImpl(compositeModel, result);
                    }
                }
            }
        }