/// <summary> /// Construct a <see cref="Documentation"/> appropriate for the given <paramref name="docNodeType" />. /// </summary> public static Documentation Parse(List <string> comments, DocNodeType docNodeType) { if (comments != null && comments.Count > 0 && comments[0].StartsWith("/**")) { // Trim inputs comments = comments .Select(s => s.Trim(' ', '\t', '*', '\r', '\n', '/')) .Where(s => !string.IsNullOrEmpty(s)) .ToList(); if (comments.Count > 0) { switch (docNodeType) { case DocNodeType.Function: case DocNodeType.InstanceFunction: return(new FunctionDocumentation(comments)); case DocNodeType.Enum: case DocNodeType.Namespace: case DocNodeType.Interface: case DocNodeType.Type: case DocNodeType.Value: case DocNodeType.Property: case DocNodeType.EnumMember: return(new DefaultDocumentation(comments)); default: throw new ArgumentOutOfRangeException(nameof(docNodeType), docNodeType, null); } } } return(null); }
void AssertTypeIs(DocNodeType type) { if (Type != type) { ThrowAccessException(type.ToString(), Type.ToString()); } }
///////////////////////////////////////////////// void CheckTypeIs(DocNodeType requiredType) { if (Type != requiredType) { throw new DocNodeAccessException(GenerateAccessExceptionMessage(requiredType.ToString())); } }
private static string CreateDocNodeTypeImage(DocNodeType nodeType) { switch (nodeType) { case DocNodeType.Namespace: return($"![Namespace](https://docs.microsoft.com/en-us/media/toolbars/namespace.svg ={IconSize})"); case DocNodeType.Enum: return($"![Enum]({TypeImageUrl} ={IconSize})"); case DocNodeType.Interface: return($"![Interface]({TypeImageUrl} ={IconSize})"); case DocNodeType.Type: return($"![Type]({TypeImageUrl} ={IconSize})"); case DocNodeType.Property: return($"![Property]({MemberImageUrl} ={IconSize})"); case DocNodeType.Value: return($"![Value]({MemberImageUrl} ={IconSize})"); case DocNodeType.Function: case DocNodeType.InstanceFunction: return($"![Function]({MemberImageUrl} ={IconSize})"); default: return(null); } }
////////////////////////////////////////////////////////////////////// // DocNode Methods ////////////////////////////////////////////////////////////////////// public ComposedDocNode(DocNodeType type, int size = -1) { m_type = type; switch (type) { case DocNodeType.Invalid: break; case DocNodeType.Dictionary: if (size > 0) { m_dictionary = new Dictionary <string, DocNode>(size); } else { m_dictionary = new Dictionary <string, DocNode>(); } break; case DocNodeType.List: if (size > 0) { m_list = new List <DocNode>(size); } else { m_list = new List <DocNode>(); } break; case DocNodeType.Scalar: m_scalar = ""; break; } }
public static object FromVector3(object obj, DocNode value) { DocNodeType parsedType = value.Type; if (parsedType == DocNodeType.Scalar) // Vector3, 3 => new Vector3(3,3, 3); { float single = value.AsFloat(); return(new Vector3(single, single, single)); } else // Vector3, [1,2,3] => new Vector2(1,2,3); { float v1 = value[0].AsFloat(); float v2 = v1; float v3 = v1; if (value.Count > 1) { v2 = value[1].AsFloat(); v3 = 0; } if (value.Count > 2) { v3 = value[2].AsFloat(); } return(new Vector3(v1, v2, v3)); } }
/// <nodoc /> public DocNode(DocNodeType docNodeType, DocNodeVisibility visibility, string name, List <string> trivia, Module module, AbsolutePath specPath, DocNode parent, string appendix) { Contract.Assert(!string.IsNullOrEmpty(name)); Contract.Assert(module != null); DocNodeType = docNodeType; Visibility = visibility; Name = name; NodeId = module.GetNextNodeId(); Module = module; SpecPath = specPath; Parent = parent; Doc = Documentation.Parse(trivia, docNodeType); Appendix = appendix; }
public static object FromVector2(object obj, DocNode value) { DocNodeType parsedType = value.Type; if (parsedType == DocNodeType.Scalar) // Vector2, 3 => new Vector2(3,3); { var single = value.AsFloat(); return(new Vector2(single, single)); } else // Vector2, [1,2] => new Vector2(1,2); { float v1 = value[0].AsFloat(); float v2 = v1; if (value.Count > 1) { v2 = value[1].AsFloat(); } return(new Vector2(v1, v2)); } }
public ComposedDocNode(DocNodeType type, int size = -1, string sourceInformation = null) { Type = type; sourceInfo = sourceInformation; switch (type) { case DocNodeType.Dictionary: dictionary = size > 0 ? new Dictionary <string, DocNode>(size) : new Dictionary <string, DocNode>(); break; case DocNodeType.List: list = size > 0 ? new List <DocNode>(size) : new List <DocNode>(); break; case DocNodeType.Scalar: scalar = ""; break; default: throw new Exception($"Can't make a ComposedDocNode instance with Type {type}"); } }
/// <nodoc /> public DocNode GetOrAdd(DocNodeType type, DocNodeVisibility visibility, AbsolutePath specPath, string name, List <string> trivia, string appendix) { return(ChildNodes.GetOrAdd(name, _ => new DocNode(type, visibility, name, trivia, Module, specPath, this, appendix))); }
private void Register <T>(T node, NodeFlags flags, DocNodeType type, string name, Action <T> visit) where T : INode { var injected = NodeExtensions.IsInjectedForDScript(node); if (injected) { return; } var visibility = DocNodeVisibility.Private; if ((flags & NodeFlags.Export) != 0) { visibility = DocNodeVisibility.Internal; } if ((flags & NodeFlags.ScriptPublic) != 0 || type == DocNodeType.Namespace) { visibility = DocNodeVisibility.Public; } List <string> triviaContent = new List <string>(); AddComments(node, triviaContent); if (type == DocNodeType.EnumMember || type == DocNodeType.Value || type == DocNodeType.Property) { // For these edge nodes, we can safely visit their children to seek out other documentation. // The documentation chunks may be in the wrong order due to search order, but the results will be complete. node.ForEachChildRecursively <TypeScript.Net.Types.Node>( n => { AddComments(n, triviaContent); return(null); }, recurseThroughIdentifiers: true); } else { if (node.Decorators?.Length > 0) { foreach (var decorator in node.Decorators.Elements) { AddComments(decorator, triviaContent); } } } string appendix = string.Empty; // Handle Tool.option attribute IPropertyAccessExpression propertyAccessExpression; ICallExpression callExpression; IIdentifier propertyIdentifier; ILiteralExpression literal; if (node.Decorators?.Count > 0 && (callExpression = node.Decorators.Elements[0].Expression.As <ICallExpression>()) != null && (propertyAccessExpression = callExpression.Expression.As <IPropertyAccessExpression>()) != null && (propertyIdentifier = propertyAccessExpression.Expression.As <IIdentifier>()) != null && propertyIdentifier.Text == "Tool" && propertyAccessExpression.Name.Text == "option" && callExpression.Arguments.Count > 0 && (literal = callExpression.Arguments[0].As <ILiteralExpression>()) != null) { appendix = $"Tool option {literal.Text}"; } DocNode newNode; var parent = m_declarations.Peek(); if (parent != null) { newNode = parent.GetOrAdd(type, visibility, m_path, name, triviaContent, appendix); } else { newNode = m_module.GetOrAdd(type, visibility, m_path, name, triviaContent, appendix); } m_declarations.Push(newNode); visit(node); m_declarations.Pop(); }
internal DocNode GetOrAdd(DocNodeType type, DocNodeVisibility visibility, AbsolutePath specPath, string name, List <string> trivia, string appendix) { return(ChildNodes.GetOrAdd(name, new DocNode(type, visibility, name, trivia, this, specPath, null, appendix))); }