This is an automated email from the ASF dual-hosted git repository.

olabusayo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 097ac3c8d Expose `UnparseResult.location` in the API
097ac3c8d is described below

commit 097ac3c8d71c2126632a8c49af734ebc326b1d64
Author: olabusayoT <[email protected]>
AuthorDate: Fri Aug 15 16:53:32 2025 -0400

    Expose `UnparseResult.location` in the API
    
    - Updated `Result` interface to extend `WithDiagnostics` to remove some 
redundant methods.
    - Added a `location` method to the `Result` interface for retrieving the 
current `DataLocation`.
    - Updated `DataProcessor` to support the new `location` method.
    
    DAFFODIL-3031
---
 .../java/org/apache/daffodil/api/ParseResult.java  | 27 +---------------------
 .../main/java/org/apache/daffodil/api/Result.java  | 26 +++++++--------------
 .../org/apache/daffodil/api/UnparseResult.java     |  4 +---
 .../runtime1/iapi/DFDLParserUnparser.scala         | 14 +++++------
 .../runtime1/processors/DataProcessor.scala        |  2 ++
 5 files changed, 19 insertions(+), 54 deletions(-)

diff --git 
a/daffodil-core/src/main/java/org/apache/daffodil/api/ParseResult.java 
b/daffodil-core/src/main/java/org/apache/daffodil/api/ParseResult.java
index 8499da3a2..9dbf9a733 100644
--- a/daffodil-core/src/main/java/org/apache/daffodil/api/ParseResult.java
+++ b/daffodil-core/src/main/java/org/apache/daffodil/api/ParseResult.java
@@ -21,29 +21,4 @@ package org.apache.daffodil.api;
  * Result of calling {@code DataProcessor.parse(input:org\.apache\.daffodil* 
DataProcessor.parse}, containing
  * any diagnostic information, and the final data location
  */
-public interface ParseResult extends Result, WithDiagnostics {
-  /**
-   * Get the {@link org.apache.daffodil.api.DataLocation} where the parse 
completed
-   *
-   * @return the data location where the parse completed
-   */
-  DataLocation location();
-
-  /**
-   * Determine if any processing errors occurred. isError() will always return
-   * true if this returns true.
-   *
-   * @return true if any processing errors occurred, false otherwise.
-   */
-  boolean isProcessingError();
-
-  /**
-   * Determine if all validation checks passed based on the validation mode of
-   * the DataProcessor. If validation mode is Off, this will always return
-   * false. This is only meaningful when isProcessingError() is false.
-   * isError() will always return true if this return true.
-   *
-   * @return true if any validation errors occurred, false otherwise.
-   */
-  boolean isValidationError();
-}
+public interface ParseResult extends Result {}
diff --git a/daffodil-core/src/main/java/org/apache/daffodil/api/Result.java 
b/daffodil-core/src/main/java/org/apache/daffodil/api/Result.java
index 655bee117..e51d50235 100644
--- a/daffodil-core/src/main/java/org/apache/daffodil/api/Result.java
+++ b/daffodil-core/src/main/java/org/apache/daffodil/api/Result.java
@@ -17,27 +17,10 @@
 
 package org.apache.daffodil.api;
 
-import java.util.List;
-
 /**
  * Interface for Parse and Unparse results
  */
-public interface Result {
-  /**
-   * @return list of diagnostics
-   */
-  List<Diagnostic> getDiagnostics();
-
-  /**
-   * @param diagnostic diagnostic to add to list of diagnostics
-   */
-  void addDiagnostic(Diagnostic diagnostic);
-
-  /**
-   * @return true if in error state
-   */
-  boolean isError();
-
+public interface Result extends WithDiagnostics {
   /**
    * @return true if cause of error state is processing error
    */
@@ -47,4 +30,11 @@ public interface Result {
    * @return true if cause of error state is validation error
    */
   boolean isValidationError();
+
+  /**
+   * Get the current {@link DataLocation}
+   *
+   * @return the current location
+   */
+  DataLocation location();
 }
diff --git 
a/daffodil-core/src/main/java/org/apache/daffodil/api/UnparseResult.java 
b/daffodil-core/src/main/java/org/apache/daffodil/api/UnparseResult.java
index a8cd2fb57..975dd0cbf 100644
--- a/daffodil-core/src/main/java/org/apache/daffodil/api/UnparseResult.java
+++ b/daffodil-core/src/main/java/org/apache/daffodil/api/UnparseResult.java
@@ -21,6 +21,4 @@ package org.apache.daffodil.api;
  * Result of calling {@code DataProcessor#unparse(InfosetInputter, 
java.nio.channels.WritableByteChannel)},
  * containing diagnostic information
  */
-public interface UnparseResult extends Result, WithDiagnostics {
-
-}
+public interface UnparseResult extends Result {}
diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/iapi/DFDLParserUnparser.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/iapi/DFDLParserUnparser.scala
index 08a5d1a41..ee4c012be 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/iapi/DFDLParserUnparser.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/iapi/DFDLParserUnparser.scala
@@ -154,9 +154,9 @@ object DFDL {
     def this(cause: Exception) = this(null, cause)
   }
 
-  trait ParseResult extends Result with WithDiagnostics with api.ParseResult
+  trait ParseResult extends Result with api.ParseResult
 
-  trait UnparseResult extends Result with api.UnparseResult with 
WithDiagnostics {
+  trait UnparseResult extends Result with api.UnparseResult {
 
     /**
      * Data is 'scannable' if it consists entirely of textual data, and that 
data
@@ -195,7 +195,7 @@ object DFDL {
   /**
    * Interface for Parse and Unparse results
    */
-  abstract class Result extends api.Result {
+  abstract class Result extends api.Result with WithDiagnostics {
     def resultState: State
     var diagnostics: Seq[api.Diagnostic] = Nil
 
@@ -210,12 +210,12 @@ object DFDL {
       (diagnostics ++ resultState.diagnostics ++ 
resultStatusDiagnostics).distinct.asJava
     }
 
-    override def addDiagnostic(d: api.Diagnostic): Unit = {
+    def addDiagnostic(d: api.Diagnostic): Unit = {
       diagnostics = d +: diagnostics
     }
 
-    override def isError = isProcessingError || isValidationError
-    override def isProcessingError = resultState.processorStatus != Success
-    override def isValidationError = resultState.validationStatus != true
+    override def isError: Boolean = isProcessingError || isValidationError
+    override def isProcessingError: Boolean = resultState.processorStatus != 
Success
+    override def isValidationError: Boolean = !resultState.validationStatus
   }
 }
diff --git 
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
 
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
index d0bffb1e8..9407eae8b 100644
--- 
a/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
+++ 
b/daffodil-core/src/main/scala/org/apache/daffodil/runtime1/processors/DataProcessor.scala
@@ -603,6 +603,8 @@ class UnparseResult(dp: DataProcessor, ustate: UState)
 
   override def resultState = ustate
 
+  override def location(): api.DataLocation = resultState.currentLocation
+
   private def maybeEncodingInfo =
     if (Maybe.WithNulls.isDefined(ustate.currentInfosetNode))
       
One(ustate.currentInfosetNode.asInstanceOf[DIElement].runtimeData.encodingInfo)

Reply via email to