Example #1
0
        public INameSpaceDeclaration BuildOrMatchNameSpace(string nameSpace)
        {
            INameSpaceDeclaration insd = GetClosestMatchingSpace(nameSpace);

            //There was no match even close.
            if (insd == null)
            {
                //Yield a new entry alltogether.
                return(this.NameSpaces.AddNew(nameSpace));
            }

            /* *
             * Yield a new namespace entity, while keeping the member names and
             * namespace states.
             * */
            insd = insd.Partials.AddNew();
            if (insd.FullName == nameSpace)
            {
                return(insd);
            }
            else
            {
                //Next truncate everything before the current location.
                //Building the path is next.
                string remainingPath = nameSpace.Substring(insd.FullName.Length + 1);
                insd = insd.ChildSpaces.AddNew(remainingPath);
                return(insd);
            }
        }
Example #2
0
 public override void TranslateNameSpace(INameSpaceDeclaration nameSpace)
 {
     foreach (CodeNamespace cns in nameSpace.GenerateGroupCodeDom(this.Options))
     {
         this.Provider.GenerateCodeFromNamespace(cns, base.Target, this.Options.Options);
     }
 }
Example #3
0
        /// <summary>
        /// Initializes the <see cref="IDeclarationResources"/> for the <see cref="IntermediateProject"/>.
        /// </summary>
        protected virtual IDeclarationResources InitializeResources()
        {
            INameSpaceDeclaration defaultNameSpace = FindOrGetChildOf <INameSpaceDeclaration, CodeNamespace, INameSpaceParent>(this.DefaultNameSpace, this);

            if (defaultNameSpace.ChildSpaces.ContainsKey("Properties"))
            {
                INameSpaceDeclaration insd = defaultNameSpace.ChildSpaces["Properties"];
                if (insd.ParentTarget != defaultNameSpace)
                {
                    defaultNameSpace = insd.Partials.AddNew(defaultNameSpace);
                }
                else
                {
                    defaultNameSpace = insd;
                }
            }
            else
            {
                defaultNameSpace = defaultNameSpace.ChildSpaces.AddNew("Properties");
            }
            if (this.IsPartial)
            {
                return((IDeclarationResources)this.GetRootDeclaration().Resources.Partials.AddNew(defaultNameSpace));
            }
            IDeclarationResources idrs = new DeclarationResources(defaultNameSpace);

            defaultNameSpace.Classes.Add(idrs);
            return(idrs);
        }
Example #4
0
 /// <summary>
 /// Creates a new <see cref="IntermediateProject"/> instance with the
 /// <paramref name="name"/> provided.
 /// </summary>
 /// <param name="name">The name of the <see cref="IntermediateProject"/>.</param>
 /// <param name="defaultNameSpace">The name of the default namespace.</param>
 public IntermediateProject(string name, string defaultNameSpace)
 {
     if ((defaultNameSpace == null) || (defaultNameSpace == string.Empty))
     {
         throw new ArgumentNullException("defaultNameSpace");
     }
     this.name             = name;
     this.defaultNameSpace = this.NameSpaces.AddNew(defaultNameSpace);
 }
Example #5
0
        private static string GetFolderName(IDeclaredType target)
        {
            if (target.ParentTarget is IDeclaredType)
            {
                return(GetFolderName((IDeclaredType)target.ParentTarget));
            }
            else if (target.ParentTarget is INameSpaceDeclaration)
            {
                Queue <string>        sources = new Queue <string>();
                var                   project = target.Project;
                var                   dns     = project.GetRootDeclaration().DefaultNameSpace;
                INameSpaceDeclaration current = (INameSpaceDeclaration)target.ParentTarget;
                if (current.FullName.StartsWith(dns.FullName))
                {
                    string partial = current.FullName.Substring(dns.FullName.Length);
                    if (partial.StartsWith("."))
                    {
                        partial = partial.Substring(1);
                    }
                    var parts = partial.Split(new[] { @"." }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var part in parts)
                    {
                        sources.Enqueue(part);
                    }
                }
                else
                {
                    return(string.Format(@"{0}\{1}", target.Module.Name, current.FullName));
                }
                //while (current != null)
                //{
                //    if (current.ParentTarget is INameSpaceDeclaration)
                //    {
                //        if (current == project.GetRootDeclaration().DefaultNameSpace)
                //            goto combineName;
                //        else
                //            sources.Push(current);
                //        current = (current.ParentTarget as INameSpaceDeclaration).GetRootDeclaration();
                //    }
                //    else if (current.ParentTarget is IIntermediateProject)
                //        goto combineName;
                //}
combineName:
                string name = target.Module.Name;
                foreach (var item in sources)
                {
                    name += @"\" + item;
                }
                return(name);
            }
            return(target.Module.Name);
        }
