/** * Returns all <i>used</i> JPackages. * * A JPackage is considered as "used" if a ClassItem or * a InterfaceItem resides in that package. * * This value is dynamically calculated every time because * one can freely remove ClassItem/InterfaceItem. * * @return * Given the same input, the order of packages in the array * is always the same regardless of the environment. */ public final JPackage[] getUsedPackages(Aspect aspect) { Set<JPackage> s = new TreeSet<JPackage>(); for (CClassInfo bean : model.beans().values()) { JClassContainer cont = getContainer(bean.parent(), aspect); if (cont.isPackage()) { s.add((JPackage) cont); } } for (CElementInfo e : model.getElementMappings(null).values()) { // at the first glance you might think we should be iterating all elements, // not just global ones, but if you think about it, local ones live inside // another class, so those packages are already enumerated when we were // walking over CClassInfos. s.add(e._package()); } return s.toArray(new JPackage[s.size()]); }
public JClassContainer getContainer(CClassInfoParent parent, Aspect aspect) { CClassInfoParent.Visitor<JClassContainer> v; switch (aspect) { case EXPOSED: v = exposedContainerBuilder; break; case IMPLEMENTATION: v = implContainerBuilder; break; default: assert false; throw new IllegalStateException(); } return parent.accept(v); }
private void dumpChildren( JClassContainer cont ) throws IOException { Iterator itr = cont.classes(); while(itr.hasNext()) { JDefinedClass cls = (JDefinedClass)itr.next(); ClassOutline ci = classSet.get(cls); if(ci!=null) dump(ci); } }
/** * Create a dummy class to recover from an error. * * We won't generate the code, so the client will never see this class * getting generated. */ private JDefinedClass createDummyClass(JClassContainer parent) { try { return parent._class("$$$garbage$$$"+(ticketMaster++)); } catch( JClassAlreadyExistsException ee ) { return ee.getExistingClass(); } }
public JClassContainer onBean(CClassInfo bean) { return getClazz(bean).ref; }
public JClassContainer onElement(CElementInfo element) { // hmm... return getElement(element).implClass; }
public JClassContainer onPackage(JPackage pkg) { return model.strategy.getPackage(pkg, EXPOSED); }
public JClassContainer onBean(CClassInfo bean) { return getClazz(bean).implClass; }
public JClassContainer onElement(CElementInfo element) { return getElement(element).implClass; }
public JClassContainer onPackage(JPackage pkg) { return model.strategy.getPackage(pkg, Aspect.IMPLEMENTATION); }
public JDefinedClass createClass( JClassContainer parent, String name, Locator source ) { return createClass( parent, JMod.PUBLIC, name, source ); }
public JDefinedClass createClass( JClassContainer parent, int mod, String name, Locator source ) { return createClass(parent,mod,name,source,ClassType.CLASS); }
public JDefinedClass createInterface( JClassContainer parent, String name, Locator source ) { return createInterface( parent, JMod.PUBLIC, name, source ); }
public JDefinedClass createInterface( JClassContainer parent, int mod, String name, Locator source ) { return createClass(parent,mod,name,source,ClassType.INTERFACE); }
public JDefinedClass createClass( JClassContainer parent, String name, Locator source, ClassType kind ) { return createClass(parent,JMod.PUBLIC,name,source,kind); }
public JDefinedClass createClass( JClassContainer parent, int mod, String name, Locator source, ClassType kind ) { if(!JJavaName.isJavaIdentifier(name)) { // report the error errorReceiver.error( new SAXParseException( Messages.format( Messages.ERR_INVALID_CLASSNAME, name ), source )); return createDummyClass(parent); } try { if(parent.isClass() && kind==ClassType.CLASS) mod |= JMod.STATIC; JDefinedClass r = parent._class(mod,name,kind); // use the metadata field to store the source location, // so that we can report class name collision errors. r.metadata = source; return r; } catch( JClassAlreadyExistsException e ) { // class collision. JDefinedClass cls = e.getExistingClass(); // report the error errorReceiver.error( new SAXParseException( Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ), (Locator)cls.metadata )); errorReceiver.error( new SAXParseException( Messages.format( Messages.ERR_CLASSNAME_COLLISION_SOURCE, name ), source )); if( !name.equals(cls.name()) ) { // on Windows, FooBar and Foobar causes name collision errorReceiver.error( new SAXParseException( Messages.format( Messages.ERR_CASE_SENSITIVITY_COLLISION, name, cls.name() ), null ) ); } if(Util.equals((Locator)cls.metadata,source)) { errorReceiver.error( new SAXParseException( Messages.format( Messages.ERR_CHAMELEON_SCHEMA_GONE_WILD ), source )); } return createDummyClass(parent); } }