Пример #1
0
        protected string GetInterfaceCSTypeFull(ExplicitAttribute attribute)
        {
            var baseNamespace = Settings.CrossAccessNamespace.Replace("." + Settings.SchemaInterfacesNamespace, "");
            var fullName      = TypeHelper.GetInterfaceCSType(attribute, Settings, GetFullNamespace(attribute.Domain, baseNamespace, Settings.CrossAccessStructure));

            return(TrimNamespace(fullName));
        }
Пример #2
0
        protected bool IsAggregationEntityCompatible(ExplicitAttribute source, ExplicitAttribute target)
        {
            if (source.Domain.GetType() != target.Domain.GetType())
            {
                return(false);
            }

            var sType = source.Domain;
            var tType = target.Domain;

            while (sType is AggregationType)
            {
                sType = ((AggregationType)sType).ElementType;
                tType = ((AggregationType)tType).ElementType;
            }

            var sEntity = sType as EntityDefinition;
            var tEntity = tType as EntityDefinition;

            if (sEntity != null && tEntity != null)
            {
                return(_matches.Any(m => m.Source == sEntity && m.Target == tEntity));
            }

            var sSelect = sType as SelectType;
            var tSelect = tType as SelectType;

            if (sSelect != null)
            {
                return(IsSelectCompatible(sSelect, tSelect, _matches));
            }

            return(false);
        }
 protected bool IsEntityOrSelectAggregation(ExplicitAttribute attribute)
 {
     if (!(attribute.Domain is AggregationType aggr))
     {
         return(false);
     }
     return(aggr.ElementType is EntityDefinition || aggr.ElementType is SelectType);
 }
Пример #4
0
 private ExplicitAttribute NameAttribute(ExplicitAttribute attribute, string name, bool optional)
 {
     attribute.Name           = name;
     attribute.PersistentName = name;
     attribute.OptionalFlag   = optional;
     attribute.Line           = Scanner.yylloc.StartLine;
     return(attribute);
 }
Пример #5
0
        protected bool IsNew(ExplicitAttribute remoteAttribute)
        {
            var hierarchy = _match.Target.AllSupertypes.Select(t => t.Name).Union(new [] { _match.Target.Name }).ToList();
            var names     = NewTargetAttributes.Where(t => hierarchy.Any(i => t.Item1 == i)).Select(t => t.Item2).ToList();

            return(names.Any() &&
                   names.Any(n => string.Equals(n, remoteAttribute.Name, StringComparison.InvariantCultureIgnoreCase)));
        }
        protected bool IsSimpleOrDefinedTypeAggregation(ExplicitAttribute attribute)
        {
            if (!(attribute.Domain is AggregationType aggr))
            {
                return(false);
            }

            return(aggr.ElementType is SimpleType || aggr.ElementType is DefinedType);
        }
Пример #7
0
        protected ExplicitAttributeMatch GetMatch(ExplicitAttribute remoteAttribute)
        {
            var match = _match.AttributeMatches.FirstOrDefault(m => m.TargetAttribute == remoteAttribute);

            if (match == null && _implementsSupertype)
            {
                match = _superMatches.FirstOrDefault(m => m.TargetAttribute == remoteAttribute);
            }
            return(match);
        }
 protected bool IsValueTypeAggregation(ExplicitAttribute attribute)
 {
     if (!(attribute.Domain is AggregationType agg))
     {
         return(false);
     }
     return
         (agg.ElementType is SimpleType &&
          !(agg.ElementType is StringType ||
            agg.ElementType is LogicalType));
 }
 protected bool IsReferenceTypeAggregation(ExplicitAttribute attribute)
 {
     if (!(attribute.Domain is AggregationType agg))
     {
         return(false);
     }
     return
         (agg.ElementType is EntityDefinition ||
          agg.ElementType is SelectType ||
          agg.ElementType is StringType ||
          agg.ElementType is LogicalType);
 }
        protected int GetUpperBound(ExplicitAttribute attribute)
        {
            var aggr = attribute.Domain as VariableSizeAggregationType;

            if (aggr?.UpperBound != null && aggr.UpperBound.Value > 0)
            {
                return(aggr.UpperBound ?? -1);
            }
            if (attribute.Domain is ArrayType arr && arr.UpperIndex > 0)
            {
                return(arr.UpperIndex);
            }
            return(0);
        }
        protected bool IsReferenceType(ExplicitAttribute attribute)
        {
            if (attribute.OptionalFlag)
            {
                return(true);
            }

            return
                (attribute.Domain is EntityDefinition ||
                 attribute.Domain is SelectType ||
                 attribute.Domain is StringType ||
                 attribute.Domain is LogicalType ||
                 attribute.Domain is AggregationType);
        }
        protected string GetAggregationElementType(ExplicitAttribute attribute)
        {
            var aggregationType = attribute.Domain as AggregationType;

            while (aggregationType != null)
            {
                var type = aggregationType.ElementType;
                aggregationType = aggregationType.ElementType as AggregationType;
                if (aggregationType == null)
                {
                    return(TypeHelper.GetCSType(type, Settings));
                }
            }
            throw new Exception("Aggregation type expected");
        }
        protected int GetLevelOfNesting(ExplicitAttribute attribute)
        {
            if (!(attribute.Domain is AggregationType aggr))
            {
                throw new Exception("This is not a nested list attribute.");
            }
            var level = -1;

            while (aggr != null)
            {
                level++;
                aggr = aggr.ElementType as AggregationType;
            }
            return(level);
        }