Example #6
0
 private void RenameAndMoveChildren(string value)
 {
     if (!value.Contains("."))
     {
         base.Name = value;
     }
     else
     {
         List <string> reverseParts = new List <string>(value.Split('.'));
         reverseParts.Reverse();
         Stack <string>        nameParts = new Stack <string>(reverseParts);
         INameSpaceDeclaration insd      = this;
         while (nameParts.Count > 0)
         {
             if (nameParts.Peek() == "")
             {
                 nameParts.Pop();
                 continue;
             }
             else
             {
                 if (insd.Name != nameParts.Peek())
                 {
                     insd.Name = nameParts.Pop();
                 }
                 else
                 {
                     nameParts.Pop();
                 }
                 if (insd.ChildSpaces.ContainsKey(nameParts.Peek()))
                 {
                     insd = insd.ChildSpaces[nameParts.Peek()];
                 }
                 else
                 {
                     insd = insd.ChildSpaces.AddNew(nameParts.Peek());
                 }
             }
         }
         //ToDo:  Add code here to move the types of the namespace.
     }
 }
Example #7
0
        public INameSpaceDeclaration GetLocalPartial(INameSpaceDeclaration targetSpace)
        {
            INameSpaceDeclaration         searchPoint = targetSpace.GetRootDeclaration();
            INameSpaceDeclaration         searchSpace;
            Stack <INameSpaceDeclaration> createTrail = new Stack <INameSpaceDeclaration>();

            for (searchSpace = searchPoint; searchSpace != null; searchSpace = (INameSpaceDeclaration)searchSpace.ParentTarget)
            {
                if (searchSpace.Project == this)
                {
                    break;
                }
                foreach (INameSpaceDeclaration insd in searchSpace.Partials)
                {
                    if (insd.Project == this)
                    {
                        searchSpace = insd;
                        break;
                    }
                }
                createTrail.Push(searchSpace);
                if (!(searchSpace.ParentTarget is INameSpaceDeclaration))
                {
                    searchSpace = null;
                    break;
                }
            }
            while (createTrail.Count > 0)
            {
                if (searchSpace == null)
                {
                    searchSpace = createTrail.Pop().Partials.AddNew(this);
                }
                else
                {
                    searchSpace = createTrail.Pop().Partials.AddNew(searchSpace);
                }
            }
            return(searchSpace);
        }
Example #8
0
        public string WriteResources()
        {
            IDeclarationTarget idt = null;

            if (this.IsPartial)
            {
                return(null);
            }
            for (idt = this; idt != null && (!(idt is INameSpaceDeclaration)); idt = idt.ParentTarget)
            {
                ;
            }
            if ((idt == null) || (!(idt is INameSpaceDeclaration)))
            {
                throw new InvalidOperationException("Object in an invalid state.");
            }
            INameSpaceDeclaration insd = (INameSpaceDeclaration)idt;
            TemporaryFile         tf;

            if (this == this.Project.Resources)
            {
                tf = TemporaryFileHelper.GetTemporaryDirectory("", true).Files.GetTemporaryFile(string.Format("Resources.resources", insd.FullName, this.Name));
            }
            else
            {
                tf = TemporaryFileHelper.GetTemporaryDirectory("", true).Files.GetTemporaryFile(string.Format("{0}.{1}.resources", insd.FullName, this.Name));
            }

            tf.OpenStream(FileMode.Create);
            ResourceWriter rw = new ResourceWriter(tf.FileStream);

            foreach (IDeclarationResourcesStringTableEntry idrste in this.StringTable.Values)
            {
                rw.AddResource(idrste.Name, idrste.Value);
            }
            rw.Close();
            tf.CloseStream();
            return(tf.FileName);
        }
