Interface ASTExpression

    • Method Detail

      • isExpression

        default boolean isExpression()
        Always returns true. This is to allow XPath queries to query like /*[@Expression=true()] to match any expression, but is useless in Java code.
      • getParenthesisDepth

        int getParenthesisDepth()
        Returns the number of parenthesis levels around this expression. If this method returns 0, then no parentheses are present.

        E.g. the expression (a + b) is parsed as an AdditiveExpression whose parenthesisDepth is 1, and in ((a + b)) it's 2.

        This is to avoid the parentheses interfering with analysis. Parentheses already influence parsing by breaking the natural precedence of operators. It would mostly hide false positives to make a ParenthesizedExpr node, because it would make semantically equivalent nodes have a very different representation.

        On the other hand, when a rule explicitly cares about parentheses, then this attribute may be used to find out whether parentheses were mentioned, so no information is lost.

      • isParenthesized

        default boolean isParenthesized()
        Returns true if this expression has at least one level of parentheses. The specific depth can be fetched with getParenthesisDepth().
      • getConstValue

        default @Nullable Object getConstValue()
        Description copied from interface: ASTMemberValue
        Returns the constant value of this node, if this is a constant expression. Otherwise, or if some references couldn't be resolved, returns null. Note that null is not a constant value, so this method's returning null is not a problem. Note that annotations are not given a constant value by this implementation.
        Specified by:
        getConstValue in interface ASTMemberValue
      • isCompileTimeConstant

        default boolean isCompileTimeConstant()
        Returns true if this expression is a compile-time constant, and is inlined.
      • getConversionContext

        @Experimental
        default @NonNull ExprContext getConversionContext()
        Returns the type expected by the context. This type may determine an implicit conversion of this value to that type (eg a boxing conversion, widening numeric conversion, or widening reference conversion).

        There are many different cases. For example, in arr['c'], TypeNode.getTypeMirror() would return char for the char literal, but the context type is int since it's used as an array index. Hence, a widening conversion occurs. Similarly, the context type of an expression in a return statement is the return type of the method, etc.

        If the context is undefined, then the returned object will answer true to ExprContext.isMissing(). This is completely normal and needs to be accounted for by rules. For instance, it occurs if this expression is used as a statement.

        Note that conversions are a language-level construct only. Converting from a type to another may not actually require any concrete operation at runtime. For instance, converting a char to an int is a noop at runtime, because chars are anyway treated as ints by the JVM (within stack frames). A boxing conversion will however in general translate to a call to e.g. Integer.valueOf(int).

        Not all contexts allow all kinds of conversions. See ExprContext.