private void mapToClass(DElementPattern p) { NameClass nc = p.getName(); if (nc.isOpen()) return; // infinite name. can't map to a class. Set<QName> names = nc.listNames(); CClassInfo[] types = new CClassInfo[names.size()]; int i = 0; for (QName n : names) { // TODO: read class names from customization String name = model.getNameConverter().toClassName(n.getLocalPart()); bindQueue.put( types[i++] = new CClassInfo(model, pkg, name, p.getLocation(), null, n, null, null /*TODO*/), p.getChild()); } classes.put(p, types); }
private void promoteTypeSafeEnums() { // we'll be trying a lot of choices, // and most of them will not be type-safe enum. // using the same list improves the memory efficiency. List<CEnumConstant> members = new ArrayList<CEnumConstant>(); OUTER: for (DDefine def : defs) { DPattern p = def.getPattern(); if (p instanceof DChoicePattern) { DChoicePattern cp = (DChoicePattern) p; members.clear(); // check if the choice consists of all value patterns // and that they are of the same datatype DValuePattern vp = null; for (DPattern child : cp) { if (child instanceof DValuePattern) { DValuePattern c = (DValuePattern) child; if (vp == null) vp = c; else { if (!vp.getDatatypeLibrary().equals(c.getDatatypeLibrary()) || !vp.getType().equals(c.getType())) continue OUTER; // different type name } members.add( new CEnumConstant( model.getNameConverter().toConstantName(c.getValue()), null, c.getValue(), c.getLocation())); } else continue OUTER; // not a value } if (members.isEmpty()) continue; // empty choice CNonElement base = CBuiltinLeafInfo.STRING; DatatypeLib lib = datatypes.get(vp.getNs()); if (lib != null) { TypeUse use = lib.get(vp.getType()); if (use instanceof CNonElement) base = (CNonElement) use; } CEnumLeafInfo xducer = new CEnumLeafInfo( model, null, new CClassInfoParent.Package(pkg), def.getName(), base, new ArrayList<CEnumConstant>(members), null, null /*TODO*/, cp.getLocation()); classes.put(cp, new CTypeInfo[] {xducer}); } } }
/** * Name converter that implements "XML->Java name conversion" as specified in the spec. * * <p>This object abstracts the detail that we use different name conversion depending on the * customization. * * <p>This object should be used to perform any name conversion needs, instead of the JJavaName * class in CodeModel. */ public NameConverter getNameConverter() { return model.getNameConverter(); }