< prev index next >

src/jdk.jextract/share/classes/com/sun/tools/jextract/HeaderFile.java

Print this page

        

@@ -21,14 +21,17 @@
  * questions.
  */
 package com.sun.tools.jextract;
 
 import java.nio.file.Path;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.logging.Logger;
+import java.util.stream.Stream;
 import jdk.internal.clang.Cursor;
 import jdk.internal.clang.CursorKind;
 import jdk.internal.clang.Type;
 import jdk.internal.clang.TypeKind;
 

@@ -41,10 +44,12 @@
     final String pkgName;
     final String clsName;
     private final TypeDictionary dict;
     // The top header file cause this file to be parsed
     private HeaderFile main;
+    // files included that are from the same directory
+    private final List<HeaderFile> includedFiles;
     private AsmCodeFactory cf;
     List<String> libraries; // immutable
     List<String> libraryPaths; // immutable
 
     private final AtomicInteger serialNo;

@@ -54,13 +59,18 @@
     HeaderFile(Context ctx, Path path, String pkgName, String clsName, HeaderFile main) {
         this.ctx = ctx;
         this.path = path;
         this.pkgName = pkgName;
         this.clsName = clsName;
-        dict = ctx.typeDictionaryFor(pkgName);
-        serialNo = new AtomicInteger();
+        this.dict = ctx.typeDictionaryFor(pkgName);
+        this.serialNo = new AtomicInteger();
         this.main = main == null ? this : main;
+        this.includedFiles = new ArrayList<>();
+    }
+
+    Stream<HeaderFile> getIncludedFiles() {
+        return includedFiles.stream();
     }
 
     void useLibraries(List<String> libraries, List<String> libraryPaths) {
         this.libraries = Collections.unmodifiableList(libraries);
         this.libraryPaths = Collections.unmodifiableList(libraryPaths);

@@ -82,10 +92,17 @@
             if (Main.DEBUG) {
                 new Throwable().printStackTrace(ctx.err);
             }
         } else {
             this.cf = cf;
+            // The 'main' header interface inherits from included header interfaces
+            // only if the included file is assigned to the same package and is from
+            // the same directory.
+            if (this != main && Objects.equals(pkgName, main.pkgName) &&
+                    Objects.equals(path.getParent(), main.path.getParent())) {
+                main.includedFiles.add(this);
+            }
         }
     }
 
     @Override
     public String toString() {

@@ -226,12 +243,10 @@
             case Unexposed:
             case Elaborated:
                 jt = define(t.canonicalType());
                 break;
             case ConstantArray:
-                jt = JType.ofArray(globalLookup(t.getElementType()));
-                break;
             case IncompleteArray:
                 jt = JType.ofArray(globalLookup(t.getElementType()));
                 break;
             case FunctionProto:
             case FunctionNoProto:
< prev index next >