Example #9
0
        public INameSpaceDeclaration GetClosestMatchingSpace(string nameSpace)
        {
            List <string> parts = new List <string>(nameSpace.Split('.'));

            //Scan through until there are no more parts.
            while (parts.Count > 0)
            {
                string currentSpace = string.Join(".", parts.ToArray());

                /* *
                 * If the current full namespace matches something, then the closest
                 * match has been found.  Because the process started at the largest
                 * and worked to the smallest.
                 * */
                INameSpaceDeclaration currentSpaceItem = null;
                if (NameSpaceExists(currentSpace, ref currentSpaceItem))
                {
                    return(currentSpaceItem);
                }
                parts.RemoveAt(parts.Count - 1);
            }
            //No result.
            return(null);
        }
Example #10
0
 /// <summary>
 /// Releases the resources associated with the <see cref="NameSpaceDeclaration"/>.
 /// And places the <see cref="NameSpaceDeclaration"/> in a disposed state.
 /// </summary>
 public override void Dispose()
 {
     base.Dispose();
     if (this.IsPartial)
     {
         this.basePartial = null;
     }
     else
     {
         this.partials.Dispose();
         this.partials = null;
     }
     this.Classes.Dispose();
     this.Delegates.Dispose();
     this.ChildSpaces.Dispose();
     this.Interfaces.Dispose();
     this.Enumerators.Dispose();
     this.Structures.Dispose();
     this.classes     = null;
     this.enumerators = null;
     this.delegates   = null;
     this.interfaces  = null;
     this.structures  = null;
 }
Example #11
0
 /// <summary>
 /// Translates a namespace declaration.
 /// </summary>
 /// <param name="nameSpace">The <see cref="INameSpaceDeclaration"/> to translate.</param>
 public abstract void TranslateNameSpace(INameSpaceDeclaration nameSpace);
Example #12
0
 /// <summary>
 /// Returns whether a namespace exits and denotes which specifically it is.
 /// </summary>
 /// <param name="nameSpace">The full path of the namespace to scan for.</param>
 /// <param name="foundSpace">The reference to the namespace to yield if a match
 /// is found.</param>
 /// <returns>true if a namespace with the <see cref="INameSpaceDeclaration.FullName"/> of <paramref name="nameSpace"/>
 /// exists in the <see cref="IntermediateProject"/> scope; false, otherwise.</returns>
 public bool NameSpaceExists(string nameSpace, ref INameSpaceDeclaration foundSpace)
 {
     return(NameSpaceExists(this.NameSpaces, nameSpace, ref foundSpace));
 }
Example #13
0
 public string FormatBeginNamespace(INameSpaceDeclaration target)
 {
     return(string.Empty);
 }
Example #14
0
 internal NameSpaceDeclaration(INameSpaceDeclaration basePartial, INameSpaceParent parentTarget)
     : base(parentTarget)
 {
     this.basePartial = basePartial;
 }
