@Override public GType arrayContents() { return new V10RamlToPojoGType(((ArrayTypeDeclaration) typeDeclaration).items()); }
private String elementType(TypeDeclaration type) { final String t = type.type(); if (t.endsWith("[]")) { return t.substring(0, t.length() - 2); } if (type instanceof ArrayTypeDeclaration) { final String items = ((ArrayTypeDeclaration) type).items().type(); return "array".equals(items) ? "string" : items; } return null; }
@Override public TypeName javaClassReference(GenerationContext generationContext, EventType type) { if ( name.contains("[") || name.equals("array")) { String itemTypeName = typeDeclaration.items().name(); if ("object".equals(itemTypeName)) { itemTypeName = typeDeclaration.items().type(); } if ("object".equals(itemTypeName)) { throw new GenerationException("unable to create type array item of type object (or maybe an inline array type ?)"); } return ParameterizedTypeName.get(ClassName.get(List.class), TypeDeclarationType.calculateTypeName(itemTypeName, typeDeclaration.items(), generationContext, type).box()); } else { // so we are an array declared return javaClassName(generationContext, type); } }
@Override public Optional<CreationResult> create(GenerationContext generationContext, CreationResult preCreationResult) { ClassName className = preCreationResult.getJavaName(EventType.INTERFACE); ArrayPluginContext arrayPluginContext = new ArrayPluginContextImpl(generationContext, preCreationResult); TypeDeclaration items = typeDeclaration.items(); TypeName itemsTypeName = ClassName.get(Object.class); if ( TypeDeclarationType.isNewInlineType(items) ){ Optional<CreationResult> cr = TypeDeclarationType.createInlineType(className, preCreationResult.getJavaName(EventType.IMPLEMENTATION), Names.typeName(items.type(), "type"), items, generationContext); if ( cr.isPresent() ) { preCreationResult.withInternalType(items.name(), cr.get()); itemsTypeName = cr.get().getJavaName(EventType.INTERFACE); } } else { itemsTypeName = findType(items.name(), items, generationContext).box(); } TypeSpec.Builder arrayClassBuilder = TypeSpec.classBuilder(className).addModifiers(Modifier.PUBLIC).superclass(ParameterizedTypeName.get(ClassName.get(ArrayList.class), itemsTypeName)); arrayClassBuilder = generationContext.pluginsForArrays(typeDeclaration).classCreated(arrayPluginContext, typeDeclaration, arrayClassBuilder, EventType.INTERFACE); return Optional.of(preCreationResult.withInterface(arrayClassBuilder.build())); }
@Override public RamlParamType getType() { if (queryParameter instanceof ArrayTypeDeclaration) { TypeDeclaration items = ((ArrayTypeDeclaration) queryParameter).items(); return ramlModelFactory.createRamlParamType(items.type()); } if (queryParameter instanceof StringTypeDeclaration) { List<String> items = ((StringTypeDeclaration) queryParameter).enumValues(); if (!items.isEmpty()) { return ramlModelFactory.createRamlParamType("DATA_TYPE"); } } return ramlModelFactory.createRamlParamType(queryParameter.type()); }
private void addFacetsForArray(FieldSpec.Builder fieldSpec, ArrayTypeDeclaration typeDeclaration) { if ( isFieldFromBuiltType(typeDeclaration.items()) ) { fieldSpec.addAnnotation(Valid.class); } AnnotationSpec.Builder minMax = null; if (typeDeclaration.minItems() != null) { minMax = AnnotationSpec.builder(Size.class).addMember("min", "$L", typeDeclaration.minItems()); } if (typeDeclaration.maxItems() != null) { if (minMax == null) { minMax = AnnotationSpec.builder(Size.class).addMember("max", "$L", typeDeclaration.maxItems()); } else { minMax.addMember("max", "$L", typeDeclaration.maxItems()); } } if (minMax != null) { fieldSpec.addAnnotation(minMax.build()); } }
); TypeName elementTypeName = objectPluginContext.dependentType(((ArrayTypeDeclaration)property).items()).getJavaName(EventType.IMPLEMENTATION);