Skip to content

Commit

Permalink
Fix #411
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Oct 6, 2017
1 parent ae990d4 commit 0dd780f
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 38 deletions.
1 change: 1 addition & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -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`
6 changes: 3 additions & 3 deletions src/main/java/com/fasterxml/jackson/core/JsonGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
}

Expand All @@ -358,7 +358,7 @@ public Object getCurrentValue() {
*</code>
*/
public void setCurrentValue(Object v) {
JsonStreamContext ctxt = getOutputContext();
TokenStreamContext ctxt = getOutputContext();
if (ctxt != null) {
ctxt.setCurrentValue(v);
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/fasterxml/jackson/core/JsonParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ protected JsonParser() { }
* @since 2.5
*/
public Object getCurrentValue() {
JsonStreamContext ctxt = getParsingContext();
TokenStreamContext ctxt = getParsingContext();
return (ctxt == null) ? null : ctxt.getCurrentValue();
}

Expand All @@ -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);
}
Expand Down Expand Up @@ -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 <b>starting</b> location of the current
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/fasterxml/jackson/core/JsonPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,15 @@ 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"
* or not.
*
* @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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*<p>
* NOTE: In jackson 2.x this class was named <code>JsonStreamContext</code>
*/
public abstract class JsonStreamContext
public abstract class TokenStreamContext
{
// // // Type constants used internally

Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public FilteringGeneratorDelegate(JsonGenerator d, TokenFilter f,

public TokenFilter getFilter() { return rootFilter; }

public JsonStreamContext getFilterContext() {
public TokenStreamContext getFilterContext() {
return _filterContext;
}

Expand All @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -887,7 +887,7 @@ public JsonParser skipChildren() throws IOException
/**********************************************************
*/

protected JsonStreamContext _filterContext() {
protected TokenStreamContext _filterContext() {
if (_exposedContext != null) {
return _exposedContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 0dd780f

Please sign in to comment.