From 0dd780fd43c312244528d5a7446aa6118efddca4 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta Date: Thu, 5 Oct 2017 19:13:13 -0700 Subject: [PATCH] Fix #411 --- release-notes/VERSION | 1 + .../fasterxml/jackson/core/JsonGenerator.java | 6 +++--- .../fasterxml/jackson/core/JsonParser.java | 6 +++--- .../fasterxml/jackson/core/JsonPointer.java | 4 ++-- ...amContext.java => TokenStreamContext.java} | 21 ++++++++++++------- .../jackson/core/base/GeneratorBase.java | 2 +- .../jackson/core/base/ParserMinimalBase.java | 2 +- .../filter/FilteringGeneratorDelegate.java | 4 ++-- .../core/filter/FilteringParserDelegate.java | 8 +++---- .../core/filter/TokenFilterContext.java | 4 ++-- .../jackson/core/json/JsonReadContext.java | 4 ++-- .../jackson/core/json/JsonWriteContext.java | 4 ++-- .../jackson/core/json/UTF8JsonGenerator.java | 2 +- .../core/json/WriterBasedJsonGenerator.java | 2 +- .../core/util/JsonGeneratorDelegate.java | 2 +- .../jackson/core/util/JsonParserDelegate.java | 2 +- .../jackson/core/json/GeneratorBasicTest.java | 2 +- .../jackson/core/main/TestGeneratorArray.java | 2 +- .../core/main/TestGeneratorObject.java | 2 +- .../jackson/core/read/JsonParserTest.java | 2 +- 20 files changed, 44 insertions(+), 38 deletions(-) rename src/main/java/com/fasterxml/jackson/core/{JsonStreamContext.java => TokenStreamContext.java} (91%) diff --git a/release-notes/VERSION b/release-notes/VERSION index 5a83c2740d..f12fdaa531 100644 --- a/release-notes/VERSION +++ b/release-notes/VERSION @@ -21,3 +21,4 @@ JSON library. #408: Rename `JsonFactory` as `TokenStreamFactory`, split JSON-specific into `JsonFactory` #410: Add `ObjectWriteContext` abstraction for databind to pass config, state to `JsonGenerator` on construction +#411: Rename `JsonStreamContext` as `TokenStreamContext` diff --git a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java index 4d310c8737..228c9f8e32 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonGenerator.java @@ -284,7 +284,7 @@ protected JsonGenerator() { } * Accessor for context object that provides information about low-level * logical position withing output token stream. */ - public abstract JsonStreamContext getOutputContext(); + public abstract TokenStreamContext getOutputContext(); /** * Accessor for context object provided by higher-level databinding @@ -347,7 +347,7 @@ public int getOutputBuffered() { * and gets passed through data-binding. */ public Object getCurrentValue() { - JsonStreamContext ctxt = getOutputContext(); + TokenStreamContext ctxt = getOutputContext(); return (ctxt == null) ? null : ctxt.getCurrentValue(); } @@ -358,7 +358,7 @@ public Object getCurrentValue() { * */ public void setCurrentValue(Object v) { - JsonStreamContext ctxt = getOutputContext(); + TokenStreamContext ctxt = getOutputContext(); if (ctxt != null) { ctxt.setCurrentValue(v); } diff --git a/src/main/java/com/fasterxml/jackson/core/JsonParser.java b/src/main/java/com/fasterxml/jackson/core/JsonParser.java index 06e9b23e00..a077ac8183 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonParser.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonParser.java @@ -391,7 +391,7 @@ protected JsonParser() { } * @since 2.5 */ public Object getCurrentValue() { - JsonStreamContext ctxt = getParsingContext(); + TokenStreamContext ctxt = getParsingContext(); return (ctxt == null) ? null : ctxt.getCurrentValue(); } @@ -404,7 +404,7 @@ public Object getCurrentValue() { * @since 2.5 */ public void setCurrentValue(Object v) { - JsonStreamContext ctxt = getParsingContext(); + TokenStreamContext ctxt = getParsingContext(); if (ctxt != null) { ctxt.setCurrentValue(v); } @@ -590,7 +590,7 @@ public NonBlockingInputFeeder getNonBlockingInputFeeder() { * Contexts can also be used for simple xpath-like matching of * input, if so desired. */ - public abstract JsonStreamContext getParsingContext(); + public abstract TokenStreamContext getParsingContext(); /** * Method that return the starting location of the current diff --git a/src/main/java/com/fasterxml/jackson/core/JsonPointer.java b/src/main/java/com/fasterxml/jackson/core/JsonPointer.java index ad79515cf9..075e600ec9 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonPointer.java +++ b/src/main/java/com/fasterxml/jackson/core/JsonPointer.java @@ -139,7 +139,7 @@ public static JsonPointer compile(String input) throws IllegalArgumentException /** * Factory method that will construct a pointer instance that describes - * path to location given {@link JsonStreamContext} points to. + * path to location given {@link TokenStreamContext} points to. * * @param context Context to build pointer expression fot * @param includeRoot Whether to include number offset for virtual "root context" @@ -147,7 +147,7 @@ public static JsonPointer compile(String input) throws IllegalArgumentException * * @since 2.9 */ - public static JsonPointer forPath(JsonStreamContext context, + public static JsonPointer forPath(TokenStreamContext context, boolean includeRoot) { // First things first: last segment may be for START_ARRAY/START_OBJECT, diff --git a/src/main/java/com/fasterxml/jackson/core/JsonStreamContext.java b/src/main/java/com/fasterxml/jackson/core/TokenStreamContext.java similarity index 91% rename from src/main/java/com/fasterxml/jackson/core/JsonStreamContext.java rename to src/main/java/com/fasterxml/jackson/core/TokenStreamContext.java index 226c435668..5e34c68e75 100644 --- a/src/main/java/com/fasterxml/jackson/core/JsonStreamContext.java +++ b/src/main/java/com/fasterxml/jackson/core/TokenStreamContext.java @@ -9,15 +9,20 @@ /** * Shared base class for streaming processing contexts used during - * reading and writing of Json content using Streaming API. + * reading and writing of token streams using Streaming API. * This context is also exposed to applications: * context object can be used by applications to get an idea of - * relative position of the parser/generator within json content + * relative position of the parser/generator within content * being processed. This allows for some contextual processing: for * example, output within Array context can differ from that of - * Object context. + * Object context. Perhaps more importantly context is hierarchic so + * that enclosing contexts can be inspected as well. All levels + * also include information about current property name (for Objects) + * and element index (for Arrays). + *

