< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/tree/EnumTree.java

Print this page




  31 public class EnumTree extends Tree {
  32     private final Optional<Tree> definition;
  33     private final List<FieldTree> constants;
  34 
  35     EnumTree(Cursor c, Optional<Tree> definition, List<FieldTree> consts) {
  36         this(c, definition, consts, c.spelling());
  37     }
  38 
  39     private EnumTree(Cursor c, Optional<Tree> definition, List<FieldTree> consts, String name) {
  40         super(c, name);
  41         this.definition = c.isDefinition()? Optional.of(this) : Objects.requireNonNull(definition);
  42         this.constants = Collections.unmodifiableList(consts);
  43     }
  44 
  45     @Override
  46     public EnumTree withName(String newName) {
  47         return name().equals(newName)? this :
  48             new EnumTree(cursor(), definition, constants, newName);
  49     }
  50 

  51     public Optional<Tree> definition() {
  52         return definition;
  53     }
  54 
  55     public List<FieldTree> constants() {
  56         return constants;
  57     }
  58 
  59     @Override
  60     public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
  61         return visitor.visitEnum(this, data);
  62     }
  63 }


  31 public class EnumTree extends Tree {
  32     private final Optional<Tree> definition;
  33     private final List<FieldTree> constants;
  34 
  35     EnumTree(Cursor c, Optional<Tree> definition, List<FieldTree> consts) {
  36         this(c, definition, consts, c.spelling());
  37     }
  38 
  39     private EnumTree(Cursor c, Optional<Tree> definition, List<FieldTree> consts, String name) {
  40         super(c, name);
  41         this.definition = c.isDefinition()? Optional.of(this) : Objects.requireNonNull(definition);
  42         this.constants = Collections.unmodifiableList(consts);
  43     }
  44 
  45     @Override
  46     public EnumTree withName(String newName) {
  47         return name().equals(newName)? this :
  48             new EnumTree(cursor(), definition, constants, newName);
  49     }
  50 
  51     // definition of this struct if available anywhere in the compilation unit
  52     public Optional<Tree> definition() {
  53         return definition;
  54     }
  55 
  56     public List<FieldTree> constants() {
  57         return constants;
  58     }
  59 
  60     @Override
  61     public <R,D> R accept(TreeVisitor<R,D> visitor, D data) {
  62         return visitor.visitEnum(this, data);
  63     }
  64 }
< prev index next >