Пример #14
0
        protected bool IsNestedListCompatible(ExplicitAttribute source, ExplicitAttribute target)
        {
            var sType         = source.Domain;
            var tType         = target.Domain;
            var isAggregation = false;
            var levels        = 0;

            while (sType is AggregationType)
            {
                isAggregation = true;
                levels++;
                sType = ((AggregationType)sType).ElementType;
                tType = ((AggregationType)tType).ElementType;
            }

            if (!isAggregation || levels < 2)
            {
                return(false);
            }

            var sEntity = sType as EntityDefinition;
            var tEntity = tType as EntityDefinition;

            if (sEntity != null && tEntity != null)
            {
                return(_matches.Any(m => m.Source == sEntity && m.Target == tEntity));
            }

            var sSelect = sType as SelectType;
            var tSelect = tType as SelectType;

            if (sSelect != null)
            {
                return(IsSelectCompatible(sSelect, tSelect, _matches));
            }

            var sDefined = sType as DefinedType;
            var tDefined = tType as DefinedType;

            if (sDefined != null)
            {
                return(sDefined.Name == tDefined.Name);
            }
            return(false);
        }
Пример #15
0
        public static string GetCSType(ExplicitAttribute attribute, GeneratorSettings settings)
        {
            var domain = attribute.Domain;
            var type   = GetCSType(domain, settings);

            if (attribute.OptionalFlag && (
                    (domain is SimpleType && !(domain is LogicalType) && !(domain is StringType) && !(domain is BinaryType)) ||
                    domain is DefinedType || domain is EnumerationType
                    ))
            {
                type += "?";
            }
            if (attribute.OptionalFlag && domain is AggregationType)
            {
                type = "IOptional" + type.Substring(1);
            }

            return(type);
        }
Пример #16
0
        protected bool IsSimpleTypeCompatible(ExplicitAttribute n, ExplicitAttribute o)
        {
            if (n.OptionalFlag != o.OptionalFlag)
            {
                return(false);
            }

            var s = n.Domain as SimpleType ?? o.Domain as SimpleType;
            var d = n.Domain as DefinedType ?? o.Domain as DefinedType;

            if (s == null || d == null)
            {
                return(false);
            }

            var nT = TypeHelper.GetCSType(s, null);
            var oT = TypeHelper.GetCSType(d.Domain, null);

            return(oT == nT);
        }
 protected bool CanBeNull(ExplicitAttribute attribute)
 {
     if (attribute.Domain is EntityDefinition)
     {
         return(true);
     }
     if (attribute.Domain is SelectType)
     {
         return(true);
     }
     if (IsStringType(attribute.Domain))
     {
         return(true);
     }
     if (attribute.OptionalFlag)
     {
         return(true);
     }
     return(false);
 }
        private bool IsDirectEntityRefOrAggr(ExplicitAttribute attribute)
        {
            if (OverridingAttributes.Any(a => a.Name == attribute.Name))
            {
                return(false);
            }
            if (IsEntityReference(attribute))
            {
                return(true);
            }
            if (!(attribute.Domain is AggregationType aggr))
            {
                return(false);
            }
            var nt = GetNamedElementType(aggr);

            if (nt is EntityDefinition)
            {
                return(true);
            }

            return(nt is SelectType select && GetAllSpecific(@select).All(s => s is EntityDefinition));
        }
