PageRenderTime 54ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/ABB.SrcML.Data/LiteralUse.cs

https://github.com/nkcsgexi/SrcML.NET
C# | 42 lines | 27 code | 4 blank | 11 comment | 17 complexity | 5c0e574a6b1a94519154a8eb48be9749 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Xml.Linq;
  6. namespace ABB.SrcML.Data {
  7. /// <summary>
  8. /// Literal use is a specific kind of type use that refers to a language's built-in types.
  9. /// </summary>
  10. [Serializable]
  11. public class LiteralUse : TypeUse {
  12. /// <summary>
  13. /// The kind of literal
  14. /// </summary>
  15. public LiteralKind Kind { get; set; }
  16. /// <summary>
  17. /// Gets the literal kind from the <paramref name="literalElement"/>
  18. /// </summary>
  19. /// <param name="literalElement">The literal element</param>
  20. /// <returns>The kind of element this is</returns>
  21. public static LiteralKind GetLiteralKind(XElement literalElement) {
  22. if(literalElement == null) throw new ArgumentNullException("literalElement");
  23. if(literalElement.Name != LIT.Literal) throw new ArgumentException("should be of type LIT.Literal", "literalElement");
  24. var typeAttribute = literalElement.Attribute("type");
  25. if(null == typeAttribute) throw new ArgumentException("should contain a \"type\" attribute", "literalElement");
  26. var kind = typeAttribute.Value;
  27. if(kind == "boolean")
  28. return LiteralKind.Boolean;
  29. else if(kind == "char")
  30. return LiteralKind.Character;
  31. else if(kind == "number")
  32. return LiteralKind.Number;
  33. else if(kind == "string")
  34. return LiteralKind.String;
  35. throw new SrcMLException(String.Format("\"{0}\" is not a valid literal kind", kind));
  36. }
  37. }
  38. }