src/share/classes/com/sun/tools/javac/util/Context.java

changeset 1358
fc123bdeddb8
parent 1326
30c36e23f154
child 2525
2eb010b6cb22
equal deleted inserted replaced
1357:c75be5bc5283 1358:fc123bdeddb8
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) {
81 * return new NewPhase(context); 81 * return new NewPhase(context);
82 * } 82 * }
83 * }); 83 * });
84 * } 84 * }
85 * } 85 * }
86 * </pre> 86 * }</pre>
87 * 87 *
88 * <p>And is registered early in the extended compiler like this 88 * <p>And is registered early in the extended compiler like this
89 * 89 *
90 * <p><pre> 90 * <p><pre>
91 * NewPhase.preRegister(context); 91 * NewPhase.preRegister(context);

mercurial