@Test public void bigRaml() throws Exception { Map<String, GType> finder = finder("big.raml"); ObjectTypeDeclaration object = (ObjectTypeDeclaration) finder.get("RamlDataType").implementation(); TypeDeclaration extending = findProperty(object, "NilValue"); ObjectTypeDeclaration extended = (ObjectTypeDeclaration) finder.get(extending.type()); assertTrue(TypeUtils.shouldCreateNewClass(extending, extended)); }
public static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended) { if (ScalarTypes.extendsScalarRamlType(extending)) { return false; } if (extending instanceof StringTypeDeclaration && extending.type() != null && extending.type().equals("string") && ((StringTypeDeclaration) extending).enumValues().size() > 0 && extended.length == 1 && extended[0] instanceof StringTypeDeclaration) { return true; } if (extending.parentTypes().size() > 1) { return true; } if (extending.type() != null && extending.type().equals("object")) { return true; } if (extended != null && extended.length > 0 && extended[0] instanceof JSONTypeDeclaration && extending instanceof JSONTypeDeclaration) { return false; } if (extended != null && extended.length > 0 && extended[0] instanceof XMLTypeDeclaration && extending instanceof XMLTypeDeclaration) { return false; } if (extending instanceof ObjectTypeDeclaration && extended.length > 0 && extended[0] instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration extendingObject = (ObjectTypeDeclaration) extending; ObjectTypeDeclaration extendedObject = (ObjectTypeDeclaration) extended[0]; return extendedObject.properties().size() < extendingObject.properties().size(); } return false; }
TypeUtils { public static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended) { if (ScalarTypes.extendsScalarRamlType(extending)) { return false; } if (extending instanceof StringTypeDeclaration && extending.type() != null && extending.type().equals("string") && ((StringTypeDeclaration) extending).enumValues().size() > 0 && extended.length == 1 && extended[0] instanceof StringTypeDeclaration) { return true; } if (extending.parentTypes().size() > 1) { return true; } if (extending.type() != null && extending.type().equals("object")) { return true; } if (extended != null && extended.length > 0 && extended[0] instanceof JSONTypeDeclaration && extending instanceof JSONTypeDeclaration) { return false; } if (extended != null && extended.length > 0 && extended[0] instanceof XMLTypeDeclaration && extending instanceof XMLTypeDeclaration) { return false; } if (extending instanceof ObjectTypeDeclaration && extended.length > 0 && extended[0] instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration extendingObject = (ObjectTypeDeclaration) extending; ObjectTypeDeclaration extendedObject = (ObjectTypeDeclaration) extended[0]; return extendedObject.properties().size() < extendingObject.properties().size(); } return false; } }
TypeUtils { public static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended) { if (ScalarTypes.extendsScalarRamlType(extending)) { return false; } if (extending instanceof StringTypeDeclaration && extending.type() != null && extending.type().equals("string") && ((StringTypeDeclaration) extending).enumValues().size() > 0 && extended.length == 1 && extended[0] instanceof StringTypeDeclaration) { return true; } if (extending.parentTypes().size() > 1) { return true; } if (extending.type() != null && extending.type().equals("object")) { return true; } if (extended != null && extended.length > 0 && extended[0] instanceof JSONTypeDeclaration && extending instanceof JSONTypeDeclaration) { return false; } if (extended != null && extended.length > 0 && extended[0] instanceof XMLTypeDeclaration && extending instanceof XMLTypeDeclaration) { return false; } if (extending instanceof ObjectTypeDeclaration && extended.length > 0 && extended[0] instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration extendingObject = (ObjectTypeDeclaration) extending; ObjectTypeDeclaration extendedObject = (ObjectTypeDeclaration) extended[0]; return extendedObject.properties().size() < extendingObject.properties().size(); } return false; }  }
TypeUtils { public static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended) { if (ScalarTypes.extendsScalarRamlType(extending)) { return false; } if (extending instanceof StringTypeDeclaration && extending.type() != null && extending.type().equals("string") && ((StringTypeDeclaration) extending).enumValues().size() > 0 && extended.length == 1 && extended[0] instanceof StringTypeDeclaration) { return true; } if (extending.parentTypes().size() > 1) { return true; } if (extending.type() != null && extending.type().equals("object")) { return true; } if (extended != null && extended.length > 0 && extended[0] instanceof JSONTypeDeclaration && extending instanceof JSONTypeDeclaration) { return false; } if (extended != null && extended.length > 0 && extended[0] instanceof XMLTypeDeclaration && extending instanceof XMLTypeDeclaration) { return false; } if (extending instanceof ObjectTypeDeclaration && extended.length > 0 && extended[0] instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration extendingObject = (ObjectTypeDeclaration) extending; ObjectTypeDeclaration extendedObject = (ObjectTypeDeclaration) extended[0]; return extendedObject.properties().size() < extendingObject.properties().size(); } return false; }  static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended); }
TypeUtils { public static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended) { if (ScalarTypes.extendsScalarRamlType(extending)) { return false; } if (extending instanceof StringTypeDeclaration && extending.type() != null && extending.type().equals("string") && ((StringTypeDeclaration) extending).enumValues().size() > 0 && extended.length == 1 && extended[0] instanceof StringTypeDeclaration) { return true; } if (extending.parentTypes().size() > 1) { return true; } if (extending.type() != null && extending.type().equals("object")) { return true; } if (extended != null && extended.length > 0 && extended[0] instanceof JSONTypeDeclaration && extending instanceof JSONTypeDeclaration) { return false; } if (extended != null && extended.length > 0 && extended[0] instanceof XMLTypeDeclaration && extending instanceof XMLTypeDeclaration) { return false; } if (extending instanceof ObjectTypeDeclaration && extended.length > 0 && extended[0] instanceof ObjectTypeDeclaration) { ObjectTypeDeclaration extendingObject = (ObjectTypeDeclaration) extending; ObjectTypeDeclaration extendedObject = (ObjectTypeDeclaration) extended[0]; return extendedObject.properties().size() < extendingObject.properties().size(); } return false; }  static boolean shouldCreateNewClass(TypeDeclaration extending, TypeDeclaration... extended);  }