コード例 #1
0
ファイル: UseParser.cs プロジェクト: ranganathsb/sharpDox
        private void ResolveCall(SDNode call)
        {
            if (call is SDTargetNode)
            {
                var targetNode = call as SDTargetNode;
                var calledType = _sdRepository.GetTypeByIdentifier(targetNode.CalledType.Identifier);
                var callerType = _sdRepository.GetTypeByIdentifier(targetNode.CallerType.Identifier);

                if (calledType != null && callerType != null && calledType.Identifier != callerType.Identifier && !calledType.IsProjectStranger && !callerType.IsProjectStranger)
                {
                    if (!calledType.IsProjectStranger && calledType.UsedBy.SingleOrDefault(u => u.Identifier == callerType.Identifier) == null)
                    {
                        calledType.UsedBy.Add(callerType);
                    }

                    if (!calledType.IsProjectStranger && callerType.Uses.SingleOrDefault(u => u.Identifier == calledType.Identifier) == null)
                    {
                        callerType.Uses.Add(calledType);
                    }

                    var calledNamespace = _sdRepository.GetNamespaceByIdentifier(calledType.Namespace.Identifier);
                    var callerNamespace = _sdRepository.GetNamespaceByIdentifier(callerType.Namespace.Identifier);

                    if (calledNamespace != null && callerNamespace != null && calledNamespace.Fullname != callerNamespace.Fullname)
                    {
                        if (calledNamespace.UsedBy.SingleOrDefault(u => u.Fullname == callerNamespace.Fullname) == null)
                        {
                            calledNamespace.UsedBy.Add(callerNamespace);
                        }

                        if (callerNamespace.Uses.SingleOrDefault(u => u.Fullname == calledNamespace.Fullname) == null)
                        {
                            callerNamespace.Uses.Add(calledNamespace);
                        }
                    }
                }
            }
            else if (call is SDBlock)
            {
                foreach (var embeddedCall in ((SDBlock)call).Statements)
                {
                    ResolveCall(embeddedCall);
                }
            }
            else if (call is SDConditionalBlock)
            {
                foreach (var embeddedCall in ((SDConditionalBlock)call).TrueStatements)
                {
                    ResolveCall(embeddedCall);
                }
                foreach (var embeddedCall in ((SDConditionalBlock)call).FalseStatements)
                {
                    ResolveCall(embeddedCall);
                }
            }
        }
コード例 #2
0
ファイル: NRefactoryParser.cs プロジェクト: llenroc/sharpDox
        private void StructureParseTypes(CSharpProject project, SDRepository sdRepository)
        {
            var types = project.Compilation.MainAssembly.TopLevelTypeDefinitions.ToList();

            for (int j = 0; j < types.Count; j++)
            {
                var type = types[j];
                if (types[j].Kind != TypeKind.Delegate)
                {
                    PostParseMessage(_parserStrings.ParsingClass + ": " + string.Format("{0}.{1}", types[j].Namespace, types[j].Name));

                    var nameSpace    = sdRepository.GetNamespaceByIdentifier(type.Namespace);
                    var namespaceRef = nameSpace ?? new SDNamespace(type.Namespace)
                    {
                        IsProjectStranger = true
                    };

                    var sdType = new SDType(type.GetIdentifier(), type.Name, namespaceRef)
                    {
                        Accessibility = type.GetDefinition().Accessibility.ToString().ToLower()
                    };

                    sdRepository.AddType(sdType);

                    EventParser.ParseMinimalFields(sdType, types[j]);
                    PropertyParser.ParseMinimalProperties(sdType, types[j]);
                    FieldParser.ParseMinimalFields(sdType, types[j]);
                    MethodParser.ParseMinimalConstructors(sdType, types[j]);
                    MethodParser.ParseMinimalMethods(sdType, types[j]);

                    sdRepository.AddNamespaceTypeRelation(types[j].Namespace, sdType.Identifier);
                }
            }
        }
コード例 #3
0
        private SDType CreateSDType(IType type)
        {
            var nameSpace    = _repository.GetNamespaceByIdentifier(type.Namespace);
            var namespaceRef = nameSpace ?? new SDNamespace(type.Namespace)
            {
                IsProjectStranger = true
            };

            var sdType = new SDType(type.GetIdentifier(), type.Name, namespaceRef)
            {
                Accessibility = type.GetDefinition().Accessibility.ToString().ToLower()
            };

            _repository.AddType(sdType);

            return(sdType);
        }
