Exemplo n.º 1
0
 internal RealObjectCollectorResult(StObjObjectEngineMap mappings,
                                    IReadOnlyList <IReadOnlyList <MutableItem> > concreteClasses,
                                    IReadOnlyList <IReadOnlyList <Type> > classAmbiguities,
                                    IReadOnlyList <IReadOnlyList <Type> > interfaceAmbiguities,
                                    IReadOnlyList <Type> abstractTails)
 {
     EngineMap            = mappings;
     _concreteClassesPath = concreteClasses;
     ClassAmbiguities     = classAmbiguities;
     InterfaceAmbiguities = interfaceAmbiguities;
     AbstractTails        = abstractTails;
 }
        internal virtual MutableItem?ResolveToStObj(IActivityMonitor monitor, StObjObjectEngineMap collector)
        {
            MutableItem?result = null;

            if (Type != null && StObjRequirementBehavior != StObjRequirementBehavior.ExternalReference)
            {
                result = collector.ToHighestImpl(Type);
                if (result == null)
                {                        // No warn on value type or string not found.
                    WarnOrErrorIfStObjRequired(monitor, skipWarnOnValueType: true, text: $"{Type.FullName} not found");
                }
            }
            return(result);
        }
Exemplo n.º 3
0
 internal override MutableItem?ResolveToStObj(IActivityMonitor monitor, StObjObjectEngineMap collector)
 {
     if (_resolved != UnresolvedMarker)
     {
         return(_resolved);
     }
     if (Type == null && !IsOptional)
     {
         Error(monitor, $"Type can not be null since the {KindName} is not optional");
         return(_resolved = null);
     }
     Debug.Assert(Type != null || IsOptional);
     if (Type != null && !UnderlyingType.IsAssignableFrom(Type))
     {
         Error(monitor, $"Type '{Type.FullName}' is not compatible with the {KindName} type ('{UnderlyingType.FullName}')");
         return(_resolved = null);
     }
     return(_resolved = base.ResolveToStObj(monitor, collector));
 }
Exemplo n.º 4
0
        RealObjectCollectorResult GetRealObjectResult()
        {
            List <MutableItem>           allSpecializations = new List <MutableItem>(_roots.Count);
            StObjObjectEngineMap         engineMap          = new StObjObjectEngineMap(_names, allSpecializations, KindDetector, _assemblies);
            List <List <MutableItem> >   concreteClasses    = new List <List <MutableItem> >();
            List <IReadOnlyList <Type> >?classAmbiguities   = null;
            List <Type> abstractTails    = new List <Type>();
            var         deepestConcretes = new List <(MutableItem, ImplementableTypeInfo)>();

            Debug.Assert(_roots.All(info => info != null && !info.IsExcluded && info.Generalization == null),
                         "_roots contains only not Excluded types.");
            foreach (RealObjectClassInfo newOne in _roots)
            {
                deepestConcretes.Clear();
                newOne.CreateMutableItemsPath(_monitor, _serviceProvider, engineMap, null, _tempAssembly, deepestConcretes, abstractTails);
                if (deepestConcretes.Count == 1)
                {
                    MutableItem last = deepestConcretes[0].Item1;
                    allSpecializations.Add(last);
                    var path = new List <MutableItem>();
                    last.InitializeBottomUp(null);
                    path.Add(last);
                    MutableItem?spec = last, toInit = last;
                    while ((toInit = toInit.Generalization) != null)
                    {
                        toInit.InitializeBottomUp(spec);
                        path.Add(toInit);
                        spec = toInit;
                    }
                    path.Reverse();
                    concreteClasses.Add(path);
                    foreach (var m in path)
                    {
                        engineMap.AddClassMapping(m.RealObjectType.Type, last);
                    }
                }
                else if (deepestConcretes.Count > 1)
                {
                    List <Type> ambiguousPath = new List <Type>()
                    {
                        newOne.Type
                    };
                    ambiguousPath.AddRange(deepestConcretes.Select(m => m.Item1.RealObjectType.Type));

                    if (classAmbiguities == null)
                    {
                        classAmbiguities = new List <IReadOnlyList <Type> >();
                    }
                    classAmbiguities.Add(ambiguousPath.ToArray());
                }
            }
            Dictionary <Type, List <Type> >?interfaceAmbiguities = null;

            foreach (var path in concreteClasses)
            {
                MutableItem finalType = path[path.Count - 1];
                finalType.RealObjectType.InitializeInterfaces(_monitor, this);
                foreach (var item in path)
                {
                    foreach (Type itf in item.RealObjectType.ThisRealObjectInterfaces)
                    {
                        MutableItem?alreadyMapped;
                        if ((alreadyMapped = engineMap.RawMappings.GetValueOrDefault(itf)) != null)
                        {
                            if (interfaceAmbiguities == null)
                            {
                                interfaceAmbiguities = new Dictionary <Type, List <Type> >
                                {
                                    { itf, new List <Type>()
                                      {
                                          itf, alreadyMapped.RealObjectType.Type, item.RealObjectType.Type
                                      } }
                                };
                            }
                            else
                            {
                                var list = interfaceAmbiguities.GetOrSet(itf, t => new List <Type>()
                                {
                                    itf, alreadyMapped.RealObjectType.Type
                                });
                                list.Add(item.RealObjectType.Type);
                            }
                        }
                        else
                        {
                            engineMap.AddInterfaceMapping(itf, item, finalType);
                        }
                    }
                }
            }
            return(new RealObjectCollectorResult(engineMap,
                                                 concreteClasses,
                                                 classAmbiguities ?? (IReadOnlyList <IReadOnlyList <Type> >)Array.Empty <IReadOnlyList <Type> >(),
                                                 interfaceAmbiguities != null
                                                    ? interfaceAmbiguities.Values.Select(list => list.ToArray()).ToArray()
                                                    : Array.Empty <IReadOnlyList <Type> >(),
                                                 abstractTails));
        }
Exemplo n.º 5
0
 internal override MutableItem?ResolveToStObj(IActivityMonitor monitor, StObjObjectEngineMap collector)
 {
     return(IsSetupLogger ? null : base.ResolveToStObj(monitor, collector));
 }