Class ASTVariableDeclaratorId

    • Method Detail

      • acceptVisitor

        protected <P,​R> R acceptVisitor​(JavaVisitor<? super P,​? extends R> visitor,
                                              P data)
      • getLocalUsages

        public List<ASTAssignableExpr.ASTNamedReferenceExpr> getLocalUsages()
        Returns an unmodifiable list of the usages of this variable that are made in this file. Note that for a record component, this returns usages both for the formal parameter symbol and its field counterpart.

        Note that a variable initializer is not part of the usages (though this should be evident from the return type).

      • getExtraDimensions

        public @Nullable ASTArrayDimensions getExtraDimensions()
        Returns the extra array dimensions associated with this variable. For example in the declaration int a[], getTypeNode() returns int, and this method returns the dimensions that follow the variable ID. Returns null if there are no such dimensions.
      • getName

        public String getName()
        Returns the name of the variable.
      • hasArrayType

        public boolean hasArrayType()
        Returns true if the declared variable has an array type.
      • isExceptionBlockParameter

        public boolean isExceptionBlockParameter()
        Returns true if this nodes declares an exception parameter in a catch statement.
      • isFormalParameter

        public boolean isFormalParameter()
        Returns true if this node declares a formal parameter for a method declaration or a lambda expression.
      • isRecordComponent

        public boolean isRecordComponent()
        Returns true if this node declares a record component. The symbol born by this node is the symbol of the corresponding field (not the formal parameter of the record constructor).
      • isLocalVariable

        public boolean isLocalVariable()
        Returns true if this node declares a local variable from within a regular ASTLocalVariableDeclaration.
      • isForeachVariable

        public boolean isForeachVariable()
        Returns true if this node is a variable declared in a foreach loop.
      • isForLoopVariable

        public boolean isForLoopVariable()
        Returns true if this node is a variable declared in the init clause of a for loop.
      • isLambdaParameter

        public boolean isLambdaParameter()
        Returns true if this node declares a formal parameter for a lambda expression. In that case, the type of this parameter is not necessarily inferred, see isTypeInferred().
      • isEnumConstant

        public boolean isEnumConstant()
        Returns true if this node declares an enum constant.
      • isResourceDeclaration

        public boolean isResourceDeclaration()
        Returns true if this declarator id declares a resource in a try-with-resources statement.
      • isTypeInferred

        public boolean isTypeInferred()
        Returns true if the declared variable's type is inferred by the compiler. In Java 8, this can happen if it's in a formal parameter of a lambda with an inferred type (e.g. (a, b) -> a + b). Since Java 10, the type of local variables can be inferred too, e.g. var i = 2;.

        This method returns true for declarator IDs in those contexts, in which case getTypeNode() returns null, since the type node is absent.

      • isPatternBinding

        public boolean isPatternBinding()
        Returns true if this is a binding variable in a pattern.
      • getInitializer

        public @Nullable ASTExpression getInitializer()
        Returns the initializer of the variable, or null if it doesn't exist.
      • getTypeNameNode

        public @Nullable Node getTypeNameNode()
        Returns the first child of the node returned by getTypeNode(). The image of that node can usually be interpreted as the image of the type.
      • getTypeNode

        public @Nullable ASTType getTypeNode()
        Determines the type node of this variable id, that is, the type node belonging to the variable declaration of this node (either a FormalParameter, LocalVariableDeclaration or FieldDeclaration).

        The type of the returned node is not necessarily the type of this node. See getType() for an explanation.

        the type node, or null if there is no explicit type, e.g. if isTypeInferred() returns true.
      • getType

        public Class<?> getType()
        Returns the type of the declared variable. The type of a declarator ID is
        • 1. not necessarily the same as the type written out at the start of the declaration, e.g. int a[];
        • 2. not necessarily the same as the types of other variables declared in the same statement, e.g. int a[], b;.

        These are consequences of Java's allowing programmers to declare additional pairs of brackets on declarator ids. The type of the node returned by getTypeNode() doesn't take into account those additional array dimensions, whereas this node's type takes into account the total number of dimensions, i.e. those declared on this node plus those declared on the type node.

        The returned type also takes into account whether this variable is a varargs formal parameter.

        The type of the declarator ID is thus always the real type of the variable.

        Specified by:
        getType in interface TypeNode
        The Java Class, may return null.
      • getTypeMirror

        public @NonNull JTypeMirror getTypeMirror()
        Description copied from interface: TypeNode
        Returns the compile-time type of this node. For example, for a string literal, returns the type mirror for String, for a method call, returns the return type of the call, etc.

        This method ignores conversions applied to the value of the node because of its context. For example, in 1 + "", the numeric literal will have type int, but it is converted to String by the surrounding concatenation expression. Similarly, in Collections.singletonList(1), the ASTNumericLiteral node has type int, but the type of the method formal is Integer, and boxing is applied at runtime. Possibly, an API will be added to expose this information.

        Specified by:
        getTypeMirror in interface TypeNode
        The type mirror. Never returns null; if the type is unresolved, returns TypeSystem.UNKNOWN.
      • acceptVisitor

        public final <P,​R> R acceptVisitor​(AstVisitor<? super P,​? extends R> visitor,
                                                 P data)
        Specified by:
        acceptVisitor in interface Node
      • addChild

        protected void addChild​( child,
                                int index)
        addChild in class AbstractJjtreeNode<,​JavaNode>
      • insertChild

        protected void insertChild​( child,
                                   int index)
        insertChild in class AbstractJjtreeNode<,​JavaNode>
      • removeChildAtIndex

        protected void removeChildAtIndex​(int childIndex)
        removeChildAtIndex in class AbstractNode<,​JavaNode>
      • setChild

        protected void setChild​( child,
                                int index)
        setChild in class AbstractNode<,​JavaNode>
      • getSymbolTable

        public @NonNull JSymbolTable getSymbolTable()
        Description copied from interface: JavaNode
        Returns the symbol table for the program point represented by this node.
        Specified by:
        getSymbolTable in interface JavaNode
      • getTypeSystem

        public TypeSystem getTypeSystem()
        Description copied from interface: JavaNode
        Returns the type system with which this node was created. This is the object responsible for representing types in the compilation unit.
        Specified by:
        getTypeSystem in interface JavaNode