예제 #1
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        /// <param name="parent">親IAnalyzeItem</param>
        /// <param name="node">対象Node</param>
        /// <param name="semanticModel">対象ソースのsemanticModel</param>
        /// <param name="container">イベントコンテナ</param>
        protected AbstractItem(IAnalyzeItem parent, SyntaxNode node, SemanticModel semanticModel, EventContainer container)
        {
            // 親インスタンスを設定
            Parent = parent;

            // 名前設定
            Name = node.DescendantTokens().
                   Where(token => token.IsKind(SyntaxKind.IdentifierToken)).
                   Select(token => semanticModel.GetDeclaredSymbol(token.Parent)).
                   Where(symbol => symbol != null).FirstOrDefault()?.Name;

            // 識別子リスト設定
            var modifiersObject = node.GetType().GetProperty("Modifiers")?.GetValue(node);

            if (modifiersObject is SyntaxTokenList modifiers)
            {
                Modifiers.AddRange(modifiers.Select(item => item.Text));
            }

            // コメント設定
            var targerComments = node.GetLeadingTrivia().ToString().Split("\n").
                                 Select(item => item.TrimStart().Replace("\n", string.Empty, StringComparison.CurrentCulture)).
                                 Select(item => item.Replace("\r", string.Empty, StringComparison.CurrentCulture)).
                                 Where(item => !string.IsNullOrEmpty(item));

            Comments.AddRange(targerComments);

            // イベントコンテナ
            eventContainer = container;
        }
예제 #2
0
        internal TheIndexer(CsIndexer pIndexer, TheClass pMyClass, FactoryExpressionCreator pCreator)
        {
            MyClass    = pMyClass;
            _creator   = pCreator;
            Arguments  = getArguments(pIndexer.parameters.parameters, pCreator);
            Signature  = getSignature(Arguments);
            ReturnType = Helpers.GetType(pIndexer.entity.specifier.return_type);
            Modifiers.AddRange(Helpers.GetModifiers(pIndexer.modifiers));

            //Name = Helpers.GetRealName(pIndexer, pIndexer.entity.name);
            Name = pIndexer.entity.name;

            FullName = MyClass.FullName + "." + Name;
            //FullRealName = MyClass.FullRealName + "." + RealName;

            string sig = Signature.Replace(',', '_').Replace("<", "").Replace(">", "");

            if (pIndexer.getter != null)
            {
                Getter = processIndexer(pIndexer.getter, false, sig);
            }

            if (pIndexer.setter != null)
            {
                Setter = processIndexer(pIndexer.setter, true, sig);
            }
        }
예제 #3
0
        internal TheConstructor(CsConstructor pConstructor, TheClass pMyClass, FactoryExpressionCreator pCreator)
        {
            _constructor = pConstructor;
            _creator     = pCreator;
            MyClass      = pMyClass;
            Modifiers.AddRange(Helpers.GetModifiers(pConstructor.modifiers));
            Arguments     = getArguments(pConstructor.parameters.parameters, pCreator);
            BaseArguments = Helpers.GetCallingArguments(pConstructor.argument_list, pCreator);

            Signature   = getSignature(Arguments);
            CodeBlock   = pConstructor.definition;
            HasBaseCall = pConstructor.basethis == CsTokenType.tkBASE;

            LinkedList <CsFormalParameter> csFormalParameters = pConstructor.parameters.parameters;

            _noFormalParams     = csFormalParameters == null;
            _name               = pConstructor.identifier.identifier;
            IsStaticConstructor = (pConstructor.modifiers.flags & (uint)CsModifierEnum.mSTATIC) != 0;

            if (pConstructor.basethis == CsTokenType.tkBASE || pConstructor.basethis == CsTokenType.tkTHIS)
            {
                _baseConstructor = pConstructor.basethis == CsTokenType.tkBASE
                                                        ? (CsEntityClass)((CsEntityClass)pConstructor.entity.parent).base_type.u
                                                        : ((CsEntityClass)pConstructor.entity.parent);
            }
        }
