PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/jsdoc_toolkit-2.3.2/jsdoc-toolkit/app/test/jsdoc_test.js

http://jsdoc-toolkit.googlecode.com/
JavaScript | 477 lines | 133 code | 60 blank | 284 comment | 7 complexity | 7fa42b2e8f1f1ff86cda63afc61b83b3 MD5 | raw file
  1. /**
  2. * @fileoverview This file is to be used for testing the JSDoc parser
  3. * It is not intended to be an example of good JavaScript OO-programming,
  4. * nor is it intended to fulfill any specific purpose apart from
  5. * demonstrating the functionality of the
  6. * <a href='http://sourceforge.net/projects/jsdoc'>JSDoc</a> parser
  7. *
  8. * @author Gabriel Reid gab_reid@users.sourceforge.net
  9. * @version 0.1
  10. */
  11. /**
  12. * Construct a new Shape object.
  13. * @class This is the basic Shape class.
  14. * It can be considered an abstract class, even though no such thing
  15. * really existing in JavaScript
  16. * @constructor
  17. * @throws MemoryException if there is no more memory
  18. * @throws GeneralShapeException rarely (if ever)
  19. * @return {Shape|Coordinate} A new shape.
  20. */
  21. function Shape(){
  22. /**
  23. * This is an example of a function that is not given as a property
  24. * of a prototype, but instead it is assigned within a constructor.
  25. * For inner functions like this to be picked up by the parser, the
  26. * function that acts as a constructor <b>must</b> be denoted with
  27. * the <b>&#64;constructor</b> tag in its comment.
  28. * @type String
  29. */
  30. this.getClassName = function(){
  31. return "Shape";
  32. }
  33. /**
  34. * This is an inner method, just used here as an example
  35. * @since version 0.5
  36. * @author Sue Smart
  37. */
  38. function addReference(){
  39. // Do nothing...
  40. }
  41. }
  42. /**
  43. * Create a new Hexagon instance.
  44. * @extends Shape
  45. * @class Hexagon is a class that is a <i>logical</i> sublcass of
  46. * {@link Shape} (thanks to the <code>&#64;extends</code> tag), but in
  47. * reality it is completely unrelated to Shape.
  48. * @param {int} sideLength The length of one side for the new Hexagon
  49. * @example
  50. * var h = new Hexagon(2);
  51. * @example
  52. * if (hasHex) {
  53. * hex = new Hexagon(5);
  54. * color = hex.getColor();
  55. * }
  56. */
  57. function Hexagon(sideLength) {
  58. }
  59. /**
  60. * This is an unattached (static) function that adds two integers together.
  61. * @param {int} One The first number to add
  62. * @param {int} Two The second number to add
  63. * @author Gabriel Reid
  64. * @deprecated So you shouldn't use it anymore! Use {@link Shape#getClassName} instead.
  65. */
  66. function Add(One, Two){
  67. return One + Two;
  68. }
  69. /**
  70. * The color of this shape
  71. * @type Color
  72. */
  73. Shape.prototype.color = null;
  74. /**
  75. * The border of this shape.
  76. * @field
  77. * @type int
  78. */
  79. Shape.prototype.border = function(){return border;};
  80. /*
  81. * These are all the instance method implementations for Shape
  82. */
  83. /**
  84. * Get the coordinates of this shape. It is assumed that we're always talking
  85. * about shapes in a 2D location here.
  86. * @requires The {@link Shape} class
  87. * @returns A Coordinate object representing the location of this Shape
  88. * @type Coordinate[]
  89. */
  90. Shape.prototype.getCoords = function(){
  91. return this.coords;
  92. }
  93. /**
  94. * Get the color of this shape.
  95. * @see #setColor
  96. * @see The <a href="http://example.com">Color</a> library.
  97. * @link Shape
  98. * @type Color
  99. */
  100. Shape.prototype.getColor = function(){
  101. return this.color;
  102. }
  103. /**
  104. * Set the coordinates for this Shape
  105. * @param {Coordinate} coordinates The coordinates to set for this Shape
  106. */
  107. Shape.prototype.setCoords = function(coordinates){
  108. this.coords = coordinates;
  109. }
  110. /**
  111. * Set the color for this Shape
  112. * @param {Color} color The color to set for this Shape
  113. * @param other There is no other param, but it can still be documented if
  114. * optional parameters are used
  115. * @throws NonExistantColorException (no, not really!)
  116. * @see #getColor
  117. */
  118. Shape.prototype.setColor = function(color){
  119. this.color = color;
  120. }
  121. /**
  122. * Clone this shape
  123. * @returns A copy of this shape
  124. * @type Shape
  125. * @author Gabriel Reid
  126. */
  127. Shape.prototype.clone = function(){
  128. return new Shape();
  129. }
  130. /**
  131. * Create a new Rectangle instance.
  132. * @class A basic rectangle class, inherits from Shape.
  133. * This class could be considered a concrete implementation class
  134. * @constructor
  135. * @param {int} width The optional width for this Rectangle
  136. * @param {int} height Thie optional height for this Rectangle
  137. * @author Gabriel Reid
  138. * @see Shape is the base class for this
  139. * @augments Shape
  140. * @hilited
  141. */
  142. function Rectangle(width, // This is the width
  143. height // This is the height
  144. ){
  145. if (width){
  146. this.width = width;
  147. if (height){
  148. this.height = height;
  149. }
  150. }
  151. }
  152. /* Inherit from Shape */
  153. Rectangle.prototype = new Shape();
  154. /**
  155. * Value to represent the width of the Rectangle.
  156. * <br>Text in <b>bold</b> and <i>italic</i> and a
  157. * link to <a href="http://sf.net">SourceForge</a>
  158. * @private
  159. * @type int
  160. */
  161. Rectangle.prototype.width = 0;
  162. /**
  163. * Value to represent the height of the Rectangle
  164. * @private
  165. * @type int
  166. */
  167. Rectangle.prototype.height = 0;
  168. /**
  169. * Get the type of this object.
  170. * @type String
  171. */
  172. Rectangle.prototype.getClassName= function(){
  173. return "Rectangle";
  174. }
  175. /**
  176. * Get the value of the width for the Rectangle
  177. * @type int
  178. * @see Rectangle#setWidth
  179. */
  180. Rectangle.prototype.getWidth = function(){
  181. return this.width;
  182. }
  183. /**
  184. * Get the value of the height for the Rectangle.
  185. * Another getter is the {@link Shape#getColor} method in the
  186. * {@link Shape} base class.
  187. * @return The height of this Rectangle
  188. * @type int
  189. * @see Rectangle#setHeight
  190. */
  191. Rectangle.prototype.getHeight = function(){
  192. return this.height;
  193. }
  194. /**
  195. * Set the width value for this Rectangle.
  196. * @param {int} width The width value to be set
  197. * @see #setWidth
  198. */
  199. Rectangle.prototype.setWidth = function(width){
  200. this.width = width;
  201. }
  202. /**
  203. * Set the height value for this Rectangle.
  204. * @param {int} height The height value to be set
  205. * @see #getHeight
  206. */
  207. Rectangle.prototype.setHeight = function(height){
  208. this.height = height;
  209. }
  210. /**
  211. * Get the value for the total area of this Rectangle
  212. * @return total area of this Rectangle
  213. * @type int
  214. */
  215. Rectangle.prototype.getArea = function(){
  216. return width * height;
  217. }
  218. /**
  219. * Create a new Square instance.
  220. * @class A Square is a subclass of {@link Rectangle}
  221. * @param {int} width The optional width for this Rectangle
  222. * @param {int} height The optional height for this Rectangle
  223. * @augments Rectangle
  224. */
  225. function Square(width, height){
  226. if (width){
  227. this.width = width;
  228. if (height){
  229. this.height = height;
  230. }
  231. }
  232. }
  233. /* Square is a subclass of Rectangle */
  234. Square.prototype = new Rectangle();
  235. /**
  236. * Set the width value for this Shape.
  237. * @param {int} width The width value to be set
  238. * @see #getWidth
  239. */
  240. Square.prototype.setWidth = function(width){
  241. this.width = this.height = width;
  242. }
  243. /**
  244. * Set the height value for this Shape
  245. * Sets the {@link Rectangle#height} attribute in the Rectangle.
  246. * @param {int} height The height value to be set
  247. */
  248. Square.prototype.setHeight = function(height){
  249. this.height = this.width = height;
  250. }
  251. /**
  252. * Create a new Circle instance based on a radius.
  253. * @class Circle class is another subclass of Shape
  254. * @extends Shape
  255. * @param {int} radius The optional radius of this {@link Circle }
  256. * @mixin Square.prototype.setWidth as this.setDiameter
  257. */
  258. function Circle(radius){
  259. if (radius) {
  260. /** The radius of the this Circle. */
  261. this.radius = radius;
  262. }
  263. }
  264. /* Circle inherits from {@link Shape} */
  265. Circle.prototype = new Shape();
  266. /**
  267. * The radius value for this Circle
  268. * @private
  269. * @type int
  270. */
  271. Circle.prototype.radius = 0;
  272. /**
  273. * A very simple class (static) field that is also a constant
  274. * @final
  275. * @type float
  276. */
  277. Circle.PI = 3.14;
  278. /**
  279. * Get the radius value for this Circle
  280. * @type int
  281. * @see #setRadius
  282. */
  283. Circle.prototype.getRadius = function(){
  284. return this.radius;
  285. }
  286. /**
  287. * Set the radius value for this Circle
  288. * @param {int} radius The {@link Circle#radius} value to set
  289. * @see #getRadius
  290. */
  291. Circle.prototype.setRadius = function(radius){
  292. this.radius = radius;
  293. }
  294. /**
  295. * An example of a class (static) method that acts as a factory for Circle
  296. * objects. Given a radius value, this method creates a new Circle.
  297. * @param {int} radius The radius value to use for the new Circle.
  298. * @type Circle
  299. */
  300. Circle.createCircle = function(radius){
  301. return new Circle(radius);
  302. }
  303. /**
  304. * Create a new Coordinate instance based on x and y grid data.
  305. * @class Coordinate is a class that can encapsulate location information.
  306. * @param {int} [x=0] The optional x portion of the Coordinate
  307. * @param {int} [y=0] The optinal y portion of the Coordinate
  308. */
  309. function Coordinate(x, y){
  310. if (x){
  311. this.x = x;
  312. if (y){
  313. this.y = y;
  314. }
  315. }
  316. }
  317. /**
  318. * The x portion of the Coordinate
  319. * @type int
  320. * @see #getX
  321. * @see #setX
  322. */
  323. Coordinate.prototype.x = 0;
  324. /**
  325. * The y portion of the Coordinate
  326. * @type int
  327. * @see #getY
  328. * @see #setY
  329. */
  330. Coordinate.prototype.y = 0;
  331. /**
  332. * Gets the x portion of the Coordinate.
  333. * @type int
  334. * @see #setX
  335. */
  336. Coordinate.prototype.getX = function(){
  337. return this.x;
  338. }
  339. /**
  340. * Get the y portion of the Coordinate.
  341. * @type int
  342. * @see #setY
  343. */
  344. Coordinate.prototype.getY = function(){
  345. return this.y;
  346. }
  347. /**
  348. * Sets the x portion of the Coordinate.
  349. * @param {int} x The x value to set
  350. * @see #getX
  351. */
  352. Coordinate.prototype.setX = function(x){
  353. this.x = x;
  354. }
  355. /**
  356. * Sets the y portion of the Coordinate.
  357. * @param {int} y The y value to set
  358. * @see #getY
  359. */
  360. Coordinate.prototype.setY = function(y){
  361. this.y = y;
  362. }
  363. /**
  364. * @class This class exists to demonstrate the assignment of a class prototype
  365. * as an anonymous block.
  366. */
  367. function ShapeFactory(){
  368. }
  369. ShapeFactory.prototype = {
  370. /**
  371. * Creates a new {@link Shape} instance.
  372. * @return A new {@link Shape}
  373. * @type Shape
  374. */
  375. createShape: function(){
  376. return new Shape();
  377. }
  378. }
  379. /**
  380. * An example of a singleton class
  381. * @param ... Arguments represent {@link coordinate}s in the shape.
  382. * @constructor
  383. */
  384. MySingletonShapeFactory = function(){
  385. /**
  386. * Get the next {@link Shape}
  387. * @type Shape
  388. * @return A new {@link Shape}
  389. */
  390. this.getShape = function(){
  391. return null;
  392. }
  393. }
  394. /**
  395. * Create a new Foo instance.
  396. * @class This is the Foo class. It exists to demonstrate 'nested' classes.
  397. * @constructor
  398. * @see Foo.Bar
  399. */
  400. function Foo(){}
  401. /**
  402. * Creates a new instance of Bar.
  403. * @class This class exists to demonstrate 'nested' classes.
  404. * @constructor
  405. * @see Foo.Bar
  406. */
  407. function Bar(){}
  408. /**
  409. * Nested class
  410. * @constructor
  411. */
  412. Foo.Bar = function(){
  413. /** The x. */ this.x = 2;
  414. }
  415. Foo.Bar.prototype = new Bar();
  416. /** The y. */
  417. Foo.Bar.prototype.y = '3';