< prev index next >

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

Print this page

        

@@ -82,11 +82,16 @@
         checkCursor(c, CursorKind.EnumDecl);
         return createEnumCommon(c, fields);
     }
 
     private EnumTree createEnumCommon(Cursor c, List<FieldTree> fields) {
-        Optional<Tree> def = Optional.ofNullable(c.isDefinition()? null : createTree(c.getDefinition()));
+        // If the current Cursor is not a definition, get the definition
+        // and wrap it only if that is a valid definition.
+        Optional<Tree> def = Optional.ofNullable(
+            (c.isDefinition() || c.getDefinition().isInvalid())?
+            null : createTree(c.getDefinition())
+        );
         return checkCache(c, EnumTree.class, ()->new EnumTree(c, def, fields));
     }
 
     public FieldTree createField(Cursor c) {
         checkCursorAny(c, CursorKind.EnumConstantDecl, CursorKind.FieldDecl);

@@ -117,11 +122,16 @@
         checkCursorAny(c, CursorKind.StructDecl, CursorKind.UnionDecl);
         return createStructCommon(c, declarations);
     }
 
     private StructTree createStructCommon(Cursor c, List<Tree> declarations) {
-        Optional<Tree> def = Optional.ofNullable(c.isDefinition()? null : createTree(c.getDefinition()));
+        // If the current Cursor is not a definition, get the definition
+        // and wrap it only if that is a valid definition.
+        Optional<Tree> def = Optional.ofNullable(
+            (c.isDefinition() || c.getDefinition().isInvalid())?
+            null : createTree(c.getDefinition())
+        );
         return checkCache(c, StructTree.class, ()->new StructTree(c, def, declarations));
     }
 
     public TypedefTree createTypedef(Cursor c) {
         checkCursor(c, CursorKind.TypedefDecl);
< prev index next >