@Test public void testRecursivlyCreateAllTypesAny() throws ClassNotFoundException { schema.setType(TYPE.ANY); JCodeModel codeModel = new JCodeModel(); JType type = driver.createOrGetType(codeModel, schema); assertNotNull(type); assertEquals(Object.class.getName(), type.fullName()); }
private boolean isFinal(JType superType) { try { Class<?> javaClass = Class.forName(superType.fullName()); return Modifier.isFinal(javaClass.getModifiers()); } catch (ClassNotFoundException e) { return false; } }
@Test public void testRecursivlyCreateAllTypesArrayNull() throws ClassNotFoundException { schema.setType(TYPE.ARRAY); ObjectSchema arrayType = new ObjectSchema(); arrayType.setType(TYPE.NULL); schema.setItems(arrayType); JCodeModel codeModel = new JCodeModel(); JType type = driver.createOrGetType(codeModel, schema); assertNotNull(type); assertEquals(List.class.getName() + "<" + Object.class.getName() + ">", type.fullName()); }
@Test public void testRecursivlyCreateAllTypesNumber() throws ClassNotFoundException { ObjectSchema schema = new ObjectSchema(); schema.setType(TYPE.NUMBER); JCodeModel codeModel = new JCodeModel(); schema.setId("org.sample.SampleClass"); JPackage _package = codeModel._package("org.sample"); JType type = driver.createOrGetType(codeModel, schema); assertNotNull(type); assertEquals(Double.class.getName(), type.fullName()); }
@Test public void testRecursivlyCreateAllTypesArrayAnySet() throws ClassNotFoundException { schema.setType(TYPE.ARRAY); // set it to be unique to get a set schema.setUniqueItems(true); ObjectSchema arrayType = new ObjectSchema(); arrayType.setType(TYPE.ANY); schema.setItems(arrayType); JCodeModel codeModel = new JCodeModel(); JType type = driver.createOrGetType(codeModel, schema); assertNotNull(type); assertEquals(Set.class.getName() + "<" + Object.class.getName() + ">", type.fullName()); }
private String getGenericType(JType jType) { if (jType.erasure().name().equals("List")) { final String typeName = jType.fullName(); int start = 0; int end = typeName.length(); for (int i = 0; i < typeName.length(); ++i) { switch (typeName.charAt(i)) { case '<': start = i; break; case '>': end = i; break; } } // plus one for excluding '<' return typeName.substring(start + 1, end); } return jType.erasure().name(); }