/** * 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); } }
/** * 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); } }
actionType.setBase(model.getType(NameParser.parseUsingCase("Identified"))); 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);