Esempio n. 1
0
        /// <summary>
        /// Merge two Class Hierarchy
        /// </summary>
        /// <param name="ch"></param>
        /// <returns></returns>
        public IClassHierarchy Merge(IClassHierarchy ch)
        {
            if (this == ch)
            {
                return(this);
            }

            if (!(ch is AvroClassHierarchy))
            {
                Utilities.Diagnostics.Exceptions.Throw(new NotSupportedException(
                                                           "Cannot merge ExternalClassHierarchies yet!"), LOGGER);
            }

            AvroClassHierarchy ach = (AvroClassHierarchy)ch;

            foreach (var pair in ach._lookupTable)
            {
                if (!this._lookupTable.ContainsKey(pair.Key))
                {
                    this._lookupTable.Add(pair);
                }
            }

            foreach (INode n in ch.GetNamespace().GetChildren())
            {
                if (!_rootNode.Contains(n.GetFullName()))
                {
                    if (n is INamedParameterNode)
                    {
                        INamedParameterNode np = (INamedParameterNode)n;
                        new NamedParameterNodeImpl(this._rootNode, np.GetName(),
                                                   np.GetFullName(), np.GetFullArgName(), np.GetSimpleArgName(),
                                                   np.IsSet(), np.IsList(), np.GetDocumentation(), np.GetShortName(),
                                                   np.GetDefaultInstanceAsStrings().ToArray());
                    }
                    else if (n is IClassNode)
                    {
                        IClassNode cn = (IClassNode)n;
                        new ClassNodeImpl(_rootNode, cn.GetName(), cn.GetFullName(),
                                          cn.IsUnit(), cn.IsInjectionCandidate(),
                                          cn.IsExternalConstructor(), cn.GetInjectableConstructors(),
                                          cn.GetAllConstructors(), cn.GetDefaultImplementation());
                    }
                }
            }
            return(this);
        }
Esempio n. 2
0
 public void Bind(Types.INode key, Types.INode value)
 {
     if (key is INamedParameterNode)
     {
         BindParameter((INamedParameterNode)key, value.GetFullName());
     }
     else if (key is IClassNode)
     {
         IClassNode k = (IClassNode)key;
         if (value is IClassNode)
         {
             IClassNode val = (IClassNode)value;
             if (val.IsExternalConstructor() && !k.IsExternalConstructor())
             {
                 BindConstructor(k, (IClassNode)val);
             }
             else
             {
                 BindImplementation(k, (IClassNode)val);
             }
         }
     }
 }
Esempio n. 3
0
        private AvroNode NewAvroNode(INode n)
        {
            IList <AvroNode> children = new List <AvroNode>();

            foreach (INode child in n.GetChildren())
            {
                children.Add(NewAvroNode(child));
            }

            if (n is IClassNode)
            {
                IClassNode cn = (IClassNode)n;
                IList <IConstructorDef> injectable = cn.GetInjectableConstructors();
                IList <IConstructorDef> all        = cn.GetAllConstructors();
                IList <IConstructorDef> others     = new List <IConstructorDef>(all);

                foreach (var c in injectable)
                {
                    others.Remove(c);
                }

                IList <AvroConstructorDef> injectableConstructors = new List <AvroConstructorDef>();
                foreach (IConstructorDef inj in injectable)
                {
                    injectableConstructors.Add(NewConstructorDef(inj));
                }

                IList <AvroConstructorDef> otherConstructors = new List <AvroConstructorDef>();
                foreach (IConstructorDef other in others)
                {
                    otherConstructors.Add(NewConstructorDef(other));
                }

                List <string> implFullNames = new List <string>();
                foreach (IClassNode impl in cn.GetKnownImplementations())
                {
                    implFullNames.Add(impl.GetFullName()); // we use class fully qualified name
                }

                return(NewClassNode(cn.GetName(), cn.GetFullName(),
                                    cn.IsInjectionCandidate(), cn.IsExternalConstructor(), cn.IsUnit(),
                                    injectableConstructors, otherConstructors, implFullNames, children));
            }

            if (n is INamedParameterNode)
            {
                INamedParameterNode np = (INamedParameterNode)n;
                return(NewNamedParameterNode(np.GetName(), np.GetFullName(),
                                             np.GetSimpleArgName(), np.GetFullArgName(), np.IsSet(), np.IsList(), np.GetDocumentation(),
                                             np.GetShortName(), np.GetDefaultInstanceAsStrings(), children));
            }

            if (n is IPackageNode)
            {
                return(NewPackageNode(n.GetName(), n.GetFullName(), children));
            }

            Utilities.Diagnostics.Exceptions.Throw(
                new IllegalStateException("Encountered unknown type of Node: " + n), LOGGER);
            return(null);
        }