// Copyright (c) 2001-2003, Jonathan Bachrach, Tom White. See file LICENSE. import net.sf.jse.Expansion; import net.sf.jse.Fragment; import net.sf.jse.StringFragment; import net.sf.jse.SyntaxMatchFailure; public syntax enum { case #{ ?modifiers:* enum ?type:name ...; }: return #{ ?modifiers final class ?type:name implements Comparable, java.io.Serializable { private final transient String name; private ?type(String name) { this.name = name; } ?(fieldDecls(..., type)) // Serialization support private static int nextOrdinal = 0; private final int ordinal = nextOrdinal++; private static final ?type[] PRIVATE_VALUES = { ... }; private Object readResolve() { return PRIVATE_VALUES[ordinal]; } // Object methods public String toString() { return name; } // Comparable support public int compareTo(Object o) { return ordinal - ((Suit) o).ordinal; } } }; private Expansion fieldDecls (Fragment inDecls, Fragment type) throws SyntaxMatchFailure { syntaxSwitch (inDecls) { case #{ }: return #{ }; case #{ ?:name, ... }: { Fragment quotedName = new StringFragment(name.getName()); return #{ public final static ?type ?name = new ?type(?quotedName); ?(fieldDecls(..., type)) }; } } } }