public ImmutableDictionary <ImmutableObject, string> GetInstanceNames(MetaModel mmodel)
        {
            ImmutableDictionary <ImmutableObject, string> .Builder result = ImmutableDictionary.CreateBuilder <ImmutableObject, string>();
            int tmpCounter = 0;

            foreach (var item in mmodel.MModel.Objects)
            {
                if (!(item is MetaRootNamespace))
                {
                    string          name = null;
                    MetaProperty    prop = item as MetaProperty;
                    MetaDeclaration decl = item as MetaDeclaration;
                    MetaType        type = item as MetaType;
                    if (prop != null)
                    {
                        name = this.CSharpName(prop, mmodel, PropertyKind.BuilderInstance);
                    }
                    else if (decl != null && !(decl is MetaConstant) && !(decl is MetaNamespace))
                    {
                        name = this.CSharpName(decl, mmodel, ClassKind.BuilderInstance);
                    }
                    if (/*(decl == null || decl.Namespace == mmodel.Namespace) &&*/ (type == null || !MetaConstants.Types.Contains(type)))
                    {
                        if (name == null)
                        {
                            ++tmpCounter;
                            name = "__tmp" + tmpCounter;
                        }
                        result.Add(item, name);
                    }
                }
            }
            return(result.ToImmutable());
        }
 private bool ContainsDeclaration(MetaModel mmodel, MetaDeclaration mdecl)
 {
     if (mmodel == null)
     {
         return(false);
     }
     if (this.IsMetaMetaModel(mmodel))
     {
         return(true);
     }
     return(mmodel.Namespace.Declarations.Contains(mdecl));
 }
        private string CSharpName(MetaDeclaration mdecl, MetaModel mmodel, ClassKind kind = ClassKind.None, bool fullName = false)
        {
            if (mdecl is MetaType)
            {
                return(this.CSharpName((MetaType)mdecl, mmodel, kind, fullName));
            }
            string result = mdecl.Name;

            if (fullName)
            {
                string fullNamePrefix;
                bool   modelContainsDecl = this.ContainsDeclaration(mmodel, mdecl);
                switch (kind)
                {
                case ClassKind.BuilderInstance:
                    fullNamePrefix = this.CSharpName(mdecl.MetaModel, this.ToModelKind(kind), !modelContainsDecl);
                    result         = fullNamePrefix + ".instance." + result;
                    break;

                case ClassKind.ImmutableInstance:
                case ClassKind.FactoryMethod:
                case ClassKind.Implementation:
                    fullNamePrefix = this.CSharpName(mdecl.MetaModel, this.ToModelKind(kind), !modelContainsDecl);
                    result         = fullNamePrefix + "." + result;
                    break;

                default:
                    if (!modelContainsDecl)
                    {
                        fullNamePrefix = this.CSharpName(mdecl.Namespace, this.ToNamespaceKind(kind), true);
                        result         = "global::" + fullNamePrefix + "." + result;
                    }
                    break;
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
     /// <summary>
 	/// Implements the constructor: MetaDeclaration()
 	/// Direct superclasses: global::MetaDslx.Core.MetaNamedElement, global::MetaDslx.Core.MetaAnnotatedElement
 	/// All superclasses: global::MetaDslx.Core.MetaNamedElement, global::MetaDslx.Core.MetaDocumentedElement, global::MetaDslx.Core.MetaAnnotatedElement
     /// </summary>
     public virtual void MetaDeclaration(MetaDeclaration @this)
     {
         this.MetaNamedElement(@this);
         this.MetaAnnotatedElement(@this);
     }