Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
PDT Analysis
J2SE Best Practices for PDT
Static analysis
- Static code analysis is the analysis of computer software that is performed without actually executing programs built from that software. Objective: find properties on a given program.
- Step after semantic analysis
- Usages: compiler optimization like constant propagation, reachability. More: detecting logical errors
- The idea: build CFG then run in “abstract mode” and do conservative operations to a least fixed point.
- Another tool is to check for best practices on the users code
Methods of usage 1. Evaluating a 3rd party code 2. Code Review 3. Bug fixes 4. Development
Using TPTP analysis tool 1. Launch 2. Launch Configuration 3. Results 4. Auto- fix (Ctrl + 1) 5. Nightly reports [1]
Rules for example
- Severe: Override both hashCode() and equals()
- Warning: Always use break; in a case branch of a switch statement
- Recommendation: Using an if/else statement instead of a ternary operator makes code longer than necessary
Write your own rule
- Preferences-> Analysis ->Add Custom Rule
- Implement the Rule class
/** * Run the analysis portion * @param history A reference to the history record */ public void analyze( AnalysisHistory history);