private static void BuildDeclarations(Namespace @namespace, IEnumerable<Declarations.Declaration> declarations) { foreach(var declaration in declarations) declaration.Match() .With<NamespaceDeclaration>(ns => { var childNamespace = new Namespace(ns.Syntax, @namespace, ns.Name); @namespace.Add(childNamespace); BuildDeclarations(childNamespace, ns.Members); }) .With<ClassDeclaration>(@classDecl => { var syntax = @classDecl.Syntax.Single(); // TODO handle partial classes var @class = new Class(syntax, @namespace, syntax.Accessibility, @classDecl.Name); @namespace.Add(@class); }) .With<FunctionDeclaration>(@functionDeclaration => { var syntax = @functionDeclaration.Syntax.Single(); // TODO handle overloads var function = new Function(syntax, @namespace, syntax.Accessibility, @functionDeclaration.Name); @namespace.Add(function); }) // TODO handle ambigouous declarations .Exhaustive(); }
protected Declaration(IEnumerable<DeclarationSyntax> syntax, Package containingPackage, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : base(syntax, declaredAccessibility, name) { Requires.NotNull(containingPackage, nameof(containingPackage)); ContainingPackage = containingPackage; ContainingNamespace = containingNamespace; }
public Class(ClassSyntax syntax, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : base(syntax, containingNamespace, declaredAccessibility, name) { }
// namespaces are implicitly public public Namespace(IEnumerable<NamespaceSyntax> syntax, Namespace containingNamespace, string name) : base(syntax, containingNamespace.ContainingPackage, containingNamespace, Accessibility.Public, name) { }
protected Entity(EntitySyntax syntax, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : base(syntax, containingNamespace.ContainingPackage, containingNamespace, declaredAccessibility, name) { Requires.NotNull(containingNamespace, nameof(containingNamespace)); }
public GlobalVariable(GlobalVariableSyntax syntax, Namespace containingNamespace) : base(syntax, containingNamespace, syntax.Accessibility, syntax.Name.ValueText) { }
public GlobalVariable(GlobalVariableSyntax syntax, Namespace containingNamespace) : base(syntax, containingNamespace, syntax.Accessibility, syntax.Name.ValueText) { }
public Class(ClassSyntax syntax, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : base(syntax, containingNamespace, declaredAccessibility, name) { }
protected Declaration(DeclarationSyntax syntax, Package containingPackage, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : this(syntax.Yield(), containingPackage, containingNamespace, declaredAccessibility, name) { }
protected Entity(EntitySyntax syntax, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : base(syntax, containingNamespace.ContainingPackage, containingNamespace, declaredAccessibility, name) { Requires.NotNull(containingNamespace, nameof(containingNamespace)); }
protected Declaration(IEnumerable <DeclarationSyntax> syntax, Package containingPackage, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : base(syntax, declaredAccessibility, name) { Requires.NotNull(containingPackage, nameof(containingPackage)); ContainingPackage = containingPackage; ContainingNamespace = containingNamespace; }
protected Declaration(DeclarationSyntax syntax, Package containingPackage, Namespace containingNamespace, Accessibility declaredAccessibility, string name) : this(syntax.Yield(), containingPackage, containingNamespace, declaredAccessibility, name) { }
public Package(PackageSyntax syntax) : base(syntax, Accessibility.NotApplicable, syntax?.Name) { GlobalNamespace = new Namespace(this); }