/** * Adds the {@code GracePeriod} type to the model. */ private void addGracePeriodType(Model model) { // Create the type: StructType gracePeriodType = new StructType(); gracePeriodType.setName(NameParser.parseUsingCase("GracePeriod")); // Add the "expiry" attribute: Attribute expiryAttribute = new Attribute(); expiryAttribute.setName(NameParser.parseUsingCase("Expiry")); expiryAttribute.setType(model.getIntegerType()); expiryAttribute.setDeclaringType(gracePeriodType); gracePeriodType.addAttribute(expiryAttribute); // Add the type to the model: gracePeriodType.setModule(model.getModule(null)); model.addType(gracePeriodType); }
public String getSchemaTypeName(Type type) { Model model = type.getModel(); if (type == model.getBooleanType()) { return "xs:boolean"; } if (type == model.getStringType()) { return "xs:string"; } if (type == model.getIntegerType()) { return "xs:int"; } if (type == model.getDateType()) { return "xs:dateTime"; } if (type == model.getDecimalType()) { return "xs:decimal"; } if (type instanceof ListType) { ListType listType = (ListType) type; Type elementType = listType.getElementType(); return getSchemaTypeName(names.getPlural(elementType.getName())); } return getSchemaTypeName(type.getName()); }
private void writeModel() { writer.writeStartElement("model"); Service root = model.getRoot(); if (root != null) { writer.writeElement("root", getServiceRef(root)); } writer.writeStartElement("types"); model.types().forEach(this::writeType); writer.writeEndElement(); writer.writeStartElement("services"); model.services().forEach(this::writeService); writer.writeEndElement(); writer.writeStartElement("documents"); model.documents().forEach(this::writeDocument); writer.writeEndElement(); writer.writeEndElement(); }
private void analyzeModule(JavaClass javaClass, Consumer<Module> moduleSetter) { String javaName = javaClass.getPackageName(); Name name = NameParser.parseUsingSeparator(javaName, '.'); Module module = model.getModule(name); if (module == null) { module = new Module(); module.setModel(model); module.setName(name); model.addModule(module); } moduleSetter.accept(module); }
actionType.setBase(model.getType(NameParser.parseUsingCase("Identified"))); statusAttribute.setType(model.getStringType()); statusAttribute.setDeclaringType(actionType); actionType.addAttribute(statusAttribute); faultAttribute.setType(model.getType(NameParser.parseUsingCase("Fault"))); faultAttribute.setDeclaringType(actionType); actionType.addAttribute(faultAttribute); gracePeriodAttribute.setType(model.getType(NameParser.parseUsingCase("GracePeriod"))); gracePeriodAttribute.setDeclaringType(actionType); actionType.addAttribute(gracePeriodAttribute); jobAttribute.setType(model.getType(NameParser.parseUsingCase("Job"))); jobAttribute.setDeclaringType(actionType); actionType.addAttribute(jobAttribute); for (Service service : model.getServices()) { for (Method method : service.getMethods()) { if (jaxrsNames.isActionName(method.getName())) { actionType.setModule(model.getModule(null)); model.addType(actionType);
case "Boolean": case "bool": typeName = model.getBooleanType().getName(); break; case "Double": case "double": case "float": typeName = model.getDecimalType().getName(); break; default: assignType(typeName, listType::setElementType); listTypes.put(typeName, listType); model.addType(listType);
/** * Adds the {@code Fault} type to the model. */ private void addFaultType(Model model) { // Create the type: StructType faultType = new StructType(); faultType.setName(NameParser.parseUsingCase("Fault")); // Add the "reason" attribute: Attribute reasonAttribute = new Attribute(); reasonAttribute.setName(NameParser.parseUsingCase("Reason")); reasonAttribute.setType(model.getStringType()); reasonAttribute.setDeclaringType(faultType); faultType.addAttribute(reasonAttribute); // Add the "detail" attribute: Attribute detailAttribute = new Attribute(); detailAttribute.setName(NameParser.parseUsingCase("Detail")); detailAttribute.setType(model.getStringType()); detailAttribute.setDeclaringType(faultType); faultType.addAttribute(detailAttribute); // Add the type to the model: faultType.setModule(model.getModule(null)); model.addType(faultType); }
Type bool = model.getBooleanType(); Type decimal = model.getDecimalType(); Type integer = model.getIntegerType();
private Expression transformLiteral(LiteralExpression expression) { // Compute the type: Object value = expression.getValue(); Type type = null; if (value != null) { if (value instanceof Boolean) { type = model.getBooleanType(); } else if (value instanceof BigInteger) { type = model.getIntegerType(); } } // Return the result: LiteralExpression result = new LiteralExpression(); result.setValue(value); result.setType(type); return result; }
private void analyzeEnum(JavaClass javaClass) { // Create the type: EnumType type = new EnumType(); analyzeSource(javaClass, type); analyzeModule(javaClass, type); analyzeName(javaClass, type); analyzeAnnotations(javaClass, type); analyzeDocumentation(javaClass, type); // Get the values: javaClass.getEnumConstants().forEach(x -> analyzeEnumValue(x, type)); // Add the type to the model: model.addType(type); }
if (type == model.getIntegerType()) { javaBuffer.addImport(BigInteger.class); javaBuffer.addLine("public BigInteger %1$s() {", field); javaBuffer.addLine(); else if (type == model.getDateType()) { javaBuffer.addImport(Date.class); javaBuffer.addLine("public Date %1$s() {", field); if (type == model.getBooleanType()) { javaBuffer.addLine(); else if (type == model.getDateType()) { javaBuffer.addImport(Date.class); javaBuffer.addLine("public void %1$s(Date new%2$s) {", field, property);
model.addService(service); Service root = model.getRoot(); if (root != null) { System.err.println( ); model.setRoot(service);
/** * Finds the references to unresolved types and replace them with the real type definitions. */ private void redefineUndefinedTypes() { for (TypeUsage usage : undefinedTypeUsages) { Name name = usage.getName(); Type type = model.getType(name); if (type == null) { System.err.println("Can't find type for name \"" + name + "\"."); continue; } TypeSetter setter = usage.getSetter(); setter.accept(type); } }
boolean isRoot = service == service.getModel().getRoot();
private Expression transformUnary(UnaryExpression expression) { // Transform the operand: Expression operand = expression.getOperand(); if (operand == null) { throw new IllegalArgumentException("The operand in expression \"" + expression + "\" is null"); } operand = transform(operand); // Compute the type: Operator operator = expression.getOperator(); Type type; switch (operator) { case NOT: type = model.getBooleanType(); break; case SUBTRACT: type = operand.getType(); break; default: throw new IllegalArgumentException( "The operator \"" + operator + "\" in expression \"" + expression + "\" isn't supported" ); } // Return the result: UnaryExpression result = new UnaryExpression(); result.setType(type); result.setOperator(operator); result.setOperand(operand); return result; }
private void generateInterfaceMembers(StructMember member) { // Get the name of the property: Name name = member.getName(); Type type = member.getType(); Model model = type.getModel(); String field = javaNames.getJavaMemberStyleName(name); // Get the type reference: JavaTypeReference typeReference = javaTypes.getTypeReference(type, false); javaBuffer.addImports(typeReference.getImports()); // Generate the getters: javaBuffer.addLine("%1$s %2$s();", typeReference, field); if (type == model.getIntegerType()) { javaBuffer.addLine("Byte %1$sAsByte();", field); javaBuffer.addLine("Short %1$sAsShort();", field); javaBuffer.addLine("Integer %1$sAsInteger();", field); javaBuffer.addLine("Long %1$sAsLong();", field); } javaBuffer.addLine(); // Generate the checker: javaBuffer.addLine("boolean %1$sPresent();", field); javaBuffer.addLine(); }
Model model = new Model(); ModelAnalyzer modelAnalyzer = new ModelAnalyzer(); modelAnalyzer.setModel(model);
model.addDocument(document);
public Model() { // Create the anonymous module: Module anonymousModule = new Module(); anonymousModule.setModel(this); modules.add(anonymousModule); // Add the builtin types: booleanType = new PrimitiveType(); booleanType.setName(NameParser.parseUsingCase("Boolean")); booleanType.setModule(anonymousModule); addType(booleanType); stringType = new PrimitiveType(); stringType.setName(NameParser.parseUsingCase("String")); stringType.setModule(anonymousModule); addType(stringType); integerType = new PrimitiveType(); integerType.setName(NameParser.parseUsingCase("Integer")); integerType.setModule(anonymousModule); addType(integerType); dateType = new PrimitiveType(); dateType.setName(NameParser.parseUsingCase("Date")); dateType.setModule(anonymousModule); addType(dateType); decimalType = new PrimitiveType(); decimalType.setName(NameParser.parseUsingCase("Decimal")); decimalType.setModule(anonymousModule); addType(decimalType); }