Class Method

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

    public class Method
    extends Callable
    implements java.io.Serializable, java.lang.Comparable<Method>, java.lang.Cloneable
    Extension of Package java.lang.reflect
    This class operates as a slightly more advanced version of the basic Java Reflection Class java.lang.reflect.Method. This class provides a hook into the native Java Parser JAR Library class MethodDeclaration.

    This class is heavily used internally, and can be used (if needed) to modify Java Doc Web-Pages, programmatically.

    When sorting Summary-Tables, using the RearrangeEntitySummaries HTML Processor, instances of this class are provided to your Summary-Sorter Handler methods.
    Java Parser Bridge: Holds all information extracted from '.java' Source Files about Method's identified in that file.

    Instances of this Class are Obtained From: ReflHTML & SummaryTableHTML

    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.
    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 method.

    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.



    Reflection-Classes Inheritance-Diagram

    Class Declaration
     
    intid
    Entityentity
     
    Stringname
    Stringsignature
    StringjdComment
     
    String[]modifiers
    String[]annotations
     
    intsignatureLineNumber
    intjdStartLineNumber
    intjdEndLineNumber
     
     
     
     
     
    Class Callable
     
    Stringbody
     
    String[]parameterNames
    String[]parameterTypes
    String[]parameterTypesJOW
    String[][]parameterAnnotations
     
    String[]exceptions
     
     
     
     
     
    Class Method
     
    StringreturnType
    StringreturnTypeJOW
     
     
     
     
     
    Class Constructor
    Inherits Class Callable
    No Additional Fields
    Java Parser Bridge
    Inheritance Diagram


    Class Field
     
    Stringdefinition
    Stringtype
    StringtypeJOW
     
     
     
     
     
    Class EnumConstant
     
    String[]paramExpressions
     
     
     
     
     
    Class AnnotationElem
     
    StringdefaultValue
    Stringtype
    StringtypeJOW
     
     
     
     
     
    Class NestedType
     
    CIETciet
    intnumFields
    intnumMethods
     
    StringfullyQualifiedName
    StringnameWithContainer
    StringpackageName
     
    String[]extendedTypesJOW
    String[]implementedTypesJOW
    String[]genericTypeParameters
     
     
     
     
     




    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


    • 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:
         public static final long serialVersionUID = 1;
        
      • returnType

        🡅  🡇    
        public final java.lang.String returnType
        The return type of the method, as a String. If this is a method with a 'void' return-type, this shall be "void".

        NOTE: The parsed return-type will include the full-package name of the returned class (or interface), if the method returns a class or interface.
        Code:
        Exact Field Declaration Expression:
         public final String returnType;
        
      • returnTypeJOW

        🡅  🡇    
        public final java.lang.String returnTypeJOW
        The return type of the method, as a String.

        JOW: Just One Word

        If the String's in a type-as-String contain complicated or intricate detailed information, and all you need is a simple identifier, the JOW-String stores the type-as-String with all package-name and generic-parameters (if they were present / included) stripped from the String. Furthermore, if the type was originally an inner-class, even the containing class-name is removed from the JOW-String.

        If a parameter to a Method, or the type of a Field had the (fully-qualified) type-name: java.util.stream.Stream.Builder<String>, the JOW-String would simply have the word "Builder".

        NOTE: If the type, itself, is an array of any kind, the array-brackets will be included in this String-name.
        Output Single-Word, Type-StringInput Type
        "Entry" "java.util.Map.Entry<K, V>"
        "Vector" "java.util.Vector<E>"
        "Vector" "Vector<TagNode>"
        "Vector" "Vector<Vector<TagNode>>"
        "Vector" "java.util.Vector<Vector<TagNode>>"
        "String" "String"
        "String" "java.lang.String"
        "String[]" "java.lang.String[]"
        "Integer" "Integer"
        "Integer[]" "java.lang.Integer[]"

        NOTE: You may view the StringParse class' methods removeGeneric, and typeToJavaIdentifier for more information.
        Code:
        Exact Field Declaration Expression:
         public final String returnTypeJOW;
        
      • methodDeclaration

        🡅  🡇    
        public final transient com.github.javaparser.ast.body.MethodDeclaration methodDeclaration

        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-Parser MethodDeclaration instance that was used to build this Method, it may be retrieved from this transient field.
        Code:
        Exact Field Declaration Expression:
         public final transient MethodDeclaration methodDeclaration;
        
    • Constructor Detail

      • Method

        🡅  🡇    
        public Method​(com.github.javaparser.ast.body.MethodDeclaration md,
                      boolean isSignatureOnly)
        Instantiates a method, and peels out the String's from a JavaParser MethodDeclaration

        EXCEPTIONS NOTE: The underlying parser code can throw exceptions, and the exception chain, and exception tree in the package is quite dense. Suffice it to say, they are all unchecked exceptions.
        Parameters:
        md - This can be retrieved in any number of ways from the JavaParser package. The instantiation process will convert a Java-Parser from of a MethodDeclaration, into this Bridge form class Method.

        Yes, this is redundant, but that's what a bridge is - a wrapper class to make the programmer's life easier. All the salient information a programmer would need when improving JavaDoc Documentation HTML Files is easily and simply encapsulated as lists of String's in the class Method.
        isSignatureOnly - This constructor may be used to build an instance of 'Method' using only the signature of the method. If you have built / received a 'MethodDeclaration' without a method-body definition, set this parameter to TRUE; the value of the public final String body field will be null.

        NOTE: If this Java-Parser MethodDeclaration does have a body-defined, but this parameter is set to TRUE, the body String-field will still be null.
        Code:
        Exact Constructor Body:
         super(
             // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
             // Declaration-Constructor Parameters
             // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        
             md.getAnnotations(),                // annotations
             md.getModifiers(),                  // modifiers
             md.getNameAsString(),               // name
             md.getDeclarationAsString(),        // signature
             md.getJavadocComment(),             // Java Doc Comment
             Entity.METHOD,                      // Simple ENUM, instead of 'getClass()'
             md.getBegin(),                      // Signature Line Number
        
        
             // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
             // Callable-Constructor Parameters
             // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        
             md.getParameters(),                 // Method-Parameters
             isSignatureOnly ? null : BODY(md),  // Method-Body
             md.getThrownExceptions()            // Exceptions
         );
        
         this.returnType     = md.getType().asString();
         this.returnTypeJOW  = StringParse.typeToJavaIdentifier(this.returnType);
        
         // Save a hook to this MethodDeclaration in the transient field
         this.methodDeclaration = md;
        
    • Method Detail

      • toString

        🡅  🡇    
        public java.lang.String toString()
        Generates a String of this method, with most information included.

        NOTE: This will not return every piece of information contained by this class. For example, both the method body, and any possible JavaDoc Comments are not included. For a more enhanced toString() version, call the one that accepts flags.
        Overrides:
        toString in class Callable
        Returns:
        A printable String of this method.
        See Also:
        PF, toString(int), StrCSV.toCSV(String[], boolean, boolean, Integer)
        Code:
        Exact Method Body:
         return
             "Name:            [" + name + "]\n" +
             "Signature:       [" + StringParse.abbrevEndRDSF(signature, MAX_STR_LEN, true) + "]\n" +
             "Modifiers:       [" + StrCSV.toCSV(modifiers, true, true, null) + "]\n" +
             printedParameterNamesTS() +
             printedParameterTypesTS() +
             "Return Type:     [" + returnType + "]\n" +
             printedExceptionsTS() +
             "Line Numbers:    [sig=" + signatureLineNumber + ", jdStart=" + jdStartLineNumber +
                 ", jdEnd=" + jdEndLineNumber + "]";
        
      • toString

        🡅  🡇    
        public java.lang.String toString​(int flags)
        This class expects a flags that has been masked using the constant (public, static, final int) fields of class PF. Please view this class for more information about the flags available for modifying the return-value of this toString() method.
        Overrides:
        toString in class Callable
        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 method, with comment information included as well.
        See Also:
        StrCSV.toCSV(String[], boolean, boolean, Integer), toString(), PF
        Code:
        Exact Method Body:
         boolean color = (flags & UNIX_COLORS) > 0;
         Ret2<Boolean, Boolean> jow = jowFlags(flags);
        
         return 
             printedName("Method", 20, color) +
             printedSignature(20, color) +
             printedModifiers(20) +
             printedParamNames() + 
             printedParamTypes(jow) +
             printedReturnType(jow, color) +
             printedExceptions() +
             printedLineNumbers(20, color) +
        
             // These are optional, they add a '\n' AT THE BEGINNING if they are included
             printedComments(20, color, (flags & JAVADOC_COMMENTS) > 0) +
             printedCallableBody(flags);
        
      • clone

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

        🡅  🡇    
        public int compareTo​(Method m)
        Java's interface Comparable<T> requirements. This does a very simple comparison using the two method's name field. If the name comparison will not suffice in making a decision, then the number of parameters, and parameter-types are used to making the sort-decision.
        Specified by:
        compareTo in interface java.lang.Comparable<Method>
        Parameters:
        m - Any other Method to be compared to 'this' Method
        Returns:
        An integer that fulfils Java's interface Comparable<Method> public boolean compareTo(Method m) method requirements.
        Code:
        Exact Method Body:
         // Identical References
         if (this == m) return 0;
        
         // Sorting by ignoring case is best - usually for the looks of a list
         // NOTE: Returning '0' is bad, because a TreeSet will remove duplicate-elements.  This
         //       means two different meethods with the same name would not "fit" into a treeset.
        
         int ret = this.name.compareToIgnoreCase(m.name);
         if (ret != 0) return ret;
        
         // Try to identify a different without ignoring case.
         ret = this.name.compareTo(m.name);
         if (ret != 0) return ret;
        
         ret = this.numParameters() - m.numParameters();
         if (ret != 0) return ret;
        
         if (this.parameterTypesJOW != null)
             for (int i=0; i < this.parameterTypesJOW.length; i++)
                 if ((ret = this.parameterTypesJOW[i].compareTo(m.parameterTypesJOW[i])) != 0)
                     return ret;
        
         return 0;
        
      • equals

        🡅    
        public boolean equals​(Method other)
        This should be called an "atypical version" of the usual equals(Object other) method. This version of equals merely compares the name and parameters-list of the method. The presumption here is that the definition of a 'method' only has meaning - at all - inside the context of a class, interface, or enumerated-type where that method is defined. Since inside any '.java' source-code file, there may only be one method with a given name and parameter-list, this shall return TRUE whenever the method being compared has the same name and parameter types as 'this' does.
        Parameters:
        other - This may be any other method. It is strongly suggested that this be a method defined in the same '.java' source-code file as 'this' method.
        Returns:
        This method returns TRUE when 'this' instance of Method has both the same public final Sting name and the same parameter-list as 'other'.
        Code:
        Exact Method Body:
         // The method's must have the same name!
         if (! this.name.equals(other.name)) return false;
        
         // If the number of parameters in the 'other' instance of Method differ from the number
         // of parameters in 'this' Method, then return FALSE immediately.  It cannot be a match.
        
         if (this.numParameters() != other.numParameters()) return false;
        
         // If both of these have zero parameters, and their names have matched, return true
         // immediately
        
         if (this.numParameters() == 0) return true;
        
         // If any of the parameter-names are different, break immediately and return false;
         if (this.parameterNames != null)
             for (int i=0; i < this.parameterNames.length; i++)
                 if (! this.parameterNames[i].equals(other.parameterNames[i])) return false;
        
         // If the parameter-types listed by the javadoc '.html' file differ from the parameter
         // types listed in the original '.java' source-code file, then break immediately.
         //
         // NOTE: The "package-information" for the FULL CLASS OR INTERFACE NAME is not always
         //       available.
        
         for (int i=0; i < this.parameterTypesJOW.length; i++)
             if (! this.parameterTypesJOW[i].equals(other.parameterTypesJOW[i]))
                 return false;
        
         // ALL TEST PASSED
         return true;