FakeDriver.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. //
  2. // FakeDriver.cs: A fake ConsoleDriver for unit tests.
  3. //
  4. using System;
  5. using System.Buffers;
  6. using System.Collections.Generic;
  7. using System.Diagnostics;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Threading;
  11. using System.Text;
  12. // Alias Console to MockConsole so we don't accidentally use Console
  13. using Console = Terminal.Gui.FakeConsole;
  14. using Unix.Terminal;
  15. using static Terminal.Gui.WindowsConsole;
  16. using System.Drawing;
  17. namespace Terminal.Gui;
  18. /// <summary>
  19. /// Implements a mock ConsoleDriver for unit testing
  20. /// </summary>
  21. public class FakeDriver : ConsoleDriver {
  22. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  23. public class Behaviors {
  24. public bool UseFakeClipboard { get; internal set; }
  25. public bool FakeClipboardAlwaysThrowsNotSupportedException { get; internal set; }
  26. public bool FakeClipboardIsSupportedAlwaysFalse { get; internal set; }
  27. public Behaviors (bool useFakeClipboard = false, bool fakeClipboardAlwaysThrowsNotSupportedException = false, bool fakeClipboardIsSupportedAlwaysTrue = false)
  28. {
  29. UseFakeClipboard = useFakeClipboard;
  30. FakeClipboardAlwaysThrowsNotSupportedException = fakeClipboardAlwaysThrowsNotSupportedException;
  31. FakeClipboardIsSupportedAlwaysFalse = fakeClipboardIsSupportedAlwaysTrue;
  32. // double check usage is correct
  33. Debug.Assert (useFakeClipboard == false && fakeClipboardAlwaysThrowsNotSupportedException == false);
  34. Debug.Assert (useFakeClipboard == false && fakeClipboardIsSupportedAlwaysTrue == false);
  35. }
  36. }
  37. public static FakeDriver.Behaviors FakeBehaviors = new Behaviors ();
  38. public FakeDriver ()
  39. {
  40. if (FakeBehaviors.UseFakeClipboard) {
  41. Clipboard = new FakeClipboard (FakeBehaviors.FakeClipboardAlwaysThrowsNotSupportedException, FakeBehaviors.FakeClipboardIsSupportedAlwaysFalse);
  42. } else {
  43. if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
  44. Clipboard = new WindowsClipboard ();
  45. } else if (RuntimeInformation.IsOSPlatform (OSPlatform.OSX)) {
  46. Clipboard = new MacOSXClipboard ();
  47. } else {
  48. if (CursesDriver.Is_WSL_Platform ()) {
  49. Clipboard = new WSLClipboard ();
  50. } else {
  51. Clipboard = new CursesClipboard ();
  52. }
  53. }
  54. }
  55. }
  56. public override void End ()
  57. {
  58. FakeConsole.ResetColor ();
  59. FakeConsole.Clear ();
  60. }
  61. public override void Init (Action terminalResized)
  62. {
  63. FakeConsole.MockKeyPresses.Clear ();
  64. TerminalResized = terminalResized;
  65. Cols = FakeConsole.WindowWidth = FakeConsole.BufferWidth = FakeConsole.WIDTH;
  66. Rows = FakeConsole.WindowHeight = FakeConsole.BufferHeight = FakeConsole.HEIGHT;
  67. FakeConsole.Clear ();
  68. ResizeScreen ();
  69. // Call InitializeColorSchemes before UpdateOffScreen as it references Colors
  70. CurrentAttribute = MakeColor (Color.White, Color.Black);
  71. InitializeColorSchemes ();
  72. ClearContents ();
  73. }
  74. public override void UpdateScreen ()
  75. {
  76. var savedRow = FakeConsole.CursorTop;
  77. var savedCol = FakeConsole.CursorLeft;
  78. var savedCursorVisible = FakeConsole.CursorVisible;
  79. var top = 0;
  80. var left = 0;
  81. var rows = Rows;
  82. var cols = Cols;
  83. System.Text.StringBuilder output = new System.Text.StringBuilder ();
  84. Attribute redrawAttr = new Attribute ();
  85. var lastCol = -1;
  86. for (var row = top; row < rows; row++) {
  87. if (!_dirtyLines [row]) {
  88. continue;
  89. }
  90. FakeConsole.CursorTop = row;
  91. FakeConsole.CursorLeft = 0;
  92. _dirtyLines [row] = false;
  93. output.Clear ();
  94. for (var col = left; col < cols; col++) {
  95. lastCol = -1;
  96. var outputWidth = 0;
  97. for (; col < cols; col++) {
  98. if (!Contents [row, col].IsDirty) {
  99. if (output.Length > 0) {
  100. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  101. } else if (lastCol == -1) {
  102. lastCol = col;
  103. }
  104. if (lastCol + 1 < cols)
  105. lastCol++;
  106. continue;
  107. }
  108. if (lastCol == -1) {
  109. lastCol = col;
  110. }
  111. Attribute attr = Contents [row, col].Attribute.Value;
  112. // Performance: Only send the escape sequence if the attribute has changed.
  113. if (attr != redrawAttr) {
  114. redrawAttr = attr;
  115. FakeConsole.ForegroundColor = (ConsoleColor)attr.Foreground;
  116. FakeConsole.BackgroundColor = (ConsoleColor)attr.Background;
  117. }
  118. outputWidth++;
  119. var rune = (Rune)Contents [row, col].Runes [0];
  120. output.Append (rune.ToString ());
  121. if (rune.IsSurrogatePair () && rune.GetColumns () < 2) {
  122. WriteToConsole (output, ref lastCol, row, ref outputWidth);
  123. FakeConsole.CursorLeft--;
  124. }
  125. Contents [row, col].IsDirty = false;
  126. }
  127. }
  128. if (output.Length > 0) {
  129. FakeConsole.CursorTop = row;
  130. FakeConsole.CursorLeft = lastCol;
  131. foreach (var c in output.ToString ()) {
  132. FakeConsole.Write (c);
  133. }
  134. }
  135. }
  136. FakeConsole.CursorTop = 0;
  137. FakeConsole.CursorLeft = 0;
  138. //SetCursorVisibility (savedVisibitity);
  139. void WriteToConsole (StringBuilder output, ref int lastCol, int row, ref int outputWidth)
  140. {
  141. FakeConsole.CursorTop = row;
  142. FakeConsole.CursorLeft = lastCol;
  143. foreach (var c in output.ToString ()) {
  144. FakeConsole.Write (c);
  145. }
  146. output.Clear ();
  147. lastCol += outputWidth;
  148. outputWidth = 0;
  149. }
  150. FakeConsole.CursorTop = savedRow;
  151. FakeConsole.CursorLeft = savedCol;
  152. FakeConsole.CursorVisible = savedCursorVisible;
  153. }
  154. public override void Refresh ()
  155. {
  156. UpdateScreen ();
  157. UpdateCursor ();
  158. }
  159. #region Color Handling
  160. // Cache the list of ConsoleColor values.
  161. private static readonly HashSet<int> ConsoleColorValues = new HashSet<int> (
  162. Enum.GetValues (typeof (ConsoleColor)).OfType<ConsoleColor> ().Select (c => (int)c)
  163. );
  164. void SetColor (int color)
  165. {
  166. if (ConsoleColorValues.Contains (color & 0xffff)) {
  167. FakeConsole.BackgroundColor = (ConsoleColor)(color & 0xffff);
  168. }
  169. if (ConsoleColorValues.Contains ((color >> 16) & 0xffff)) {
  170. FakeConsole.ForegroundColor = (ConsoleColor)((color >> 16) & 0xffff);
  171. }
  172. }
  173. /// <remarks>
  174. /// In the FakeDriver, colors are encoded as an int; same as NetDriver
  175. /// Extracts the foreground and background colors from the encoded value.
  176. /// Assumes a 4-bit encoded value for both foreground and background colors.
  177. /// </remarks>
  178. internal override void GetColors (int value, out Color foreground, out Color background)
  179. {
  180. // Assume a 4-bit encoded value for both foreground and background colors.
  181. foreground = (Color)((value >> 16) & 0xF);
  182. background = (Color)(value & 0xF);
  183. }
  184. /// <remarks>
  185. /// In the FakeDriver, colors are encoded as an int; same as NetDriver
  186. /// However, the foreground color is stored in the most significant 16 bits,
  187. /// and the background color is stored in the least significant 16 bits.
  188. /// </remarks>
  189. public override Attribute MakeColor (Color foreground, Color background)
  190. {
  191. // Encode the colors into the int value.
  192. return new Attribute (
  193. value: ((((int)foreground) & 0xffff) << 16) | (((int)background) & 0xffff),
  194. foreground: foreground,
  195. background: background
  196. );
  197. }
  198. #endregion
  199. public ConsoleKeyInfo FromVKPacketToKConsoleKeyInfo (ConsoleKeyInfo consoleKeyInfo)
  200. {
  201. if (consoleKeyInfo.Key != ConsoleKey.Packet) {
  202. return consoleKeyInfo;
  203. }
  204. var mod = consoleKeyInfo.Modifiers;
  205. var shift = (mod & ConsoleModifiers.Shift) != 0;
  206. var alt = (mod & ConsoleModifiers.Alt) != 0;
  207. var control = (mod & ConsoleModifiers.Control) != 0;
  208. var keyChar = ConsoleKeyMapping.GetKeyCharFromConsoleKey (consoleKeyInfo.KeyChar, consoleKeyInfo.Modifiers, out uint virtualKey, out _);
  209. return new ConsoleKeyInfo ((char)keyChar, (ConsoleKey)virtualKey, shift, alt, control);
  210. }
  211. Key MapKey (ConsoleKeyInfo keyInfo)
  212. {
  213. switch (keyInfo.Key) {
  214. case ConsoleKey.Escape:
  215. return MapKeyModifiers (keyInfo, Key.Esc);
  216. case ConsoleKey.Tab:
  217. return keyInfo.Modifiers == ConsoleModifiers.Shift ? Key.BackTab : Key.Tab;
  218. case ConsoleKey.Clear:
  219. return MapKeyModifiers (keyInfo, Key.Clear);
  220. case ConsoleKey.Home:
  221. return MapKeyModifiers (keyInfo, Key.Home);
  222. case ConsoleKey.End:
  223. return MapKeyModifiers (keyInfo, Key.End);
  224. case ConsoleKey.LeftArrow:
  225. return MapKeyModifiers (keyInfo, Key.CursorLeft);
  226. case ConsoleKey.RightArrow:
  227. return MapKeyModifiers (keyInfo, Key.CursorRight);
  228. case ConsoleKey.UpArrow:
  229. return MapKeyModifiers (keyInfo, Key.CursorUp);
  230. case ConsoleKey.DownArrow:
  231. return MapKeyModifiers (keyInfo, Key.CursorDown);
  232. case ConsoleKey.PageUp:
  233. return MapKeyModifiers (keyInfo, Key.PageUp);
  234. case ConsoleKey.PageDown:
  235. return MapKeyModifiers (keyInfo, Key.PageDown);
  236. case ConsoleKey.Enter:
  237. return MapKeyModifiers (keyInfo, Key.Enter);
  238. case ConsoleKey.Spacebar:
  239. return MapKeyModifiers (keyInfo, keyInfo.KeyChar == 0 ? Key.Space : (Key)keyInfo.KeyChar);
  240. case ConsoleKey.Backspace:
  241. return MapKeyModifiers (keyInfo, Key.Backspace);
  242. case ConsoleKey.Delete:
  243. return MapKeyModifiers (keyInfo, Key.DeleteChar);
  244. case ConsoleKey.Insert:
  245. return MapKeyModifiers (keyInfo, Key.InsertChar);
  246. case ConsoleKey.PrintScreen:
  247. return MapKeyModifiers (keyInfo, Key.PrintScreen);
  248. case ConsoleKey.Oem1:
  249. case ConsoleKey.Oem2:
  250. case ConsoleKey.Oem3:
  251. case ConsoleKey.Oem4:
  252. case ConsoleKey.Oem5:
  253. case ConsoleKey.Oem6:
  254. case ConsoleKey.Oem7:
  255. case ConsoleKey.Oem8:
  256. case ConsoleKey.Oem102:
  257. case ConsoleKey.OemPeriod:
  258. case ConsoleKey.OemComma:
  259. case ConsoleKey.OemPlus:
  260. case ConsoleKey.OemMinus:
  261. if (keyInfo.KeyChar == 0) {
  262. return Key.Unknown;
  263. }
  264. return (Key)((uint)keyInfo.KeyChar);
  265. }
  266. var key = keyInfo.Key;
  267. if (key >= ConsoleKey.A && key <= ConsoleKey.Z) {
  268. var delta = key - ConsoleKey.A;
  269. if (keyInfo.Modifiers == ConsoleModifiers.Control) {
  270. return (Key)(((uint)Key.CtrlMask) | ((uint)Key.A + delta));
  271. }
  272. if (keyInfo.Modifiers == ConsoleModifiers.Alt) {
  273. return (Key)(((uint)Key.AltMask) | ((uint)Key.A + delta));
  274. }
  275. if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
  276. return MapKeyModifiers (keyInfo, (Key)((uint)Key.A + delta));
  277. }
  278. if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  279. if (keyInfo.KeyChar == 0) {
  280. return (Key)(((uint)Key.AltMask | (uint)Key.CtrlMask) | ((uint)Key.A + delta));
  281. } else {
  282. return (Key)((uint)keyInfo.KeyChar);
  283. }
  284. }
  285. return (Key)((uint)keyInfo.KeyChar);
  286. }
  287. if (key >= ConsoleKey.D0 && key <= ConsoleKey.D9) {
  288. var delta = key - ConsoleKey.D0;
  289. if (keyInfo.Modifiers == ConsoleModifiers.Alt) {
  290. return (Key)(((uint)Key.AltMask) | ((uint)Key.D0 + delta));
  291. }
  292. if (keyInfo.Modifiers == ConsoleModifiers.Control) {
  293. return (Key)(((uint)Key.CtrlMask) | ((uint)Key.D0 + delta));
  294. }
  295. if (keyInfo.Modifiers == (ConsoleModifiers.Shift | ConsoleModifiers.Alt)) {
  296. return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
  297. }
  298. if ((keyInfo.Modifiers & (ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  299. if (keyInfo.KeyChar == 0 || keyInfo.KeyChar == 30) {
  300. return MapKeyModifiers (keyInfo, (Key)((uint)Key.D0 + delta));
  301. }
  302. }
  303. return (Key)((uint)keyInfo.KeyChar);
  304. }
  305. if (key >= ConsoleKey.F1 && key <= ConsoleKey.F12) {
  306. var delta = key - ConsoleKey.F1;
  307. if ((keyInfo.Modifiers & (ConsoleModifiers.Shift | ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  308. return MapKeyModifiers (keyInfo, (Key)((uint)Key.F1 + delta));
  309. }
  310. return (Key)((uint)Key.F1 + delta);
  311. }
  312. if (keyInfo.KeyChar != 0) {
  313. return MapKeyModifiers (keyInfo, (Key)((uint)keyInfo.KeyChar));
  314. }
  315. return (Key)(0xffffffff);
  316. }
  317. KeyModifiers keyModifiers;
  318. private Key MapKeyModifiers (ConsoleKeyInfo keyInfo, Key key)
  319. {
  320. Key keyMod = new Key ();
  321. if ((keyInfo.Modifiers & ConsoleModifiers.Shift) != 0) {
  322. keyMod = Key.ShiftMask;
  323. }
  324. if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) {
  325. keyMod |= Key.CtrlMask;
  326. }
  327. if ((keyInfo.Modifiers & ConsoleModifiers.Alt) != 0) {
  328. keyMod |= Key.AltMask;
  329. }
  330. return keyMod != Key.Null ? keyMod | key : key;
  331. }
  332. Action<KeyEvent> _keyDownHandler;
  333. Action<KeyEvent> _keyHandler;
  334. Action<KeyEvent> _keyUpHandler;
  335. private CursorVisibility _savedCursorVisibility;
  336. public override void PrepareToRun (MainLoop mainLoop, Action<KeyEvent> keyHandler, Action<KeyEvent> keyDownHandler, Action<KeyEvent> keyUpHandler, Action<MouseEvent> mouseHandler)
  337. {
  338. _keyDownHandler = keyDownHandler;
  339. _keyHandler = keyHandler;
  340. _keyUpHandler = keyUpHandler;
  341. // Note: Net doesn't support keydown/up events and thus any passed keyDown/UpHandlers will never be called
  342. (mainLoop.MainLoopDriver as FakeMainLoop).KeyPressed += (consoleKey) => ProcessInput (consoleKey);
  343. }
  344. void ProcessInput (ConsoleKeyInfo consoleKey)
  345. {
  346. if (consoleKey.Key == ConsoleKey.Packet) {
  347. consoleKey = FromVKPacketToKConsoleKeyInfo (consoleKey);
  348. }
  349. keyModifiers = new KeyModifiers ();
  350. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Shift)) {
  351. keyModifiers.Shift = true;
  352. }
  353. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Alt)) {
  354. keyModifiers.Alt = true;
  355. }
  356. if (consoleKey.Modifiers.HasFlag (ConsoleModifiers.Control)) {
  357. keyModifiers.Ctrl = true;
  358. }
  359. var map = MapKey (consoleKey);
  360. if (map == (Key)0xffffffff) {
  361. if ((consoleKey.Modifiers & (ConsoleModifiers.Shift | ConsoleModifiers.Alt | ConsoleModifiers.Control)) != 0) {
  362. _keyDownHandler (new KeyEvent (map, keyModifiers));
  363. _keyUpHandler (new KeyEvent (map, keyModifiers));
  364. }
  365. return;
  366. }
  367. _keyDownHandler (new KeyEvent (map, keyModifiers));
  368. _keyHandler (new KeyEvent (map, keyModifiers));
  369. _keyUpHandler (new KeyEvent (map, keyModifiers));
  370. }
  371. /// <inheritdoc/>
  372. public override bool GetCursorVisibility (out CursorVisibility visibility)
  373. {
  374. visibility = FakeConsole.CursorVisible
  375. ? CursorVisibility.Default
  376. : CursorVisibility.Invisible;
  377. return FakeConsole.CursorVisible;
  378. }
  379. /// <inheritdoc/>
  380. public override bool SetCursorVisibility (CursorVisibility visibility)
  381. {
  382. _savedCursorVisibility = visibility;
  383. return FakeConsole.CursorVisible = visibility == CursorVisibility.Default;
  384. }
  385. /// <inheritdoc/>
  386. public override bool EnsureCursorVisibility ()
  387. {
  388. if (!(Col >= 0 && Row >= 0 && Col < Cols && Row < Rows)) {
  389. GetCursorVisibility (out CursorVisibility cursorVisibility);
  390. _savedCursorVisibility = cursorVisibility;
  391. SetCursorVisibility (CursorVisibility.Invisible);
  392. return false;
  393. }
  394. SetCursorVisibility (_savedCursorVisibility);
  395. return FakeConsole.CursorVisible;
  396. }
  397. public override void SendKeys (char keyChar, ConsoleKey key, bool shift, bool alt, bool control)
  398. {
  399. ProcessInput (new ConsoleKeyInfo (keyChar, key, shift, alt, control));
  400. }
  401. public void SetBufferSize (int width, int height)
  402. {
  403. FakeConsole.SetBufferSize (width, height);
  404. Cols = width;
  405. Rows = height;
  406. SetWindowSize (width, height);
  407. ProcessResize ();
  408. }
  409. public void SetWindowSize (int width, int height)
  410. {
  411. FakeConsole.SetWindowSize (width, height);
  412. if (width != Cols || height != Rows) {
  413. SetBufferSize (width, height);
  414. Cols = width;
  415. Rows = height;
  416. }
  417. ProcessResize ();
  418. }
  419. public void SetWindowPosition (int left, int top)
  420. {
  421. if (Left > 0 || Top > 0) {
  422. Left = 0;
  423. Top = 0;
  424. }
  425. FakeConsole.SetWindowPosition (Left, Top);
  426. }
  427. void ProcessResize ()
  428. {
  429. ResizeScreen ();
  430. ClearContents ();
  431. TerminalResized?.Invoke ();
  432. }
  433. public virtual void ResizeScreen ()
  434. {
  435. if (FakeConsole.WindowHeight > 0) {
  436. // Can raise an exception while is still resizing.
  437. try {
  438. FakeConsole.CursorTop = 0;
  439. FakeConsole.CursorLeft = 0;
  440. FakeConsole.WindowTop = 0;
  441. FakeConsole.WindowLeft = 0;
  442. } catch (System.IO.IOException) {
  443. return;
  444. } catch (ArgumentOutOfRangeException) {
  445. return;
  446. }
  447. }
  448. Clip = new Rect (0, 0, Cols, Rows);
  449. }
  450. public override void UpdateCursor ()
  451. {
  452. if (!EnsureCursorVisibility ()) {
  453. return;
  454. }
  455. // Prevents the exception of size changing during resizing.
  456. try {
  457. // BUGBUG: Why is this using BufferWidth/Height and now Cols/Rows?
  458. if (Col >= 0 && Col < FakeConsole.BufferWidth && Row >= 0 && Row < FakeConsole.BufferHeight) {
  459. FakeConsole.SetCursorPosition (Col, Row);
  460. }
  461. } catch (System.IO.IOException) {
  462. } catch (ArgumentOutOfRangeException) {
  463. }
  464. }
  465. #region Not Implemented
  466. public override void Suspend ()
  467. {
  468. throw new NotImplementedException ();
  469. }
  470. #endregion
  471. public class FakeClipboard : ClipboardBase {
  472. public Exception FakeException = null;
  473. string _contents = string.Empty;
  474. bool _isSupportedAlwaysFalse = false;
  475. public override bool IsSupported => !_isSupportedAlwaysFalse;
  476. public FakeClipboard (bool fakeClipboardThrowsNotSupportedException = false, bool isSupportedAlwaysFalse = false)
  477. {
  478. _isSupportedAlwaysFalse = isSupportedAlwaysFalse;
  479. if (fakeClipboardThrowsNotSupportedException) {
  480. FakeException = new NotSupportedException ("Fake clipboard exception");
  481. }
  482. }
  483. protected override string GetClipboardDataImpl ()
  484. {
  485. if (FakeException != null) {
  486. throw FakeException;
  487. }
  488. return _contents;
  489. }
  490. protected override void SetClipboardDataImpl (string text)
  491. {
  492. if (text == null) {
  493. throw new ArgumentNullException (nameof (text));
  494. }
  495. if (FakeException != null) {
  496. throw FakeException;
  497. }
  498. _contents = text;
  499. }
  500. }
  501. #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member
  502. }