Package Torello.JavaDoc
Class EnumConstant
- java.lang.Object
-
- Torello.JavaDoc.Declaration
-
- Torello.JavaDoc.EnumConstant
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<EnumConstant>
public class EnumConstant extends Declaration implements java.io.Serializable, java.lang.Comparable<EnumConstant>, java.lang.Cloneable
Extension of Packagejava.lang.reflect
This class provides a hook into the native Java Parser JAR LibraryEnumConstantDeclaration
.
This class is heavily used internally, and can be used (if needed) to modify Java Doc Web-Pages, programmatically.
HTML Processors that sort the Web-Page "Summary-Tables" will provide instances of this class to your Summary-Sorter Handler methods. Summary-Sorter handlers usually implement theSummarySorterHelper
interface; please review that class for more about sorting Java-Doc Page Summary Tables.
The HTML Processors that upgrade Web-Page "Detail Elements" also rely heavily on this class. Please review the class:ReflHTML
for more information about Java-Doc Web-Page Detail Sections.Java Parser Bridge: Holds all information extracted from'.java' enum
Source-Files about Enumerated-Constants's identified in that'enum'
file.
Instances of this Class are Obtained From:
Use of the Reflection-HTML API is *NOT REQUIRED* to perform a standard Java Doc HTML File Upgrade. This "extra API" allows for programmatic modification of Java Doc HTML. This class contains quite a bit of reflected information, and furthermore, here there is a hook to the Native Java Parser Reflection Class.ReflHTML
&SummaryTableHTML
The purpose of this bridge is provide a pared down, easier-to-use (but-with less-features) version of the publicly available "JavaParser" package. Thisclass EnumConstant
allows for storing the name and (optional) initializations for anEnumerated Constant
. These are found inside of a Java'enum'
type-definition.
There is a Java-Parser Library that is required to use this Package. The Java Doc Upgrader Package / Tool will not work without this'.jar'
file being placed in yourCLASSPATH
environment-variable. That'.jar'
is available here:
http://developer.torello.directory/ralphsReference/jars/javaparser-core-3.16.2.jar
There is a book available and an internet "Gitter" support web-site chat-room with some of the people involved in writing this library. There are quite a number of available jars in the "Master Jar Distribution" - but the core library jar is fully sufficient for running the tasks needed by this Java-Doc Upgrade Tool's logic.
Reflection-Classes Inheritance-Diagram
IMPORTANT:
All reflection classes above, also contain an additional (transient
, non-Serializable
) field that hooks into the native Java-Parser Library classes, providing an option for a more in-depth or complete analysis using that Library's features & extensive utilities.- See Also:
- Serialized Form
Hi-Lited Source-Code:- View Here: Torello/JavaDoc/EnumConstant.java
- Open New Browser-Tab: Torello/JavaDoc/EnumConstant.java
-
-
Field Summary
Serializable ID Modifier and Type Field static long
serialVersionUID
Reflection & Inspection final-String(s) Modifier and Type Field protected String[]
paramExpressions
Source-Parser Library-Hook References (Transient / Not Serializable) Modifier and Type Field EnumConstantDeclaration
enumConstantDeclaration
com.sun.source.tree.VariableTree
variableTree
-
Fields inherited from class Torello.JavaDoc.Declaration
annotations, body, entity, id, jdComment, location, modifiers, name, signature
-
-
Constructor Summary
Constructors Constructor EnumConstant(com.sun.source.tree.VariableTree vt, TreeUtils util)
-
Method Summary
Methods: Parameter-Initialization Expressions, Reflection Modifier and Type Method String[]
getParamExpressions()
void
getParamExpressions(Consumer<String> acceptParamExpressionAsStringConsumer)
boolean
hasParamExpressions()
int
numParamExpressions()
Methods: interface java.lang.Cloneable Modifier and Type Method EnumConstant
clone()
Methods: interface java.lang.Comparable Modifier and Type Method int
compareTo(EnumConstant ec)
Methods: class java.lang.Object Modifier and Type Method boolean
equals(EnumConstant other)
String
toString()
String
toString(int flags)
-
Methods inherited from class Torello.JavaDoc.Declaration
getAnnotations, getAnnotations, getModifiers, getModifiers, hasAnnotations, hasModifier, hasModifiers, numAnnotations, numModifiers
-
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
This fulfils the SerialVersion UID requirement for all classes that implement Java'sinterface java.io.Serializable
. Using theSerializable
Implementation offered by java is very easy, and can make saving program state when debugging a lot easier. It can also be used in place of more complicated systems like "hibernate" to store data as well.- See Also:
- Constant Field Values
- Code:
- Exact Field Declaration Expression:
public static final long serialVersionUID = 1;
-
paramExpressions
protected final java.lang.String[] paramExpressions
The parameters passed to the constructor that constructed the enumerated-constant instance.
Manyenum's
do not use constructors for their constants - using a constructor is an extra-feature that allows other, informational data to be ascribed to the constant. If no constructor was used, then there (obviously) couldn't have been any expressions passed to a constructor for the constant. In such cases, this field will be null.
NOTE: Access to the internal-arrays is restricted as'protected'
to prevent any accidental or intentional changing of the values. This is to ensure that the contents of this class are always consistent with the source-code'.java'
file on disk.- Code:
- Exact Field Declaration Expression:
protected final String[] paramExpressions;
-
enumConstantDeclaration
public final transient com.github.javaparser.ast.body.EnumConstantDeclaration enumConstantDeclaration
Hook Reference to Java-Parser Refletion Class
Though this class offers a streamlined set of reflection features, the Native Java-Parser Library Reflection-Classes offer a near-complete set of analysis tools for just about any kind of code-analysis neccessary. If you would like your Java Doc Pages to include more analytical-information, this field is provided as a convenience for such purposes.
If a user decides to make use of the Java-ParserEnumConstantDeclaration
instance that was used to build thisEnumConstant
, it may be retrieved from thistransient
field.- Code:
- Exact Field Declaration Expression:
public final transient EnumConstantDeclaration enumConstantDeclaration;
-
variableTree
public final transient com.sun.source.tree.VariableTree variableTree
Hook Reference to Sun/Oracle Parser-Refletion Class
Though this class offers a streamlined set of reflection features, the Native Oracle Library Reflection-Classes offer a detailed AST interface into the standard Java Compiler. If you would like to use these Tree's to provide further code analysis on your Java-Doc Pages, this field is provided as a convenience for such purposes.
If a user decides to make use of the native Sun/OracleVariableTree
instance that was used to build thisEnumConstant
instance, it may be retrieved from thistransient
field.
NOTE: The packagecom.sun.source.tree
"reuses" or "overloads" theVariableTree
object such that it may represent either a Field, or an Enumerated Constant.- Code:
- Exact Field Declaration Expression:
public final transient VariableTree variableTree;
-
-
Constructor Detail
-
EnumConstant
public EnumConstant(com.sun.source.tree.VariableTree vt, TreeUtils util)
Constructs an instance of this class,EnumConstant
. A parsed AST node that has been compiled by Java's Source-Parser, and the exact instance ofTreeUtils
that generated the parsed node must be passed by parameter to this constructor.- Parameters:
vt
- Any instance of a Java ASTEnumConstant
Node. It is required that this member / entity AST-Node is one which the Java-Compiler generated using the exact sameTreeUtils
instance also being passed by parameter here.
Any time that the Java-Compiler parses a 'EnumConstant' Member / Entity, that member is converted into an instance of the AST-NodeVariableTree
.util
- This utility class will contain references to all of the most important instances that are used when compiling a standard Java Souce-Code ('.java'
File). In this Java-Doc Web-Page'Upgrade'
Package, whenever any'.java'
file is compiled and converted into an Abstract Syntax Tree, a new instance ofTreeUtils
will be created / generated.
Each source-file in a Java-Project will be compiled once, and converted into an instance ofTreeUtils
. Note that it is imperative that theTreeUtils
instance being passed to this method is the same instance that was used to generate theEnumConstant
-Node instance with this constructor-invocation.
An instance ofTreeUtils
. is always available as a member-field of the top-level classJavaDocHTMLFile.treeUtils
.
-
-
Method Detail
-
getParamExpressions
public java.lang.String[] getParamExpressions()
Retrieves the list of'paramExpressions'
- which may or may not have been used to construct this constant - asString
-array.- Returns:
- An instance of
String[]
that employs theclone()
method of the internal data-structure, protecting its contents. If thisEnumConstant
did not employ a constructor, or that constructor was a zero-argument constructor, then this method will return null. - Code:
- Exact Method Body:
return (paramExpressions != null) ? paramExpressions.clone() : null;
-
getParamExpressions
public void getParamExpressions (java.util.function.Consumer<java.lang.String> acceptParamExpressionAsStringConsumer)
Invokes a user-providedConsumer
with each of theString's
contained by the internalString[]
-ArrayparamExpressions
.- Parameters:
acceptParamExpressionAsStringConsumer
- This should be anyjava.util.function.Consumer
that will accept a reference from thegetParamExpressions
array, and perform whatever operations needed.- See Also:
paramExpressions
- Code:
- Exact Method Body:
if (paramExpressions != null) for (String paramExpression : paramExpressions) acceptParamExpressionAsStringConsumer.accept(paramExpression);
-
hasParamExpressions
public boolean hasParamExpressions()
Reports whether this instance ofEnumConstant
was constructed using a constructor that accepts parameters. This method simply returns whether or not the internalparamExpressions
array is non-null and has length bigger than zero.- Returns:
- Returns
TRUE
if there were any modifiers -public, static, final
etc... - that were specified in this declaration. - See Also:
paramExpressions
- Code:
- Exact Method Body:
return (paramExpressions != null) ? (paramExpressions.length > 0) : false;
-
numParamExpressions
public int numParamExpressions()
Return the number of parameters that are employed by the constructor that built this instance ofEnumConstant
. If a constructor was not used to build this constant, or if that constructor doesn't require or accept parameters, then this method simply returns 0.- Returns:
- Returns the length of the
protected
(internal)paramExpressions
array, or zero if that array is null. - See Also:
paramExpressions
- Code:
- Exact Method Body:
return (paramExpressions != null) ? paramExpressions.length : 0;
-
toString
public java.lang.String toString()
Generates aString
of thisEnum Constant
, with all information included.- Overrides:
toString
in classDeclaration
- Returns:
- A printable
String
of thisEnumConstant
. - See Also:
StrCSV.toCSV(String[], boolean, boolean, Integer)
,toString(int)
- Code:
- Exact Method Body:
return "Name: [" + name + "]\n" + "Declaration: [" + StrPrint.abbrevEndRDSF(signature, MAX_STR_LEN, true) + "]\n" + // This will **NEVER** be null - unless 'this' instance was built from an HTML File, // rather than a source-code file. Instances like that are only used temporarily, and // are garbage collected instantly. Do this check anyway (just in case). "Location: " + ((this.location == null) ? "null" : ('[' + this.location.quickSummary() + ']'));
-
toString
public java.lang.String toString(int flags)
Generates aString
of thisEnumConst
, with all information included. This will also included any content requested by the'flags'
parameter. For this class (EnumConstant
), the only additional information printed by this'toString'
method is the Java-Doc CommentString
.
ThisString
may also have UNIX color codes added.- Overrides:
toString
in classDeclaration
- Parameters:
flags
- These are thetoString(...)
flags from classPF
("Print Flags"). View available flags listed in classPF
.- Returns:
- A printable
String
of thisAnnotationElem
. - See Also:
PF
,StrCSV.toCSV(String[], boolean, boolean, Integer)
,toString()
- Code:
- Exact Method Body:
boolean color = (flags & UNIX_COLORS) > 0; return printedName("Enum-Const", 17, color) + printedDeclaration(17, color) + printedParamExpressions(17) + printedLocation(17, color, (flags & BRIEF_LOCATION) > 0) + // The previous method does not add a '\n' end to the end of the returned string // This is optional, it adds a '\n' AT THE BEGINNING if it is included printedComments(17, color, (flags & JAVADOC_COMMENTS) > 0);
-
clone
public EnumConstant clone()
Java'sinterface Cloneable
requirements. This instantiates a newEnumConstant
with identical fields.- Overrides:
clone
in classjava.lang.Object
- Returns:
- A new
EnumConstant
whose internal fields are identical to this one. A deep copy on all internal arrays is performed. New arrays are instantiated. - Code:
- Exact Method Body:
return new EnumConstant(this);
-
compareTo
public int compareTo(EnumConstant ec)
Java'sinterface Comparable<T>
requirements. This does a very simple comparison using the two constants''name'
field.- Specified by:
compareTo
in interfacejava.lang.Comparable<EnumConstant>
- Parameters:
ec
- Any otherEnumConstant
to be compared to'this' EnumConstant
- Returns:
- An integer that fulfills Java's
interface Comparable<EnumConstant> public boolean compareTo(EnumConstant ec)
method requirements. - Code:
- Exact Method Body:
return (this == ec) ? 0 : this.name.compareTo(ec.name);
-
equals
public boolean equals(EnumConstant other)
This should be called an "atypical version" of the usualequals(Object other)
method. This version of equals merely compares the name of the constant defined. The presumption here is that the definition of an 'constant' only has meaning - at all - inside the context of anenum
where that constant has been defined. Since inside any'.java'
enum
, there may only be one element with a given name, this method shall return TRUE whenever the constant being compared also has the same name.- Parameters:
other
- This may be any otherEnumConstant
. It is strongly suggested that'other'
be aconstant
defined in the same'.java'
source-code file as'this'
constant.- Returns:
- This method returns TRUE when
'this'
instance ofEnumConstant
has the same'name'
as the name of input-parameter'other'
- Code:
- Exact Method Body:
return this.name.equals(other.name);
-
-