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); }
/** * Finds the type corresponding to the given name and assigns it using the given setter. If there is no type * corresponding to the given name yet then a new undefined type will be created and assigned, and it will be * remembered so that it can later be replaced with the real type. * * @param typeName the name of the type to find * @param typeSetter the setter used to assign the type */ private void assignType(Name typeName, TypeSetter typeSetter) { // First try to find a type that has already been defined: Type type = model.getType(typeName); // If the type hasn't been defined then we create need to create a dummy type if (type == null) { type = new UndefinedType(); type.setName(typeName); } // If we are returning an undefined type then we need to to remember to replace it later, saving the name of // the type and the setter provided by the calller: if (type instanceof UndefinedType) { TypeUsage typeUsage = new TypeUsage(); typeUsage.setName(typeName); typeUsage.setSetter(typeSetter); undefinedTypeUsages.add(typeUsage); } // Assign the type: if (typeSetter != null) { typeSetter.accept(type); } }