< prev index next >
src/jdk.jextract/share/classes/com/sun/tools/jextract/JavaSourceFactory.java
Print this page
@@ -88,16 +88,17 @@
this.types = new HashMap<>();
this.libraryNames = ctx.options.libraryNames;
this.libraryPaths = ctx.options.recordLibraryPath? ctx.options.libraryPaths : null;
this.noNativeLocations = ctx.options.noNativeLocations;
this.global_jsb = new JavaSourceBuilder();
- this.srcDir = Paths.get(ctx.options.srcDumpDir)
- .resolve(headerFile.pkgName.replace('.', File.separatorChar));
+ this.srcDir = ctx.options.srcDumpDir != null?
+ Paths.get(ctx.options.srcDumpDir).resolve(headerFile.pkgName.replace('.', File.separatorChar)) :
+ null;
}
// main entry point that generates & saves .java files for the header file
- public void generate(List<Tree> decls) {
+ public Map<String, String> generate(List<Tree> decls) {
global_jsb.addPackagePrefix(headerFile.pkgName);
Map<String, Object> header = new HashMap<>();
header.put("path", headerFile.path.toAbsolutePath().toString());
if (!libraryNames.isEmpty()) {
@@ -139,19 +140,25 @@
global_jsb.addNestedType(jsb);
}
global_jsb.interfaceEnd();
String src = global_jsb.build();
+ if (srcDir != null) {
try {
Files.createDirectories(srcDir);
Path srcPath = srcDir.resolve(clsName + ".java");
Files.write(srcPath, List.of(src));
} catch (Exception ex) {
handleException(ex);
}
}
+ Map<String, String> srcMap = new HashMap<>();
+ srcMap.put(headerClassName, src);
+ return srcMap;
+ }
+
protected void handleException(Exception ex) {
log.printError("cannot.write.class.file", headerFile.pkgName + "." + headerFile.headerClsName, ex);
log.printStackTrace(ex);
}
@@ -348,11 +355,11 @@
@Override
public Boolean visitFunction(FunctionTree funcTree, JType jt) {
assert (jt instanceof JType.Function);
JType.Function fn = (JType.Function)jt;
- log.print(Level.FINE, () -> "Add method: " + fn.getSignature(false));
+ log.print(Level.FINE, () -> "Add method: " + fn.getSourceSignature(false));
addNativeLocation(global_jsb, funcTree);
Type type = funcTree.type();
final String descStr = Utils.getFunction(type).toString();
global_jsb.addAnnotation(NATIVE_FUNCTION, Map.of("value", descStr));
< prev index next >