Example #15
0
            public static string BuildMemberReferenceComment(ICodeTranslationOptions options, IMember member)
            {
                if (options == null)
                {
                    throw new ArgumentNullException("options");
                }
                string parentCref = ((IType)member.ParentTarget).GetTypeName(options, true);

                //If there is a build trail to go by, check to see what kind of scope
                //is available.  If the parent of the field is available, then referencing
                //field should be easier.
                if (options.BuildTrail != null)
                {
                    IDeclarationTarget idt = member.ParentTarget;
                    while (idt != null && !(idt is INameSpaceDeclaration))
                    {
                        idt = idt.ParentTarget;
                    }
                    INameSpaceDeclaration currentNameSpace = null;
                    bool importsContainsNameSpace          = false;
                    if (idt != null && options.ImportList != null)
                    {
                        importsContainsNameSpace = options.ImportList.Contains(((INameSpaceDeclaration)(idt)).FullName);
                    }
                    if (!importsContainsNameSpace)
                    {
                        for (int i = 0; i < options.BuildTrail.Count; i++)
                        {
                            if (Special.GetThisAt(options.BuildTrail, i) is INameSpaceDeclaration)
                            {
                                currentNameSpace = (INameSpaceDeclaration)Special.GetThisAt(options.BuildTrail, i);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }

                    if (currentNameSpace != null && idt != null && (currentNameSpace.FullName == ((INameSpaceDeclaration)idt).FullName || currentNameSpace.FullName.Contains(((INameSpaceDeclaration)idt).FullName + ".")))
                    {
                        /* *
                         * The build trail's current namespace contains the full name of the
                         * parent namespace.
                         * */
                        parentCref = parentCref.Substring(currentNameSpace.FullName.Length + 1);
                    }
                    else if (importsContainsNameSpace)
                    {
                        /* *
                         * The import list contains the namespace
                         * */
                        parentCref = parentCref.Substring(((INameSpaceDeclaration)idt).FullName.Length + 1);
                    }
                    else
                    {
                        goto _verbose;
                    }
                }
                return(string.Format(_CommentConstants.SeeCrefTag, string.Format("{0}.{1}", parentCref, member.Name)));

_verbose:
                return(string.Format(_CommentConstants.SeeCrefTag, string.Format("{0}.{1}", parentCref, member.Name)));
            }
Example #16
0
        /// <summary>
        /// Returns the type name of the <see cref="IType"/>.
        /// </summary>
        /// <param name="options">The code-dom generator options that direct the
        /// generation process.</param>
        /// <param name="commentStyle">Whether or not the type name is represented in
        /// comment style with the type-parameters expanded and encased in curly
        /// braces ('{' and '}').</param>
        /// <param name="typeParameterValues">The series of <see cref="ITypeReference"/> instance
        /// implementations which relate to the generic-parameters of the <see cref="IType"/>.</param>
        /// <returns>A <see cref="System.String"/> which is a qualified name relative to the <see cref="IType"/>.</returns>
        public string GetTypeName(ICodeTranslationOptions options, bool commentStyle, ITypeReference[] typeParameterValues)
        {
            INameSpaceDeclaration nsdType = GetNamespace();

            if (nsdType == null)
            {
                return(this.Name);
            }
            IList <IDeclarationTarget> hierarchy = GetDeclarationHierarchy(this);

            string[] typeArgNames = new string[0];
            string   tArgNames    = "";
            int      tpChainArgs  = 0;

            string[] names = new string[hierarchy.Count];
            for (int i = 0; i < hierarchy.Count; i++)
            {
                string currentName = null;
                if (options.NameHandler.HandlesName((IDeclaration)hierarchy[i]))
                {
                    currentName = options.NameHandler.HandleName((IDeclaration)hierarchy[i]);
                }
                else
                {
                    currentName = hierarchy[i].Name;
                }
                if (hierarchy[i] is IParameteredDeclaredType && ((IParameteredDeclaredType)hierarchy[i]).TypeParameters != null && ((IParameteredDeclaredType)hierarchy[i]).TypeParameters.Count > 0)
                {
                    IParameteredDeclaredType pdt = (IParameteredDeclaredType)hierarchy[i];
                    //string[] tpNam = new string[pdt.TypeParameters.Count];
                    if (!commentStyle)
                    {
                        currentName += string.Format("`{0}", pdt.TypeParameters.Count);
                    }
                    else
                    {
                        typeArgNames = new string[pdt.TypeParameters.Count];
                        for (int tpArgIndex = 0; tpArgIndex < pdt.TypeParameters.Count; tpArgIndex++)
                        {
                            typeArgNames[tpArgIndex] = ((ITypeParameterMember)pdt.TypeParameters.Values[tpArgIndex]).Name;
                        }
                        currentName += string.Format("{{{0}}}", String.Join(", ", typeArgNames));
                    }
                    if (!commentStyle)
                    {
                        tpChainArgs += pdt.TypeParameters.Count;
                    }
                }
                names[i] = currentName;
            }
            if ((!(commentStyle)) && (tpChainArgs == typeParameterValues.Length && tpChainArgs > 0))
            {
                typeArgNames = new string[tpChainArgs];
                for (int tpArgIndex = 0; tpArgIndex < typeParameterValues.Length; tpArgIndex++)
                {
                    if (((typeParameterValues[tpArgIndex].ResolutionOptions & TypeReferenceResolveOptions.FullType) == TypeReferenceResolveOptions.FullType) || ((typeParameterValues[tpArgIndex].ResolutionOptions & TypeReferenceResolveOptions.GlobalType) == TypeReferenceResolveOptions.GlobalType))
                    {
                        bool autoResolve = options.AutoResolveReferences;
                        if (autoResolve)
                        {
                            options.AutoResolveReferences = false;
                        }
                        typeArgNames[tpArgIndex] = typeParameterValues[tpArgIndex].TypeInstance.GetTypeName(options, typeParameterValues[tpArgIndex].TypeParameters.ToArray());
                        if (autoResolve)
                        {
                            options.AutoResolveReferences = autoResolve;
                        }
                    }
                    else
                    {
                        typeArgNames[tpArgIndex] = typeParameterValues[tpArgIndex].TypeInstance.GetTypeName(options, typeParameterValues[tpArgIndex].TypeParameters.ToArray());
                    }
                    typeArgNames[tpArgIndex] = string.Format("[{0}]", typeArgNames[tpArgIndex]);
                }
                tArgNames = String.Format("[{0}]", String.Join(",", typeArgNames));
            }

            if (options.CurrentNameSpace != null)
            {
                //The namespace the generator is 'in' contains the this's namespace.
                //Thus checking the imports list is un-necessary.
                if (options.CurrentNameSpace.FullName.Contains(String.Format("{0}.", nsdType.FullName)))
                {
                    return(String.Join("+", names));
                }
                if (options.AutoResolveReferences)
                {
                    if (!(options.ImportList.Contains(nsdType.Name)))
                    {
                        options.ImportList.Add(nsdType.FullName);
                    }
                    if (commentStyle)
                    {
                        return(String.Format("{0}{1}", String.Join(".", names), tArgNames));
                    }
                    return(String.Format("{0}{1}", String.Join("+", names), tArgNames));
                }
            }
            if (options.ImportList.Contains(nsdType.FullName) && options.AutoResolveReferences)
            {
                if (commentStyle)
                {
                    return(String.Join(".", names));
                }
                else
                {
                    return(String.Format("{0}{1}", String.Join("+", names), tArgNames));
                }
            }
            if (commentStyle)
            {
                return(string.Format("{0}.{1}", nsdType.FullName, String.Join(".", names)));
            }
            return(string.Format("{0}.{1}{2}", nsdType.FullName, String.Join("+", names), tArgNames));
        }
Example #17
0
 private static bool NameSpaceExists(INameSpaceDeclarations nameSpaces, string nameSpace, ref INameSpaceDeclaration foundSpace)
 {
     foreach (INameSpaceDeclaration insd in nameSpaces.Values)
     {
         bool childrenContain = false;
         if (insd.FullName == nameSpace)
         {
             foundSpace = insd;
             return(true);
         }
         childrenContain = NameSpaceExists(insd.ChildSpaces, nameSpace, ref foundSpace);
         if (childrenContain)
         {
             return(true);
         }
     }
     return(false);
 }