Example #1
0
        /// <summary>
        /// Visit a <see cref="NREnum"/>.
        /// </summary>
        /// <param name="nrEnum">The <see cref="NREnum"/> to visit.</param>
        public void Visit(NREnum nrEnum)
        {
            if (!string.IsNullOrWhiteSpace(nrEnum.DeclaringTypeFullName) && (currentType != null && nrEnum.DeclaringTypeFullName != currentType.FullName || currentType == null))
            {
                // Do not output the enum since it is nested and we are not inside the parent type.
                return;
            }
            NRTypeBase oldCurrentType = currentType;

            currentType = nrEnum;

            VisitAttributes(nrEnum);

            OutputLine(nrEnum.Declaration());
            OutputLine("{");
            indent++;
            foreach (NREnumValue nrEnumValue in nrEnum.Values)
            {
                nrEnumValue.Accept(this);
            }
            indent--;
            OutputLine("}");
            OutputEmptyLineAfterType();

            currentType = oldCurrentType;
        }
Example #2
0
        /// <summary>
        /// Visit a <see cref="NRInterface"/>.
        /// </summary>
        /// <param name="nrInterface">The <see cref="NRInterface"/> to visit.</param>
        public void Visit(NRInterface nrInterface)
        {
            if (!string.IsNullOrWhiteSpace(nrInterface.DeclaringTypeFullName) && (currentType != null && nrInterface.DeclaringTypeFullName != currentType.FullName || currentType == null))
            {
                // Do not output the interface since it is nested and we are not inside the parent type.
                return;
            }
            NRTypeBase oldCurrentType = currentType;

            currentType = nrInterface;

            VisitAttributes(nrInterface);

            OutputLine(nrInterface.Declaration());
            OutputLine("{");
            indent++;
            foreach (NRProperty nrProperty in nrInterface.Properties)
            {
                nrProperty.Accept(this);
            }
            foreach (NREvent nrEvent in nrInterface.Events)
            {
                nrEvent.Accept(this);
            }
            foreach (NRMethod nrMethod in nrInterface.Methods)
            {
                nrMethod.Accept(this);
            }
            indent--;
            OutputLine("}");
            OutputEmptyLineAfterType();

            currentType = oldCurrentType;
        }
 /// <summary>
 /// Prints the members of the supplied <see cref="NRTypeBase"/>.
 /// </summary>
 /// <param name="nrTypeBase">The members of this <see cref="NRTypeBase"/> are printed.</param>
 private void PrintMembers(NRTypeBase nrTypeBase)
 {
     OutputLine("AccessModifier: " + nrTypeBase.AccessModifier);
     nrTypeBase.Attributes.ForEach(nrAttribute => nrAttribute.Accept(this));
     OutputLine("FullName: " + nrTypeBase.FullName);
     OutputLine("Name: " + nrTypeBase.Name);
     OutputLine("DeclaringTypeFullName: " + nrTypeBase.DeclaringTypeFullName);
 }
Example #4
0
 /// <summary>
 /// Visits all types which are nested within the given type.
 /// </summary>
 /// <param name="declaringType">The declaring type.</param>
 private void VisitNestedTypes(NRTypeBase declaringType)
 {
     if (NRAssembly == null)
     {
         return;
     }
     foreach (NRTypeBase nrTypeBase in NRAssembly.Types.Where(t => t.DeclaringTypeFullName == declaringType.FullName))
     {
         nrTypeBase.Accept(this);
     }
 }
Example #5
0
        /// <summary>
        /// Visit a <see cref="NRClass"/>.
        /// </summary>
        /// <param name="nrClass">The <see cref="NRClass"/> to visit.</param>
        public void Visit(NRClass nrClass)
        {
            if (!string.IsNullOrWhiteSpace(nrClass.DeclaringTypeFullName) && (currentType != null && nrClass.DeclaringTypeFullName != currentType.FullName || currentType == null))
            {
                // Do not output the class since it is nested and we are not inside the parent type.
                return;
            }
            NRTypeBase oldCurrentType = currentType;

            currentType = nrClass;

            VisitAttributes(nrClass);

            OutputLine(nrClass.Declaration());
            OutputLine("{");
            indent++;
            foreach (NRField nrField in nrClass.Fields)
            {
                nrField.Accept(this);
            }
            foreach (NRConstructor nrConstructor in nrClass.Constructors)
            {
                nrConstructor.Accept(this);
            }
            foreach (NRProperty nrProperty in nrClass.Properties)
            {
                nrProperty.Accept(this);
            }
            foreach (NREvent nrEvent in nrClass.Events)
            {
                nrEvent.Accept(this);
            }
            foreach (NRMethod nrMethod in nrClass.Methods)
            {
                nrMethod.Accept(this);
            }
            foreach (NROperator nrOperator in nrClass.Operators)
            {
                nrOperator.Accept(this);
            }
            VisitNestedTypes(nrClass);
            indent--;
            OutputLine("}");
            OutputEmptyLineAfterType();

            currentType = oldCurrentType;
        }
Example #6
0
 /// <summary>
 ///     Initializes a new instance of <see cref="NRNesting" />.
 /// </summary>
 /// <param name="parentType">The parent type of the nesting relationship.</param>
 /// <param name="innerType">The inner type of the nesting relationship.</param>
 public NRNesting(NRSingleInheritanceType parentType, NRTypeBase innerType)
 {
     ParentType = parentType;
     InnerType  = innerType;
 }
