The present invention relates to a method and system for developing software. More particularly, the invention relates to a method and system for locating source code corresponding to a message from a verification tool.
Computer instructions are written in source code. Although a skilled programmer can understand source code to determine what the code is designed to accomplish, with highly complex software systems, a graphical representation or model of the source code is helpful to organize and visualize the structure and components of the system. Using models, the complex systems are easily identified, and the structural and behavioral patterns can be visualized and documented.
The well-known Unified Modeling Language (UML) is a general-purpose notational language for visualizing, specifying, constructing, and documenting complex software systems. UML is used to model systems ranging from business information systems to Web-based distributed systems, to real-time embedded systems. UML formalizes the notion that real-world objects are best modeled as self-contained entities that contain both data and functionality. UML is more clearly described in the following references, which are incorporated herein by reference: (1) Martin Fowler, UML Distilled Second Edition: Applying the Standard Object Modeling Language, Addison-Wesley (1999); (2) Booch, Rumbaugh, and Jacobson, The Unified Modeling Language User Guide, Addison-Wesley (1998); (3) Peter Coad, Jeff DeLuca, and Eric Lefebvre, Java Modeling in Color with UML: Enterprise Components and Process, Prentice Hall (1999); and (4) Peter Coad, Mark Mayfield, and Jonathan Kern, Java Design: Building Better Apps & Applets (2nd Ed.), Prentice Hall (1998).
As shown in
Methods and systems consistent with the present invention provide an improved software development tool that overcomes the limitations of conventional software development tools. The improved software development tool of the present invention allows a developer to simultaneously view a graphical and a textual display of source code. The graphical and textual views are synchronized so that a modification in one view is automatically reflected in the other view. In addition, the software development tool is designed for use with more than one programming language.
The improved software development tool enables a developer to quickly determine the location of an error detected by a verification tool. Not only can the developer locate the specific line of source code, but the software development tool also displays the graphical representation of the source code corresponding to the message in a visually distinctive manner. This assists the developer in debugging the source code by allowing the developer to visually determine the location of the error.
In accordance with methods consistent with the present invention, a method is provided in a data processing system for developing source code. The method comprises the steps of receiving a message corresponding to a portion of the source code, and displaying the graphical representation of the portion of the source code corresponding to the message in a visually distinctive manner.
In accordance with methods consistent with the present invention, a method is provided in a data processing system for developing source code. The method comprises the steps of detecting an error in the source code, generating a message reflecting the error, and displaying the graphical representation of the portion of the source code corresponding to the message in a visually distinctive manner.
In accordance with articles of manufacture consistent with the present invention, a computer-readable medium is provided. The computer-readable medium contains instructions for controlling a data processing system to perform a method. The data processing system has source code. The method comprises the steps of receiving a message corresponding to a portion of the source code, and displaying the graphical representation of the portion of the source code corresponding to the message in a visually distinctive manner.
In accordance with articles of manufacture consistent with the present invention, a computer-readable medium is provided. The computer-readable medium contains instructions for controlling a data processing system to perform a method. The data processing system has source code. The method comprises the steps of detecting an error in the source code, generating a message reflecting the error, and displaying the graphical representation of the portion of the source code corresponding to the message in a visually distinctive manner.
Other systems, methods, features and advantages of the invention will be or will become apparent to one with skill in the art upon examination of the following figures and detailed description. It is intended that all such additional systems, methods, features and advantages be included within this description, be within the scope of the invention, and be protected by the accompanying claims.
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate an implementation of the invention and, together with the description, serve to explain the advantages and principles of the invention. In the drawings,
Methods and systems consistent with the present invention provide an improved software development tool that creates a graphical representation of source code regardless of the programming language in which the code is written. In addition, the software development tool simultaneously reflects any modifications to the source code to both the display of the graphical representation as well as the textual display of the source code.
As depicted in
The improved software development tool provides simultaneous round-trip engineering, i.e., the graphical representation 204 is synchronized with the textual representation 206. Thus, if a change is made to the source code 202 via the graphical representation 204, the textual representation 206 is updated automatically. Similarly, if a change is made to the source code 202 via the textual representation 206, the graphical representation 204 is updated to remain synchronized. There is no repository, no batch code generation, and no risk of losing code.
The data structure 300 of the language-neutral representation is depicted in FIG. 3. The data structure 300 comprises a Source Code Interface (SCI) model 302, an SCI package 304, an SCI class 306, and an SCI member 308. The SCI model 302 is the source code organized into packages. The SCI model 302 corresponds to a directory for a software project being developed by the user, and the SCI package 304 corresponds to a subdirectory. The software project comprises the source code in at least one file that is compiled to form a sequence of instructions to be run by a data processing system. The data processing system is discussed in detail below. As is well known in object-oriented programming, the class 306 is a category of objects which describes a group of objects with similar properties (attributes), common behavior (operations or methods), common relationships to other objects, and common semantics. The members 308 comprise attributes and/or operations.
For example, the data structure 500 for the source code 400 depicted in
Although aspects of the present invention are described as being stored in memory, one skilled in the art will appreciate that these aspects can also be stored on or read from other types of computer-readable media, such as secondary storage devices, like hard disks, floppy disks or CD-ROM; a carrier wave from a network, such as Internet; or other forms of RAM or ROM either currently known or later developed.
IDE 708 is the API 702 needed to generate custom outputs based on information contained in a model. It is a read-only interface, i.e., the user can extract information from the model, but not change the model. IDE 708 provides the functionality related to the model's representation in IDE 708 and interaction with the user. Each package composing the IDE group has a description highlighting the areas of applicability of this concrete package. RWI 710 enables the user to go deeper into the architecture. Using RWI 710, information can be extracted from and written to the models. RWI not only represents packages, classes and members, but it may also represent different diagrams (class diagrams, use case diagrams, sequence diagrams and others), links, notes, use cases, actors, states, etc.
SCI 712 is at the source code level, and allows the user to work with the source code almost independently of the language being used.
The improved software development tool of the present invention is used to develop source code in a project. The project comprises a plurality of files and the source code of a chosen one of the plurality of files is written in a given language. The software development tool determines the language of the source code of the chosen file, converts the source code from the language into a language-neutral representation, uses the language-neutral representation to textually display the source code of the chosen file in the language, and uses the language-neutral representation to display a graphical representation of at least a portion of the project. The source code and the graphical representation are displayed simultaneously.
The improved software development tool of the present invention is also used to develop source code. The software development tool receives an indication of a selected language for the source code, creates a file to store the source code in the selected language, converts the source code from the selected language into a language-neutral representation, uses the language-neutral representation to display the source code of the file, and uses the language-neutral representation to display a graphical representation of the file. Again, the source code and the graphical representation are displayed simultaneously.
Moreover, if the source code in the file is modified, the modified source code and a graphical representation of at least a portion of the modified source code are displayed simultaneously. The QA module of the software development tool provides an error message if the modification does not conform to predefined or user-defined styles, as described above. The modification to the source code may be received by the software development tool via the programmer editing the source code in the textual pane or the graphical pane, or via some other independent software tool that the programmer uses to modify the code. The graphical representation of the project may be in Unified Modeling Language; however, one skilled in the art will recognize that other graphical representations of the source code may be displayed. Further, although the present invention is described and shown using the various views of the UML, one of ordinary skill in the art will recognize that other views may be displayed.
Applications to be developed using the software development tool are collectively broken into three views of the application: the static view, the dynamic view, and the functional view. The static view is modeled using the use-case and class diagrams. A use case diagram 1100, depicted in
The dynamic view is modeled using the sequence, collaboration and statechart diagrams. As depicted in
A statechart diagram 1500 is depicted in FIG. 15. The statechart diagram 1500 includes the sequences of states 1502 that an object or interaction goes through during its life in response to stimuli, together with its responses and actions. It uses a graphic notation that shows states of an object, the events that cause a transition from one state to another, and the actions that result from the transition.
The functional view can be represented by activity diagrams 1600 and more traditional descriptive narratives such as pseudo code and minispecifications. An activity diagram 1600 is depicted in
There is also a fourth view mingled with the static view called the architectural view. This view is modeled using package, component and deployment diagrams. Package diagrams show packages of classes and the dependencies among them. Component diagrams 1700, depicted in
Although discussed in terms of class diagrams, one skilled in the art will recognize that the software development tool of the present invention may support these and other graphical views.
There are a variety of modules 704 in the software development tool 610 of the present invention. Some of the modules 704 access information to generate graphical and code documentation in custom formats, export to different file formats, or develop patterns. The software development tool also includes a quality assurance (QA) module which monitors the modifications to the source code and calculates various complexity metrics, i.e., various measurements of the program's performance or efficiency, to support quality assurance. The types of metrics calculated by the software development tool include basic metrics, cohesion metrics, complexity metrics, coupling metrics, Halstead metrics, inheritance metrics, maximum metrics, polymorphism metrics, and ratio metrics. Examples of these metrics with their respective definitions are identified in Tables 1-9 below.
The QA module also provides audits, i.e., the module checks for conformance to predefined or user-defined styles. The types of audits provided by the module include coding style, critical errors, declaration style, documentation, naming style, performance, possible errors and superfluous content. Examples of these audits with their respective definitions are identified in Tables 10-17 below.
If the QA module determines that the source code does not conform to the audit and/or the metrics requirements, an error message is provided to the developer. The audit and metrics requirements are well known in software development. For example, as depicted in
i*=j++
in the source code 1910 in
j++
i*=j
Both the complex and the non-complex formulas perform the same operations, i.e., add 1 to j and multiply j with i. If the complex assignment identified in the source code 1910 in
An example for each of the audits identified above in Tables 11-18 is provided below:
Avoid Complex Initialization or Update Clause in for Loops
When using the comma operator in the initialization or update clause of a for statement, the developer should avoid the complexity of using more than three variables. The following source code illustrates the use of more than three variables in a “for statement”:
To remedy the complexity of using more than three variables, the source code may be rewritten as follows:
Avoid Implementation Packages Referencing
This rule helps a developer avoid referencing packages that normally should not be referenced. For example, if the developer uses Facade or AbstractFactory patterns, he or she can make sure that no one uses direct calls to the underlying constructors of the classes.
The developer can divide his or her packages into interface and implementation packages, and ensure that no one ever refers to the implementation packages, while the interface packages are accessible for reference. The developer can set up two lists of packages: the allowed (interface) and banned (implementation) packages. For each class reference in source code, this rule verifies that the package where this class belongs is in the allowed list and not in the banned list.
In case of conflict, the narrower rule prevails. For example, if the following list is specifically allowed:
Static members should be referenced through class names rather than through objects. For example, the following code is incorrect:
The following source code corrects the above code so that the static members are referenced via class names:
Assignment to Formal Parameters
Formal parameters should not be assigned values. For example, the following code increments param by 11, and returns the new value for param:
Rather than reassigning the value for param, the following code declares a new variable result, sets result to equal param+11, and returns the value for result:
Avoid Too Long Files
Files longer than 2000 lines are cumbersome and should be avoided.
Avoid Too Long Lines
Lines longer than 80 characters should be avoided, since they are not handled well by many terminals and tools.
Complex Assignment
This audit checks for the occurrence of multiple assignments and assignments to variables within the same expression. Complex assignments should be avoided since they decrease program readability.
If the ‘strict’ option is off, assignments of equal value to several variables in one operation are permitted. For example the following statement would raise violation if ‘strict’ option were on; otherwise there would be no violation:
i=j=k=0;
The following source code is an example of a compound assignment, which should be avoided:
i*=j++;
k=j=10;
1=j+=15;
The following source code is an example of a nested assignment, which should be avoided:
i=j+++20;
i=(j=25)+30;
The source code shown above is corrected by breaking the statements into several statements. For example, the following source code:
i*=j++;
may be replaced by:
j++;
i*=j
The following code:
k=j=10;
may be replaced by:
k=10;
j=10;
The following code:
1=j+=15;
may be replaced by:
j+=15;
1=j;
The following code:
i=j+++20;
may be replaced by:
j++;
i=j+20;
The following source code:
i=(j=25)+30;
may be replaced by:
j=25;
i=j+30;
Don't Code Numerical Constants Directly
Numerical constants (literals) should not be coded directly, except for −1, 0, and 1, which can appear in a for loop as counter values. Rather than coding numerical constants directly, add static final attributes for numeric constants.
Don't Place Multiple Statements on the Same Line
Each line should contain at most one statement. For example, for the following code:
The negation operator slows down the readability of the program, so it is recommended that it should not be used frequently. The following source code illustrates a violation of this rule:
The program logic should be changed to avoid negation:
Operator ‘?:’ may not be Used
The operator ‘?:’ makes the code harder to read, than the alternative form with an if-statement. Thus, in the following source code:
The ‘?:’ operator should be replaced with the appropriate if-else statement.
Parenthesize Conditional Part of Ternary Conditional Expression
Declarations should be placed only at the beginning of blocks. A block is any code surrounded by curly braces “{” and “}”. Waiting to declare variables until their first use can confuse the unwary programmer and hamper code portability within the scope.
Thus, in the following source code:
the declarations should be moved to the beginning of the block, as follows:
Provide Incremental in For-statement or Use While-statement
This audit checks if the third argument of the for-statement is missing, as shown below:
Either the incremental part of a for-structure must be provided or the for-statement must be cast into a while-statement, as shown below:
Replacement for Demand Imports
Demand import-declarations must be replaced with a list of single import-declarations that are actually imported into the compilation unit. In other words, import-statements may not end with an asterisk. For example, the following source code violates this audit:
To remedy the above, the demand imports should be replaced with a list of single import declarations, as shown below:
Switch Statement Should Include a Default Case
Every switch statement should include a default case.
Use Abbreviated Assignment Operator
The abbreviated assignment operator should be used to write programs more rapidly. This also increases the speed of some compilers. Thus, the following source code:
should be replaced by:
Use ‘this’ Explicitly To Access Class Members
‘This’ should be used explicitly to access class members because using the same class members' and parameters' names makes references confusing. For example, the following source code:
should be replaced by:
Avoid Hiding Inherited Attributes
This audit detects when attributes declared in child classes hide inherited attributes.
Thus, in the following source code:
the child class attribute should be renamed, as follows:
Avoid Hiding Inherited Static Methods
This audit detects when inherited static operations are hidden by child classes. Thus, in the following source code:
either ancestor or descendant class operations should be renamed, as follows:
Command Query Separation
This audit prevents methods that return a value from modifying state. The methods used to query the state of an object must be different from the methods used to perform commands (change the state of the object). For example, the following source code violates this audit:
Hiding Of Names
Declarations of names should not hide other declarations of the same name. The option ‘Formally’ regulates whether hiding of names should be detected for parameter variable, if the only usage of it is to assign its value to the attribute with the same name. Thus, for the following source code:
The variable which hides the attribute or another variable should be renamed, as follows:
In the above example, the second violation would be raised only if the “formally” option is switched on.
Inaccessible Constructor or Method Matches
Overload resolution only considers constructors and methods that are visible at the point of the call. If, however, all the constructors and methods were considered, there may be more matches, which would violate this audit.
For example, in the source code below, if ClassB is in a different package than ClassA, then the allocation of ClassB violates this rule since the second constructor is not visible at the point of the allocation, but it still matches the allocation (based on signature). Also the call to oper in ClassB violates this rule since the second and the third declarations of oper is not visible at the point of the call, but it still matches the call (based on signature).
Either such methods or constructors must be given equal visibility, or their signature must be changed, as follows:
Multiple Visible Declarations with Same Name
Multiple declarations with the same name must not be simultaneously visible except for overloaded methods. Thus, in the following source code:
The members (or variables) with clashing names should be renamed, as follows:
Overriding a Non-abstract Method with an Abstract Method
This audit checks for the overriding of non-abstract methods by abstract methods in a subclass. For example, in the following source code, the non-abstract method “func( )” is overridden by the abstract method “func( )” in a subclass:
To remedy this audit, the method may be renamed, or the method should be made abstract in an ancestor class or non-abstract in a descendant, as follows:
Overriding a Private Method
A subclass should not contain a method with the same name and signature as in a superclass if these methods are declared to be private. Thus, in the following source code:
the descendant class' method should be renamed, as follows:
Overloading within a Subclass
A superclass method may not be overloaded within a subclass unless all overloadings in the superclass are also overridden in the subclass. It is very unusual for a subclass to be overloading methods in its superclass without also overriding the methods it is overloading. More frequently this happens due to inconsistent changes between the superclass and subclass—i.e., the intention of the user is to override the method in the superclass, but due to the error, the subclass method ends up overloading the superclass method. The following source code violates this audit:
In the above code, the other methods should also be overloaded, as follows:
Use of Static Attribute for Initialization
Non-final static attributes should not be used in initializations of attributes. Thus, in the following source code:
The static attributes used for initialization should be made final, or another constant should be used for initialization, as follows:
Badly Located Array Declarators
Array declarators must be placed next to the type descriptor of their component type. Thus, the following source code:
should be replaced by:
Constant Private Attributes must be Final
Private attributes that never get their values changed must be declared final. By explicitly declaring them in such a way, a reader of the source code gets some information regarding how the attribute should be used. Thus, in the following source code:
all private attributes that never change should be made final, as follows:
Constant Variables Must be Final
Local variables that never get their values changed must be declared final. By explicitly declaring them in such a way, a reader of the source code gets some information regarding how the variable should be used. Thus, in the following source code:
all variables which are never changed should be made final, as follows:
Declare Variables in One Statement Each
Several variables (attributes and local variables) should not be declared in the same statement. The ‘different types only’ option can weaken this rule. When such option is chosen, violation is raised only when variables are of different types, for example: “int foo, fooarray[ ];” is definitely wrong. To correct the following source code:
each variable should be declared in separate statements, as follows:
Instantiated Classes Should be Final
This rule recommends making all instantiated classes final. It checks classes which are present in the object model. Classes from search/classpath are ignored. In the following source code:
all instantiated classes should be made final, as follows:
List all Public and Package Members First
Enforces standard to improve readability. Methods and/or data in classes should be ordered properly. Thus, in the following source code:
Public and package members should be placed before protected and private ones, as follows:
Order of Class Members Declaration
The parts of a class or interface declaration should appear in the following order:
This audit checks for correct ordering of modifiers. For classes, the ordering is: visibility (public, protected or private), abstract, static, final. For attributes, the ordering is: visibility (public, protected or private), static, final, transient, volatile. For operations, the ordering is: visibility (public, protected or private), abstract, static, final, synchronized, native. Thus, the following source code is incorrect:
The order of modifiers above should be changed, as follows:
Put the Main Function Last
This audit requires that in class definitions, the main function should be placed later in the definition. Thus, the following source code:
should be modified to:
Place Public Class First
The public class or interface should be the first class or interface in the file. Thus, the following source code:
should be modified to:
Bad Tag in JavaDoc Comments
This audit prevents the accidental use of improper JavaDoc tags. The following example illustrates the use of a bad tag:
The misspelled tags in the above code should be replaced, or any non-standard tags should be added to the list of valid tags.
Distinguish Between JavaDoc And Ordinary Comments
This audit checks whether JavaDoc comments end with ‘**/’ and ordinary C-style documents end with ‘*/’. Thus, the following code:
should be replaced by:
Provide File Comments
All source files should begin with a c-style comment that lists the class name, version information, date, and copyright notice, as follows
This audit verifies whether the file begins with a c-style comment.
Provide JavaDoc Comments
This audit checks whether JavaDoc comments are provided for classes, interfaces, methods and attributes.
Class Name must Match its File Name
This audit checks whether the top level class and/or interface has the same name as the file in which it resides. Thus, in the following source code:
This audit requires that group operations with the same name be placed together to improve readability. Thus, the following example:
should be modified, as follows:
Naming Conventions
This audit takes a regular expression and item name and reports all occurrences where the pattern does not match the declaration. Thus, in the following example,
The packages, classes, members etc., should be renamed in a proper way, as follows:
Names of Exception Classes
Names of classes which inherit from Exception should end with Exception.
Thus, the following source code:
One-character local variable or parameter names should be avoided, except for temporary and looping variables, or where a variable holds an undistinguished value of a type. Conventional one-character names are:
Local variable or parameter names that consist of only two or three uppercase letters should be avoided to avoid potential conflicts with the initial country codes and domain names that are the first component of unique package names.
The following source code does not give conventional names to all local variables:
and should be replaced by:
Avoid Declaring Variables Inside Loops
This rule recommends that local variables be declared outside the loops because declaring variables inside the loop is less efficient. Thus, in the following source code:
the variable declarations should be moved out of the loop, as follows:
Append to String within a Loop
Performance enhancements can be obtained by replacing String operations with StringBuffer operations if a String object is appended within a loop. Thus, in the following example source code:
StringBuffer class should be used instead of String, as follows:
Complex Loop Expressions
Avoid using complex expressions as repeat conditions within loops. The following source code violates this audit by using “vector.size( )” within a condition of a “for” loop:
In the above code, the expression “vector.size( )” should be assigned to a variable before the loop, and that variable should be used in the loop, as follows:
Avoid Empty Catch Blocks
Catch blocks should not be empty. Programmers frequently forget to process negative outcomes of a program and tend to focus more on the positive outcomes.
When the ‘Check parameter usage’ option is chosen, this rule also checks whether the code does something with the exception parameter or not. If not, a violation is raised.
Avoid Public and Package Attributes
Public and package attributes should be avoided. Rather, the attributes should be declared either private or protected, and operations should be provided to access or change the attribute declarations.
The visibility of attributes should be changed to either private or protected, and access operations for these attributes should be provided, as follows:
Avoid Statements with Empty Body
Statements having empty bodies should be avoided. For example, in the following source code:
a statement body should be provided. In the alternative, the logic of the program may be changed. For example, the “for” statement can be replaced by a “while” statement, as follows:
Assignment to For-Loop Variables
For-loop variables should not be assigned a value. For example, the for-loop variable “i” should not be assigned the value i++ as follows:
A continue operator should be used to correct the above code, as follows:
In the alternative, the for-loop may be converted to a while-loop.
Don't Compare Floating Point Types
Avoid testing floating point numbers for equality. Floating-point numbers that should be equal are not exactly equal due to rounding problems. Thus, the direct comparison in the following code:
should be replaced with an estimation of the absolute value of the difference, as follows:
Enclosing Body within a Block
The statement of a loop must always be a block. The then and else parts of if—statements must always be blocks. This makes it easier to add statements without accidentally introducing bugs due to missing braces. Thus, the following code is missing braces for both the if-loop and the while-loop:
The correct form for the above code is as follows:
Explicitly Initialize all Variables
All variables should explicitly be initialized. The only reason not to initialize a declared variable is if the initial value depends on a previous computation. For example, the following source code violates this rule since var 0 and var 2 are not initialized:
The correct form for the above source code is as follows:
Method finalize( ) Doesn't Call super.finalize( )
It is a good practice of programming to call super.finalize( ) from finalize( ), even if the base class doesn't define the finalize( ) method. This makes class implementations less dependent on each other. Thus, the following source code:
should be modified to:
Mixing Logical Operators without Parentheses
An expression containing multiple logical operators together should be parenthesized properly. Thus, in the following source code:
the parenthesis should be used to clarify complex logical expression to the reader, as follows:
No Assignments in Conditional Expressions
Assignments within conditions should be avoided since they make the source code difficult to understand. For example, the following source code:
should be replaced by:
Supply Break or Comment in Case Statement
Every time a case falls through and doesn't include a break statement, a comment should be added where the break statement would normally be. The break in the default case is redundant, but it prevents a fall-through error if later another case is added. Thus in the following source code:
a/* falls through */comment should be added, as follows:
Use ‘equals’ Instead of ‘=’
The ‘=’ operator is used on strings to check if two string objects are identical. However, in most cases, one would like to check if two strings have the same value. In these cases, the ‘equals’ method should be used. Thus, the following source code:
should be replaced by:
Use ‘L’ Instead Of ‘l’ at the end of integer constant
It is difficult to distinguish between lower case letter ‘l’ and digit ‘1’. As far as the letter ‘l’ can be used as a long modifier at the end of integer constant, it can be mixed with the digit. Thus, it is better to use an uppercase ‘L’. In the following example:
the trailing ‘l’ letter at the end of integer constants should be replaced with ‘L,’ as follows:
Use of the ‘Synchronized’ Modifier
The ‘synchronized’ modifier on methods can sometimes cause confusion during maintenance and debugging. This rule recommends avoiding the use of this modifier and encourages using ‘synchronized’ statements instead. Thus, in the following source code:
synchronized statements should be used instead of synchronized methods, as follows:
Duplicate Import Declarations
There should be only one import declaration that imports a particular class/package. The following source code violates this audit by containing multiple import declarations for java.io.* and java.sql.time:
To correct the above code, duplicate declarations should be deleted.
Don't Import the Package the Source File Belongs To
No. classes or interfaces need to be imported from the package that the source code file belongs to. Everything in that package is available without explicit import statements. Thus, the following source code contains the unnecessary import of “audit”:
To correct the above code, the unnecessary import statement should be deleted.
Explicit Import of the java.lang Classes
Explicit import of classes from the package ‘java.lang’ should not be performed. Thus, in the following source code, the unnecessary import of “java.lang.*” should be deleted:
Equality Operations on Boolean Arguments
Avoid performing equality operations on boolean operands. True and false literals should not be used in conditional clauses, as shown below:
The above source code should be replaced with the following:
Imported Items must be Used
It is not legal to import a class or an interface and never use it. This audit checks classes and interfaces that are explicitly imported with their names, not those with import of a complete package, i.e., using an asterisk. If unused class and interface imports are omitted, the amount of meaningless source code is reduced, thus the amount of code to be understood by a reader is minimized. Thus, the unnecessary import of “stack” in the following source code should be deleted:
Unnecessary Casts
This audit checks for the use of type casts that are not necessary. A cast is a Java™ language construct that performs a narrowing conversion. Thus, in the following example the cast “(elephant) el” is not necessary since el is already defined as type elephant:
In the above example, the unnecessary cast should be deleted to improve readability.
Unnecessary ‘Instanceof’ Evaluations
This audit determines whether the runtime type of the left-hand side expression is the same as the one specified on the right-hand side. Thus, in the following source code, the “if-loops” are unnecessary since both statements within the if loop are defined to be true. In particular, “Animal animal” defines animal as type Animal, “Elephant elephant” defines elephant as type Elephant, and “class Elephant extends Animal { }” defines Elephant to be the same type as Animal. Thus, elephant is also defined as type “Animal.”
To correct the above code, the if-loops can be removed, as follows:
Unused Local Variables and Formal Parameters
Local variables and formal parameters declarations must be used. Thus, in the following source code, the unused local variables and formal parameters should not be used.
Use of Obsolete Interface Modifier
The modifier ‘abstract,’ as shown in the following code, is considered obsolete and should not be used:
All interface operations are implicitly public and abstract. All interface attributes are implicitly public, final and static. Thus, the following source code contains unnecessary interface member modifiers:
The above code may be corrected, as follows:
Unused Private Class Member
An unused class member might indicate a logical flaw in the program. The class declaration has to be reconsidered in order to determine the need of the unused member(s). Thus, in the following source code, the unnecessary members, i.e., “bad_attr” and “bad_oper( ),” should be removed.
Unnecessary Return Statement Parentheses
A return statement with a value should not use parentheses unless it makes the return value more obvious in some way. For example, the following source code violates this audit:
and should be replaced by:
Locating Source Code Referenced by Verification Tool
The QA module is a verification tool. Conventional compilers are also verification tools, which provide messages to the user if an error is detected within the source code. The software development tool in accordance with methods and systems consistent with the present invention uses the error message from the verification tool to locate the source code corresponding to the message. Thus, the developer can use the improved software development tool to determine which line of source code corresponds to an error message from a verification tool. The verification tool may be part of the software development tool, or it may be external to the software development tool.
The choices for the severity 2110 are low, normal, and high. An example of an audit error message having low severity is “Avoid Too Long Files” (“ATLF”), which occurs when a file contains more than 2000 lines. According to standard code conventions for the Java™ programming language, having more than 2000 lines are cumbersome and should be avoided. Because this audit identifies a suggested format that will not affect the compilation or execution of the source code, it is considered a low severity message. The explanation 2114 of this message is “Avoid Too Long Files,” and the message uses the abbreviation 2112 “ATLF.” This message relates to a file that contains more than 2000 lines. Thus, the item 2118 to which the message occurs identifies the file name. The file 2120 in which the error occurs also identifies the same file, but includes the path to the file with the file name. With the ATLF audit, the line number 2122 of the source code where the error occurs is 2001 because the audit feature will not identify this error until it reaches the 2001st line of the source code. An example of a “normal” severity message is “Use Abbreviated Assignment Operator” (“UAAO”). The abbreviated assignment operator is preferred in order to write programs more rapidly and because some compilers run faster using abbreviated assignment operators. Although the failure to use the abbreviated assignment operator may slow the compilation of the source code, it will not prevent the program from compiling or executing properly, and is thus not a high severity message. Because of its effect on the compilation time, however, the failure to use the abbreviated assignment operator is considered a normal severity message rather than a low severity message. Finally, a high priority message is one that will prevent the source code from executing properly. For example, “Avoid Hiding Inherited Static Methods” (“AHISM”) identifies when inherited static operations are hidden by child classes. Thus, if the same term is used to define a class field in both a parent and a child class, the software development tool will use the same definition in both cases because the term is defined more than once within the project, thus making it ambiguous.
Returning to the flow diagram in
Although discussed in terms of the audit function of the QA module, the software development tool of the present invention may also use other verification tools to receive messages and locate specific lines of source code referenced by the message. These verification tools may be integrated into the software development tool, as in the case of the QA module, or may be external to the software development tool. Any verification tool known in the art may be used, and any known technique to locate the line of source code may be used.
While various embodiments of the present invention have been described, it will be apparent to those of skill in the art that many more embodiments and implementations are possible that are within the scope of this invention. Accordingly, the present invention is not to be restricted except in light of the attached claims and their equivalents.
This application claims the benefit of the filing date of U.S. Provisional Application No. 60/199,046, entitled “Software Development Tool,” filed on Apr. 21, 2000, and is a continuation-in-part of U.S. patent application Ser. No. 09/680,063, entitled “Method and System for Developing Software,” filed on Oct. 4, 2000, which claims the benefit of the filing date of U.S. Provisional Application No. 60/157,826, entitled “Visual Unified Modeling Language Development Tool,” filed on Oct. 5, 1999, and U.S. Provisional Application No. 60/199,046, entitled “Software Development Tool,” filed on Apr. 21, 2000; all of which are incorporated herein by reference. The following identified U.S. patent applications are also relied upon and are incorporated by reference in this application: U.S. patent application Ser. No. 09/680,065, entitled “Method And System For Displaying Changes Of Source Code,” filed on Oct. 4, 2000; U.S. patent application Ser. No. 09/680,030, entitled “Method And System For Generating, Applying, And Defining A Pattern,” filed on Oct. 4, 2000; U.S. patent application Ser. No. 09/680,064, entitled “Method And System For Collapsing A Graphical Representation Of Related Elements,” filed on Oct. 4, 2000; U.S. patent application Ser. No. 09/839,045, entitled “Methods and Systems for Generating Source Code for Object Oriented Elements,” and filed on the same date herewith; U.S. patent application Ser. No. 09/839,526, entitled “Methods and Systems for Relating Data Structures and Object Oriented Elements for Distributed Computing,” and filed on the same date herewith; U.S. patent application Ser. No. 09/839,645, entitled “Methods and Systems for Finding and Displaying Linked Objects,” and filed on the same date herewith; U.S. patent application Ser. No. 09/839,527, entitled “Methods and Systems for Animating the Interaction of Objects in an Object Oriented Program,” and filed on the same date herewith; U.S. patent application Ser. No. 09/839,646, entitled “Methods and Systems for Supporting and Deploying Distributed Computing Components,” and filed on the same date herewith; U.S. patent application Ser. No. 09/838,580, entitled “Diagrammatic Control of a Software in a Version Control System,” and filed on the same date herewith; U.S. patent application Ser. No. 09/838,578, entitled “Navigation Links in Generated Documentation,” and filed on the same date herewith; U.S. patent application Ser. No. 09/839,644, entitled “Methods and Systems for Identifying Dependencies Between Object-Oriented Elements,” and filed on the same date herewith; and U.S. patent application Ser. No. 09/839,524, entitled “Methods and Systems for Relating a Data Definition File and a Data Model for Distributed Computing,” and filed on the same date herewith.
Number | Name | Date | Kind |
---|---|---|---|
5410648 | Pazel | Apr 1995 | A |
5918053 | Graham | Jun 1999 | A |
6473896 | Hicken et al. | Oct 2002 | B1 |
Number | Date | Country |
---|---|---|
1 030 242 | Aug 2000 | EP |
1 030 252 | Aug 2000 | EP |
Number | Date | Country | |
---|---|---|---|
20020023257 A1 | Feb 2002 | US |
Number | Date | Country | |
---|---|---|---|
60199046 | Apr 2000 | US | |
60157826 | Oct 1999 | US | |
60199046 | Apr 2000 | US |
Number | Date | Country | |
---|---|---|---|
Parent | 09680063 | Oct 2000 | US |
Child | 09839525 | US |