Class JavaExpressionParseUtil

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static @Regex(1) java.util.regex.Pattern ANCHORED_PARAMETER_PATTERN
      Anchored pattern for a formal parameter use; matches a string that is exactly a formal parameter use.
      protected static java.lang.String PARAMETER_REGEX
      Regular expression for a formal parameter use.
      protected static @Regex(1) java.util.regex.Pattern UNANCHORED_PARAMETER_PATTERN
      Unanchored pattern for a formal parameter use; can be used to find all formal parameter uses.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int parameterIndex​(java.lang.String s)
      If s is exactly a formal parameter, return its 1-based index.
      static JavaExpression parse​(java.lang.String expression, javax.lang.model.type.TypeMirror enclosingType, @Nullable ThisReference thisReference, @Nullable java.util.List<FormalParameter> parameters, @Nullable com.sun.source.util.TreePath localVarPath, com.sun.source.util.TreePath pathToCompilationUnit, javax.annotation.processing.ProcessingEnvironment env)
      Parses a string to a JavaExpression.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • PARAMETER_REGEX

        protected static final java.lang.String PARAMETER_REGEX
        Regular expression for a formal parameter use.
        See Also:
        Constant Field Values
      • ANCHORED_PARAMETER_PATTERN

        protected static final @Regex(1) java.util.regex.Pattern ANCHORED_PARAMETER_PATTERN
        Anchored pattern for a formal parameter use; matches a string that is exactly a formal parameter use.
      • UNANCHORED_PARAMETER_PATTERN

        protected static final @Regex(1) java.util.regex.Pattern UNANCHORED_PARAMETER_PATTERN
        Unanchored pattern for a formal parameter use; can be used to find all formal parameter uses.
    • Constructor Detail

      • JavaExpressionParseUtil

        public JavaExpressionParseUtil()
    • Method Detail

      • parse

        public static JavaExpression parse​(java.lang.String expression,
                                           javax.lang.model.type.TypeMirror enclosingType,
                                           @Nullable ThisReference thisReference,
                                           @Nullable java.util.List<FormalParameter> parameters,
                                           @Nullable com.sun.source.util.TreePath localVarPath,
                                           com.sun.source.util.TreePath pathToCompilationUnit,
                                           javax.annotation.processing.ProcessingEnvironment env)
                                    throws JavaExpressionParseUtil.JavaExpressionParseException
        Parses a string to a JavaExpression.

        For most uses, clients should call one of the static methods in StringToJavaExpression rather than calling this method directly.

        Parameters:
        expression - the string expression to parse
        enclosingType - type of the class that encloses the JavaExpression
        thisReference - the JavaExpression to which to parse "this", or null if "this" should not appear in the expression
        parameters - list of JavaExpressions to which to parse formal parameter references such as "#2", or null if formal parameter references should not appear in the expression
        localVarPath - if non-null, the expression is parsed as if it were written at this location; affects only parsing of local variables
        pathToCompilationUnit - required to use the underlying Javac API
        env - the processing environment
        Returns:
        expression as a JavaExpression
        Throws:
        JavaExpressionParseUtil.JavaExpressionParseException - if the string cannot be parsed
      • parameterIndex

        public static int parameterIndex​(java.lang.String s)
        If s is exactly a formal parameter, return its 1-based index. Returns -1 otherwise.
        Parameters:
        s - a Java expression
        Returns:
        the 1-based index of the formal parameter that s represents, or -1