From 79e31d081583b1de2e228c309130dbf739dbe53c Mon Sep 17 00:00:00 2001 From: Oleksii PELYKH Date: Fri, 21 Jun 2024 08:44:36 +0200 Subject: [PATCH] (feat) lib: expose api() and handle() --- lib/src/main/java/org/pcre4j/Pcre2Code.java | 23 ++++++++++++++++++- .../java/org/pcre4j/Pcre2CompileContext.java | 23 ++++++++++++++++++- .../java/org/pcre4j/Pcre2GeneralContext.java | 20 +++++++++++++++- .../java/org/pcre4j/Pcre2MatchContext.java | 20 +++++++++++++++- .../main/java/org/pcre4j/Pcre2MatchData.java | 22 +++++++++++++++++- 5 files changed, 103 insertions(+), 5 deletions(-) diff --git a/lib/src/main/java/org/pcre4j/Pcre2Code.java b/lib/src/main/java/org/pcre4j/Pcre2Code.java index 53e090a..8b4dc8c 100644 --- a/lib/src/main/java/org/pcre4j/Pcre2Code.java +++ b/lib/src/main/java/org/pcre4j/Pcre2Code.java @@ -25,14 +25,17 @@ public class Pcre2Code { private static final Cleaner cleaner = Cleaner.create(); + /** * The compiled pattern handle */ /* package-private */ final long handle; + /** * The PCRE2 API reference to use across the entire lifecycle of the object */ - private final IPcre2 api; + /* package-private */ final IPcre2 api; + /** * The cleaner to free the compiled pattern */ @@ -120,6 +123,24 @@ private long getPatternSizeInfo(int info) { throw new Pcre2PatternInfoSizeError(Pcre2PatternInfo.valueOf(IPcre2.INFO_FRAMESIZE).orElseThrow(), infoSize); } + /** + * Get the PCRE2 API backing this compiled pattern + * + * @return the PCRE2 API + */ + public IPcre2 api() { + return api; + } + + /** + * Get the handle of the compiled pattern + * + * @return the handle of the compiled pattern + */ + public long handle() { + return handle; + } + /** * Get the number of highest backreference * diff --git a/lib/src/main/java/org/pcre4j/Pcre2CompileContext.java b/lib/src/main/java/org/pcre4j/Pcre2CompileContext.java index f54f3d9..36caef9 100644 --- a/lib/src/main/java/org/pcre4j/Pcre2CompileContext.java +++ b/lib/src/main/java/org/pcre4j/Pcre2CompileContext.java @@ -21,14 +21,17 @@ public class Pcre2CompileContext { private static final Cleaner cleaner = Cleaner.create(); + /** * The compile context handle */ /* package-private */ final long handle; + /** * The PCRE2 API reference to use across the entire lifecycle of the object */ - private final IPcre2 api; + /* package-private */ final IPcre2 api; + /** * The cleaner to free the resources */ @@ -54,6 +57,24 @@ public Pcre2CompileContext(Pcre2GeneralContext generalContext) { this.cleanable = cleaner.register(this, new Pcre2CompileContext.Clean(api, handle)); } + /** + * Get the PCRE2 API backing this compile context + * + * @return the PCRE2 API + */ + public IPcre2 api() { + return api; + } + + /** + * Get the handle of the compile context + * + * @return the handle of the compile context + */ + public long handle() { + return handle; + } + private record Clean(IPcre2 api, long compileContext) implements Runnable { @Override public void run() { diff --git a/lib/src/main/java/org/pcre4j/Pcre2GeneralContext.java b/lib/src/main/java/org/pcre4j/Pcre2GeneralContext.java index 1341468..2461013 100644 --- a/lib/src/main/java/org/pcre4j/Pcre2GeneralContext.java +++ b/lib/src/main/java/org/pcre4j/Pcre2GeneralContext.java @@ -28,7 +28,7 @@ public class Pcre2GeneralContext { /** * The PCRE2 API reference to use across the entire lifecycle of the object */ - private final IPcre2 api; + /* package-private */ final IPcre2 api; /** * The cleaner to free the resources */ @@ -50,6 +50,24 @@ public Pcre2GeneralContext() { this.cleanable = cleaner.register(this, new Pcre2GeneralContext.Clean(api, handle)); } + /** + * Get the PCRE2 API backing this general context + * + * @return the PCRE2 API + */ + public IPcre2 api() { + return api; + } + + /** + * Get the handle of the general context + * + * @return the handle of the general context + */ + public long handle() { + return handle; + } + private record Clean(IPcre2 api, long generalContext) implements Runnable { @Override public void run() { diff --git a/lib/src/main/java/org/pcre4j/Pcre2MatchContext.java b/lib/src/main/java/org/pcre4j/Pcre2MatchContext.java index 88423d2..3145251 100644 --- a/lib/src/main/java/org/pcre4j/Pcre2MatchContext.java +++ b/lib/src/main/java/org/pcre4j/Pcre2MatchContext.java @@ -28,7 +28,7 @@ public class Pcre2MatchContext { /** * The PCRE2 API reference to use across the entire lifecycle of the object */ - private final IPcre2 api; + /* package-private */ final IPcre2 api; /** * The cleaner to free the resources */ @@ -54,6 +54,24 @@ public Pcre2MatchContext(Pcre2GeneralContext generalContext) { this.cleanable = cleaner.register(this, new Pcre2MatchContext.Clean(api, handle)); } + /** + * Get the PCRE2 API backing this match context + * + * @return the PCRE2 API + */ + public IPcre2 api() { + return api; + } + + /** + * Get the handle of the match context + * + * @return the handle of the match context + */ + public long handle() { + return handle; + } + private record Clean(IPcre2 api, long matchContext) implements Runnable { @Override public void run() { diff --git a/lib/src/main/java/org/pcre4j/Pcre2MatchData.java b/lib/src/main/java/org/pcre4j/Pcre2MatchData.java index 1430cbc..bd0adbb 100644 --- a/lib/src/main/java/org/pcre4j/Pcre2MatchData.java +++ b/lib/src/main/java/org/pcre4j/Pcre2MatchData.java @@ -28,10 +28,12 @@ public class Pcre2MatchData { * The match data handle */ /* package-private */ final long handle; + /** * The PCRE2 API reference to use across the entire lifecycle of the object */ - private final IPcre2 api; + /* package-private */ final IPcre2 api; + /** * The cleaner to free the resources */ @@ -79,6 +81,24 @@ public Pcre2MatchData(Pcre2Code code) { this.cleanable = cleaner.register(this, new Pcre2MatchData.Clean(api, handle)); } + /** + * Get the PCRE2 API backing this match data + * + * @return the PCRE2 API + */ + public IPcre2 api() { + return api; + } + + /** + * Get the handle of the match data + * + * @return the handle of the match data + */ + public long handle() { + return handle; + } + /** * Get number of the offset pairs in the output vector *