Skip to content

Commit

Permalink
Issue highsource#11. Added Object[] handling and a test schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
highsource committed Dec 1, 2014
1 parent 75200fa commit 2b9c876
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import com.sun.codemodel.JType;
import com.sun.codemodel.JVar;

public class PrimitiveArrayHashCodeGenerator extends BlockHashCodeCodeGenerator {
public class ArrayHashCodeGenerator extends BlockHashCodeCodeGenerator {

public PrimitiveArrayHashCodeGenerator(
public ArrayHashCodeGenerator(
TypedHashCodeCodeGeneratorFactory factory, JCodeModel codeModel) {
super(factory, codeModel);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,30 @@ public HashCodeCodeGeneratorFactory(JCodeModel codeModel) {
new DoubleHashCodeCodeGenerator(this, this.codeModel));

addCodeGenerator(this.codeModel.BOOLEAN.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.BYTE.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.SHORT.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.CHAR.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.INT.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.FLOAT.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.LONG.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.DOUBLE.array(),
new PrimitiveArrayHashCodeGenerator(this, this.codeModel));
new ArrayHashCodeGenerator(this, this.codeModel));
addCodeGenerator(this.codeModel.ref(Object.class).array(),
new ArrayHashCodeGenerator(this, this.codeModel));

addCodeGenerator(this.codeModel.ref(JAXBElement.class),
new JAXBElementHashCodeCodeGenerator(this, this.codeModel));

addCodeGenerator(this.codeModel.ref(List.class).narrow(Object.class),
new ListHashCodeCodeGenerator(this, this.codeModel));
// TODO Object[]

// TODO Collections/Lists
addCodeGenerator(this.codeModel.ref(Object.class),
new ObjectHashCodeCodeGenerator(this, this.codeModel));
Expand Down
29 changes: 29 additions & 0 deletions tests/simple-hashCode-equals-01/src/main/resources/cases.xsd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" elementFormDefault="qualified"
attributeFormDefault="unqualified" targetNamespace="urn:t" xmlns:tns="urn:t"
jaxb:version="2.1">

<xs:annotation>
<xs:appinfo>
<jaxb:schemaBindings>
<jaxb:package
name="org.jvnet.jaxb2_commons.tests.simple_hashcode_equals_01.cases" />
</jaxb:schemaBindings>
</xs:appinfo>
</xs:annotation>

<xs:complexType name="arrays">
<xs:sequence>
<xs:element name="objects" type="xs:string">
<xs:annotation>
<xs:appinfo>
<jaxb:property>
<jaxb:baseType name="java.lang.Object[]" />
</jaxb:property>
</xs:appinfo>
</xs:annotation>
</xs:element>
</xs:sequence>
</xs:complexType>

</xs:schema>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.jvnet.jaxb2_commons.tests.simple_hashcode_equals_01.cases;

import java.io.File;
import java.net.URL;

import org.junit.Before;
import org.junit.Test;

import com.sun.codemodel.JCodeModel;
import com.sun.tools.xjc.ConsoleErrorReporter;
import com.sun.tools.xjc.ModelLoader;
import com.sun.tools.xjc.Options;
import com.sun.tools.xjc.model.Model;

public class RunPluginsForCases {

@Before
public void setUp() {
System.setProperty("javax.xml.accessExternalSchema", "all");
}

@Test
public void compilesSchema() throws Exception {

new File("target/generated-sources/xjc").mkdirs();

URL schema = getClass().getResource("/cases.xsd");
// URL binding = getClass().getResource("/cases.xjb");
final String[] arguments = new String[] { "-xmlschema",
schema.toExternalForm(),
// "-b", binding.toExternalForm(),
"-d",
"target/generated-sources/xjc", "-extension",
"-XsimpleHashCode", "-XsimpleEquals", "-XsimpleToString" };

Options options = new Options();
options.parseArguments(arguments);
ConsoleErrorReporter receiver = new ConsoleErrorReporter();
Model model = ModelLoader.load(options, new JCodeModel(), receiver);
model.generateCode(options, receiver);
com.sun.codemodel.CodeWriter cw = options.createCodeWriter();
model.codeModel.build(cw);
}
}

0 comments on commit 2b9c876

Please sign in to comment.