CodeAnalysis for 4D

Dani Beaubien released v1.6 of the CodeAnalysis component.


These are the features in this release:

  • #1 – Total refactor of the code  to do the method statistics. The results are persisted and the component will only redo the statistics on the methods that have changes.
  • #2 – There is a new feature that will scan the host database’s code and provide reports on which fields are used in queries. This helps the developer do some analysis to determine which fields should (or should not) be indexed.
  • #3 – Added a few graphs that show the code complexity and line count of the methods. They are still a work in progress.

What is CodeAnalysis?

CodeAnalysis is easy to use and offers the following features:

  • Can perform analysis on “all” stored methods in the structure including project methods, project form/object methods, table form/object methods, database methods and trigger methods.
  • Gathers stats on line counts, comment line counts, blank line counts, code line counts, and cyclomatic complexity.
  • Can export, as disk files, every method in the structure. Can be used for archiving, backups, and source code management.
  • Can export, as JSON files, every available form and form object property in the structure. Can be used for archiving, backups, and source code management.
  • Can export, as JSON files, every available table and field property in the structure. Can be used for archiving, backups, and source code management.
  • Can create HTML documentation of the methods in the structure. The HTML docs can be limited to only those methods that have been marked as shared with host. This gives 4D developers to easily produce documentation for components that they share.
  • Can create a docset for the shared methods. Third party Docset viewers are available on many platforms.

Please feel free to drop me a note on suggestions and feature requests. I do plan to do some more tweaks and add new features in the future.

HOW TO GET IT

Go to http://openroaddevelopment.com/projects_4dComponent_CodeAnalysis.html  to get more information and download the component.

VERSION 1.6 CHANGES

Method Analysis Engine
– Completely refactored the code that does all the analysis of the methods reducing complexity and removing duplication.
– The results of the analysis is now persisted to the local disk along with the other Code Analysis component preferences.
– Refreshing the analysis only performs updates on the methods that have been updates since the last time the analysis was run. This is determined by using the modification data and time as reported by 4D.
– Exposed “MethodStats_RecalculateAll” to the host database. Calling this method does a full recalculation of the method statistics in the host database.
– Exposed “MethodStats_RecalculateModified” to the host database. Calling this method does a recalculation of the method statistics of the methods in the host database that have been modified since the last recalculation.
– Improved detection algorithm used to determine if the required project form has been copied to the host database prior to exporting the properties. The message displayed to the user is improved as well.

Complexity
– Added a “View Graphs” button that is enabled once the code has been analysed. Pressing this button will open a dialog that will allow you to view a graph of the # of methods by lines of code and # of methods by complexity. These graphs can be used to have a higher level view of some metrics of your code.
– The results of the last analysis is persisted and restored when the main Code Analysis window is opened.
– Holding down the option or alt key and pressing the “Analyse Code” button will bring up a prompt that will allow you to select if only the update methods or all the methods will be analysed.

Method DIFF
– Fixed bug where a method diff window would not open if the method name matched an already running process. The process name is prepended with “diff:”.

Method Export
– Altered how methods are exported. The component will not do a full replace of the contents of the export folder. Only the method files that differ will be exported. The change has been made to improve the workflow when using external code repositories.
– Added a check to ensure that the folder the methods are being exported to is writable. An error is displayed if it is not.

Structure Export
– Added a “Index Field Stats”. Using this button will perform a code scan of they entire code base and will save two reports to the default export folder. One report contains a full listing of the fields that are used in query statements along with a count and if the field is indexed or not. The 2nd report shows the methods (and line) that each field query is performed in.
– Fixed bug that caused no index information to be exported in the table/field info export file.

Methods That Are Shared With Host Database
– “Structure_SaveStructDefn2Folder” is now shared with the host database. This method will export the structure definition to a file. See the Component API Docs for more information.
– “Structure_ScanIndexedFieldUsage” is a new method that is shared with the host database. This method will scan the host database for where fields are used in queries and produce a report that shows usage and if they are indexed or not. See the Component API Docs for more information.
– “MethodStats_RecalculateAll” is a new method that is shared with the host database. This method will recalculate all the method metrics that the component captures. The results are stored back to disk for future usage. See the Component API Docs for more information.
– “MethodStats_RecalculateModified” is a new method that is shared with the host database. This method will loads the previously method metrics and updates the metrics on the methods that have been updated since the last time the calculations where performed. See the Component API Docs for more information.

Dani Beaubien
Open Road Development