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

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

public class ConstantEvaluator
extends java.lang.Object

Evaluates constant expressions


Constructor Summary
ConstantEvaluator(JavaContext context)
          Creates a new constant evaluator
 
Method Summary
 ConstantEvaluator allowUnknowns()
          Whether we allow computing values where some terms are unknown.
static java.lang.Object evaluate(JavaContext context, lombok.ast.Node node)
          Evaluates the given node and returns the constant value it resolves to, if any.
 java.lang.Object evaluate(lombok.ast.Node node)
          Evaluates the given node and returns the constant value it resolves to, if any
static java.lang.String evaluateString(JavaContext context, lombok.ast.Node node, boolean allowUnknown)
          Evaluates the given node and returns the constant string it resolves to, if any.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConstantEvaluator

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

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

allowUnknowns

public ConstantEvaluator allowUnknowns()
Whether we allow computing values where some terms are unknown. For example, the expression "foo" + x + "bar" would return null without and "foobar" with.

Returns:
this for constructor chaining

evaluate

@Nullable
public java.lang.Object evaluate(@NonNull
                                          lombok.ast.Node node)
Evaluates the given node and returns the constant value it resolves to, if any

Parameters:
node - the node to compute the constant value for
Returns:
the corresponding constant value - a String, an Integer, a Float, and so on

evaluate

@Nullable
public static java.lang.Object evaluate(@NonNull
                                                 JavaContext context,
                                                 @NonNull
                                                 lombok.ast.Node node)
Evaluates the given node and returns the constant value it resolves to, if any. Convenience wrapper which creates a new ConstantEvaluator, 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 constant value for
Returns:
the corresponding constant value - a String, an Integer, a Float, and so on

evaluateString

@Nullable
public static java.lang.String evaluateString(@NonNull
                                                       JavaContext context,
                                                       @NonNull
                                                       lombok.ast.Node node,
                                                       boolean allowUnknown)
Evaluates the given node and returns the constant string it resolves to, if any. Convenience wrapper which creates a new ConstantEvaluator, evaluates the node and returns the result if the result is a string.

Parameters:
context - the context to use to resolve field references, if any
node - the node to compute the constant value for
allowUnknown - whether we should construct the string even if some parts of it are unknown
Returns:
the corresponding string, if any