예제 #4
0
        internal Property(CsPropertyAccessor pGetter, TheProperty pTheProperty)
        {
            List <string> mods = Helpers.GetModifiers(pGetter.modifiers);

            Modifiers.AddRange(mods.Count == 0 ? pTheProperty.Modifiers : mods);
            Name       = pGetter.entity.name;      //RealName =
            ReturnType = pTheProperty.ReturnType;
            CodeBlock  = pGetter.definition;
        }
예제 #5
0
        internal TheMethod(CsMethod pCsMethod, TheClass pMyClass, FactoryExpressionCreator pCreator)
        {
            MyClass = pMyClass;
            Modifiers.AddRange(Helpers.GetModifiers(pCsMethod.modifiers));
            Arguments = getArguments(pCsMethod.parameters.parameters, pCreator);
            Signature = getSignature(Arguments);
            CodeBlock = pCsMethod.definition;

            //_sig = Signature.Replace(',', '_').Replace("<", "").Replace(">", "");
            //_name = Helpers.GetRealName(pCsMethod, pCsMethod.identifier.identifier);
            _realName = _name = pCsMethod.identifier.identifier;
            //FullRealName = MyClass.FullRealName + "." + RealName;

            ReturnType        = Helpers.GetType(pCsMethod.return_type);
            IsExtensionMethod = pCsMethod.entity.isExtensionMethod();
        }
예제 #6
0
        public TheConstant(CsConstantDeclaration pCsConstantDeclaration, TheClass pTheClass, FactoryExpressionCreator pCreator)
        {
            Modifiers.AddRange(Helpers.GetModifiers(pCsConstantDeclaration.modifiers));

            foreach (CsConstantDeclarator declarator in pCsConstantDeclaration.declarators)
            {
                Constant v = new Constant {
                    //RealName = declarator.identifier.identifier,
                    //Name = Helpers.GetRealName(declarator, declarator.identifier.identifier),
                    Name        = declarator.identifier.identifier,
                    Initializer = pCreator.Parse(declarator.expression),
                    ReturnType  = Helpers.GetType(declarator.entity.type)
                };

                v.Modifiers.AddRange(Modifiers);
                Constants.Add(v);
            }
        }
예제 #7
0
        internal TheVariable(CsVariableDeclaration pCsVariableDeclaration, TheClass pTheClass, FactoryExpressionCreator pCreator)
        {
            Modifiers.AddRange(Helpers.GetModifiers(pCsVariableDeclaration.modifiers));

            foreach (CsVariableDeclarator declarator in pCsVariableDeclaration.declarators)
            {
                Variable v = new Variable {
                    //RealName = declarator.identifier.identifier,
                    //Name = Helpers.GetRealName(declarator, declarator.identifier.identifier),
                    Name        = declarator.identifier.identifier,
                    Initializer =
                        declarator.initializer == null ? null : pCreator.Parse(declarator.initializer as CsExpression),
                    ReturnType = Helpers.GetType(declarator.entity.type)
                };

                v.Modifiers.AddRange(Modifiers);
                Variables.Add(v);
            }
        }
예제 #8
0
        public TheProperty(CsProperty pCsProperty, TheClass pTheClass, FactoryExpressionCreator pCreator)
        {
            MyClass = pTheClass;
            Modifiers.AddRange(Helpers.GetModifiers(pCsProperty.modifiers));
            Name     = pCsProperty.identifier.identifier;
            FullName = MyClass.FullName + "." + Name;

            ReturnType = Helpers.GetType(pCsProperty.type);

            if (pCsProperty.getter != null)
            {
                Getter = new Property(pCsProperty.getter, this);
            }

            if (pCsProperty.setter != null)
            {
                Setter = new Property(pCsProperty.setter, this);
            }
        }
