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
    Java Parser Bridge, Method - 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;
        
      • returnType

        public final java.lang.String returnType
        The return type of the method, as a String.

        NOTE: The parsed return-type often, but not always include the full-package name of the returned class (or interface), if the method returns a class or interface. This class 'Method' does not fill the full package-name of the returned-type if the underlying Java-Parser mechanism does not include this information. If the full-package class or interface name is included, it is left 'as is'.
        Code:
        Exact Field Declaration Expression:
        1
        public final String returnType;
        
      • returnTypeNoPackage

        public final java.lang.String returnTypeNoPackage
        The return type of the method, as a String. If this method returned a class or interface, (as opposed to a primitive or was a 'void' method), and the value of the public final String 'returnType' contains the full package-name, this method will contain just the class or interface name, without any package information that may or may not have been present.
        Code:
        Exact Field Declaration Expression:
        1
        public final String returnTypeNoPackage;
        
    • Constructor Detail

      • Method

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

        JavaParser, VALUE-ADDED Software: This method was not initially visible past the package-level, although when used in combination with method: StaticJavaParser.parseMethodDeclaration(String someMethodSignature), this can be an invaluable constructor to have around.

        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. 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.
    • 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 java.lang.Object
        Returns:
        A printable String of this field.
        See Also:
        PF, toString(int), StrCSV.toCSV(String[], boolean, boolean, Integer)
        Code:
        Exact Method Body:
        1
        2
        3
        4
        5
        6
        7
        8
         return
             "Name:            [" + name + "]\n" +
             "Signature:       [" + signature + "]\n" +
             "Modifiers:       [" + StrCSV.toCSV(modifiers, true, true, null) + "]\n" +
             "Parameter Names: [" + StrCSV.toCSV(parameterNames, true, true, null) + "]\n" +
             "Parameter Types: [" + StrCSV.toCSV(parameterTypesNoPackage, true, true, null) + "]\n" +
             "Return Type:     [" + returnTypeNoPackage + "]\n" +
             "Exceptions:      [" + StrCSV.toCSV(exceptions, true, true, null) + "]\n";
        
      • 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.
        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, with comment information included as well.
        See Also:
        StrCSV.toCSV(String[], boolean, boolean, Integer), toString(), PF
        Code:
        Exact Method Body:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
        23
        24
        25
        26
        27
        28
         boolean color           = (flags & PF.UNIX_COLORS) > 0;
         boolean comments        = (flags & PF.JAVADOC_COMMENTS) > 0;
         boolean methodBody      = (flags & PF.BODY) > 0;
         boolean shortMethodBody = (flags & PF.BODY_SHORT) > 0;
        
         if (methodBody && shortMethodBody) methodBody = false;
        
         String  bodyStr         = this.body;
        
         if (shortMethodBody)
         {
             if (body != null)
             {
                 int pos = StrIndexOf.nth(body, 3, '\n');
                 if (pos != -1) bodyStr = body.substring(0, pos);
             }
         }
        
         return  "Name:              [" + (color ? C.BCYAN : "") + name + (color ? C.RESET : "") + "]\n" +
                 "Signature:         [" + (color ? C.BYELLOW : "") + signature + (color ? C.RESET : "") + "]\n" +
                 "Modifiers:         [" + StrCSV.toCSV(modifiers, true, true, null) + "]\n" +
                 "Parameter Names:   [" + StrCSV.toCSV(parameterNames, true, true, null) + "]\n" +
                 "Parameter Types:   [" + StrCSV.toCSV(parameterTypesNoPackage, true, true, null) + "]\n" +
                 "Return Type:       [" + returnTypeNoPackage + "]\n" +
                 "Exceptions:        [" + StrCSV.toCSV(exceptions, true, true, null) + "]\n" +
                 (comments ?         ("Comments:          [\n" + (color ? C.BGREEN : "") + jdComment + (color ? C.RESET : "") + "\n]\n") : "") +
                 (methodBody ?       ("Method Body:       [\n" + bodyStr + "\n]\n") : "") +
                 (shortMethodBody ?  ("Short Method Body: [\n" + bodyStr + "\n]\n") : "");
        
      • 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:
        1
         return new Method(this);
        
      • compareTo

        public int compareTo​(Method m)
        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<Method>
        Parameters:
        m - Any other Method to be compared to 'this' Method
        Returns:
        An integer that fulfils Java's interface Comparable<T> public boolean compareTo(T t) method requirements.
        Code:
        Exact Method Body:
        1
        2
         int ret = this.name.compareTo(m.name);
         return (ret != 0) ? ret : this.signature.compareTo(m.signature);
        
      • 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:
         1
         2
         3
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13
        14
        15
        16
        17
        18
        19
        20
        21
        22
         // 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.parameterNames.length != other.parameterNames.length) return false;
        
         // If any of the parameter-names are different, break immediately and return false;
         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.parameterTypes.length; i++)
             if (! this.parameterTypesNoPackage[i].equals(other.parameterTypesNoPackage[i]))
                 return false;
        
         // ALL TEST PASSED
         return true;