Пример #19
0
        public override void Reflect(RunInvokerTree tree, RunInvokerVertex parent, Type t)
        {
            object fixture = null;

            try
            {
                // Check if fixture is ignored or explicit
                IgnoreAttribute ignore = null;
                if (TypeHelper.HasCustomAttribute(t, typeof(IgnoreAttribute)))
                {
                    ignore = TypeHelper.GetFirstCustomAttribute(t, typeof(IgnoreAttribute)) as IgnoreAttribute;
                }
                ExplicitAttribute expl = null;
                if (TypeHelper.HasCustomAttribute(t, typeof(ExplicitAttribute)))
                {
                    expl = TypeHelper.GetFirstCustomAttribute(t, typeof(ExplicitAttribute)) as ExplicitAttribute;
                }

                foreach (MethodInfo method in TypeHelper.GetAttributedMethods(t, typeof(CombinatorialTestAttribute)))
                {
                    if (fixture == null)
                    {
                        fixture = TypeHelper.CreateInstance(t);
                    }

                    this.ReflectTestMethod(tree, parent, fixture, method, ignore, expl);
                }
            }
            finally
            {
                IDisposable disposable = fixture as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
        }
Пример #20
0
        public static string GetInterfaceCSType(ExplicitAttribute attribute, GeneratorSettings settings, string fullNamespace = null)
        {
            var domain = attribute.Domain;
            var type   = GetCSType(domain, settings, false, true, fullNamespace);

            if (attribute.OptionalFlag && (
                    (domain is SimpleType && !(domain is LogicalType) && !(domain is StringType) && !(domain is BinaryType)) ||
                    domain is DefinedType || domain is EnumerationType
                    ))
            {
                type += "?";
            }
            if (domain is AggregationType)
            {
                if (ReadOnlyItemSets.Any(s => s.Attribute == attribute.Name && s.Class == attribute.ParentEntity.Name))
                {
                    //replace item set with IEnumerable
                    type = type.Substring(type.IndexOf('<'));
                    type = "IEnumerable" + type;
                }
            }

            return(type);
        }
Пример #21
0
        private ExplicitAttribute RedefineAttribute(ExplicitAttribute attribute, IEnumerable <string> accessor,
                                                    bool optional)
        {
            var attrName = accessor.LastOrDefault();

            if (attrName == null)
            {
                throw new Exception("Name of redeclaring attribute not defined.");
            }
            var attr = NameAttribute(attribute, attrName, optional);

            ToDoPostActions.Add(() =>
            {
                var entity      = attribute.ParentEntity;
                var redeclaring = entity.AllExplicitAttributes.FirstOrDefault(a => a.Name == attrName);
                if (redeclaring == null)
                {
                    throw new InstanceNotFoundException();
                }

                attr.Redeclaring = redeclaring;
            });
            return(attr);
        }
 private static bool IsEntityReference(ExplicitAttribute attribute)
 {
     return(IsEntityReference(attribute.Domain));
 }
 protected bool IsEntityOrSelect(ExplicitAttribute attribute)
 {
     return(attribute.Domain is EntityDefinition || attribute.Domain is SelectType);
 }
 protected bool IsAggregation(ExplicitAttribute attribute)
 {
     return(attribute.Domain is AggregationType);
 }
 protected bool IsOwnAttribute(ExplicitAttribute attribute)
 {
     return(ExplicitAttributes.Contains(attribute));
 }
 protected bool IsPartOfInverse(ExplicitAttribute attribute)
 {
     return(Type.SchemaModel.Get <InverseAttribute>(i => i.InvertedAttr == attribute).Any());
 }
        protected bool IsSimpleOrDefinedType(ExplicitAttribute attribute)
        {
            var domain = attribute.Domain;

            return(domain is SimpleType || domain is DefinedType);
        }
        // ReSharper disable once InconsistentNaming
        protected virtual string GetCSTypeNN(ExplicitAttribute attribute)
        {
            var result = TypeHelper.GetCSType(attribute, Settings);

            return(result.Trim('?'));
        }
 protected bool IsOverridenAttribute(ExplicitAttribute attribute)
 {
     return(Type.SchemaModel.Get <DerivedAttribute>(d => d.Redeclaring == attribute).Any());
 }
 private static bool IsEntityReferenceDoubleAggregation(ExplicitAttribute attribute)
 {
     return(IsEntityReferenceDoubleAggregation(attribute.Domain));
 }