Class Field

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Field>

    public class Field
    extends Declaration
    implements java.io.Serializable, java.lang.Comparable<Field>, java.lang.Cloneable
    Java Parser Bridge, Field Class - Documentation.

    The purpose of this bridge is provide a pared down, easier-to-use (but-with less-features) version of the publicly available "JavaParser" package. This class Field allows for storing the name, definition and modifiers list of a field. Such information, (hopefully) obviously, is mostly readily available from Java's reflection API. The reflection API has been around since Java was first created in the 1990's. The Java Parser library, however, allows a programmer to parse java source files that have as yet been compiled to class files and/or allow more access to the specifics of a source file.

    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 your CLASSPATH 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.
    See Also:
    Serialized Form



    • Field Detail

      • serialVersionUID

        public static final long serialVersionUID
        This fulfils the SerialVersion UID requirement for all classes that implement Java's interface java.io.Serializable. Using the Serializable 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:
        1
        public static final long serialVersionUID = 1;
        
      • definition

        public final java.lang.String definition
        The definition of this field, as a String.
        Code:
        Exact Field Declaration Expression:
        1
        public final String     definition;
        
      • type

        public final java.lang.String type
        The type / class of this field, as a String.
        Code:
        Exact Field Declaration Expression:
        1
        public final String     type;
        
    • Constructor Detail

      • Field

        protected Field​(com.github.javaparser.ast.body.FieldDeclaration fd,
                        com.github.javaparser.ast.body.VariableDeclarator vd,
                        java.lang.String declaration,
                        java.lang.String[] modifiers,
                        java.lang.String jdComment)
        Constructs an instance of 'Field' using the parameters that the 'Visitor' class from Java-Parser passes to the class 'SourceFile'. These parameters are passed to this constructor as the class 'SourceFile' parses a '.java' source-code file.

        IMPORTANT NOTE: A field is the line of Java that reads like: public static final int MYINT = 1;

        HOWEVER: A VariableDeclarator and FieldDeclaration are basically the same, but sometimes there are more more than one variable-declarations per field-declaration.

        For example: public static final int myIntA, myIntB;

        IN THAT CASE: The method calling this constructor, will have to call it once for each variable that is defined.
        Parameters:
        fd - This is a JavaParser type. It may define one or more fields in a java class, interface, enumerated-type, etc. The number of fields declared in this single declaration are equal to the number of fields that the original software developer typed at the line that defined those fields.
        vd - This the complete lists of fields defined in the FieldDeclaration. This is also an internal class from the 'JavaParser' JAR-library.
        declaration - This is the original FieldDeclaration instance that has been converted into a java.lang.String.
        modifiers - This is the list of modifiers that were picked out of the FieldDeclaration. They are just the plain-old String's often seen in front of variable/field definitions in a '.java' source-code file, such as: public, private, protected, etc...
        jdComment - If a JavaDoc comment was included with this field definitions, it shall be passed as a String here.
      • Field

        protected Field​(com.github.javaparser.ast.body.FieldDeclaration fd,
                        java.lang.String fieldName)
        Constructor used internally by class 'JavaDocHTMLFile' for class Field
        Parameters:
        fd - The java-parser 'FieldDeclaration' that needs to be converted to an instance of locally define class Field
        fieldName - This is needed because of the way declarations are handled.
    • Method Detail

      • toString

        public java.lang.String toString()
        Generates a String of this field, with all information included.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A printable string of this field.
        See Also:
        StrCSV.toCSV(String[], boolean, boolean, Integer), toString(int)
        Code:
        Exact Method Body:
        1
        2
        3
        4
        5
        6
         return
             "Name:        [" + name + "]\n" +
             "Declaration: [" + signature /* used to be: declaration */ + "]\n" +
             "Type:        [" + type + "]\n" + 
             "Definition:  [" + definition + "]\n" +
             "Modifiers:   [" + StrCSV.toCSV(modifiers, true, true, null) + "]\n";
        
      • toString

        public java.lang.String toString​(int flags)
        Generates a String of this field, with all information included. This will also included any content requested by the 'flags' parameter. In the case of class Field (this class), the only additional information available is the Java-Doc Comment String. This String may also have UNIX color codes added.
        Parameters:
        flags - These are the toString(...) flags from class PF ("Print Flags"). View available flags listed in class PF.
        Returns:
        A printable String of this Field.
        See Also:
        PF, StrCSV.toCSV(String[], boolean, boolean, Integer), toString()
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
         boolean color       = (flags & PF.UNIX_COLORS) > 0;
         boolean comments    = (flags & PF.JAVADOC_COMMENTS) > 0;
        
         return
             "Name:        [" + (color ? C.BCYAN : "") + name + (color ? C.RESET : "") + "]\n" +
             "Declaration: [" + (color ? C.BYELLOW : "") + signature /* was called: declaration */ + (color ? C.RESET : "") + "]\n" +
             "Type:        [" + type + "]\n" + 
             "Definition:  [" + definition + "]\n" +
             "Modifiers:   [" + StrCSV.toCSV(modifiers, true, true, null) + "]\n" +
             (comments ? ("Comments:    [\n" + (color ? C.BGREEN : "") +  jdComment + (color ? C.RESET : "") + "\n]\n") : "");
        
      • clone

        public Field clone()
        Java's interface Cloneable requirements. This instantiates a new Field with identical fields.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A new Field 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:
        1
         return new Field(this);
        
      • compareTo

        public int compareTo​(Field f)
        Java's interface Comparable<T> requirements. This does a very simple comparison using the underlying field final String name and also final String signature.
        Specified by:
        compareTo in interface java.lang.Comparable<Field>
        Parameters:
        f - Any other Field to be compared to 'this' Field
        Returns:
        An integer that fulfills Java's interface Comparable<T> public boolean compareTo(T t) method requirements.
        Code:
        Exact Method Body:
        1
        2
         int ret = this.name.compareTo(f.name);
         return (ret != 0) ? ret : this.signature.compareTo(f.signature);
        
      • equals

        public boolean equals​(Field other)
        This should be called an "atypical version" of the usual equals(Object other) method. This version of equals merely compares the name of the field defined. The presumption here is that the definition of a 'field' only has meaning - at all - inside the context of a class, interface, or enumerated-type where that field is defined. Since inside any '.java' source-code file, there may only be one field with a given name, this method shall return TRUE whenever the field being compared also has the same name.
        Parameters:
        other - This may be any other field. It is strongly suggested that this be a field defined in the same '.java' source-code file as 'this' field.
        Returns:
        This method returns TRUE when 'this' instance of Field has the same public final Sting name as the name-field of input-parameter 'other'
        Code:
        Exact Method Body:
        1
         return this.name.equals(other.name);