< prev index next >

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

Print this page




  39     StructTree(Cursor c, Optional<Tree> definition, List<Tree> decls) {
  40         this(c, definition, decls, c.spelling());
  41     }
  42 
  43     private StructTree(Cursor c, Optional<Tree> definition, List<Tree> decls, String name) {
  44         super(c, name);
  45         this.definition = c.isDefinition()? Optional.of(this) : Objects.requireNonNull(definition);
  46         this.declarations = Collections.unmodifiableList(decls);
  47     }
  48 
  49     @Override
  50     public StructTree withName(String newName) {
  51         return name().equals(newName)? this :
  52             new StructTree(cursor(), definition, declarations, newName);
  53     }
  54 
  55     public StructTree withNameAndDecls(String newName, List<Tree> newDecls) {
  56         return new StructTree(cursor(), definition, newDecls, newName);
  57     }
  58 

  59     public Optional<Tree> definition() {
  60         return definition;
  61     }
  62 
  63     public List<Tree> declarations() {
  64         return declarations;
  65     }
  66 
  67     public List<FieldTree> fields() {
  68         // Note that we have to include fields from nested annoymous unions and structs
  69         // in the containing struct.
  70         List<FieldTree> fields = new ArrayList<>();
  71         for (Tree decl : declarations) {
  72             if (decl instanceof FieldTree) {
  73                 fields.add((FieldTree)decl);
  74             } else if (decl instanceof StructTree) {
  75                 StructTree s = (StructTree)decl;
  76                 if (s.isAnonymous()) {
  77                     fields.addAll(s.fields());
  78                 }




  39     StructTree(Cursor c, Optional<Tree> definition, List<Tree> decls) {
  40         this(c, definition, decls, c.spelling());
  41     }
  42 
  43     private StructTree(Cursor c, Optional<Tree> definition, List<Tree> decls, String name) {
  44         super(c, name);
  45         this.definition = c.isDefinition()? Optional.of(this) : Objects.requireNonNull(definition);
  46         this.declarations = Collections.unmodifiableList(decls);
  47     }
  48 
  49     @Override
  50     public StructTree withName(String newName) {
  51         return name().equals(newName)? this :
  52             new StructTree(cursor(), definition, declarations, newName);
  53     }
  54 
  55     public StructTree withNameAndDecls(String newName, List<Tree> newDecls) {
  56         return new StructTree(cursor(), definition, newDecls, newName);
  57     }
  58 
  59     // definition of this struct if available anywhere in the compilation unit
  60     public Optional<Tree> definition() {
  61         return definition;
  62     }
  63 
  64     public List<Tree> declarations() {
  65         return declarations;
  66     }
  67 
  68     public List<FieldTree> fields() {
  69         // Note that we have to include fields from nested annoymous unions and structs
  70         // in the containing struct.
  71         List<FieldTree> fields = new ArrayList<>();
  72         for (Tree decl : declarations) {
  73             if (decl instanceof FieldTree) {
  74                 fields.add((FieldTree)decl);
  75             } else if (decl instanceof StructTree) {
  76                 StructTree s = (StructTree)decl;
  77                 if (s.isAnonymous()) {
  78                     fields.addAll(s.fields());
  79                 }


< prev index next >