Example #7
0
        /// <summary>
        ///     Checks if there is a matching rule for the specified type.
        /// </summary>
        /// <param name="nrElement">The type of the element to check.</param>
        /// <param name="nrType">The type to check.</param>
        /// <returns><c>True</c> if there is a matching rule.</returns>
        private bool Reflect(FilterElements nrElement, NRTypeBase nrType)
        {
            FilterModifiers filterModifiers = GetFilterModifier(nrType.AccessModifier);

            return(RuleMatch(nrElement, filterModifiers));
        }
Example #8
0
 /// <summary>
 ///     Initializes a new instance of <see cref="NRAssociation" />.
 /// </summary>
 /// <param name="startType">The start type of the assotiation.</param>
 /// <param name="endType">The end type of the assotiation.</param>
 public NRAssociation(NRTypeBase startType, NRTypeBase endType)
 {
     StartType = startType;
     EndType   = endType;
 }
Example #9
0
        // ========================================================================
        // Methods

        #region === Methods

        /// <summary>
        /// Extracts the relationships between the types of <paramref name="nrAssembly"/>.
        /// </summary>
        /// <param name="nrAssembly">The relationships are extracted from the types within
        ///                          this <see cref="NRAssembly"/>.</param>
        /// <param name="createNesting">Set to <c>true</c> to create nesting relationships.</param>
        /// <param name="createGeneralization">Set to <c>true</c> to create generalization relationships.</param>
        /// <param name="createRealization">Set to <c>true</c> to create realization relationships.</param>
        /// <param name="createAssociation">Set to <c>true</c> to create association relationships.</param>
        /// <returns>The extracted relationships.</returns>
        public NRRelationships CreateRelationships(NRAssembly nrAssembly, bool createNesting = true, bool createGeneralization = true, bool createRealization = true, bool createAssociation = true)
        {
            NRRelationships nrRelationships          = new NRRelationships();
            Dictionary <string, NRTypeBase> entities = nrAssembly.Types.ToDictionary(nrTypeBase => nrTypeBase.FullName);

            //Create the nesting relationships
            if (createNesting)
            {
                foreach (NRTypeBase nrTypeBase in entities.Values)
                {
                    if (!String.IsNullOrWhiteSpace(nrTypeBase.DeclaringTypeFullName))
                    {
                        if (entities.ContainsKey(nrTypeBase.DeclaringTypeFullName))
                        {
                            if (entities[nrTypeBase.DeclaringTypeFullName] is NRSingleInheritanceType parent)
                            {
                                nrRelationships.Nestings.Add(new NRNesting(parent, nrTypeBase));
                            }
                        }
                    }
                }
            }

            //Create the generalization relationships
            if (createGeneralization)
            {
                foreach (NRSingleInheritanceType derivedType in nrAssembly.SingleInheritanceTypes)
                {
                    if (derivedType.BaseType != null && derivedType.BaseType.FullName != null)
                    {
                        var key = string.IsNullOrEmpty(derivedType.BaseType.FullName)
                            ? derivedType.BaseType.Name
                            : derivedType.BaseType.FullName;
                        if (entities.ContainsKey(key))
                        {
                            if (entities[key] is NRSingleInheritanceType baseType)
                            {
                                nrRelationships.Generalizations.Add(new NRGeneralization(baseType, derivedType));
                            }
                        }
                    }
                }

                // Interfaces may derive from other interfaces as well.
                foreach (NRInterface derivedInterface in nrAssembly.Interfaces)
                {
                    foreach (NRTypeUsage implementedInterface in derivedInterface.ImplementedInterfaces)
                    {
                        var key = string.IsNullOrEmpty(implementedInterface.FullName)
                            ? implementedInterface.Name
                            : implementedInterface.FullName;
                        if (entities.ContainsKey(key))
                        {
                            if (entities[key] is NRInterface nrInterface)
                            {
                                nrRelationships.Generalizations.Add(new NRGeneralization(nrInterface, derivedInterface));
                            }
                        }
                    }
                }
            }

            //Create the realization relationships
            if (createRealization)
            {
                foreach (NRSingleInheritanceType implementingType in nrAssembly.SingleInheritanceTypes)
                {
                    foreach (NRTypeUsage implementedInterface in implementingType.ImplementedInterfaces)
                    {
                        var key = string.IsNullOrEmpty(implementedInterface.FullName)
                            ? implementedInterface.Name
                            : implementedInterface.FullName;
                        if (entities.ContainsKey(key))
                        {
                            if (entities[key] is NRInterface nrInterface)
                            {
                                nrRelationships.Realizations.Add(new NRRealization(nrInterface, implementingType));
                            }
                        }
                    }
                }
            }

            //Create the association relationships
            if (createAssociation)
            {
                foreach (NRSingleInheritanceType startType in nrAssembly.SingleInheritanceTypes)
                {
                    foreach (NRField nrField in startType.Fields)
                    {
                        string fullName = nrField.TypeFullName;
                        bool   array    = false;
                        if (fullName.EndsWith("[]"))
                        {
                            //Array!
                            fullName = fullName.Substring(0, fullName.IndexOf('['));
                            array    = true;
                        }
                        if (fullName.Contains("["))
                        {
                            //Generic!
                            fullName = fullName.Substring(0, fullName.IndexOf('['));
                        }
                        if (entities.ContainsKey(fullName))
                        {
                            NRTypeBase    endType     = entities[fullName];
                            NRAssociation association = new NRAssociation
                            {
                                StartType       = startType,
                                EndMultiplicity = array ? "*" : "1",
                                StartRole       = nrField.Name,
                                EndType         = endType
                            };
                            nrRelationships.Associations.Add(association);
                        }
                    }
                }
            }

            return(nrRelationships);
        }