42 * the component itself, and (2) a convention for a pattern of usage |
42 * the component itself, and (2) a convention for a pattern of usage |
43 * in which each base component registers itself by calling an |
43 * in which each base component registers itself by calling an |
44 * instance method that is overridden in extended components. A base |
44 * instance method that is overridden in extended components. A base |
45 * phase supporting extension would look something like this: |
45 * phase supporting extension would look something like this: |
46 * |
46 * |
47 * <p><pre> |
47 * <p><pre>{@code |
48 * public class Phase { |
48 * public class Phase { |
49 * protected static final Context.Key<Phase> phaseKey = |
49 * protected static final Context.Key<Phase> phaseKey = |
50 * new Context.Key<Phase>(); |
50 * new Context.Key<Phase>(); |
51 * |
51 * |
52 * public static Phase instance(Context context) { |
52 * public static Phase instance(Context context) { |
60 * protected Phase(Context context) { |
60 * protected Phase(Context context) { |
61 * context.put(phaseKey, this); |
61 * context.put(phaseKey, this); |
62 * // other intitialization follows... |
62 * // other intitialization follows... |
63 * } |
63 * } |
64 * } |
64 * } |
65 * </pre> |
65 * }</pre> |
66 * |
66 * |
67 * <p>In the compiler, we simply use Phase.instance(context) to get |
67 * <p>In the compiler, we simply use Phase.instance(context) to get |
68 * the reference to the phase. But in extensions of the compiler, we |
68 * the reference to the phase. But in extensions of the compiler, we |
69 * must register extensions of the phases to replace the base phase, |
69 * must register extensions of the phases to replace the base phase, |
70 * and this must be done before any reference to the phase is accessed |
70 * and this must be done before any reference to the phase is accessed |
71 * using Phase.instance(). An extended phase might be declared thus: |
71 * using Phase.instance(). An extended phase might be declared thus: |
72 * |
72 * |
73 * <p><pre> |
73 * <p><pre>{@code |
74 * public class NewPhase extends Phase { |
74 * public class NewPhase extends Phase { |
75 * protected NewPhase(Context context) { |
75 * protected NewPhase(Context context) { |
76 * super(context); |
76 * super(context); |
77 * } |
77 * } |
78 * public static void preRegister(final Context context) { |
78 * public static void preRegister(final Context context) { |