Skip to content

Commit

Permalink
Merge pull request EsotericSoftware#392 from magro/move-generics-to-s…
Browse files Browse the repository at this point in the history
…erializers

Move Generics(Resolver) to serializers, reduce visibility, go back to 3.1.0-SNAPSHOT
  • Loading branch information
magro committed Mar 2, 2016
2 parents 04b019e + e22ffb8 commit 051b2ce
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 52 deletions.
26 changes: 24 additions & 2 deletions pom-main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>./pom.xml</relativePath>
</parent>
<artifactId>kryo</artifactId>
Expand Down Expand Up @@ -77,11 +77,33 @@
</executions>
<!-- See http://mojo.codehaus.org/clirr-maven-plugin/check-mojo.html -->
<configuration>
<skip>true</skip>
<skip>false</skip>
<logResults>true</logResults>
<minSeverity>warning</minSeverity>
<!-- Configure ignored differences: http://mojo.codehaus.org/clirr-maven-plugin/examples/ignored-differences.html -->
<ignored>
<!-- Internal APIs -->
<difference>
<className>com/esotericsoftware/kryo/Kryo</className>
<method>*GenericsScope*</method>
<differenceType>7002</differenceType>
</difference>
<difference>
<className>com/esotericsoftware/kryo/serializers/FieldSerializer</className>
<method>*getGenericsScope*</method>
<differenceType>7006</differenceType>
<to>*</to>
</difference>
<difference>
<className>com/esotericsoftware/kryo/serializers/FieldSerializer</className>
<method>*getGenericsScope*</method>
<differenceType>7009</differenceType>
<to>*</to>
</difference>
<difference>
<className>com/esotericsoftware/kryo/Generics</className>
<differenceType>8001</differenceType>
</difference>
<!-- reflectasm classes are reported to be removed (as they're added by shade/bundle plugin during packaging) -->
<difference>
<className>com/esotericsoftware/reflectasm/**</className>
Expand Down
2 changes: 1 addition & 1 deletion pom-shaded.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<parent>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<relativePath>./pom.xml</relativePath>
</parent>
<artifactId>kryo-shaded</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</parent>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Kryo Parent</name>
<description>Fast, efficient Java serialization. This is the parent pom that assembles the main kryo and shaded kryo artifacts.</description>
Expand Down
10 changes: 1 addition & 9 deletions src/com/esotericsoftware/kryo/Kryo.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.TreeSet;

import com.esotericsoftware.kryo.serializers.OptionalSerializers;
import com.esotericsoftware.kryo.serializers.GenericsResolver;
import org.objenesis.instantiator.ObjectInstantiator;
import org.objenesis.strategy.InstantiatorStrategy;
import org.objenesis.strategy.SerializingInstantiatorStrategy;
Expand Down Expand Up @@ -1180,15 +1181,6 @@ static final class DefaultSerializerEntry {
}
}

public void pushGenericsScope (Class type, Generics generics) {
if (TRACE) trace("kryo", "Settting a new generics scope for class " + type.getName() + ": " + generics);
genericsResolver.pushScope(generics);
}

public void popGenericsScope () {
genericsResolver.popScope();
}

public GenericsResolver getGenericsResolver () {
return genericsResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
* SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

package com.esotericsoftware.kryo.serializers;

import java.lang.reflect.Array;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Modifier;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;

import com.esotericsoftware.kryo.Generics;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Registration;
import com.esotericsoftware.kryo.Serializer;
Expand Down Expand Up @@ -427,4 +423,4 @@ public void setGenerics(Kryo kryo, Class[] generics) {
this.generics = generics;
}
}
}
}
15 changes: 7 additions & 8 deletions src/com/esotericsoftware/kryo/serializers/FieldSerializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import java.util.HashSet;
import java.util.List;

import com.esotericsoftware.kryo.Generics;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.NotNull;
import com.esotericsoftware.kryo.Serializer;
Expand Down Expand Up @@ -203,7 +202,7 @@ protected void rebuildCachedFields (boolean minorRebuild) {
genericsScope = genScope;

// Push proper scopes at serializer construction time
if (genericsScope != null) kryo.pushGenericsScope(type, genericsScope);
if (genericsScope != null) kryo.getGenericsResolver().pushScope(type, genericsScope);

List<Field> validFields;
List<Field> validTransientFields;
Expand Down Expand Up @@ -272,7 +271,7 @@ protected void rebuildCachedFields (boolean minorRebuild) {

initializeCachedFields();

if (genericsScope != null) kryo.popGenericsScope();
if (genericsScope != null) kryo.getGenericsResolver().popScope();

if (!minorRebuild) {
for (CachedField field : removedFields)
Expand Down Expand Up @@ -512,7 +511,7 @@ public void write (Kryo kryo, Output output, T object) {

if (genericsScope != null) {
// Push proper scopes at serializer usage time
kryo.pushGenericsScope(type, genericsScope);
kryo.getGenericsResolver().pushScope(type, genericsScope);
}

CachedField[] fields = this.fields;
Expand All @@ -527,7 +526,7 @@ public void write (Kryo kryo, Output output, T object) {

if (genericsScope != null) {
// Pop the scope for generics
kryo.popGenericsScope();
kryo.getGenericsResolver().popScope();
}
}

Expand All @@ -542,7 +541,7 @@ public T read (Kryo kryo, Input input, Class<T> type) {

if (genericsScope != null) {
// Push a new scope for generics
kryo.pushGenericsScope(type, genericsScope);
kryo.getGenericsResolver().pushScope(type, genericsScope);
}

T object = create(kryo, input, type);
Expand All @@ -561,7 +560,7 @@ public T read (Kryo kryo, Input input, Class<T> type) {
} finally {
if (genericsScope != null && kryo.getGenericsResolver() != null) {
// Pop the scope for generics
kryo.popGenericsScope();
kryo.getGenericsResolver().popScope();
}
}
}
Expand Down Expand Up @@ -683,7 +682,7 @@ public T copy (Kryo kryo, T original) {
return copy;
}

public final Generics getGenericsScope () {
final Generics getGenericsScope () {
return genericsScope;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,12 @@
import static com.esotericsoftware.minlog.Log.TRACE;
import static com.esotericsoftware.minlog.Log.trace;

import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import com.esotericsoftware.kryo.Generics;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.factories.ReflectionSerializerFactory;
import com.esotericsoftware.kryo.serializers.FieldSerializer.Bind;
import com.esotericsoftware.kryo.serializers.FieldSerializer.CachedField;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import java.util.HashMap;
import java.util.Map;

import com.esotericsoftware.kryo.Generics;
import com.esotericsoftware.kryo.GenericsResolver;
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.serializers.FieldSerializer.CachedField;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

package com.esotericsoftware.kryo;
package com.esotericsoftware.kryo.serializers;

import java.util.HashMap;
import java.util.Map;

/*** Helper class to map type name variables to concrete classes that are used during instantiation
/**
* INTERNAL API
*
* Helper class to map type name variables to concrete classes that are used during instantiation
*
* @author Roman Levenstein <[email protected]> */
public class Generics {
final class Generics {
private Map<String, Class> typeVar2class;

public Generics () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,43 @@
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */

package com.esotericsoftware.kryo;
package com.esotericsoftware.kryo.serializers;

import java.util.LinkedList;

/** Helper class that resolves a type name variable to a concrete class using the current class serialization stack
import static com.esotericsoftware.minlog.Log.TRACE;
import static com.esotericsoftware.minlog.Log.trace;

/**
* INTERNAL API
*
* Helper class that resolves a type name variable to a concrete class using the current class serialization stack
*
* @author Jeroen van Erp <[email protected]> */
public class GenericsResolver {
public final class GenericsResolver {
private LinkedList<Generics> stack = new LinkedList<Generics>();

GenericsResolver () {
public GenericsResolver () {
}

public Class getConcreteClass (String typeVar) {
Class getConcreteClass(String typeVar) {
for (Generics generics : stack) {
Class clazz = generics.getConcreteClass(typeVar);
if (clazz != null) return clazz;
}
return null;
}

public boolean isSet () {
boolean isSet () {
return !stack.isEmpty();
}

void pushScope (Generics scope) {
void pushScope(Class type, Generics scope) {
if (TRACE) trace("generics", "Settting a new generics scope for class " + type.getName() + ": " + scope);
stack.addFirst(scope);
}

void popScope () {
void popScope() {
stack.removeFirst();
}
}

0 comments on commit 051b2ce

Please sign in to comment.