private static string IntrospectionTypeToLiteralGraphTypeMemberInfoTypeName(TypeElementType type) { switch (type.Kind) { case TypeElementTypeKind.Object: case TypeElementTypeKind.Scalar: return(type.Name); case TypeElementTypeKind.List: case TypeElementTypeKind.NonNull: return(IntrospectionTypeToLiteralGraphTypeMemberInfoTypeName(type.OfType)); default: return(null); } }
/// <summary> /// Parses a type definition. /// </summary> /// <param name="access">The access.</param> /// <param name="typeAttributes">The type attributes.</param> /// <param name="elementType">Type of the element.</param> /// <returns>A type code element.</returns> private TypeElement ParseType( CodeAccess access, TypeModifiers typeAttributes, TypeElementType elementType) { TypeElement typeElement = new TypeElement(); EatWhiteSpace(); string className = CaptureWord(); typeElement.Name = className; typeElement.Access = access; typeElement.Type = elementType; typeElement.TypeModifiers = typeAttributes; if (elementType == TypeElementType.Enum) { EatLineContinuation(); if (NextChar == VBKeyword.As[0]) { EatWord(VBKeyword.As); string interfaceName = CaptureTypeName(); InterfaceReference interfaceReference = new InterfaceReference(interfaceName, InterfaceReferenceType.None); typeElement.AddInterface(interfaceReference); } string enumText = ParseBlock(VBKeyword.Enumeration); // TODO: Parse enum values as fields typeElement.BodyText = enumText; } else { EatWhiteSpace(); bool isGeneric = TryReadChar(VBSymbol.BeginParameterList); if (isGeneric) { EatWord(VBKeyword.Of, "Expected Of"); this.ParseTypeParameters(typeElement); } EatWhiteSpace(); // // Parse child elements // List<ICodeElement> childElements = ParseElements(typeElement); foreach (ICodeElement childElement in childElements) { typeElement.AddChild(childElement); } EatWhiteSpace(); string elementTypeString = EnumUtilities.ToString(elementType); EatWord(elementTypeString, "Expected End " + elementTypeString); } return typeElement; }
/// <summary> /// Gets the type of the element. /// </summary> /// <param name="wordList">The word list.</param> /// <param name="elementType">Type of the element.</param> /// <param name="typeElementType">Type of the type element.</param> private static void GetElementType( StringCollection wordList, out ElementType elementType, out TypeElementType? typeElementType) { elementType = ElementType.NotSpecified; typeElementType = null; if (wordList.Contains(VBKeyword.Class)) { elementType = ElementType.Type; typeElementType = TypeElementType.Class; return; } if (wordList.Contains(VBKeyword.Structure)) { elementType = ElementType.Type; typeElementType = TypeElementType.Structure; return; } if (wordList.Contains(VBKeyword.Enumeration)) { elementType = ElementType.Type; typeElementType = TypeElementType.Enum; return; } if (wordList.Contains(VBKeyword.Interface)) { elementType = ElementType.Type; typeElementType = TypeElementType.Interface; return; } if (wordList.Contains(VBKeyword.Module)) { elementType = ElementType.Type; typeElementType = TypeElementType.Module; return; } if (wordList.Contains(VBKeyword.Property)) { elementType = ElementType.Property; return; } if (wordList.Contains(VBKeyword.Sub) || wordList.Contains(VBKeyword.Function) || wordList.Contains(VBKeyword.Operator)) { elementType = ElementType.Method; return; } if (wordList.Contains(VBKeyword.Event)) { elementType = ElementType.Event; return; } if (wordList.Contains(VBKeyword.Delegate)) { elementType = ElementType.Delegate; return; } }
/// <summary> /// Parses a type definition. /// </summary> /// <param name="access">Type accessibility.</param> /// <param name="typeAttributes">Type modifiers.</param> /// <param name="elementType">Type element type.</param> /// <returns>Type code element.</returns> private TypeElement ParseType( CodeAccess access, TypeModifiers typeAttributes, TypeElementType elementType) { TypeElement typeElement = new TypeElement(); EatWhiteSpace(); string className = CaptureWord(); typeElement.Name = className; typeElement.Access = access; typeElement.Type = elementType; typeElement.TypeModifiers = typeAttributes; EatWhiteSpace(); if (elementType == TypeElementType.Enum) { EatWhiteSpace(); if (NextChar == CSharpSymbol.TypeImplements) { TryReadChar(); string interfaceName = CaptureTypeName(); InterfaceReference interfaceReference = new InterfaceReference(interfaceName, InterfaceReferenceType.None); typeElement.AddInterface(interfaceReference); } string enumText = ParseBlock(true, typeElement); // TODO: Parse enum values as fields typeElement.BodyText = enumText; } else { bool isGeneric = TryReadChar(CSharpSymbol.BeginGeneric); if (isGeneric) { string[] typeParameterNames = ParseAliasList(); foreach (string typeParameterName in typeParameterNames) { TypeParameter typeParameter = new TypeParameter(); typeParameter.Name = typeParameterName; typeElement.AddTypeParameter(typeParameter); } EatWhiteSpace(); if (!TryReadChar(CSharpSymbol.EndGeneric)) { this.OnParseError("Expected " + CSharpSymbol.EndGeneric); } } EatWhiteSpace(); bool implements = TryReadChar(CSharpSymbol.TypeImplements); if (implements) { string[] typeList = ParseAliasList(); foreach (string type in typeList) { InterfaceReference interfaceReference = new InterfaceReference(type, InterfaceReferenceType.None); typeElement.AddInterface(interfaceReference); } } EatWhiteSpace(); ParseTypeParameterConstraints(typeElement); // Associate any additional comments in the type definition with the type. ReadOnlyCollection<ICommentElement> extraComments = ParseComments(); foreach (ICommentElement comment in extraComments) { typeElement.AddHeaderComment(comment); } EatChar(CSharpSymbol.BeginBlock); EatWhiteSpace(); if (NextChar != CSharpSymbol.EndBlock) { // // Parse child elements // List<ICodeElement> childElements = ParseElements(typeElement); foreach (ICodeElement childElement in childElements) { typeElement.AddChild(childElement); } } EatChar(CSharpSymbol.EndBlock); } // // Types allow a trailing semi-colon // EatTrailingEndOfStatement(); return typeElement; }
/// <summary> /// Gets the type of the element. /// </summary> /// <param name="wordList">The word list.</param> /// <param name="elementType">Type of the element.</param> /// <param name="typeElementType">Type of the type element.</param> private static void GetElementType( StringCollection wordList, out ElementType elementType, out TypeElementType? typeElementType) { elementType = ElementType.NotSpecified; typeElementType = null; if (TryFindAndRemoveWord(wordList, CSharpKeyword.Class)) { elementType = ElementType.Type; typeElementType = TypeElementType.Class; return; } if (TryFindAndRemoveWord(wordList, CSharpKeyword.Structure)) { elementType = ElementType.Type; typeElementType = TypeElementType.Structure; return; } if (TryFindAndRemoveWord(wordList, CSharpKeyword.Enumeration)) { elementType = ElementType.Type; typeElementType = TypeElementType.Enum; return; } if (TryFindAndRemoveWord(wordList, CSharpKeyword.Interface)) { elementType = ElementType.Type; typeElementType = TypeElementType.Interface; return; } if (TryFindAndRemoveWord(wordList, CSharpKeyword.Event)) { elementType = ElementType.Event; return; } if (TryFindAndRemoveWord(wordList, CSharpKeyword.Delegate)) { elementType = ElementType.Delegate; return; } }
private static LiteralGraphTypeMemberInfoType IntrospectionTypeToLiteralGraphTypeMemberInfoType(TypeElementType type) { switch (type.Kind) { case TypeElementTypeKind.List: case TypeElementTypeKind.Object: return(LiteralGraphTypeMemberInfoType.Complex); case TypeElementTypeKind.Scalar: return(ScalarGraphTypeNameToMemberInfoType(type.Name)); case TypeElementTypeKind.NonNull: return(IntrospectionTypeToLiteralGraphTypeMemberInfoType(type.OfType)); default: return(LiteralGraphTypeMemberInfoType.Unknown); } }