コード例 #4
0
        public static void AddKnownTypes(SDRepository sdRepository)
        {
            var systemNamespace = sdRepository.GetNamespaceByIdentifier("System");

            if (systemNamespace != null)
            {
                sdRepository.AddType(new SDType("dynamic", "Dynamic", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "dynamic"
                });
                sdRepository.AddType(new SDType("System.Object", "Object", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "object"
                });
                sdRepository.AddType(new SDType("System.Boolean", "Boolean", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "bool"
                });
                sdRepository.AddType(new SDType("System.Char", "Char", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "char"
                });
                sdRepository.AddType(new SDType("System.SByte", "SByte", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "sbyte"
                });
                sdRepository.AddType(new SDType("System.Byte", "Byte", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "byte"
                });
                sdRepository.AddType(new SDType("System.Int16", "Int16", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "short"
                });
                sdRepository.AddType(new SDType("System.UInt16", "UInt16", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "ushort"
                });
                sdRepository.AddType(new SDType("System.Int32", "Int32", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "int"
                });
                sdRepository.AddType(new SDType("System.UInt32", "UInt32", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "uint"
                });
                sdRepository.AddType(new SDType("System.Int64", "Int64", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "long"
                });
                sdRepository.AddType(new SDType("System.UInt64", "UInt64", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "ulong"
                });
                sdRepository.AddType(new SDType("System.Single", "Single", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "float"
                });
                sdRepository.AddType(new SDType("System.Double", "Double", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "double"
                });
                sdRepository.AddType(new SDType("System.Decimal", "Decimal", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "decimal"
                });
                sdRepository.AddType(new SDType("System.String", "String", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "string"
                });
                sdRepository.AddType(new SDType("System.Void", "Void", systemNamespace)
                {
                    IsProjectStranger = true, CSharpName = "void"
                });
            }
        }
コード例 #5
0
        private void ParseTargetExpression(InvocationExpressionSyntax expression)
        {
            var compilation = _file.Project.GetCompilationAsync().Result;
            var symbolInfo  = compilation.GetSemanticModel(_file.GetSyntaxTreeAsync().Result).GetSymbolInfo(expression);

            if (symbolInfo.Symbol != null)
            {
                var member = symbolInfo.Symbol;
                var method = member as IMethodSymbol;

                if (method != null)
                {
                    var callerType   = _type;
                    var callerMethod = _method;

                    SDType calledType = null;
                    var    sdType     = _repository.GetTypeByIdentifier(member.ContainingType.GetIdentifier());
                    if (sdType == null)
                    {
                        var sdNamespace = _repository.GetNamespaceByIdentifier(member.ContainingNamespace.ToDisplayString());
                        sdNamespace = sdNamespace ?? new SDNamespace(member.ContainingNamespace.ToDisplayString())
                        {
                            IsProjectStranger = true
                        };
                        calledType = new SDType(member.ContainingType.GetIdentifier(), member.ContainingType.Name, sdNamespace)
                        {
                            IsProjectStranger = true
                        };
                    }
                    else
                    {
                        calledType = sdType;
                    }

                    SDMethod calledMethod = null;
                    if (calledType.IsProjectStranger)
                    {
                        calledMethod = new SDMethod(method.GetIdentifier(), method.Name);
                    }
                    else
                    {
                        SDMethod sdMethod = sdType.Methods.Concat(sdType.Constructors).SingleOrDefault(m => m.Identifier == method.GetIdentifier());
                        if (sdMethod != null)
                        {
                            calledMethod = sdMethod;
                        }
                    }

                    // Only add method, if it is project stranger, public or private (if not only public members option on)
                    if (calledMethod != null)
                    {
                        var token = new SDTargetNode
                        {
                            CalledType   = calledType,
                            CallerType   = callerType,
                            CalledMethod = calledMethod,
                            CallerMethod = callerMethod
                        };

                        _tokenList.Add(token);
                    }
                }
            }
        }
コード例 #6
0
        private void ParseTargetExpression(Expression expression)
        {
            if (_file != null)
            {
                var resolver      = new CSharpAstResolver(_file.Project.Compilation, _file.SyntaxTree, _file.UnresolvedTypeSystemForFile);
                var resolveResult = resolver.Resolve(expression);

                if (resolveResult is CSharpInvocationResolveResult)
                {
                    var member = ((CSharpInvocationResolveResult)resolveResult).Member;
                    var method = member as IMethod;

                    if (method != null)
                    {
                        var callerType   = _type;
                        var callerMethod = _method;

                        SDType calledType = null;
                        var    sdType     = _repository.GetTypeByIdentifier(member.DeclaringType.GetIdentifier());
                        if (sdType == null)
                        {
                            var sdNamespace = _repository.GetNamespaceByIdentifier(member.DeclaringType.Namespace);
                            sdNamespace = sdNamespace == null ? new SDNamespace(member.DeclaringType.Namespace)
                            {
                                IsProjectStranger = true
                            } : sdNamespace;
                            calledType = new SDType(member.DeclaringType.GetIdentifier(), member.DeclaringType.Name, sdNamespace)
                            {
                                IsProjectStranger = true
                            };
                        }
                        else
                        {
                            calledType = sdType;
                        }

                        SDMethod calledMethod = null;
                        if (calledType.IsProjectStranger)
                        {
                            calledMethod = new SDMethod(method.GetIdentifier(), method.Name);
                        }
                        else
                        {
                            SDMethod sdMethod = sdType.Methods.Concat(sdType.Constructors).SingleOrDefault(m => m.Identifier == method.GetIdentifier());
                            if (sdMethod != null)
                            {
                                calledMethod = sdMethod;
                            }
                        }

                        // Only add method, if it is project stranger, public or private (if not only public members option on)
                        if (calledMethod != null)
                        {
                            var token = new SDTargetNode
                            {
                                CalledType   = calledType,
                                CallerType   = callerType,
                                CalledMethod = calledMethod,
                                CallerMethod = callerMethod
                            };

                            _tokenList.Add(token);
                        }
                    }
                }
            }
        }