Skip to content

Commit

Permalink
Fixed ERRAI-794: @mapsto parameter order no longer affects back refer…
Browse files Browse the repository at this point in the history
…ence resolution
  • Loading branch information
csadilek committed Sep 25, 2014
1 parent 1e2d852 commit b87bfa7
Show file tree
Hide file tree
Showing 16 changed files with 603 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public String getModuleName() {
}

@Override
@SuppressWarnings("rawtypes")
protected void gwtSetUp() throws Exception {
originalHandler = GWT.getUncaughtExceptionHandler();
testHandler = new TestUncaughtExceptionHandler(originalHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
import org.jboss.errai.bus.client.tests.support.Koron;
import org.jboss.errai.bus.client.tests.support.NeverDeclareAnArrayOfThisType;
import org.jboss.errai.bus.client.tests.support.OneDimensionalPrimitiveArrayPortable;
import org.jboss.errai.bus.client.tests.support.Outer;
import org.jboss.errai.bus.client.tests.support.Outer2;
import org.jboss.errai.bus.client.tests.support.Person;
import org.jboss.errai.bus.client.tests.support.Student;
import org.jboss.errai.bus.client.tests.support.StudyTreeNodeContainer;
Expand Down Expand Up @@ -2278,4 +2280,44 @@ public void callback(EntityWithFactoryMethodAndMixedMappingTypes response) {
public void testInheritedBuiltInMappings() {
assertNotNull(Marshalling.getMarshaller(EmptyStackException.class));
}

// This is a regression test for ERRAI-794
public void testBackReferenceOrderingWithMapsTo() {
runAfterInit(new Runnable() {
@Override
public void run() {

final Outer.Nested key = new Outer.Nested("exp");
final Outer outer = new Outer (Arrays.asList(key), key);

MessageBuilder.createCall(new RemoteCallback<Outer>() {
@Override
public void callback(Outer response) {
assertEquals(outer, response);
finishTest();
}
}, TestSerializationRPCService.class).testBackReferenceOrderingWithMapsTo(outer);
}
});
}

// This is a regression test for ERRAI-794
public void testBackReferenceOrderingWithMapsToInverted() {
runAfterInit(new Runnable() {
@Override
public void run() {

final Outer2.Nested key = new Outer2.Nested("exp");
final Outer2 outer = new Outer2(key, Arrays.asList(key));

MessageBuilder.createCall(new RemoteCallback<Outer2>() {
@Override
public void callback(Outer2 response) {
assertEquals(outer, response);
finishTest();
}
}, TestSerializationRPCService.class).testBackReferenceOrderingWithMapsToInverted(outer);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.jboss.errai.bus.client.tests.support;

import java.util.List;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;

@Portable
public class Outer {
private final Nested key;
private final List<Nested> keys;

public Outer(@MapsTo("keys") List<Nested> _keys, @MapsTo("key") Nested _key) {
this.key = _key;
this.keys = _keys;
}

@Portable
public static class Nested {
private final String value;

public Nested(@MapsTo("value") String value) {
this.value = value;
}

@Override
public String toString() {
return "Nested [value=" + value + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Nested other = (Nested) obj;
if (value == null) {
if (other.value != null)
return false;
}
else if (!value.equals(other.value))
return false;
return true;
}
}

@Override
public String toString() {
return "Outer [key=" + key + ", keys=" + keys + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((keys == null) ? 0 : keys.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Outer other = (Outer) obj;
if (key == null) {
if (other.key != null)
return false;
}
else if (!key.equals(other.key))
return false;
if (keys == null) {
if (other.keys != null)
return false;
}
else if (!keys.equals(other.keys))
return false;
return true;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package org.jboss.errai.bus.client.tests.support;

import java.util.List;

import org.jboss.errai.common.client.api.annotations.MapsTo;
import org.jboss.errai.common.client.api.annotations.Portable;

@Portable
public class Outer2 {
private final Nested key;
private final List<Nested> keys;

public Outer2(@MapsTo("key") Nested key, @MapsTo("keys") List<Nested> keys) {
this.key = key;
this.keys = keys;
}

@Portable
public static class Nested {
private final String value;

public Nested(@MapsTo("value") String value) {
this.value = value;
}

@Override
public String toString() {
return "Nested [value=" + value + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Nested other = (Nested) obj;
if (value == null) {
if (other.value != null)
return false;
}
else if (!value.equals(other.value))
return false;
return true;
}
}

@Override
public String toString() {
return "Outer [key=" + key + ", keys=" + keys + "]";
}

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((key == null) ? 0 : key.hashCode());
result = prime * result + ((keys == null) ? 0 : keys.hashCode());
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Outer2 other = (Outer2) obj;
if (key == null) {
if (other.key != null)
return false;
}
else if (!key.equals(other.key))
return false;
if (keys == null) {
if (other.keys != null)
return false;
}
else if (!keys.equals(other.keys))
return false;
return true;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,8 @@ public EntityWithConstructorAndMethodMappedLong testConstructorAndMethodMappedLo
public EntityWithMixedMappingTypes testEntityWithMixedMappingTypes(EntityWithMixedMappingTypes entity);

public EntityWithFactoryMethodAndMixedMappingTypes testEntityWithFactoryMethodAndMixedMappingTypes(EntityWithFactoryMethodAndMixedMappingTypes entity);

public Outer testBackReferenceOrderingWithMapsTo(Outer entity);

public Outer2 testBackReferenceOrderingWithMapsToInverted(Outer2 entity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
import org.jboss.errai.bus.client.tests.support.ImplicitEnum;
import org.jboss.errai.bus.client.tests.support.Koron;
import org.jboss.errai.bus.client.tests.support.NeverDeclareAnArrayOfThisType;
import org.jboss.errai.bus.client.tests.support.Outer;
import org.jboss.errai.bus.client.tests.support.Outer2;
import org.jboss.errai.bus.client.tests.support.SubMoron;
import org.jboss.errai.bus.client.tests.support.TestEnumA;
import org.jboss.errai.bus.client.tests.support.TestSerializationRPCService;
Expand Down Expand Up @@ -493,4 +495,14 @@ public EntityWithMixedMappingTypes testEntityWithMixedMappingTypes(EntityWithMix
public EntityWithFactoryMethodAndMixedMappingTypes testEntityWithFactoryMethodAndMixedMappingTypes(EntityWithFactoryMethodAndMixedMappingTypes entity) {
return entity;
}

@Override
public Outer testBackReferenceOrderingWithMapsTo(Outer entity) {
return entity;
}

@Override
public Outer2 testBackReferenceOrderingWithMapsToInverted(Outer2 entity) {
return entity;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,15 @@ public ClassStructureBuilder<?> getMarshaller(String marshallerClassName) {
final Mapping[] cMappings = instantiationMapping.getMappings();
if (cMappings.length > 0) {
// use constructor mapping.
final List<String> memberKeys = new ArrayList<String>();
for (MemberMapping memberMapping : mappingDefinition.getMemberMappings()) {
memberKeys.add(memberMapping.getKey());
}

final Statement[] constructorParameters = new Statement[cMappings.length];

final List<Statement> constructorParameters = new ArrayList<Statement>();

for (final Mapping mapping : mappingDefinition.getInstantiationMapping().getMappings()) {
for (final Mapping mapping : instantiationMapping.getMappingsInKeyOrder(memberKeys)) {
int parmIndex = instantiationMapping.getIndex(mapping.getKey());
final MetaClass type = mapping.getType().asBoxed();
BlockBuilder<?> lazyInitMethod = (needsLazyInit(type)) ? initMethod : null;
if (type.isArray()) {
Expand All @@ -187,14 +192,14 @@ public ClassStructureBuilder<?> getMarshaller(String marshallerClassName) {
Statement deferred = context.getArrayMarshallerCallback().deferred(type, arrayMarshaller);
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod,
deferred);
constructorParameters.add(
constructorParameters[parmIndex] =
Stmt.loadVariable(MarshallingGenUtil.getVarName(type)).invoke("demarshall",
extractJSONObjectProperty(mapping.getKey(), EJObject.class), Stmt.loadVariable("a1")));
extractJSONObjectProperty(mapping.getKey(), EJObject.class), Stmt.loadVariable("a1"));
}
else {
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod);
constructorParameters.add(context.getArrayMarshallerCallback()
.demarshall(type, extractJSONObjectProperty(mapping.getKey(), EJObject.class)));
constructorParameters[parmIndex] = context.getArrayMarshallerCallback()
.demarshall(type, extractJSONObjectProperty(mapping.getKey(), EJObject.class));
}
}
else {
Expand All @@ -206,11 +211,10 @@ public ClassStructureBuilder<?> getMarshaller(String marshallerClassName) {
MarshallingGenUtil.ensureMarshallerFieldCreated(classStructureBuilder, toMap, type, lazyInitMethod);
if (context.canMarshal(type.getFullyQualifiedName())) {
Statement s = maybeAddAssumedTypes(builder,
"c" + constructorParameters.size(),
// null,
"c" + parmIndex,
mapping, fieldDemarshall(mapping, EJObject.class));

constructorParameters.add(s);
constructorParameters[parmIndex] = s;
}
else {
throw new MarshallingException("Encountered non-marshallable type " + type +
Expand All @@ -227,8 +231,7 @@ public ClassStructureBuilder<?> getMarshaller(String marshallerClassName) {
builder
.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(
Stmt.newObject(toMap, constructorParameters
.toArray(new Object[constructorParameters.size()]))));
Stmt.newObject(toMap, (Object[]) constructorParameters)));
}
else {
PrivateAccessUtil.addPrivateAccessStubs(gwtTarget ? "jsni" : "reflection", classStructureBuilder,
Expand All @@ -238,14 +241,14 @@ public ClassStructureBuilder<?> getMarshaller(String marshallerClassName) {
Stmt.invokeStatic(
classStructureBuilder.getClassDefinition(),
PrivateAccessUtil.getPrivateMethodName(constructor),
constructorParameters.toArray(new Object[constructorParameters.size()]))));
(Object[]) constructorParameters)));
}
}
else if (instantiationMapping instanceof FactoryMapping) {
builder.append(Stmt.declareVariable(toMap).named("entity")
.initializeWith(
Stmt.invokeStatic(toMap, ((FactoryMapping) instantiationMapping).getMember().getName(),
constructorParameters.toArray(new Object[constructorParameters.size()]))));
(Object[]) constructorParameters)));
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@
*/
public interface ConstructorMapping extends InstantiationMapping {
public MetaConstructor getMember();

public boolean isNoConstruct();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.jboss.errai.marshalling.rebind.api.model;

import java.util.List;

import org.jboss.errai.codegen.meta.MetaClass;
import org.jboss.errai.codegen.meta.MetaClassMember;

Expand All @@ -24,6 +26,9 @@
*/
public interface InstantiationMapping {
public Mapping[] getMappings();
public Mapping[] getMappingsInKeyOrder(List<String> keys);
public int getIndex(String key);

public Class<?>[] getSignature();

public MetaClassMember getMember();
Expand Down
Loading

0 comments on commit b87bfa7

Please sign in to comment.