本文整理匯總了Java中org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration類的典型用法代碼示例。如果您正苦於以下問題:Java ArrayTypeDeclaration類的具體用法?Java ArrayTypeDeclaration怎麽用?Java ArrayTypeDeclaration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ArrayTypeDeclaration類屬於org.raml.v2.api.model.v10.datamodel包,在下文中一共展示了ArrayTypeDeclaration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateArrayProperty
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
/**
* @param type
* @param property
*/
private void generateArrayProperty(ArrayTypeDeclaration property) {
String fieldName = Names.buildVariableName(property);
String itemTypeName = context.getApiModel().getItemType(property);
String typeVar = Annotations.findTypeVar(property);
String tsItemType;
if (typeVar != null) {
tsItemType = typeVar;
}
else {
tsItemType = itemTypeName;
}
MustacheEngine engine = context.getTemplateEngine().getEngine();
Map<String, String> contextObject = ImmutableMap.of("name", fieldName, "tsPropType",
tsItemType + "[]");
engine.getMustache("property").render(context.getOutput(), contextObject);
}
示例2: generateFieldAndAccessors
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
private void generateFieldAndAccessors(JDefinedClass klass, TypeDeclaration property) {
if (isAdditionalProperties(property)) {
generateAdditionalPropertiesFieldAndAccessors(klass, property);
}
else if (property instanceof ObjectTypeDeclaration) {
generateObjectFieldAndAccessors(klass, property);
}
else if (property instanceof ArrayTypeDeclaration) {
generateListFieldAndAccessors(klass, (ArrayTypeDeclaration) property);
}
else if (property instanceof BooleanTypeDeclaration) {
generateBooleanFieldAndAccessors(klass, (BooleanTypeDeclaration) property);
}
else if (property instanceof AnyTypeDeclaration) {
generateAnyFieldAndAccessors(klass, property);
}
else {
generateSimpleFieldAndAccessor(klass, property);
}
}
示例3: generateListFieldAndAccessors
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
private void generateListFieldAndAccessors(JDefinedClass klass, ArrayTypeDeclaration property) {
String fieldName = Names.buildVariableName(property);
String itemTypeName = context.getApiModel().getItemType(property);
JType elementType = findTypeVar(klass, property).orElse(context.getJavaType(itemTypeName));
JClass listType = codeModel.ref(List.class).narrow(elementType);
JFieldVar field = klass.field(JMod.PRIVATE, listType, fieldName);
annotateFieldWithPropertyName(field, property);
JMethod getter = klass.method(JMod.PUBLIC, listType, getGetterName(fieldName));
getter.body()._return(field);
if (property.description() != null) {
getter.javadoc().add(property.description().value());
}
generateSetter(klass, listType, fieldName);
}
示例4: traverse
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
/**
* Lets the given visitor traverse the model tree of the given type declaration.
*
* @param type
* type declaration
* @param visitor
* concrete visitor
*/
public void traverse(TypeDeclaration type, ApiVisitor visitor) {
if (type instanceof AnyTypeDeclaration) {
visitor.visitAnyType((AnyTypeDeclaration) type);
}
else if (type instanceof ArrayTypeDeclaration) {
visitor.visitArrayType((ArrayTypeDeclaration) type);
}
else if (type instanceof BooleanTypeDeclaration) {
visitor.visitBooleanType((BooleanTypeDeclaration) type);
}
else if (type instanceof NumberTypeDeclaration) {
visitor.visitNumberType((NumberTypeDeclaration) type);
}
else if (type instanceof ObjectTypeDeclaration) {
traverse((ObjectTypeDeclaration) type, visitor);
}
else if (type instanceof StringTypeDeclaration) {
visitor.visitStringType((StringTypeDeclaration) type);
}
}
示例5: getDeclaration
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
private TypeSpec.Builder getDeclaration(ClassName interfaceName, GenerationContext generationContext) {
TypeSpec.Builder typeSpec = TypeSpec.interfaceBuilder(interfaceName).addModifiers(Modifier.PUBLIC);
for (TypeDeclaration unitedType : union.of()) {
if ( unitedType instanceof ArrayTypeDeclaration ) {
throw new GenerationException("ramltopojo currently does not support arrays in unions");
}
TypeName typeName = findType(unitedType.name(), unitedType, generationContext).box();
String shortened = shorten(typeName);
typeSpec
.addMethod(
MethodSpec
.methodBuilder(Names.methodName("get", shortened))
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(typeName).build())
.addMethod(
MethodSpec.methodBuilder(Names.methodName("is", shortened))
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
.returns(TypeName.BOOLEAN).build()
);
}
return typeSpec;
}
示例6: visitArrayType
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
@Override
public void visitArrayType(ArrayTypeDeclaration type) {
String itemTypeName = context.getApiModel().getItemType(type);
Map<String, String> imports = addTypeToImports(itemTypeName);
createTypeAlias(type, itemTypeName + "[]", imports);
}
示例7: getTypescriptPropertyType
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
/**
* Gets the Typescript name for a given RAML property type.
*
* @param propertyType
* property type
* @return Typescript name
*/
public String getTypescriptPropertyType(TypeDeclaration propertyType) {
String typeName = propertyType.type();
if (propertyType instanceof StringTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (propertyType instanceof NumberTypeDeclaration) {
return getDeclaredName(typeName, NUMBER);
}
if (propertyType instanceof BooleanTypeDeclaration) {
return getDeclaredName(typeName, BOOLEAN);
}
if (propertyType instanceof DateTimeTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (propertyType instanceof DateTimeOnlyTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (propertyType instanceof DateTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (propertyType instanceof TimeOnlyTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (propertyType instanceof AnyTypeDeclaration) {
return getDeclaredName(typeName, ANY);
}
if (propertyType instanceof ObjectTypeDeclaration) {
return typeName;
}
if (propertyType instanceof ArrayTypeDeclaration) {
return apiModel.getItemType(propertyType) + "[]";
}
throw new GeneratorException(
"unsupported declaration type: " + propertyType.getClass().getName());
}
示例8: getTypescriptType
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
/**
* Gets the Typescript name for a given user-defined RAML type.
*
* @param type
* RAML type
* @return Typescript name
*/
public String getTypescriptType(TypeDeclaration type) {
String typeName = type.name();
if (type instanceof StringTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (type instanceof NumberTypeDeclaration) {
return getDeclaredName(typeName, NUMBER);
}
if (type instanceof BooleanTypeDeclaration) {
return getDeclaredName(typeName, BOOLEAN);
}
if (type instanceof DateTimeTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (type instanceof DateTimeOnlyTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (type instanceof DateTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (type instanceof TimeOnlyTypeDeclaration) {
return getDeclaredName(typeName, STRING);
}
if (type instanceof ObjectTypeDeclaration) {
return typeName;
}
if (type instanceof ArrayTypeDeclaration) {
return apiModel.getItemType(type) + "[]";
}
throw new GeneratorException("unsupported declaration type: " + type.getClass().getName());
}
示例9: visitObjectTypeProperty
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
@Override
public void visitObjectTypeProperty(ObjectTypeDeclaration type, TypeDeclaration property) {
if (property instanceof ArrayTypeDeclaration) {
generateArrayProperty((ArrayTypeDeclaration) property);
}
else {
generateProperty(property);
}
}
示例10: getItemType
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
/**
* Gets the item type name of the given array type.
*
* @param type
* type declaration
* @return item type, or null if type is not an array type
*/
public String getItemType(TypeDeclaration type) {
if (!isArray(type)) {
return null;
}
ArrayTypeDeclaration array = (ArrayTypeDeclaration) type;
TypeDeclaration item = array.items();
if (item.type() == null) {
return item.name().replaceFirst("\\[\\]", "");
}
if (getDeclaredType(item.name()) != null) {
return item.name();
}
return item.type();
}
示例11: assertMemberTypes
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
private void assertMemberTypes(TypeDeclaration type, String typeName, String memberName, String memberType, Metatype metatype) {
ObjectTypeDeclaration objectType = (ObjectTypeDeclaration) type;
assertThat(objectType.name()).isEqualTo(typeName);
TypeDeclaration member = objectType.properties().get(0);
assertThat(member).isInstanceOf(ArrayTypeDeclaration.class);
assertThat(member.name()).isEqualTo(memberName);
assertThat(member.type()).isEqualTo(memberType);
assertThat(apiModel.metatype(member)).isEqualTo(metatype);
}
示例12: assertTypes
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
private void assertTypes(TypeDeclaration type, String typeName, String itemName, String itemType, String realItemType, Metatype metatype) {
ObjectTypeDeclaration objectType = (ObjectTypeDeclaration) type;
assertThat(objectType.name()).isEqualTo(typeName);
TypeDeclaration member = objectType.properties().get(0);
assertThat(member).isInstanceOf(ArrayTypeDeclaration.class);
ArrayTypeDeclaration arrayType = (ArrayTypeDeclaration) member;
TypeDeclaration item = arrayType.items();
assertThat(item.name()).isEqualTo(itemName);
assertThat(item.type()).isEqualTo(itemType);
assertThat(apiModel.getItemType(member)).isEqualTo(realItemType);
assertThat(apiModel.metatype(item)).isEqualTo(metatype);
}
示例13: resolveCollectionClass
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
private JClass resolveCollectionClass(ArrayTypeDeclaration arrayType, JClass resolvedClass, JCodeModel builderModel) {
Class<?> container = List.class;
if (arrayType.uniqueItems() != null && arrayType.uniqueItems()) {
container = Set.class;
}
return builderModel.ref(container).narrow(resolvedClass);
}
示例14: getType
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
@Override
public RamlParamType getType() {
if (queryParameter instanceof ArrayTypeDeclaration) {
TypeDeclaration items = ((ArrayTypeDeclaration) queryParameter).items();
return ramlModelFactory.createRamlParamType(items.type());
}
return ramlModelFactory.createRamlParamType(queryParameter.type());
}
示例15: ramlRootShouldReflectDataTypes
import org.raml.v2.api.model.v10.datamodel.ArrayTypeDeclaration; //導入依賴的package包/類
@Test
public void ramlRootShouldReflectDataTypes() {
Map<String, RamlDataType> personType = ramlRoot.getTypes();
ObjectTypeDeclaration personDataType = (ObjectTypeDeclaration) personType.get("Person").getType();
assertThat(personDataType.displayName().value(), equalTo("Person"));
assertThat(personDataType.type(), equalTo("object"));
StringTypeDeclaration testXProp = (StringTypeDeclaration) personDataType.properties().get(0);
assertThat(testXProp.displayName().value(), equalTo("testX"));
assertThat(testXProp.defaultValue(), equalTo("def_value"));
assertThat(testXProp.minLength(), equalTo(3));
assertThat(testXProp.maxLength(), equalTo(10));
ArrayTypeDeclaration testY = (ArrayTypeDeclaration) personDataType.properties().get(1);
assertThat(testY.description().value(), equalTo("array attribute"));
assertThat(testY.example().value(), endsWith("[a,b]"));
assertThat(testY.items().type(), equalTo("string"));
assertThat(testY.minItems(), equalTo(2));
assertThat(testY.maxItems(), equalTo(5));
ObjectTypeDeclaration managerDataType = (ObjectTypeDeclaration) personType.get("Manager").getType();
assertThat(managerDataType.type(), equalTo("Person"));
ArrayTypeDeclaration personsDataType = (ArrayTypeDeclaration) personType.get("Persons").getType();
assertThat(personsDataType.type(), equalTo("array"));
assertThat(personsDataType.items().type(), equalTo("Person"));
}