예제 #9
0
        public TheClass(CsInterface pCsInterface, FactoryExpressionCreator pCreator)
        {
            IsInterface = true;
            List <string> name   = new List <string>();
            CsNamespace   parent = pCsInterface.parent as CsNamespace;

            if (parent != null)
            {
                name.AddRange(parent.qualified_identifier.Select(pArt => pArt.identifier.identifier));
            }

            NameSpace = string.Join(".", name.ToArray());
            Name      = pCsInterface.identifier.identifier;
            FullName  = NameSpace + "." + Name;

            if (pCsInterface.type_base != null && pCsInterface.type_base.base_list.Count != 0)
            {
                foreach (CsTypeRef typeRef in pCsInterface.type_base.base_list)
                {
                    object u = typeRef.entity_typeref.u;
                    if (u == null)
                    {
                        continue;
                    }

                    if (u is CsEntityClass)
                    {
                        Extends.Add(Helpers.GetType(typeRef.type_name));
                        _baseTyperef = typeRef;
                    }
                    else if (u is CsEntityInterface)
                    {
                        Implements.Add(Helpers.GetType(typeRef.type_name));
                    }
                    else if (u is CsEntityInstanceSpecifier)
                    {
                        Implements.Add(Helpers.GetType(typeRef.type_name));
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
            }

            Dictionary <string, int> methodNames = new Dictionary <string, int>();
            bool methodsDone = false;

            if (pCsInterface.member_declarations != null)
            {
                foreach (CsNode memberDeclaration in pCsInterface.member_declarations)
                {
                    CsMethod m = memberDeclaration as CsMethod;
                    if (m != null)
                    {
                        if (m.interface_type != null)
                        {
                            continue;
                        }

                        TheMethod tm = new TheMethod(m, this, pCreator);
                        if (methodNames.ContainsKey(tm.Name))
                        {
                            methodNames[tm.Name]++;
                            int index = tm._index = methodNames[tm.Name];

                            if (!methodsDone)
                            {
                                methodsDone = true;
                                foreach (KeyValuePair <CsMethod, TheMethod> method in _methods)
                                {
                                    method.Value._isUnique = false;
                                    method.Value._index    = --index;
                                }
                            }

                            tm._isUnique = false;
                        }
                        else
                        {
                            methodNames[tm.Name] = tm._index = 1;
                        }

                        _methods.Add(m, tm);
                        continue;
                    }

                    CsIndexer i = memberDeclaration as CsIndexer;
                    if (i != null)
                    {
                        _indexers.Add(i, new TheIndexer(i, this, pCreator));
                        continue;
                    }

                    CsVariableDeclaration v = memberDeclaration as CsVariableDeclaration;
                    if (v != null)
                    {
                        _variables.Add(v, new TheVariable(v, this, pCreator));
                        continue;
                    }

                    CsProperty p = memberDeclaration as CsProperty;
                    if (p != null)
                    {
                        if (p.interface_type == null)
                        {
                            _properties.Add(p, new TheProperty(p, this, pCreator));
                        }
                        continue;
                    }

                    throw new NotImplementedException("Unknown type not implemented");
                }
            }

            Modifiers.AddRange(Helpers.GetModifiers(pCsInterface.modifiers));
        }
예제 #10
0
        public TheClass(CsClassStruct pCsClass, FactoryExpressionCreator pCreator)
        {
            CsNamespace csNamespace;

            _creator = pCreator;
            List <string> name = new List <string>();

            if (pCsClass.parent is CsClass)
            {
                IsPrivate   = true;
                csNamespace = (CsNamespace)pCsClass.parent.parent;
            }
            else
            {
                csNamespace = (CsNamespace)pCsClass.parent;
            }

            CsQualifiedIdentifier list = csNamespace.qualified_identifier;

            name.AddRange(list.Select(pIdentifier => pIdentifier.identifier.identifier));

            if (IsPrivate)
            {
                name.Add(((CsClass)pCsClass.parent).identifier.identifier);
            }

            NameSpace = string.Join(".", name.ToArray());
            //RealName = pCsClass.identifier.identifier;
            //Name = Helpers.GetRealName(pCsClass, RealName);
            Name = pCsClass.identifier.identifier;

            FullName = NameSpace + "." + Name;
            //FullRealName = NameSpace + "." + RealName;

            if (pCsClass.type_base != null && pCsClass.type_base.base_list.Count != 0)
            {
                foreach (CsTypeRef typeRef in pCsClass.type_base.base_list)
                {
                    object u = typeRef.entity_typeref.u;
                    if (u == null)
                    {
                        continue;
                    }

                    if (u is CsEntityClass)
                    {
                        Extends.Add(Helpers.GetType(typeRef.type_name));
                        _baseTyperef = typeRef;
                    }
                    else if (u is CsEntityInterface)
                    {
                        Implements.Add(Helpers.GetType(typeRef.type_name));
                    }
                    else if (u is CsEntityInstanceSpecifier)
                    {
                        Implements.Add(Helpers.GetType(typeRef.type_name));

                        //CsEntityInstanceSpecifier specifier = (CsEntityInstanceSpecifier)typeRef.entity_typeref.u;
                    }
                    else
                    {
                        throw new NotSupportedException();
                    }
                }
            }

            Dictionary <string, int> methodNames = new Dictionary <string, int>();
            bool constructorsDone = false;
            bool methodsDone      = false;

            if (pCsClass.member_declarations != null)
            {
                foreach (CsNode memberDeclaration in pCsClass.member_declarations)
                {
                    CsConstructor c = memberDeclaration as CsConstructor;
                    if (c != null)
                    {
                        TheConstructor tm = new TheConstructor(c, this, pCreator);

                        if (methodNames.ContainsKey(tm.Name))
                        {
                            methodNames[tm.Name]++;
                            int index = tm._index = methodNames[tm.Name];

                            if (!constructorsDone)
                            {
                                constructorsDone = true;
                                foreach (KeyValuePair <CsConstructor, TheConstructor> constructor in _constructors)
                                {
                                    constructor.Value._isUnique = false;
                                    constructor.Value._index    = --index;
                                }
                            }

                            tm._isUnique = false;
                        }
                        else
                        {
                            methodNames[tm.Name] = tm._index = 1;
                        }

                        _constructors.Add(c, tm);
                        continue;
                    }

                    CsMethod m = memberDeclaration as CsMethod;
                    if (m != null)
                    {
                        if (m.interface_type != null)
                        {
                            continue;
                        }

                        TheMethod tm = new TheMethod(m, this, pCreator);
                        if (methodNames.ContainsKey(tm.Name))
                        {
                            methodNames[tm.Name]++;
                            int index = tm._index = methodNames[tm.Name];

                            if (!methodsDone)
                            {
                                methodsDone = true;
                                foreach (KeyValuePair <CsMethod, TheMethod> method in _methods)
                                {
                                    method.Value._isUnique = false;
                                    method.Value._index    = --index;
                                }
                            }

                            tm._isUnique = false;
                        }
                        else
                        {
                            methodNames[tm.Name] = tm._index = 1;
                        }

                        _methods.Add(m, tm);
                        continue;
                    }

                    CsIndexer i = memberDeclaration as CsIndexer;
                    if (i != null)
                    {
                        _indexers.Add(i, new TheIndexer(i, this, pCreator));
                        continue;
                    }

                    CsVariableDeclaration v = memberDeclaration as CsVariableDeclaration;
                    if (v != null)
                    {
                        _variables.Add(v, new TheVariable(v, this, pCreator));
                        continue;
                    }

                    CsConstantDeclaration k = memberDeclaration as CsConstantDeclaration;
                    if (k != null)
                    {
                        _constants.Add(k, new TheConstant(k, this, pCreator));
                        continue;
                    }

                    CsProperty p = memberDeclaration as CsProperty;
                    if (p != null)
                    {
                        if (p.interface_type == null)
                        {
                            _properties.Add(p, new TheProperty(p, this, pCreator));
                        }
                        continue;
                    }

                    CsDelegate d = memberDeclaration as CsDelegate;
                    if (d != null)
                    {
                        _delegates.Add(d, new TheDelegate(d, this, pCreator));
                        continue;
                    }

                    CsEvent e = memberDeclaration as CsEvent;
                    if (e != null)
                    {
                        TheEvent theEvent = new TheEvent(e, this, pCreator);
                        _events.Add(theEvent.Name, theEvent);
                        continue;
                    }

                    CsClass csClass = memberDeclaration as CsClass;
                    if (csClass != null)
                    {
                        continue;
                    }

                    throw new NotImplementedException("Unknown type not implemented");
                }
            }

            Modifiers.AddRange(Helpers.GetModifiers(pCsClass.modifiers));
        }