Using a Custom Annotation3:20 with Chris Ramacciotti
@Doc annotation written, we can now use it like any other. In this video, we'll apply the annotation to the
MathUtils class and a few of its methods.
I'm back in our workspaces project and we're ready to use our doc annotation and 0:00 the MathUtils class. 0:04 First, we'll need to import the annotation itself, 0:05 import com.teamtreehouse.docgen.Doc. 0:10 We'll start by applying the annotation to the class itself. 0:14 And in this annotation, we'll need to include just a description since 0:18 parameters and return types will not apply to the class. 0:21 You can list the annotation on separate lines if you'd like to keep it well 0:25 formatted. 0:28 I'll say that this is a Utility class for commonly used math functions. 0:29 Notice that I've had to explicitly list D-E-S-C. 0:38 Remember, the only time you can omit the element name is when the element name 0:42 is exactly value. 0:46 Now, let's add some annotations to a few methods and make some of them incomplete 0:48 just to verify that our tool is able to catch both successes and failures. 0:52 For the triangle area method, I'll include a description for only one parameter. 0:58 So include our doc annotation, I'll put this on three separate lines. 1:03 For the description, I'll write that it calculates the area of a triangle. 1:07 I'll abbreviate here. 1:14 For the parameters, again, I will include a description for just one parameter. 1:16 And again, our params element is a string array, so 1:21 I'll have to use array notation with the curly braces. 1:24 And for the returnVal, I will say returns the calculated area of the triangle. 1:35 Cool. 1:44 For the distance method, I'll make the returnVal an empty string. 1:46 I'll include as its description that it calculates 1:57 the distance between the given points. 2:01 I'll include descriptions for both parameters, 2:07 the first one being the coordinates of one point, 2:11 the second one being the coordinates of another point. 2:15 And finally, the returnVal, as I said, I will leave as an empty string. 2:24 As for the quadraticRoots method, I'll leave this one out completely and 2:29 go right to the epsilon method. 2:33 For this one, I'll include only a description since it has no parameters and 2:36 is a void method. 2:40 I'll say that this displays the value of epsilon. 2:46 The arePointsClose method won't need documentation 2:55 to past our tools test since it's a private method. 2:58 And there you have it, 3:02 a class that utilizes the annotation that we wrote ourselves. 3:03 The writing of the doc annotation was fairly brief. 3:07 The lengthier work for us will come in the form of examining the presence of our 3:09 annotation on classes and methods through a technique called reflection. 3:13 More on that next. 3:18
You need to sign up for Treehouse in order to download course files.Sign up