--- old/src/jdk.jextract/share/classes/com/sun/tools/jextract/tree/StructTree.java 2018-09-18 19:08:07.000000000 +0530 +++ new/src/jdk.jextract/share/classes/com/sun/tools/jextract/tree/StructTree.java 2018-09-18 19:08:06.000000000 +0530 @@ -26,16 +26,38 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; +import java.util.Optional; import java.util.function.BiFunction; import jdk.internal.clang.Cursor; import jdk.internal.clang.CursorKind; public class StructTree extends Tree { + private final Optional definition; private final List declarations; - public StructTree(Cursor c, List declarations) { - super(c); - this.declarations = Collections.unmodifiableList(declarations); + StructTree(Cursor c, Optional definition, List decls) { + this(c, definition, decls, c.spelling()); + } + + private StructTree(Cursor c, Optional definition, List decls, String name) { + super(c, name); + this.definition = c.isDefinition()? Optional.of(this) : Objects.requireNonNull(definition); + this.declarations = Collections.unmodifiableList(decls); + } + + @Override + public StructTree withName(String newName) { + return name().equals(newName)? this : + new StructTree(cursor(), definition, declarations, newName); + } + + public StructTree withNameAndDecls(String newName, List newDecls) { + return new StructTree(cursor(), definition, newDecls, newName); + } + + public Optional definition() { + return definition; } public List declarations() { @@ -87,6 +109,7 @@ return cursor().kind() == CursorKind.UnionDecl; } + /** * Is this struct/union declared as anonymous member of another struct/union? *