PageRenderTime 25ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/Python/Product/IronPython/Interpreter/IronPythonParameterInfo.cs

https://gitlab.com/SplatoonModdingHub/PTVS
C# | 116 lines | 85 code | 15 blank | 16 comment | 19 complexity | e919c5002b4e7491ab5b798f9b498681 MD5 | raw file
  1. // Python Tools for Visual Studio
  2. // Copyright(c) Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the License); you may not use
  6. // this file except in compliance with the License. You may obtain a copy of the
  7. // License at http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
  10. // OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY
  11. // IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  12. // MERCHANTABLITY OR NON-INFRINGEMENT.
  13. //
  14. // See the Apache Version 2.0 License for specific language governing
  15. // permissions and limitations under the License.
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Reflection;
  19. using IronPython.Runtime;
  20. using IronPython.Runtime.Operations;
  21. using Microsoft.PythonTools.Interpreter;
  22. using Microsoft.Scripting;
  23. using Microsoft.Scripting.Generation;
  24. namespace Microsoft.IronPythonTools.Interpreter {
  25. class IronPythonParameterInfo : IParameterInfo {
  26. private readonly IronPythonInterpreter _interpreter;
  27. private RemoteInterpreterProxy _remote;
  28. private readonly ObjectIdentityHandle _parameterInfo;
  29. private string _name;
  30. private ParameterKind _paramKind;
  31. private IPythonType[] _paramType;
  32. private string _defaultValue;
  33. private static readonly string _noDefaultValue = "<No Default Value>"; // sentinel value to mark when an object doesn't have a default value
  34. public IronPythonParameterInfo(IronPythonInterpreter interpreter, ObjectIdentityHandle parameterInfo) {
  35. _interpreter = interpreter;
  36. _interpreter.UnloadingDomain += Interpreter_UnloadingDomain;
  37. _remote = _interpreter.Remote;
  38. _parameterInfo = parameterInfo;
  39. }
  40. private void Interpreter_UnloadingDomain(object sender, EventArgs e) {
  41. _remote = null;
  42. _interpreter.UnloadingDomain -= Interpreter_UnloadingDomain;
  43. }
  44. #region IParameterInfo Members
  45. public IList<IPythonType> ParameterTypes {
  46. get {
  47. if (_paramType == null) {
  48. var ri = _remote;
  49. if (ri != null) {
  50. _paramType = new[] { _interpreter.GetTypeFromType(ri.GetParameterPythonType(_parameterInfo)) };
  51. }
  52. }
  53. return _paramType;
  54. }
  55. }
  56. // FIXME
  57. public string Documentation {
  58. get { return ""; }
  59. }
  60. public string Name {
  61. get {
  62. if (_name == null) {
  63. var ri = _remote;
  64. _name = ri != null ? ri.GetParameterName(_parameterInfo) : string.Empty;
  65. }
  66. return _name;
  67. }
  68. }
  69. public bool IsParamArray {
  70. get {
  71. if (_paramKind == ParameterKind.Unknown) {
  72. var ri = _remote;
  73. _paramKind = ri != null ? ri.GetParameterKind(_parameterInfo) : ParameterKind.Unknown;
  74. }
  75. return _paramKind == ParameterKind.List;
  76. }
  77. }
  78. public bool IsKeywordDict {
  79. get {
  80. if (_paramKind == ParameterKind.Unknown) {
  81. var ri = _remote;
  82. _paramKind = ri != null ? ri.GetParameterKind(_parameterInfo) : ParameterKind.Unknown;
  83. }
  84. return _paramKind == ParameterKind.Dictionary;
  85. }
  86. }
  87. public string DefaultValue {
  88. get {
  89. if (_defaultValue == null) {
  90. var ri = _remote;
  91. _defaultValue = (ri != null ? ri.GetParameterDefaultValue(_parameterInfo) : null) ?? _noDefaultValue;
  92. }
  93. if (Object.ReferenceEquals(_defaultValue, _noDefaultValue)) {
  94. return null;
  95. }
  96. return _noDefaultValue;
  97. }
  98. }
  99. #endregion
  100. }
  101. }