FeaturesPluginsDocs & SupportCommunityPartners

API Examples

Here are some example queries:
  • StatsReporter.java: a simple counter of classes, methods, fields, statements, and AST nodes.
  • FindUnusedVariables.java: finds variables which are not referenced by any source files.
  • BadFinallyBlocks.java: locates try blocks with finally clauses which contain throws or return statements.
  • ConstPublicCalls.java: locates constructors which call "dangerous" methods, which are defined as any overridable public method, or methods where "this" is passed as a parameter.  In both cases, an incompletely initialized object may be passed outside of the class.
  • CouldBeStatic.java: reports which methods could be made static, which can reduce coupling when used by other classes.
  • FindSelfAssignments.java: finds cases where a variable is initialized to its own value, which is usually a mistake often found in constructors.
Here are some example transformers:
  • AddOverrides.java: adds an "@Overrides" annotation to each method which overrides a superclass method.  The javac compiler will then verify that contract with each build.
  • AddDeprecateds.java: a similar transformer that adds "@Deprecated" annotations to methods and fields which are deprecated (unless their class is deprecated).
  • MinimizeFieldAccess.java, MinimizeMethodAccess.java: restricts field and method access as much as possible given their current usage by other classes.
  • TailMerge.java: finds common trailing code in the then and else clauses of an if statement, then pulls it out to follow that statement.
  • SimplifyLoops.java: finds unnecessarily complicated code in loops, if statements and blocks and simplifies it without changing its semantics.
  • SimplifyIfStatements.java: transforms if statements that can be expressed more simply.
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Virtual Box - full virtualizer  Open ESB - The Open Enterprise Service Bus Powered by