~ubuntu-branches/ubuntu/wily/aspectj/wily-proposed

« back to all changes in this revision

Viewing changes to org.aspectj/modules/bridge/src/org/aspectj/bridge/context/CompilationAndWeavingContext.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.2.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110315235431-iq2gxbsx08kpwuiw
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
import java.lang.ref.WeakReference;
15
15
import java.util.Collections;
16
16
import java.util.HashMap;
17
 
import java.util.Iterator;
18
17
import java.util.Map;
19
18
import java.util.Stack;
20
19
 
89
88
                        "type munging for @AspectJ aspectOf" };
90
89
 
91
90
        // context stacks, one per thread
92
 
        private static Map contextMap = Collections.synchronizedMap(new HashMap());
 
91
        private static Map<Thread, Stack<ContextStackEntry>> contextMap = Collections
 
92
                        .synchronizedMap(new HashMap<Thread, Stack<ContextStackEntry>>());
93
93
 
94
94
        // single thread mode stack
95
 
        private static Stack contextStack = new Stack();
 
95
        private static Stack<ContextStackEntry> contextStack = new Stack<ContextStackEntry>();
96
96
 
97
97
        // formatters, by phase id
98
 
        private static Map formatterMap = new HashMap();
 
98
        private static Map<Integer, ContextFormatter> formatterMap = new HashMap<Integer, ContextFormatter>();
99
99
 
100
100
        private static ContextFormatter defaultFormatter = new DefaultFormatter();
101
101
 
132
132
         * Returns a string description of what the compiler/weaver is currently doing
133
133
         */
134
134
        public static String getCurrentContext() {
135
 
                Stack contextStack = getContextStack();
136
 
                Stack explanationStack = new Stack();
137
 
                for (Iterator iter = contextStack.iterator(); iter.hasNext();) {
138
 
                        ContextStackEntry entry = (ContextStackEntry) iter.next();
 
135
                Stack<ContextStackEntry> contextStack = getContextStack();
 
136
                Stack<String> explanationStack = new Stack<String>();
 
137
                for (ContextStackEntry entry : contextStack) {
139
138
                        Object data = entry.getData();
140
139
                        if (data != null) {
141
140
                                explanationStack.push(getFormatter(entry).formatEntry(entry.phaseId, data));
151
150
        }
152
151
 
153
152
        public static ContextToken enteringPhase(int phaseId, Object data) {
154
 
                Stack contextStack = getContextStack();
 
153
                Stack<ContextStackEntry> contextStack = getContextStack();
155
154
                ContextTokenImpl nextToken = nextToken();
156
 
                contextStack.push(new ContextStackEntry(nextToken, phaseId, new WeakReference(data)));
 
155
                contextStack.push(new ContextStackEntry(nextToken, phaseId, new WeakReference<Object>(data)));
157
156
                return nextToken;
158
157
        }
159
158
 
164
163
                Stack contextStack = getContextStack();
165
164
                while (!contextStack.isEmpty()) {
166
165
                        ContextStackEntry entry = (ContextStackEntry) contextStack.pop();
167
 
                        if (entry.contextToken == aToken)
 
166
                        if (entry.contextToken == aToken) {
168
167
                                break;
 
168
                        }
169
169
                }
170
170
        }
171
171
 
173
173
         * Forget about the context for the current thread
174
174
         */
175
175
        public static void resetForThread() {
176
 
                if (!multiThreaded)
 
176
                if (!multiThreaded) {
177
177
                        return;
 
178
                }
178
179
                contextMap.remove(Thread.currentThread());
179
180
        }
180
181
 
181
 
        private static Stack getContextStack() {
 
182
        private static Stack<ContextStackEntry> getContextStack() {
182
183
                if (!multiThreaded) {
183
184
                        return contextStack;
184
185
                } else {
185
 
                        Stack contextStack = (Stack) contextMap.get(Thread.currentThread());
 
186
                        Stack<ContextStackEntry> contextStack = contextMap.get(Thread.currentThread());
186
187
                        if (contextStack == null) {
187
 
                                contextStack = new Stack();
 
188
                                contextStack = new Stack<ContextStackEntry>();
188
189
                                contextMap.put(Thread.currentThread(), contextStack);
189
190
                        }
190
191
                        return contextStack;
198
199
        private static ContextFormatter getFormatter(ContextStackEntry entry) {
199
200
                Integer key = new Integer(entry.phaseId);
200
201
                if (formatterMap.containsKey(key)) {
201
 
                        return (ContextFormatter) formatterMap.get(key);
 
202
                        return formatterMap.get(key);
202
203
                } else {
203
204
                        return defaultFormatter;
204
205
                }
216
217
        private static class ContextStackEntry {
217
218
                public ContextTokenImpl contextToken;
218
219
                public int phaseId;
219
 
                private WeakReference dataRef;
 
220
                private WeakReference<Object> dataRef;
220
221
 
221
 
                public ContextStackEntry(ContextTokenImpl ct, int phase, WeakReference data) {
 
222
                public ContextStackEntry(ContextTokenImpl ct, int phase, WeakReference<Object> data) {
222
223
                        this.contextToken = ct;
223
224
                        this.phaseId = phase;
224
225
                        this.dataRef = data;