com.android.tools.lint.detector.api
Class TypeEvaluator

java.lang.Object
  extended by com.android.tools.lint.detector.api.TypeEvaluator

public class TypeEvaluator
extends java.lang.Object

Evaluates the types of nodes. This goes deeper than JavaContext.getType(Node) in that it analyzes the flow and for example figures out that if you ask for the type of var in this code snippet:

     Object o = new StringBuilder();
     Object var = o;
 
it will return "java.lang.StringBuilder".

NOTE: This type evaluator does not (yet) compute the correct types when involving implicit type conversions, so be careful if using this for primitives; e.g. for "int * long" it might return the type "int".


Constructor Summary
TypeEvaluator(JavaContext context)
          Creates a new constant evaluator
 
Method Summary
static JavaParser.TypeDescriptor evaluate(JavaContext context, lombok.ast.Node node)
          Evaluates the given node and returns the likely type of the instance.
 JavaParser.TypeDescriptor evaluate(lombok.ast.Node node)
          Returns true if the node evaluates to an instance of type SecureRandom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeEvaluator

public TypeEvaluator(@Nullable
                     JavaContext context)
Creates a new constant evaluator

Parameters:
context - the context to use to resolve field references, if any
Method Detail

evaluate

@Nullable
public JavaParser.TypeDescriptor evaluate(@NonNull
                                                   lombok.ast.Node node)
Returns true if the node evaluates to an instance of type SecureRandom


evaluate

@Nullable
public static JavaParser.TypeDescriptor evaluate(@NonNull
                                                          JavaContext context,
                                                          @NonNull
                                                          lombok.ast.Node node)
Evaluates the given node and returns the likely type of the instance. Convenience wrapper which creates a new TypeEvaluator, evaluates the node and returns the result.

Parameters:
context - the context to use to resolve field references, if any
node - the node to compute the type for
Returns:
the corresponding type descriptor, if found