-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce DebuggableTransformerFunctions to debug each step in tranfo…
…rmer operation. (java-0.6.0, js-1.1.0, js-core-1.1.1)
- Loading branch information
Showing
46 changed files
with
667 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ plugins { | |
} | ||
|
||
group 'co.nlighten' | ||
version = '0.5.2' | ||
version = '0.6.0' | ||
|
||
ext { | ||
gsonVersion = "2.10.1" | ||
|
44 changes: 44 additions & 0 deletions
44
...son-transform/src/main/java/co/nlighten/jsontransform/DebuggableTransformerFunctions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package co.nlighten.jsontransform; | ||
|
||
import co.nlighten.jsontransform.adapters.JsonAdapter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class DebuggableTransformerFunctions<JE, JA extends Iterable<JE>, JO extends JE> extends TransformerFunctions<JE, JA, JO>{ | ||
private final Map<String, TransformerDebugInfo> debugResults; | ||
|
||
public record TransformerDebugInfo(Object result) {} | ||
|
||
public DebuggableTransformerFunctions(JsonAdapter<JE, JA, JO> adapter) { | ||
super(adapter); | ||
debugResults = new HashMap<>(); | ||
} | ||
|
||
private TransformerFunctions.FunctionMatchResult<Object> auditAndReturn(String path, TransformerFunctions.FunctionMatchResult<Object> matchResult) { | ||
if (matchResult == null) { | ||
return null; | ||
} | ||
// if the function result is the transformer's output, don't audit it | ||
if ("$".equals(path)) return matchResult; | ||
|
||
if (matchResult.result() instanceof JsonElementStreamer<?,?,?> streamer) { | ||
debugResults.put(matchResult.resultPath(), new TransformerDebugInfo(streamer.toJsonArray())); | ||
return matchResult; | ||
} | ||
debugResults.put(matchResult.resultPath(), new TransformerDebugInfo(matchResult.result())); | ||
return matchResult; | ||
} | ||
|
||
public TransformerFunctions.FunctionMatchResult<Object> matchObject(String path, JO definition, ParameterResolver resolver, JsonTransformerFunction<JE> transformer) { | ||
return auditAndReturn(path, super.matchObject(path, definition, resolver, transformer)); | ||
} | ||
|
||
public TransformerFunctions.FunctionMatchResult<Object> matchInline(String path, String value, ParameterResolver resolver, JsonTransformerFunction<JE> transformer) { | ||
return auditAndReturn(path, super.matchInline(path, value, resolver, transformer)); | ||
} | ||
|
||
public Map<String, TransformerDebugInfo> getDebugResults() { | ||
return debugResults; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.