Class CheckBundlesScanner

All Implemented Interfaces:
TreeVisitor<Object,Trees>

public class CheckBundlesScanner extends TreePathScanner<Object,Trees>
Tree path scanner for bundle getString() method invocations.
Collects the invocations of getString with a single argument that refer to a bundle, i.e. a static method of a bundle class, such as AppBundle.getString("key"), or a method of a ResourceBundle, such as getBundle().getString("key").
The key must be a compile-time constant expression of string literals and constant variables, such as "key", KEY, Keys.GREETING or PREFIX + "title". Invocations with other keys cannot be verified and are listed in getUnverifiedKeys().
Invocations referring to the bundle of a class annotated with NoBundle are skipped.
Invocations within a declaration annotated with @SuppressWarnings("bundle") (see Constants.SUPPRESS_WARNINGS_BUNDLE) are neither listed as unverified nor as unresolved.
A bundle class is annotated with an annotation that registers bundles, such as @Bundle, i.e. one that is annotated with Analyze referring to a BundleAnalyzeHandler.

The trees must be attributed, see scan(JavacTask, Iterable). If the invoked method or the type of the reference cannot be determined, the invocation is collected nevertheless and, in addition, listed in getUnresolvedKeys().

Author:
harald
  • Constructor Details

    • CheckBundlesScanner

      public CheckBundlesScanner()
  • Method Details

    • scan

      public void scan(JavacTask task, Iterable<? extends CompilationUnitTree> units)
      Scans the attributed compilation units of a task.
      Parameters:
      task - the task, already analyzed
      units - the compilation units of the task
    • visitMethodInvocation

      public Object visitMethodInvocation(MethodInvocationTree mit, Trees trees)
      Specified by:
      visitMethodInvocation in interface TreeVisitor<Object,Trees>
      Overrides:
      visitMethodInvocation in class TreeScanner<Object,Trees>
    • getBundleKeys

      public List<BundleKey> getBundleKeys()
      Gets the collected bundle keys.
      Returns:
      the bundle keys, never null
    • getSkippedKeys

      public List<BundleKey> getSkippedKeys()
      Gets the getString invocations that were ignored because they don't refer to a bundle.
      This includes the invocations referring to the bundle of a class annotated with NoBundle.
      Returns:
      the ignored keys, never null
    • getUnresolvedKeys

      public List<BundleKey> getUnresolvedKeys()
      Gets the collected bundle keys whose invocation could not be resolved, unless suppressed.
      Those keys are checked nevertheless, i.e. they are contained in getBundleKeys() as well.
      Returns:
      the unresolved keys, never null
    • getUnverifiedKeys

      public List<BundleKey> getUnverifiedKeys()
      Gets the getString invocations that refer to a bundle or could not be resolved, but whose argument is not a compile-time constant, unless suppressed.
      The key of those bundle keys is the source text of the argument expression.
      Returns:
      the unverified keys, never null