@Test public void shouldExtendingObject() throws Exception { ObjectTypeDeclaration typeDeclaration = (ObjectTypeDeclaration) finder("extendObject.raml").get("ObjectOne").implementation(); TypeDeclaration property = findProperty(typeDeclaration, "name"); assertTrue(TypeUtils.shouldCreateNewClass(property, null)); }
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);  }