+ * NOTE: In jackson 2.x this class was named JsonStreamContext */ -public abstract class JsonStreamContext +public abstract class TokenStreamContext { // // // Type constants used internally @@ -42,17 +47,17 @@ public abstract class JsonStreamContext /********************************************************** */ - protected JsonStreamContext() { } + protected TokenStreamContext() { } /** * Copy constructor used by sub-classes for creating copies for buffering. */ - protected JsonStreamContext(JsonStreamContext base) { + protected TokenStreamContext(TokenStreamContext base) { _type = base._type; _index = base._index; } - protected JsonStreamContext(int type, int index) { + protected TokenStreamContext(int type, int index) { _type = type; _index = index; } @@ -67,7 +72,7 @@ protected JsonStreamContext(int type, int index) { * Accessor for finding parent context of this context; will * return null for root context. */ - public abstract JsonStreamContext getParent(); + public abstract TokenStreamContext getParent(); /** * Method that returns true if this context is an Array context; diff --git a/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java b/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java index 1ff87d82e8..0f085bf2c1 100644 --- a/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java +++ b/src/main/java/com/fasterxml/jackson/core/base/GeneratorBase.java @@ -243,7 +243,7 @@ protected void _checkStdFeatureChanges(int newFeatureFlags, int changedFeatures) /********************************************************** */ - @Override public JsonStreamContext getOutputContext() { return _outputContext; } + @Override public TokenStreamContext getOutputContext() { return _outputContext; } @Override public ObjectWriteContext getObjectWriteContext() { return _objectWriteContext; } /* diff --git a/src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java b/src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java index 3e4638f447..43dcc949cf 100644 --- a/src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java +++ b/src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java @@ -249,7 +249,7 @@ public JsonParser skipChildren() throws IOException @Override public abstract void close() throws IOException; @Override public abstract boolean isClosed(); - @Override public abstract JsonStreamContext getParsingContext(); + @Override public abstract TokenStreamContext getParsingContext(); // public abstract JsonLocation getTokenLocation(); diff --git a/src/main/java/com/fasterxml/jackson/core/filter/FilteringGeneratorDelegate.java b/src/main/java/com/fasterxml/jackson/core/filter/FilteringGeneratorDelegate.java index 02ffdd55c6..847748ccc8 100644 --- a/src/main/java/com/fasterxml/jackson/core/filter/FilteringGeneratorDelegate.java +++ b/src/main/java/com/fasterxml/jackson/core/filter/FilteringGeneratorDelegate.java @@ -99,7 +99,7 @@ public FilteringGeneratorDelegate(JsonGenerator d, TokenFilter f, public TokenFilter getFilter() { return rootFilter; } - public JsonStreamContext getFilterContext() { + public TokenStreamContext getFilterContext() { return _filterContext; } @@ -118,7 +118,7 @@ public int getMatchCount() { */ @Override - public JsonStreamContext getOutputContext() { + public TokenStreamContext getOutputContext() { /* 11-Apr-2015, tatu: Choice is between pre- and post-filter context; * let's expose post-filter context that correlates with the view * of caller. diff --git a/src/main/java/com/fasterxml/jackson/core/filter/FilteringParserDelegate.java b/src/main/java/com/fasterxml/jackson/core/filter/FilteringParserDelegate.java index 7abaeb7aeb..fee6797755 100644 --- a/src/main/java/com/fasterxml/jackson/core/filter/FilteringParserDelegate.java +++ b/src/main/java/com/fasterxml/jackson/core/filter/FilteringParserDelegate.java @@ -157,16 +157,16 @@ public int getMatchCount() { @Override public JsonLocation getCurrentLocation() { return delegate.getCurrentLocation(); } @Override - public JsonStreamContext getParsingContext() { + public TokenStreamContext getParsingContext() { return _filterContext(); } // !!! TODO: Verify it works as expected: copied from standard JSON parser impl @Override public String getCurrentName() throws IOException { - JsonStreamContext ctxt = _filterContext(); + TokenStreamContext ctxt = _filterContext(); if (_currToken == JsonToken.START_OBJECT || _currToken == JsonToken.START_ARRAY) { - JsonStreamContext parent = ctxt.getParent(); + TokenStreamContext parent = ctxt.getParent(); return (parent == null) ? null : parent.getCurrentName(); } return ctxt.getCurrentName(); @@ -887,7 +887,7 @@ public JsonParser skipChildren() throws IOException /********************************************************** */ - protected JsonStreamContext _filterContext() { + protected TokenStreamContext _filterContext() { if (_exposedContext != null) { return _exposedContext; } diff --git a/src/main/java/com/fasterxml/jackson/core/filter/TokenFilterContext.java b/src/main/java/com/fasterxml/jackson/core/filter/TokenFilterContext.java index c414633ee6..3adbfa88b5 100644 --- a/src/main/java/com/fasterxml/jackson/core/filter/TokenFilterContext.java +++ b/src/main/java/com/fasterxml/jackson/core/filter/TokenFilterContext.java @@ -5,12 +5,12 @@ import com.fasterxml.jackson.core.*; /** - * Alternative variant of {@link JsonStreamContext}, used when filtering + * Alternative variant of {@link TokenStreamContext}, used when filtering * content being read or written (based on {@link TokenFilter}). * * @since 2.6 */ -public class TokenFilterContext extends JsonStreamContext +public class TokenFilterContext extends TokenStreamContext { /** * Parent context for this context; null for root context. diff --git a/src/main/java/com/fasterxml/jackson/core/json/JsonReadContext.java b/src/main/java/com/fasterxml/jackson/core/json/JsonReadContext.java index aff577696a..a450e14f58 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/JsonReadContext.java +++ b/src/main/java/com/fasterxml/jackson/core/json/JsonReadContext.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.core.*; /** - * Extension of {@link JsonStreamContext}, which implements + * Extension of {@link TokenStreamContext}, which implements * core methods needed, and also exposes * more complete API to parser implementation classes. */ -public final class JsonReadContext extends JsonStreamContext +public final class JsonReadContext extends TokenStreamContext { // // // Configuration diff --git a/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContext.java b/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContext.java index dca35d3eb3..adc6d238e9 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContext.java +++ b/src/main/java/com/fasterxml/jackson/core/json/JsonWriteContext.java @@ -3,11 +3,11 @@ import com.fasterxml.jackson.core.*; /** - * Extension of {@link JsonStreamContext}, which implements + * Extension of {@link TokenStreamContext}, which implements * core methods needed, and also exposes * more complete API to generator implementation classes. */ -public class JsonWriteContext extends JsonStreamContext +public class JsonWriteContext extends TokenStreamContext { // // // Return values for writeValue() diff --git a/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java index 3f358bb402..ef4ca5bd91 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java +++ b/src/main/java/com/fasterxml/jackson/core/json/UTF8JsonGenerator.java @@ -1115,7 +1115,7 @@ public void close() throws IOException if ((_outputBuffer != null) && isEnabled(Feature.AUTO_CLOSE_JSON_CONTENT)) { while (true) { - JsonStreamContext ctxt = getOutputContext(); + TokenStreamContext ctxt = getOutputContext(); if (ctxt.inArray()) { writeEndArray(); } else if (ctxt.inObject()) { diff --git a/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java b/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java index 7638ab3255..7f1074ace2 100644 --- a/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java +++ b/src/main/java/com/fasterxml/jackson/core/json/WriterBasedJsonGenerator.java @@ -899,7 +899,7 @@ public void close() throws IOException if (_outputBuffer != null && isEnabled(Feature.AUTO_CLOSE_JSON_CONTENT)) { while (true) { - JsonStreamContext ctxt = getOutputContext(); + TokenStreamContext ctxt = getOutputContext(); if (ctxt.inArray()) { writeEndArray(); } else if (ctxt.inObject()) { diff --git a/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java b/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java index a352b547bf..8d076dfb5f 100644 --- a/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java +++ b/src/main/java/com/fasterxml/jackson/core/util/JsonGeneratorDelegate.java @@ -410,7 +410,7 @@ public void copyCurrentStructure(JsonParser p) throws IOException { /********************************************************** */ - @Override public JsonStreamContext getOutputContext() { return delegate.getOutputContext(); } + @Override public TokenStreamContext getOutputContext() { return delegate.getOutputContext(); } @Override public ObjectWriteContext getObjectWriteContext() { return delegate.getObjectWriteContext(); } /* diff --git a/src/main/java/com/fasterxml/jackson/core/util/JsonParserDelegate.java b/src/main/java/com/fasterxml/jackson/core/util/JsonParserDelegate.java index 3566b588f8..4a9a3b7b94 100644 --- a/src/main/java/com/fasterxml/jackson/core/util/JsonParserDelegate.java +++ b/src/main/java/com/fasterxml/jackson/core/util/JsonParserDelegate.java @@ -110,7 +110,7 @@ public JsonParser overrideFormatFeatures(int values, int mask) { @Override public String getCurrentName() throws IOException { return delegate.getCurrentName(); } @Override public JsonLocation getCurrentLocation() { return delegate.getCurrentLocation(); } - @Override public JsonStreamContext getParsingContext() { return delegate.getParsingContext(); } + @Override public TokenStreamContext getParsingContext() { return delegate.getParsingContext(); } @Override public boolean isExpectedStartArrayToken() { return delegate.isExpectedStartArrayToken(); } @Override public boolean isExpectedStartObjectToken() { return delegate.isExpectedStartObjectToken(); } @Override public boolean isNaN() throws IOException { return delegate.isNaN(); } diff --git a/src/test/java/com/fasterxml/jackson/core/json/GeneratorBasicTest.java b/src/test/java/com/fasterxml/jackson/core/json/GeneratorBasicTest.java index a490d5fe70..4a79f506b7 100644 --- a/src/test/java/com/fasterxml/jackson/core/json/GeneratorBasicTest.java +++ b/src/test/java/com/fasterxml/jackson/core/json/GeneratorBasicTest.java @@ -175,7 +175,7 @@ public void testOutputContext() throws Exception { StringWriter sw = new StringWriter(); JsonGenerator gen = JSON_F.createGenerator(sw); - JsonStreamContext ctxt = gen.getOutputContext(); + TokenStreamContext ctxt = gen.getOutputContext(); assertTrue(ctxt.inRoot()); gen.writeStartObject(); diff --git a/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorArray.java b/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorArray.java index 7b86c6dcdf..9320869d3c 100644 --- a/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorArray.java +++ b/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorArray.java @@ -17,7 +17,7 @@ public void testEmptyArrayWrite() StringWriter sw = new StringWriter(); JsonGenerator gen = new JsonFactory().createGenerator(sw); - JsonStreamContext ctxt = gen.getOutputContext(); + TokenStreamContext ctxt = gen.getOutputContext(); assertTrue(ctxt.inRoot()); assertFalse(ctxt.inArray()); assertFalse(ctxt.inObject()); diff --git a/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorObject.java b/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorObject.java index e92f1dd559..8aa478b6a6 100644 --- a/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorObject.java +++ b/src/test/java/com/fasterxml/jackson/core/main/TestGeneratorObject.java @@ -18,7 +18,7 @@ public void testEmptyObjectWrite() StringWriter sw = new StringWriter(); JsonGenerator gen = new JsonFactory().createGenerator(sw); - JsonStreamContext ctxt = gen.getOutputContext(); + TokenStreamContext ctxt = gen.getOutputContext(); assertTrue(ctxt.inRoot()); assertFalse(ctxt.inArray()); assertFalse(ctxt.inObject()); diff --git a/src/test/java/com/fasterxml/jackson/core/read/JsonParserTest.java b/src/test/java/com/fasterxml/jackson/core/read/JsonParserTest.java index 12d2db5c89..e1699fc81a 100644 --- a/src/test/java/com/fasterxml/jackson/core/read/JsonParserTest.java +++ b/src/test/java/com/fasterxml/jackson/core/read/JsonParserTest.java @@ -113,7 +113,7 @@ public void testKeywords() throws Exception private void _testKeywords(JsonParser p, boolean checkColumn) throws Exception { - JsonStreamContext ctxt = p.getParsingContext(); + TokenStreamContext ctxt = p.getParsingContext(); assertEquals("/", ctxt.toString()); assertTrue(ctxt.inRoot()); assertFalse(ctxt.inArray());