From 9e0c5c2af7143290a1a4ce97127fb2eb81c482ee Mon Sep 17 00:00:00 2001 From: squid233 <60126026+squid233@users.noreply.github.com> Date: Thu, 14 Dec 2023 13:51:18 +0800 Subject: [PATCH] Rename NativeApi to Downcall --- README.md | 2 +- .../overrun/marshal/test/CMarshalTest.java | 2 +- .../marshal/test/CMarshalTestWithLoader.java | 4 ++-- .../marshal/{NativeApi.java => Downcall.java} | 6 ++--- ...iProcessor.java => DowncallProcessor.java} | 24 +++++++++---------- .../java/overrun/marshal/LibraryLoader.java | 2 +- .../java/overrun/marshal/package-info.java | 2 +- .../javax.annotation.processing.Processor | 2 +- 8 files changed, 22 insertions(+), 22 deletions(-) rename src/main/java/overrun/marshal/{NativeApi.java => Downcall.java} (95%) rename src/main/java/overrun/marshal/{NativeApiProcessor.java => DowncallProcessor.java} (97%) diff --git a/README.md b/README.md index db4de5e..e66442f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ import java.lang.foreign.MemorySegment; * The documentation will be automatically copied * into the generated file */ -@NativeApi(libname = "libglfw.so", name = "GLFW") +@Downcall(libname = "libglfw.so", name = "GLFW") interface CGLFW { /** * A field diff --git a/demo/src/main/java/overrun/marshal/test/CMarshalTest.java b/demo/src/main/java/overrun/marshal/test/CMarshalTest.java index 1d8e0a8..6646861 100644 --- a/demo/src/main/java/overrun/marshal/test/CMarshalTest.java +++ b/demo/src/main/java/overrun/marshal/test/CMarshalTest.java @@ -26,7 +26,7 @@ * @author squid233 * @since 0.1.0 */ -@NativeApi(libname = "NativeLib.dll", name = "MarshalTest", makeFinal = false) +@Downcall(libname = "NativeLib.dll", name = "MarshalTest", makeFinal = false) public interface CMarshalTest { int CONST_VALUE = 42; boolean BOOL_VALUE = true; diff --git a/demo/src/main/java/overrun/marshal/test/CMarshalTestWithLoader.java b/demo/src/main/java/overrun/marshal/test/CMarshalTestWithLoader.java index b519bb3..c311766 100644 --- a/demo/src/main/java/overrun/marshal/test/CMarshalTestWithLoader.java +++ b/demo/src/main/java/overrun/marshal/test/CMarshalTestWithLoader.java @@ -16,7 +16,7 @@ package overrun.marshal.test; -import overrun.marshal.NativeApi; +import overrun.marshal.Downcall; import java.lang.foreign.MemorySegment; @@ -26,7 +26,7 @@ * @author squid233 * @since 0.1.0 */ -@NativeApi(libname = "NativeLib", name = "MarshalTestWithLoader", loader = NativeLibLoader.class) +@Downcall(libname = "NativeLib", name = "MarshalTestWithLoader", loader = NativeLibLoader.class) public interface CMarshalTestWithLoader { MemorySegment testWithArgAndReturnValue(MemorySegment segment); } diff --git a/src/main/java/overrun/marshal/NativeApi.java b/src/main/java/overrun/marshal/Downcall.java similarity index 95% rename from src/main/java/overrun/marshal/NativeApi.java rename to src/main/java/overrun/marshal/Downcall.java index 1677ac1..a5ccd43 100644 --- a/src/main/java/overrun/marshal/NativeApi.java +++ b/src/main/java/overrun/marshal/Downcall.java @@ -19,7 +19,7 @@ import java.lang.annotation.*; /** - * Marks a class or interface as a native API provider. + * Marks a class or interface as a downcall handles provider. *

Constants

* The generated file will include constants of primitive * (boolean, byte, short, int, long, float, double) and String types in the marked class or interface. @@ -45,7 +45,7 @@ * See {@link FixedSize @FixedSize} and {@link Ref @Ref}. *

Example

*
{@code
- * @NativeApi(libname = "libGL.so", name = "GL")
+ * @Downcall(libname = "libGL.so", name = "GL")
  * interface CGL {
  *     int COLOR_BUFFER_BIT = 0x00004000;
  *     void glClear(int mask);
@@ -65,7 +65,7 @@
 @Documented
 @Target(ElementType.TYPE)
 @Retention(RetentionPolicy.SOURCE)
-public @interface NativeApi {
+public @interface Downcall {
     /**
      * {@return the name of the native library}
      * 

diff --git a/src/main/java/overrun/marshal/NativeApiProcessor.java b/src/main/java/overrun/marshal/DowncallProcessor.java similarity index 97% rename from src/main/java/overrun/marshal/NativeApiProcessor.java rename to src/main/java/overrun/marshal/DowncallProcessor.java index 26cfcb0..e25d867 100644 --- a/src/main/java/overrun/marshal/NativeApiProcessor.java +++ b/src/main/java/overrun/marshal/DowncallProcessor.java @@ -41,16 +41,16 @@ import java.util.stream.Stream; /** - * The annotation processor + * Downcall annotation processor * * @author squid233 * @since 0.1.0 */ -public final class NativeApiProcessor extends AbstractProcessor { +public final class DowncallProcessor extends AbstractProcessor { /** * constructor */ - public NativeApiProcessor() { + public DowncallProcessor() { } @Override @@ -64,7 +64,7 @@ public boolean process(Set annotations, RoundEnvironment } private void processClasses(RoundEnvironment roundEnv) { - ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(NativeApi.class)).forEach(e -> { + ElementFilter.typesIn(roundEnv.getElementsAnnotatedWith(Downcall.class)).forEach(e -> { final var enclosed = e.getEnclosedElements(); try { writeFile(e, ElementFilter.fieldsIn(enclosed), ElementFilter.methodsIn(enclosed)); @@ -79,11 +79,11 @@ private void writeFile( List fields, List methods ) throws IOException { - final NativeApi nativeApi = type.getAnnotation(NativeApi.class); + final Downcall downcall = type.getAnnotation(Downcall.class); final String className = type.getQualifiedName().toString(); final int lastDot = className.lastIndexOf('.'); final String packageName = lastDot > 0 ? className.substring(0, lastDot) : null; - final String simpleClassName = nativeApi.name(); + final String simpleClassName = downcall.name(); final SourceFile file = new SourceFile(packageName); file.addImports( @@ -98,7 +98,7 @@ private void writeFile( ); file.addClass(simpleClassName, classSpec -> { classSpec.setDocument(getDocument(type)); - classSpec.setFinal(nativeApi.makeFinal()); + classSpec.setFinal(downcall.makeFinal()); // fields addFields(fields, classSpec); @@ -426,9 +426,9 @@ private void addFields(List fields, ClassSpec classSpec) { } private void addLoader(TypeElement type, ClassSpec classSpec) { - final NativeApi nativeApi = type.getAnnotation(NativeApi.class); + final Downcall downcall = type.getAnnotation(Downcall.class); final String loader = type.getAnnotationMirrors().stream() - .filter(m -> NativeApi.class.getName().equals(m.getAnnotationType().toString())) + .filter(m -> Downcall.class.getName().equals(m.getAnnotationType().toString())) .findFirst() .orElseThrow() .getElementValues().entrySet().stream() @@ -436,7 +436,7 @@ private void addLoader(TypeElement type, ClassSpec classSpec) { .findFirst() .map(e -> e.getValue().getValue().toString()) .orElse(null); - final String libname = nativeApi.libname(); + final String libname = downcall.libname(); classSpec.addField(new VariableStatement(SymbolLookup.class.getSimpleName(), "_LOOKUP", (loader == null ? @@ -454,7 +454,7 @@ private void addLoader(TypeElement type, ClassSpec classSpec) { } private void addMethodHandles(TypeElement type, List methods, ClassSpec classSpec) { - methods.stream().collect(Collectors.toMap(NativeApiProcessor::methodEntrypoint, Function.identity(), (e1, e2) -> { + methods.stream().collect(Collectors.toMap(DowncallProcessor::methodEntrypoint, Function.identity(), (e1, e2) -> { final Overload o1 = e1.getAnnotation(Overload.class); final Overload o2 = e2.getAnnotation(Overload.class); // if e1 is not an overload @@ -690,6 +690,6 @@ public SourceVersion getSupportedSourceVersion() { @Override public Set getSupportedAnnotationTypes() { - return Set.of(NativeApi.class.getName()); + return Set.of(Downcall.class.getName()); } } diff --git a/src/main/java/overrun/marshal/LibraryLoader.java b/src/main/java/overrun/marshal/LibraryLoader.java index 76c2391..9a69c6e 100644 --- a/src/main/java/overrun/marshal/LibraryLoader.java +++ b/src/main/java/overrun/marshal/LibraryLoader.java @@ -23,7 +23,7 @@ * A library loader. * * @author squid233 - * @see NativeApi + * @see Downcall * @since 0.1.0 */ public interface LibraryLoader { diff --git a/src/main/java/overrun/marshal/package-info.java b/src/main/java/overrun/marshal/package-info.java index 9fe1b9a..a620e4d 100644 --- a/src/main/java/overrun/marshal/package-info.java +++ b/src/main/java/overrun/marshal/package-info.java @@ -18,7 +18,7 @@ * The main package of marshal. * * @author squid233 - * @see overrun.marshal.NativeApi + * @see overrun.marshal.Downcall * @since 0.1.0 */ package overrun.marshal; diff --git a/src/main/resources/META-INF/services/javax.annotation.processing.Processor b/src/main/resources/META-INF/services/javax.annotation.processing.Processor index e87a907..6a48f28 100644 --- a/src/main/resources/META-INF/services/javax.annotation.processing.Processor +++ b/src/main/resources/META-INF/services/javax.annotation.processing.Processor @@ -1 +1 @@ -overrun.marshal.NativeApiProcessor +overrun.marshal.DowncallProcessor