Class ParsedFile




    • 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;
        
      • fileName

        protected final java.lang.String fileName
        Contains the file-name from which this instance was derived
        Code:
        Exact Field Declaration Expression:
        1
        protected final String fileName;
        
      • name

        public final java.lang.String name
        Holds the name. A 'ParsedFile' represents a class, interface, or enumerated-type. If this were for public interface java.lang.Integer, this name field would be 'Integer'
        Code:
        Exact Field Declaration Expression:
        1
        public final String name;
        
      • packageName

        public final java.lang.String packageName
        Holds the package-name. If this 'ParsedFile' were for class 'java.lang.String' the 'packageName' would be 'java.lang'
        Code:
        Exact Field Declaration Expression:
        1
        public final String packageName;
        
      • ciet

        public final CIET ciet
        The acronym 'CIET' simply means "Class, Interface or Enumerated-Type. This public field identifies whether this 'ParsedFile' is for a class, an interface or an enumerated-type.
        Code:
        Exact Field Declaration Expression:
        1
        public final CIET ciet;
        
      • genericParameters

        protected final java.util.Vector<java.lang.String> genericParameters
        If this represents a Generic Class or Interface, with generic type information, the generic type parameters shall be listed here.
        Code:
        Exact Field Declaration Expression:
        1
        protected final Vector<String> genericParameters = new Vector<>();
        
      • methods

        protected final java.util.Vector<Method> methods
        This is the list of methods identified by the parser for this ParsedFile
        Code:
        Exact Field Declaration Expression:
        1
        protected final Vector<Method> methods = new Vector<>();
        
      • constructors

        protected final java.util.Vector<Constructor> constructors
        This is the list of constructors identified by the parser for this ParsedFile
        Code:
        Exact Field Declaration Expression:
        1
        protected final Vector<Constructor> constructors = new Vector<>();
        
      • fields

        protected final java.util.Vector<Field> fields
        This is the list of fields identified by the JavaParser jar-file tools for the specific java source-file, which may be specified when invoking parse(String javaSourceFile).

        This 'bridge to JavaParser' extrapolates that class-hierarchy API's copious information, to retrieve the salient details about methods, classes and fields into String-arrays.
        See Also:
        Field
        Code:
        Exact Field Declaration Expression:
        1
        protected final Vector<Field> fields = new Vector<>();
        
    • Constructor Detail

      • ParsedFile

        protected ParsedFile​(java.lang.String fileName,
                             java.lang.String name,
                             java.lang.String packageName,
                             CIET ciet,
                             java.lang.String[] genericParameters)
        Subclasses of 'ParsedFile' should use this constructor to initialize these three fields.
        Parameters:
        name - The name of the class, interface or enumerated-type contained by this ParsedFile
        packageName - The package-name that holds the class, interface or enumerated-type.
        ciet - Identifies what type of Java Construct is specified by this instance of 'ParsedFile'. The value will be class, interface or enumerated-type
    • Method Detail

      • getGenericParameters

        public java.lang.String[] getGenericParameters()
        Returns any / all generic type parameters (if any) for this class or interface
        Returns:
        The generic type parameters as a String[] array.
        Code:
        Exact Method Body:
        1
         return genericParameters.toArray(new String[genericParameters.size()]);
        
      • addMethod

        protected final void addMethod​(Method m)
        Inserts another method into the internal "Method List" Vector. The different subclasses this class use this method to build a list of methods for EITHER a particular '.java' source-file OR a '.html' Java Doc File.
        Parameters:
        m - This is a new method to insert into the list of methods. Internally, the order in which these methods are inserted is preserved. The internal data-structure used is Vector<Method>
        Code:
        Exact Method Body:
        1
         methods.add(m);
        
      • numMethods

        public int numMethods()
        Returns the number of methods that were successfully parsed by whichever parser was used.
        Returns:
        The number of methods in this class' internally stored list of method's
        Code:
        Exact Method Body:
        1
         return methods.size();
        
      • getMethod

        public Method getMethod​(int i)
        This will retrieve the 'ith' Method that was defined in the original source-code ('.java') or documentation ('.html') file.
        Parameters:
        i - This is the index into the internally-stored Vector<Method> methods
        Returns:
        This returns the 'ith' element of the Vector.
        Code:
        Exact Method Body:
        1
         return methods.elementAt(i);
        
      • getMethods

        public Method[] getMethods()
        This will retrieve the list of Method's that were defined in the original source-code ('.java') or documentation ('.html') file.
        Returns:
        A copy of the contents of the internal-Vector - 'methods'
        Code:
        Exact Method Body:
        1
         return methods.toArray(new Method[methods.size()]);
        
      • getMethods

        public void getMethods​
                    (java.util.function.Consumer<Method> acceptMethodAndInsert)
        
        This will retrieve the list of Method's that were defined in this source-code file.
        Parameters:
        acceptMethodAndInsert - This is a java.util.function.Consumer that will simply receive a reference to every Method that was defined in 'this' source-code file. This consumer's 'accept(Method)' method may save this reference to whatever data-structure is needed.

        • decl.getMethods(ts::add); - Inserts the list of methods into a 'TreeSet' assuming variable 'ts' was of type TreeSet<Method>

        • decl.getMethods(v::add); - Inserts the list of methods into a 'Vector' assuming variable 'v' was of type Vector<Method>
        Code:
        Exact Method Body:
        1
         methods.forEach((Method method) -> acceptMethodAndInsert.accept(method));
        
      • addConstructor

        protected final void addConstructor​(Constructor c)
        Inserts another constructor into the internal "Constructor List" Vector. The different subclasses this class use this method to build a list of constructors for EITHER a particular '.java' source-file OR a '.html' Java Doc File.
        Parameters:
        c - This is a new constructor to insert into the list of constructors. Internally, the order in which these constructors are inserted is preserved. The internal data-structure used is Vector<Constructor>
        Code:
        Exact Method Body:
        1
         constructors.add(c);
        
      • numConstructors

        public int numConstructors()
        Returns the number of constructors that were successfully parsed by whichever parser was used.
        Returns:
        The number of constructors in this class' internally stored list of constructor's.
        Code:
        Exact Method Body:
        1
         return constructors.size();
        
      • getConstructor

        public Constructor getConstructor​(int i)
        This will retrieve the 'ith' Constructor that was defined in the original source-code ('.java') or documentation ('.html') file.
        Parameters:
        i - This is the index into the internally-stored Vector<Constructor> constructors
        Returns:
        This returns the 'ith' element of the Vector.
        Code:
        Exact Method Body:
        1
         return constructors.elementAt(i);
        
      • getConstructors

        public Constructor[] getConstructors()
        This will retrieve the list of Constructor's that were defined in the original source-code ('.java') or documentation ('.html') file.
        Returns:
        A copy of the contents of the internal-Vector - 'constructors'
        Code:
        Exact Method Body:
        1
         return constructors.toArray(new Constructor[constructors.size()]);
        
      • getConstructors

        public void getConstructors​
                    (java.util.function.Consumer<Constructor> acceptConstructorAndInsert)
        
        This will retrieve the list of Constructor's that were defined in this source-code file.
        Parameters:
        acceptConstructorAndInsert - This is a java.util.function.Consumer that will simply receive a reference to every Constructor that was defined in 'this' source-code file. This Consumer's 'accept(Constructor)' method may save this reference to whatever data-structure is needed.

        • decl.getConstructors(ts::add); - Inserts the list of constructors into a 'TreeSet' assuming variable 'ts' was of type TreeSet<Constructor>

        • decl.getConstructors(v::add); - Inserts the list of constructors into a 'Vector' assuming variable 'v' was of type Vector<Constructor>
        Code:
        Exact Method Body:
        1
        2
         constructors.forEach
             ((Constructor constructor) -> acceptConstructorAndInsert.accept(constructor));
        
      • addField

        protected final void addField​(Field f)
        Inserts another field into the internal "Field List" Vector. Subclasses of this class use this to build a list of fields for a particular "source-code file" (a '.java' file).
        Parameters:
        f - This is a new field to insert into the list of fields. Internally, the order in which these fields are inserted is preserved. The internal data-structure used is Vector<Field>
        Code:
        Exact Method Body:
        1
         fields.add(f);
        
      • numFields

        public int numFields()
        Returns the number of fields that were successfully parsed by whichever parser was used.
        Returns:
        The number of fields in this class' internally stored list of field's
        Code:
        Exact Method Body:
        1
         return fields.size();
        
      • getField

        public Field getField​(int i)
        This will retrieve the 'ith' Field that was defined in the original source-code ('.java') or documentation ('.html') file.
        Parameters:
        i - This is the index into the internally-stored Vector<Field> fields
        Returns:
        This returns the 'ith' element of the vector.
        Code:
        Exact Method Body:
        1
         return fields.elementAt(i);
        
      • getFields

        public Field[] getFields()
        This will retrieve the list of Field's that were defined in the original source-code ('.java') or documentation ('.html') file.
        Returns:
        A copy of the contents of the internal-Vector - 'fields'
        Code:
        Exact Method Body:
        1
         return fields.toArray(new Field[fields.size()]);
        
      • getFields

        public void getFields​
                    (java.util.function.Consumer<Field> acceptFieldAndInsert)
        
        This will retrieve the list of Field's that were defined in this source-code file.
        Parameters:
        acceptFieldAndInsert - This is a java.util.function.Consumer that will simply receive a reference to every Field that was defined in 'this' source-code file. This Consumer's 'accept(Field)' method may save this reference to whatever data-structure is needed.

        • decl.getFields(ts::add) - Inserts the list of fields into a 'TreeSet' assuming variable 'ts' was of type TreeSet<Field>

        • decl.getFields(v::add); - Inserts the list of fields into a 'Vector' assuming variable 'v' was of type Vector<Field>
        Code:
        Exact Method Body:
        1
         fields.forEach((Field field) -> acceptFieldAndInsert.accept(field));
        
      • findMethod

        public Method findMethod​(Method other)
        This method will iterate through every Method that was found while parsing 'this' File. This method can be used to match the Method's found in source-code files with the Method's found in '.html' files that were generated by javadoc. This facilitates, by the way, the retrieving of the Method-body source-code (as a 'String'), so that it can be code-hilited by the Pretty Print HiLiter and inserted in the '.html' file.
        Parameters:
        other - This is usually an instance of the class 'Method' that was generated by the alternate parser-version for the exact same class.
        Returns:
        The Method in this source-file that was identified based on comparing it with the input-parameter request-information. If no Method in 'this' source-file was found that had this signature, then null will be returned.

        The returned instance of 'Method' should be identical to the 'inputMethod' - with the primary-difference being that the one returned will not have a 'null' value for the public final String 'body' field. This body can then be hilited and inserted into the javadoc '.html' file.
        Code:
        Exact Method Body:
        1
        2
        3
        4
        5
         // 'methods' is the array defined in this 'SourceFile' class.  It was created by parsing
         // a '.java' source-code file. 'other' is usually a Method parsed from a JavaDoc
         // Generated HTML file.
         for (Method method : methods) if (method.equals(other)) return method;
         return null;
        
      • findConstructor

        public Constructor findConstructor​(Constructor other)
        This method will iterate through every Constructor that was found while parsing 'this' Source-File. This method can be used to match the Constructor's found in source-code '.java' files with the Constructor's found in '.html' files that were generated by javadoc. This facilitates, by the way, the retrieving of the Constructor-body source-code (as a 'String'), so that it can be code-hilited by the Pretty Print HiLiter and inserted in the '.html' file.
        Parameters:
        other - This is usually an instance of the class 'Constructor' that was generated by the alternate parser-version for the exact same class.
        Returns:
        The Constructor in this source-file that was identified based on comparing it with the input-parameter request-information. If no Constructor in 'this' source-file was found that had this signature, then null will be returned.

        The returned instance of 'Constructor' should be identical to the 'other' Constructor - with the primary-difference being that the one returned will not have a 'null' value for the public final String 'body' field. This body can then be hilited and inserted into the javadoc '.html' file.
        Code:
        Exact Method Body:
        1
        2
        3
        4
        5
        6
        7
        8
         // 'constructors' is the array defined in this 'SourceFile' class.  It was created by 
         // parsing a '.java' source-code file. 'other' is usually a Constructor parsed from a 
         // JavaDoc Generated HTML file.
         for (Constructor constructor : constructors)
             if (constructor.equals(other))
                 return constructor;
        
         return null;
        
      • findField

        public Field findField​(Field other)
        This method will iterate through every field / variable that was found while parsing 'this' Source-File, and attempt to find a match based on the 'name' input request parameter. If a match is found, then the (String-text) of the field declaration shall be returned. If no match is identified, then null is returned.
        Parameters:
        other - This is usually an instance of the class 'Field' that was generated by the alternate parser-version for the exact same class.
        Returns:
        This will return the complete Field definition of a Field whose name matches other.name.
        Code:
        Exact Method Body:
        1
        2
        3
        4
        5
         // 'fields' is the array defined in this 'SourceFile' class.  It was created by parsing a
         // '.java' source-code file. 'other' is usually a Field parsed from a JavaDoc Generated
         // HTML file.
         for (Field field : fields) if (field.equals(other)) return field;
         return null;
        
      • toString

        public java.lang.String toString()
        Turns a ParsedFile result object, 'this', into a String. Passes '0' to the standard flags-print method.
        Overrides:
        toString in class java.lang.Object
        Code:
        Exact Method Body:
        1
         return toString(0);
        
      • toString

        public java.lang.String toString​(int flags)
        Turns a ParsedFile result object, 'this', into a java.lang.String.

        This will check for the 'UNIX_COLORS' flag in class PF. If this flag is identified, then a few unix color codes are added to the output.

        IMPORTANT NOTE: The value of this flag will be propagated to the individual toString(int flag) methods in each of the three class Method, class Field and also class Constructor toString(flag) methods.
        Returns:
        This returns a String that obeys the flag-requests by parameter flag.
        See Also:
        Method.toString(int), Constructor.toString(int), Field.toString(int)
        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
         StringBuilder sb = new StringBuilder();
         boolean c = (flags & PF.UNIX_COLORS) > 0;
        
         sb.append(  "******************************************************************\n" + 
                     (c ? C.BRED : "") + "Methods:\n" + (c ? C.RESET : "") +
                     "******************************************************************\n"  );
        
         for (Method m : methods) sb.append(m.toString(flags) + '\n');
        
         sb.append(  "******************************************************************\n" + 
                     (c ? C.BRED : "") + "Constructors:\n" + (c ? C.RESET : "") +
                     "******************************************************************\n"  );
        
         for (Constructor cs : constructors)  sb.append(cs.toString(flags) + '\n');
        
         sb.append(  "******************************************************************\n" + 
                     (c ? C.BRED : "") + "Fields:\n" + (c ? C.RESET : "") +
                     "******************************************************************\n"  );
        
         for (Field f : fields) sb.append(f.toString(flags) + '\n');
        
         return sb.toString();