Package Torello.JavaDoc
Annotation Type LinkJavaSource
-
@Retention(SOURCE) @Target({TYPE,FIELD,CONSTRUCTOR,METHOD}) @Repeatable(Torello.JavaDoc.hidden.LJSRepeatable.class) public @interface LinkJavaSource
LinkJavaSource Annotation.
This Annotation is a feature of the Java-Doc Upgrader that allows a user to insert HTML Anchor-Links to external / secondary HiLited-HTML Source-Code Files. These links can be specified by annotating a method, field, constructor, etc... (anEntity
) with this Annotation. When a Detail-Entity is annotated with this Annotation, the "@LinkJavaSource
-Annotation", the Java-Doc Upgrader Tool will generate an "External-Java" Button (HTML Anchor-Link) that connects a User to a Hi-Lited HTML Source-Code File that is named by thehandle
element.
The user has the option of specifying, explicity, line-number within that'.java'
Source-File. There are a series of additional Annotation-Elements which provide a seamless way of expressing, exactly, a specific method, field, constructor, annotation-element or enum-constant (These are the 5 available "Entities" of a Java-Doc Web-Page)
The only "Required Annotation Element" for this annotation is thehandle
element. This is required because it is how a user is expected to specify the actual Source-Code file that is expected to be linked to the Detail-Entity that is being annotated. The remainder of the available elements are all "Optional Annotation Elements" - meaning that the user does not have to provide values for these "parameters" when using this annotation.
The following are the two variants for using this Documentation-Upgrade Annotation:
- When specifying a File Handle (the only required annotation element), the
Upgrader Tool will generate a simple link to the top of the highlighted source file.
- In addition to the File Handle, users may provide any combination of the
following optional annotation elements to specify a more precise location within the source
file:
entity
- the type of entity (e.g., METHOD, FIELD, etc.). name
- the name of the method, field, or constructor. paramCount
- the number of parameters. paramNames
- the names of the parameters. paramTypesJOW
- the types of the parameters. typeName
- the full name of an inner or auxiliary type.
Providing any of these elements allows the Upgrader Tool to parse the Java file's Abstract Syntax Tree (AST) to identify the exact line number and create a link that directs the browser to that precise location. However, if the source file is short, parsing may not be necessary, and the link will default to the top of the file. For larger files, it's recommended to specify a location to enhance navigation. This feature improves the user experience by helping "My Users" guide "His Users" to the right part of the code.
@LinkJavaSource
Example
The following is an example of the use of this Annotation. The following example will attempt to elucidate
Example:
/** * This is an example of linking a Java Source-File, and providing the name of a method. * @return The value {@code '0'}. */ @LinkJavaSource(handle="FileHandle01", name="allFieldDetails", entity=FIELD) public int mainExample() { return 0; }
handle
: The User-Provided value'FileHandle01'
specifies a Syntax-HiLited'.java'
Source-File which has been assiged the moniker (handle)'FileHandle01'
name
: The assigned value'allFieldDetails'
states that this particular use of the@LinkJavaSource
-Annotation is requesting that a field named'allFieldDetails'
be directly linked - explicitly by that field's line-number within the Class' Source-File - to this particular Java-Doc Detail-HTML.entity
: The assigned value 'Entity.FIELD
' further specifies that the Entity / Member which is being named by this element, the'name'
element, (which, again, is'allFieldDetails'
as explained directly above) is indeed a field contained by the Syntax-HiLited ClassJavaDocHTMLFile
(rather than, say, a method, an enum-constant, a constructor etc...)
The Source which is Linked:
Here is the Source-Code to which this@LinkJavaSource
link shall be pointing on the Java-Doc Page which has placed this annotation. Note that it is not mandatory to specify a method, field or constructor when using the@LinkJavaSource
annotation. If the specific entity is not named inside the Annotation Elements / Parameters, then the<A HREF='...>
which is inserted shall point to directly to the top of the class, interface (the type) etc...
In the above example, their is actual entity that is named by the annotation. Specifically, the fieldJavaDocHTMLFile.allFieldDetails
is the actual member / entity that the user would like to show-case to his users on this particular Java-Doc File. Note that the HTML<A HREF='...>
which is inserted will be to the Hi-Lited Source-Code, rather than the Java-Doc HTML Page.
Example:
public final class JavaDocHTMLFile extends ParsedFile implements java.io.Serializable { ... // Much of this Class-Content has been eliminated for brevity. This class may be viewed // in its entirety on the Java-Doc Page within this particular package (Torello.JavaDoc) /** * This is the list of all fields in the "Field Details", stored as Reflection-HTML * instances */ public final ReadOnlyList<ReflHTML<Field>> allFieldDetails;
The Generated HTML:
The link which is inserted by this Ugrader-Tool will look as follows. The HTML depiction, directly below contains the inserted HTML. There is an Animated Red-Arrow which is pointing to the button that this Java-Annotation has asked be created. You may click on that Arrow-Button, itself, and your browser will be redirected to a segment of the Hi-Lited Source-Code which has been specified by this Annotation.
The Text-Label which states, simply, "External-Java" is the purpose of the@LinkJavaSource
Annotation. Again, as mentioned earlier, in this particular example, the link will redirect your browser to a Hi-Lited Source-File for the classJavaDocHTMLFile
(which is an actual class of the Java-Doc Upgrader-Class).
Note, Chat-GPT wrote all of the CSS for this entire thing. This is what I said to Mr. GPT and the below hiliting is what it came up with:
OK, you are thinking "boredom", and I'm trying to think of a giant thing that shoots out rainbows & unicorns.
-
mainExample
public int mainExample()
This is an example of linking a secondary or tertiary Hi-Lited Java Source-File, by placing this annotation on this (the primary) method.
Due to this Annotation-Placement, the Java-HTML Java-Doc Upgrader Tool has inserted a Label (directly above) which says "External-Java", along with an Anchor-Link Button that connects the user to the field which is specified inside the annotation.- Returns:
- The value
'0'
.
HiLiting the File:
Below is the'.json'
-File Object that maps the specified'handle'
(which, as should be obvious by the hiliting below, is'FileHandle01'
) - maps that'handle'
to an actual on disk'.java'
Source-Code File that needs to be hilited in order for any and all Annotations that are place on your Entities..
It should also be evident by inspecting the belowJSON-Object
, that this particular use of the@LinkJavaSource
-Annotation has been applied in order to hilite the Java-Doc Upgrader Source-File for the classJavaDocHTMLFile
This JSON-Object should be placed within any'.json'
-File as long as it is located in the directory:[Your Source Packge Dir]/upgrade-files/json-config/link-java-source/
Any'.json'
-Files which are located inside this directory will be parsed by the Upgrader's JSON-Parser, and if they have been properly formatted, the Java-Files which have been specified will by hilited and saved to the appropriate output'javadoc/'
directory.
Java Script Object Notation (JSON):
{ "Handle" : "FileHandle01", "JavaFileName" : "Torello/JavaDoc/package-source/Reflection HTML/JavaDocHTMLFile.java", "Parse" : true }
Handle:
This Json-Property simply informs the Java-Doc Upgrader that this particular Source-Code File should be passed through the Syntax-HiLiter, and saved to the[package-javadoc-dir]/ljs-hilite-files/
directory so that it may be properly linked to this - or any - HTML Detail-Element.
In order to acheive this, simply place the@LinkJavaSource
-Annotation on any Method, Field, Constructor, etc... within your Class and be sure to use thehandle="FileHandle01"
. When the Upgrader runs, it will automatically insert an HTML Link onto annotated HTML-Detail Element for the Java-Doc HTML-Page for that class.JavaFileName:
Simply put, the aforementioned'handle'
is, formally, being assigned to the Java Source-Code File'JavaDocHTMLFile.java'
. It is importat to note that this particular file (in this example) is actually one of the Source-Code Files for the Java-HTML Jar-Library. However, it is not a mandatory condition that the named Source-File be a part of your'.jar'
, Package or Project. Literally any Source-File within the entire File-System can be named for hiliting by the Upgrader's Syntax-HiLiter.Parse:
This is an optional Object-Property, and it's Default-Value is actually assigned'true'
. For this reason, generally, if this Json Object-Property is assigned a value at all that value will always be false! (Precisely because it's an optional property, which is by default'true'
).
When using the@LinkJavaSource
there may be many Source-Files in which there is no need to actually parse the actual'.java'
-Code itself. In fact, the only reason that an actual AST-Parse is ever necessary is if the user would like to name an actual entity (Method, Field, Constructor, etc...) within the Class-File / Source-File so that the explicit line-number within the file may be linked.
Any Source-File that is short enough such that actual direct Line-Number links would be largely superfluous should use the"Parse": false
Object-Property. An AST-Parse does, indeed, consume some cycles - so if it can be avoided, it should be in order to make your buid run faster!
Again, the actual naming of a Field, Method, Constructor, etc... for linking (using an HTML<A HREF='...>
) is of value only if the Source-File, itself, is extremely long and a link to the top of the Source-File would be confusing and unclear! The actual Line-Number Links into the file is is generated by running an AST-Parse of the file, and then identifying the Detail-Entities (Methods, Fields, Constructors, etc...) within that file. Afterwards the explicit Line-Numbers for the Detail-Entity is obtained by querying thecom.sun.soure.tree.LineMap
class.
This is a somewhat expensive operation!
Hi-Lited Source-Code:This File's Source Code:
- View Here: Torello/JavaDoc/LinkJavaSource.java
- Open New Browser-Tab: Torello/JavaDoc/LinkJavaSource.java
File Size: 7,417 Bytes Line Count: 169 '\n' Characters Found
Annotation Processor Class:
- View Here: ../ReflAnnotations/Processor/LinkJSourceProcessor.java
- Open New Browser-Tab: ../ReflAnnotations/Processor/LinkJSourceProcessor.java
File Size: 10,037 Bytes Line Count: 261 '\n' Characters Found
Annotation Mirror Class:
- View Here: ../ReflAnnotations/Mirror/LJSMirror.java
- Open New Browser-Tab: ../ReflAnnotations/Mirror/LJSMirror.java
File Size: 15,767 Bytes Line Count: 348 '\n' Characters Found
All Detail-Annotation Mirrors:
- View Here: ../ReflAnnotations/Mirror/ReflAnnotationMirrors.java
- Open New Browser-Tab: ../ReflAnnotations/Mirror/ReflAnnotationMirrors.java
File Size: 8,610 Bytes Line Count: 205 '\n' Characters Found
- When specifying a File Handle (the only required annotation element), the
Upgrader Tool will generate a simple link to the top of the highlighted source file.
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description String
handle
TheString
-Value which is provided to this element specifies which HiLited Source-Code File to use for the URL-Link in this<A HREF>
-Button.
-
Optional Element Summary
Specify which Source-File to be linked due to this Annotation's Placement Modifier and Type Optional Element Description Entity
entity
When specifying a Line-Number to use for the link, identifies which kind ofEntity
is being linked.String
name
When specifying a Line-Number to use, identifies theEntity
or "Member" Name.byte
paramCount
When specifying the Line-Number of either aMethod
or aConstructor
, identifies the number of parameters contained by the Method or Constructor Signature.String[]
paramNames
When specifying the Line-Number of either aMethod
or aConstructor
, identifies the names of the parameters accepted by the Method or Constructor.String[]
paramTypesJOW
When specifying the Line-Number of either aMethod
or aConstructor
, identifies the Single-Word-Names for the'types'
of the Method's or Constructor's parameters.String
typeName
ThisString
may be used to specify an 'Inner-Type', 'Nested-Type' or possibly an 'Auxilliary-Class'.
-
-
-
Element Detail
-
handle
java.lang.String handle
TheString
-Value which is provided to this element specifies which HiLited Source-Code File to use for the URL-Link in this<A HREF>
-Button.
This must be equal to one of the listed File-Handle's which you have placed inside of your'upgrade-files/json-config/ExtraJavaHiLiting.json'
file.- Code:
- Exact Element Declaration:
public String handle();
-
-
-
typeName
java.lang.String typeName
ThisString
may be used to specify an 'Inner-Type', 'Nested-Type' or possibly an 'Auxilliary-Class'.
This is an optional element, and should only be used if the {@code '.java'} Source-File which you've specified actually has more than one class or type that resides in it. For example, you may have specified a file named'MyMainClass.java'
which could be a class having several inner-classes such as'MyMainClass.MyInnerClass1', 'MyInnerClass2'
and'MyMainClass.MyInnerClass3'}
.
When this Optional-Annotation Element is non-null, it must be used to explicity name the Inner-type whoseMETHOD, FIELD
orCONSTRUCTOR
you are attempting to link.
If you'.java'
-File has an 'Auxiliary Class', that class may be indicated by simply typing the Auxiliary Class' Name.
WARNING:
This Annotation-Element mandates that you leave-off or "elide" any and all Package-Name Information that may be included as part of your Class-Name. If you had a'.java'
-File that contained a class whose "Complete-Name" or "Full-Name" were"com.MyCompany.MyPackage.MyMainClass"
, you would want to specify that class by using the Class-Name Only, leaving off all Package-Names!
You would enter:"MyMainClass.MyInnerClass1"
Rather than entering:"com.MyCompany.MyPackage.MyInnerClass1"
Auxiliary Class:
A Java 'Auxiliary Class' is just a Second Class Definition that has been placed inside of a'.java'
-File, in addition to whatever class or interface has been defined at the top of the file.
An 'Auxiliary Class' may not be declared public, and it is only usable inside the'.java'
-File in which it resides.
In order to specify an 'Auxilary Class' when linking another'.java'
Source-Code File, just type the name of that class, again leaving off any containing Java Package Information from that class or interface's name.- Default:
- ""
- Code:
- Exact Element Declaration:
public String typeName() default
-
-
-
entity
Entity entity
When specifying a Line-Number to use for the link, identifies which kind ofEntity
is being linked.
TheEntity
is a simple Java-Doc Upgrader Enumeration that specifies whether the named "thing" whose Source-Code you would like Hi-Lited, linked & inserted is the Source-Code for amethod
, or for afield
or anenumerated-constant
, etc.
This Annotation-Element is optional, and if no value were provided when placing aLinkJavaSource
-Annotation on a target, the default value isMETHOD
.
The vast majority of 'things' (entities) which are linked within Java-Doc Documentation-Pages are HTML-Anchor Elements to methods within other'.java'
Source-Files.Constructors
,Fields
and evenEnumeration-Constants
, may actually be linked as well, but when doing so, this Annotation-Value must be assigned a value.- Default:
- Torello.JavaDoc.Entity.METHOD
- Code:
- Exact Element Declaration:
public Entity entity() default
-
-
-
name
java.lang.String name
When specifying a Line-Number to use, identifies theEntity
or "Member" Name.
This must be the name of a Method, Field, Constructor or Enum-Constant located inside one of the classes that reside in the file you have specified withhandle()
This element likely could be referred to as the class' "Member-Name." In Java-Doc-Upgrader parlance a type's "members" are referred to as "Entities", and this element coud be called the "Member-Name". Since Java-Oracle does not constructors to be "members" of a type, the term "entity" was chosen instead. In any case, this field should be the name of the entity you would like to see linked to your Detail-HTML.
These six entites are the constants listed within the enum, specificallymethods
,fields
,constructors
,enumerated-constatns
(which are only valid within 'enum' types), and finallyannotation-elements
. You may request an HTML Anchor-Element (<A HREF=...>
) link be inserted into your Detail HTML by specifying the name of the entity / member whose line number you want linked.
Thisname
must be the name of the entity whose source should be linked by a button that redirects the browser's {@code URL} onto the hilited Source-Code Page for that type.
Inner-Classes may also be located/contained within a type, and they are therefore also considered "Entities" by the Java-Doc Upgrader.
Optional vs. Required
This Annotation Element is, indeed, optional and if you do not provide a name to this element, the Java Annotation-Processor will not flag your annotation as an error.- Default:
- ""
- Code:
- Exact Element Declaration:
public String name() default
-
-
-
paramCount
byte paramCount
When specifying the Line-Number of either aMethod
or aConstructor
, identifies the number of parameters contained by the Method or Constructor Signature.
It is sometimes easier and faster to simply pass a parameter count when specifying either a Method or a Constructor.
Note that if this element is used, the number that is passed by the user cannot be negative. This Annotation-Element should only be used on when specifying a Method or a Constructor.- Default:
- (byte)0xff
- Code:
- Exact Element Declaration:
public byte paramCount() default
-
-
-
paramNames
java.lang.String[] paramNames
When specifying the Line-Number of either aMethod
or aConstructor
, identifies the names of the parameters accepted by the Method or Constructor.
If a constructor or method is to be link, one option for specifying which method in the'.java'
Source-File should be linked would be to include the method's list of parameter names.- Default:
- {}
- Code:
- Exact Element Declaration:
public String[] paramNames() default
-
-
-
paramTypesJOW
java.lang.String[] paramTypesJOW
When specifying the Line-Number of either aMethod
or aConstructor
, identifies the Single-Word-Names for the'types'
of the Method's or Constructor's parameters.
For example, if a method such asboolean equals(Object other)
were needing to be linked, the "Single Word Name" would beString
, rather than'java.lang.String'
If a constructor or method is to be link, one option for specifying which method in the'.java'
Source-File should be linked would be to include the method's list of parameter types.- Default:
- {}
- Code:
- Exact Element Declaration:
public String[] paramTypesJOW() default
-
-