Top Description Methods
com.github.javaparser.ast.nodeTypes

public Interface NodeWithVariables<N extends Node>

Known Direct Implementers
com.github.javaparser.ast.body.FieldDeclaration, com.github.javaparser.ast.expr.VariableDeclarationExpr
Imports
com.github.javaparser.ast.Node, .NodeList, com.github.javaparser.ast.body.VariableDeclarator, com.github.javaparser.ast.type.ArrayType, .Type, com.github.javaparser.metamodel.DerivedProperty, java.util.List, .Optional, java.util.stream.Collectors

A node which has a list of variables.

Method Summary

Modifier and TypeMethod and Description
public default N
addVariable(VariableDeclarator variableDeclarator)

public static Optional<Type>
public default Type
getCommonType()

Returns the type that is shared between all variables.

public default Type
getElementType()

Returns the element type.

public default Optional<Type>
getMaximumCommonType()

Returns the type that maximum shared type between all variables.

public default VariableDeclarator
getVariable(int i)

public NodeList<VariableDeclarator>
public default N
setAllTypes(Type newType)

Sets the type of all variables.

public default N
setVariable(int i, VariableDeclarator variableDeclarator)

public N

Method Detail

addVariableback to summary
public default N addVariable(VariableDeclarator variableDeclarator)
Annotations
@SuppressWarnings:unchecked
calculateMaximumCommonTypeback to summary
public static Optional<Type> calculateMaximumCommonType(List<Type> types)
getCommonTypeback to summary
public default Type getCommonType()

Returns the type that is shared between all variables. This is a shortcut for when you are certain that all variables share one type. What makes this difficult is arrays, and being able to set the type.
For int a; this is int.
For int a,b,c,d; this is also int.
For int a,b[],c; this is an assertion error since b is an int[], not an int.
For int a,b;, then doing setType(String) on b, this is an assertion error. It is also a situation that you don't really want.

getElementTypeback to summary
public default Type getElementType()

Returns the element type.
For int a; this is int.
For int a,b,c,d; this is also int.
For int a,b[],c; this is also int.

Note

no mention of b being an array.
For int a,b;, then doing setType(String) on b, then calling getElementType(). This is an assertion error. It is also a situation that you don't really want.

getMaximumCommonTypeback to summary
public default Optional<Type> getMaximumCommonType()

Returns the type that maximum shared type between all variables. The minimum common type does never include annotations on the array level.


For int a; this is int.
For int a,b,c,d; this is also int.
For int a,b[],c; this is also int.
For int[] a[][],b[],c[][]; this is int[][].

Annotations
@DerivedProperty
getVariableback to summary
public default VariableDeclarator getVariable(int i)
getVariablesback to summary
public NodeList<VariableDeclarator> getVariables()
setAllTypesback to summary
public default N setAllTypes(Type newType)

Sets the type of all variables. Erases any existing type. This is a shortcut for setting a type on all variable declarators separately.

Annotations
@SuppressWarnings:unchecked
setVariableback to summary
public default N setVariable(int i, VariableDeclarator variableDeclarator)
Annotations
@SuppressWarnings:unchecked
setVariablesback to summary
public N setVariables(NodeList<VariableDeclarator> variables)