Skip to content

Commit

Permalink
Merge branch 'release/1.0.0-RC3'
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Apr 5, 2021
2 parents 78b8998 + 1baf4a5 commit 3f925e9
Show file tree
Hide file tree
Showing 14 changed files with 208 additions and 106 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
![logoimage](https://raw.githubusercontent.com/DominoKit/DominoKit.github.io/master/logo/128.png)

<a title="Gitter" href="https://gitter.im/DominoKit/domino"><img src="https://badges.gitter.im/Join%20Chat.svg"></a>
[![Development Build Status](https://github.com/DominoKit/domino-jackson/actions/workflows/deploy.yaml/badge.svg?branch=development)](https://github.com/DominoKit/domino-jackson/actions/workflows/deploy.yaml/badge.svg?branch=development)
![Maven Central](https://img.shields.io/badge/Release-1.0.0--RC2-green)
![Maven Central](https://img.shields.io/badge/Release-1.0.0--RC3-green)
![Sonatype Nexus (Snapshots)](https://img.shields.io/badge/Snapshot-HEAD--SNAPSHOT-orange)
![GWT3/J2CL compatible](https://img.shields.io/badge/GWT3/J2CL-compatible-brightgreen.svg)

Expand Down
2 changes: 1 addition & 1 deletion domino-jackson-processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson-parent</artifactId>
<version>1.0.0-RC2</version>
<version>1.0.0-RC3</version>
</parent>

<artifactId>domino-jackson-processor</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,29 @@ public AbstractJsonMapperGenerator(String packageName, TypeMirror beanType, File
* @throws java.io.IOException if any.
*/
protected void generate() throws IOException {
String classNameString = Type.stringifyType(beanType) + namePostfix();
FieldSpec instance =
FieldSpec.builder(ClassName.bestGuess(classNameString), "INSTANCE")
.addModifiers(Modifier.PRIVATE, Modifier.STATIC, Modifier.FINAL)
.initializer(
CodeBlock.builder().add("new $T()", ClassName.bestGuess(classNameString)).build())
.build();

MethodSpec getInstanceMethod =
MethodSpec.methodBuilder("getInstance")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.returns(ClassName.bestGuess(classNameString))
.addStatement("return INSTANCE")
.build();

MethodSpec constructor = MethodSpec.constructorBuilder().addModifiers(Modifier.PUBLIC).build();

final TypeSpec.Builder builder =
TypeSpec.classBuilder(Type.stringifyType(beanType) + namePostfix())
TypeSpec.classBuilder(classNameString)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.superclass(superClass())
.addField(instance)
.addMethod(getInstanceMethod)
.addMethod(constructor)
.addMethod(targetTypeMethod());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/
package org.dominokit.jackson.processor;

import static org.dominokit.jackson.processor.AbstractMapperProcessor.filer;
import static org.dominokit.jackson.processor.AbstractMapperProcessor.typeUtils;
import static org.dominokit.jackson.processor.AbstractMapperProcessor.*;
import static org.dominokit.jackson.processor.ObjectMapperProcessor.DEFAULT_WILDCARD;

import com.google.auto.common.MoreElements;
Expand Down Expand Up @@ -146,7 +145,12 @@ protected MethodSpec makeNewDeserializerMethod(Element element, TypeMirror beanT
new FieldDeserializersChainBuilder(getElementType(element))
.getInstance(getElementType(element)));
} else {
builder.addStatement("return new " + deserializerName(beanType));
builder.addStatement(
"return $T.getInstance()",
ClassName.bestGuess(
elementUtils.getPackageOf(typeUtils.asElement(beanType)).getQualifiedName().toString()
+ "."
+ deserializerName(beanType)));
}

return MethodSpec.methodBuilder("newDeserializer")
Expand Down Expand Up @@ -176,7 +180,12 @@ protected MethodSpec makeNewSerializerMethod(TypeMirror beanType) {
builder.addStatement(
"return $L", new FieldSerializerChainBuilder(beanType).getInstance(beanType));
} else {
builder.addStatement("return new " + serializerName(beanType));
builder.addStatement(
"return $T.getInstance()",
ClassName.bestGuess(
elementUtils.getPackageOf(typeUtils.asElement(beanType)).getQualifiedName().toString()
+ "."
+ serializerName(beanType)));
}

return MethodSpec.methodBuilder("newSerializer")
Expand All @@ -196,7 +205,7 @@ protected MethodSpec makeNewSerializerMethod(TypeMirror beanType) {
* @return deserializer name as String
*/
private String deserializerName(TypeMirror type) {
return Type.stringifyType(type) + "BeanJsonDeserializerImpl()";
return Type.stringifyType(type) + "BeanJsonDeserializerImpl";
}

/**
Expand All @@ -208,7 +217,7 @@ private String deserializerName(TypeMirror type) {
* @return serializer name as String
*/
private String serializerName(TypeMirror type) {
return Type.stringifyType(type) + "BeanJsonSerializerImpl()";
return Type.stringifyType(type) + "BeanJsonSerializerImpl";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion domino-jackson-super/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson-parent</artifactId>
<version>1.0.0-RC2</version>
<version>1.0.0-RC3</version>
</parent>

<artifactId>domino-jackson-super</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion domino-jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.dominokit</groupId>
<artifactId>domino-jackson-parent</artifactId>
<version>1.0.0-RC2</version>
<version>1.0.0-RC3</version>
</parent>

<artifactId>domino-jackson</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,32 @@

/** Stack interface. */
public interface Stack<T> {

/** @return remove the top of the stack and return the value */
T pop();

/** @return the top of the stack without removing it */
T peek();

/** @return int size of the stack */
int size();

/** Removes all elements of the stack */
void clear();

/**
* setAt.
* add the value to the top of the stack
*
* @param index a int.
* @param value a T object.
* @param value to be placed at the top of the stack
*/
void setAt(int index, T value);
void push(T value);

/** @param newTop the value to replace the top of the stack, the stack size remain the same */
void replaceTop(T newTop);

/**
* getAt.
*
* @param index a int.
* @return a T object.
* @param value the value to be inserted the start of the stack, this means it will be popped
* last.
*/
T getAt(int index);
void insertFirst(T value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.dominokit.jackson.stream.impl;

import java.util.ArrayDeque;
import java.util.Deque;
import org.dominokit.jackson.GwtIncompatible;
import org.dominokit.jackson.stream.Stack;

Expand All @@ -26,18 +28,49 @@
@GwtIncompatible
public class DefaultIntegerStack implements Stack<Integer> {

private java.util.Stack<Integer> stack = new java.util.Stack<>();
private Deque<Integer> stack = new ArrayDeque<>();

/** {@inheritDoc} */
@Override
public Integer getAt(int index) {
return stack.get(index);
public Integer pop() {
return stack.pop();
}

/** {@inheritDoc} */
@Override
public void setAt(int index, Integer value) {
if (stack.empty() || index >= stack.size()) stack.push(value);
else stack.set(index, value);
public Integer peek() {
return stack.peek();
}

/** {@inheritDoc} */
@Override
public int size() {
return stack.size();
}

/** {@inheritDoc} */
@Override
public void clear() {
stack.clear();
}

/** {@inheritDoc} */
@Override
public void push(Integer value) {
stack.push(value);
}

/** {@inheritDoc} */
@Override
public void replaceTop(Integer newTop) {
stack.pop();
stack.push(newTop);
}

/** {@inheritDoc} */
@Override
public void insertFirst(Integer value) {
stack.pollLast();
stack.offerLast(value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,10 @@ public class DefaultJsonReader implements org.dominokit.jackson.stream.JsonReade
* The nesting stack. Using a manual array rather than an ArrayList saves 20%.
*/
private Stack<Integer> stack = JacksonContextProvider.get().integerStackFactory().make();
private int stackSize = 0;
// private int stackSize = 0;

{
stack.setAt(stackSize++, JsonScope.EMPTY_DOCUMENT);
stack.push(JsonScope.EMPTY_DOCUMENT);
}

/**
Expand Down Expand Up @@ -359,7 +359,7 @@ public void endArray() {
p = doPeek();
}
if (p == PEEKED_END_ARRAY) {
stackSize--;
stack.pop();
peeked = PEEKED_NONE;
} else {
throw new IllegalStateException(
Expand Down Expand Up @@ -401,7 +401,7 @@ public void endObject() {
p = doPeek();
}
if (p == PEEKED_END_OBJECT) {
stackSize--;
stack.pop();
peeked = PEEKED_NONE;
} else {
throw new IllegalStateException(
Expand Down Expand Up @@ -467,9 +467,9 @@ public JsonToken peek() {

private int doPeek() {

final int peekStack = stack.getAt(stackSize - 1);
final int peekStack = stack.peek();
if (peekStack == JsonScope.EMPTY_ARRAY) {
stack.setAt(stackSize - 1, JsonScope.NONEMPTY_ARRAY);
stack.replaceTop(JsonScope.NONEMPTY_ARRAY);
} else if (peekStack == JsonScope.NONEMPTY_ARRAY) {
// Look for a comma before the next element.
int c = nextNonWhitespace(true);
Expand All @@ -484,7 +484,7 @@ private int doPeek() {
throw syntaxError("Unterminated array");
}
} else if (peekStack == JsonScope.EMPTY_OBJECT || peekStack == JsonScope.NONEMPTY_OBJECT) {
stack.setAt(stackSize - 1, JsonScope.DANGLING_NAME);
stack.replaceTop(JsonScope.DANGLING_NAME);
// Look for a comma before the next element.
if (peekStack == JsonScope.NONEMPTY_OBJECT) {
int c = nextNonWhitespace(true);
Expand Down Expand Up @@ -522,7 +522,7 @@ private int doPeek() {
}
}
} else if (peekStack == JsonScope.DANGLING_NAME) {
stack.setAt(stackSize - 1, JsonScope.NONEMPTY_OBJECT);
stack.replaceTop(JsonScope.NONEMPTY_OBJECT);
// Look for a colon before the value.
int c = nextNonWhitespace(true);
switch (c) {
Expand All @@ -541,7 +541,7 @@ private int doPeek() {
if (lenient) {
consumeNonExecutePrefix();
}
stack.setAt(stackSize - 1, JsonScope.NONEMPTY_DOCUMENT);
stack.replaceTop(JsonScope.NONEMPTY_DOCUMENT);
} else if (peekStack == JsonScope.NONEMPTY_DOCUMENT) {
int c = nextNonWhitespace(false);
if (c == -1) {
Expand Down Expand Up @@ -575,7 +575,7 @@ private int doPeek() {
checkLenient();
return peeked = PEEKED_SINGLE_QUOTED;
case '"':
if (stackSize == 1) {
if (stack.size() == 1) {
checkLenient();
}
return peeked = PEEKED_DOUBLE_QUOTED;
Expand All @@ -587,7 +587,7 @@ private int doPeek() {
pos--; // Don't consume the first character in a literal value.
}

if (stackSize == 1) {
if (stack.size() == 1) {
checkLenient(); // Top-level value isn't an array or an object.
}

Expand Down Expand Up @@ -1211,8 +1211,8 @@ public int nextInt() {
@Override
public void close() {
peeked = PEEKED_NONE;
stack.setAt(0, JsonScope.CLOSED);
stackSize = 1;
stack.clear();
stack.push(JsonScope.CLOSED);
}

/** {@inheritDoc} */
Expand All @@ -1232,10 +1232,10 @@ public void skipValue() {
push(JsonScope.EMPTY_OBJECT);
count++;
} else if (p == PEEKED_END_ARRAY) {
stackSize--;
stack.pop();
count--;
} else if (p == PEEKED_END_OBJECT) {
stackSize--;
stack.pop();
count--;
} else if (p == PEEKED_UNQUOTED_NAME || p == PEEKED_UNQUOTED) {
skipUnquotedValue();
Expand All @@ -1251,7 +1251,7 @@ public void skipValue() {
}

private void push(int newTop) {
stack.setAt(stackSize++, newTop);
stack.push(newTop);
}

/**
Expand Down Expand Up @@ -1575,11 +1575,11 @@ public String nextValue() {
count++;
writer.beginObject();
} else if (p == PEEKED_END_ARRAY) {
stackSize--;
stack.pop();
count--;
writer.endArray();
} else if (p == PEEKED_END_OBJECT) {
stackSize--;
stack.pop();
count--;
writer.endObject();
} else if (p == PEEKED_UNQUOTED_NAME) {
Expand Down
Loading

0 comments on commit 3f925e9

Please sign in to comment.