~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/PDOMProxy.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*******************************************************************************
 
2
 * Copyright (c) 2007, 2010 Wind River Systems, Inc. and others.
 
3
 * All rights reserved. This program and the accompanying materials
 
4
 * are made available under the terms of the Eclipse Public License v1.0
 
5
 * which accompanies this distribution, and is available at
 
6
 * http://www.eclipse.org/legal/epl-v10.html
 
7
 *
 
8
 * Contributors:
 
9
 *     Markus Schorn - initial API and implementation
 
10
 *     Sergey Prigogin (Google)
 
11
 *     Jens Elmenthaler - http://bugs.eclipse.org/173458 (camel case completion)
 
12
 *******************************************************************************/
 
13
package org.eclipse.cdt.internal.core.pdom;
 
14
 
 
15
import java.util.HashMap;
 
16
import java.util.HashSet;
 
17
import java.util.Map;
 
18
import java.util.Set;
 
19
import java.util.regex.Pattern;
 
20
 
 
21
import org.eclipse.cdt.core.dom.ast.IASTName;
 
22
import org.eclipse.cdt.core.dom.ast.IBinding;
 
23
import org.eclipse.cdt.core.index.IIndexFileLocation;
 
24
import org.eclipse.cdt.core.index.IIndexLinkage;
 
25
import org.eclipse.cdt.core.index.IIndexMacro;
 
26
import org.eclipse.cdt.core.index.IndexFilter;
 
27
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
 
28
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
 
29
import org.eclipse.cdt.internal.core.index.IIndexFragmentFileSet;
 
30
import org.eclipse.cdt.internal.core.index.IIndexFragmentInclude;
 
31
import org.eclipse.cdt.internal.core.index.IIndexFragmentName;
 
32
import org.eclipse.cdt.internal.core.index.IIndexScope;
 
33
import org.eclipse.cdt.internal.core.pdom.PDOM.ChangeEvent;
 
34
import org.eclipse.cdt.internal.core.pdom.PDOM.DebugLockInfo;
 
35
import org.eclipse.cdt.internal.core.pdom.PDOM.IListener;
 
36
import org.eclipse.cdt.internal.core.pdom.dom.PDOMLinkage;
 
37
import org.eclipse.core.runtime.CoreException;
 
38
import org.eclipse.core.runtime.IProgressMonitor;
 
39
 
 
40
/**
 
41
 * The PDOMProxy is returned by the PDOMManager before the indexer kicks in. Also and more
 
42
 * importantly it is returned when the indexer has been shut down (clients may not be aware
 
43
 * of this yet). Doing that prevents the creation of empty pdoms for deleted projects.
 
44
 */
 
45
public class PDOMProxy implements IPDOM {
 
46
        private PDOM fDelegate;
 
47
        private int fReadLockCount;
 
48
        private Set<IListener> fListeners= new HashSet<IListener>();
 
49
        private Map<Thread, DebugLockInfo> fLockDebugging;
 
50
 
 
51
        public PDOMProxy() {
 
52
                if (PDOM.sDEBUG_LOCKS) {
 
53
                        fLockDebugging= new HashMap<Thread, DebugLockInfo>();
 
54
                }
 
55
        }
 
56
        public synchronized void acquireReadLock() throws InterruptedException {
 
57
                if (fDelegate != null) {
 
58
                        fDelegate.acquireReadLock();
 
59
                } else {
 
60
                        fReadLockCount++;
 
61
                        if (PDOM.sDEBUG_LOCKS) {
 
62
                                PDOM.incReadLock(fLockDebugging);
 
63
                        }
 
64
                }
 
65
        }
 
66
 
 
67
        public IIndexMacro[] findMacros(char[] name, boolean isPrefix, boolean caseSensitive,
 
68
                        IndexFilter filter, IProgressMonitor monitor) throws CoreException {
 
69
                if (fDelegate != null)
 
70
                        return fDelegate.findMacros(name, isPrefix, caseSensitive, filter, monitor);
 
71
                return IIndexMacro.EMPTY_INDEX_MACRO_ARRAY;
 
72
        }
 
73
 
 
74
        public synchronized IIndexFragmentBinding adaptBinding(IBinding binding) throws CoreException {
 
75
                if (fDelegate != null)
 
76
                        return fDelegate.adaptBinding(binding);
 
77
                return null;
 
78
        }
 
79
 
 
80
        public synchronized IIndexFragmentBinding findBinding(IASTName astName) throws CoreException {
 
81
                if (fDelegate != null)
 
82
                        return fDelegate.findBinding(astName);
 
83
                return null;
 
84
        }
 
85
 
 
86
        public synchronized IIndexFragmentBinding[] findBindings(char[][] names, IndexFilter filter,
 
87
                        IProgressMonitor monitor) throws CoreException {
 
88
                if (fDelegate != null)
 
89
                        return fDelegate.findBindings(names, filter, monitor);
 
90
 
 
91
                return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
 
92
        }
 
93
 
 
94
        public synchronized IIndexFragmentBinding[] findBindings(Pattern[] patterns, boolean isFullyQualified,
 
95
                        IndexFilter filter, IProgressMonitor monitor) throws CoreException {
 
96
                if (fDelegate != null)
 
97
                        return fDelegate.findBindings(patterns, isFullyQualified, filter, monitor);
 
98
 
 
99
                return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
 
100
        }
 
101
 
 
102
        public synchronized IIndexFragmentBinding[] findBindings(char[] name, boolean filescope,
 
103
                        IndexFilter filter, IProgressMonitor monitor) throws CoreException {
 
104
                if (fDelegate != null)
 
105
                        return fDelegate.findBindings(name, filescope, filter, monitor);
 
106
 
 
107
                return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
 
108
        }
 
109
 
 
110
        public synchronized IIndexFragmentBinding[] findBindingsForPrefix(char[] prefix, boolean filescope,
 
111
                        IndexFilter filter, IProgressMonitor monitor) throws CoreException {
 
112
                if (fDelegate != null)
 
113
                        return fDelegate.findBindingsForPrefix(prefix, filescope, filter, monitor);
 
114
 
 
115
                return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
 
116
        }
 
117
 
 
118
        public synchronized IIndexFragmentBinding[] findBindingsForContentAssist(char[] prefix, boolean filescope,
 
119
                        IndexFilter filter, IProgressMonitor monitor) throws CoreException {
 
120
                if (fDelegate != null)
 
121
                        return fDelegate.findBindingsForContentAssist(prefix, filescope, filter, monitor);
 
122
 
 
123
                return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
 
124
        }
 
125
 
 
126
        public synchronized IIndexFragmentInclude[] findIncludedBy(IIndexFragmentFile file) throws CoreException {
 
127
                if (fDelegate != null)
 
128
                        return fDelegate.findIncludedBy(file);
 
129
 
 
130
                return new IIndexFragmentInclude[0];
 
131
        }
 
132
 
 
133
        public synchronized IIndexFragmentName[] findNames(IBinding binding, int flags)
 
134
                        throws CoreException {
 
135
                if (fDelegate != null)
 
136
                        return fDelegate.findNames(binding, flags);
 
137
 
 
138
                return IIndexFragmentName.EMPTY_NAME_ARRAY;
 
139
        }
 
140
 
 
141
        public synchronized long getCacheHits() {
 
142
                if (fDelegate != null)
 
143
                        return fDelegate.getCacheHits();
 
144
 
 
145
                return 0;
 
146
        }
 
147
 
 
148
        public synchronized long getCacheMisses() {
 
149
                if (fDelegate != null)
 
150
                        return fDelegate.getCacheMisses();
 
151
 
 
152
                return 0;
 
153
        }
 
154
 
 
155
        public synchronized IIndexFragmentFile getFile(int linkageID, IIndexFileLocation location) throws CoreException {
 
156
                if (fDelegate != null)
 
157
                        return fDelegate.getFile(linkageID, location);
 
158
 
 
159
                return null;
 
160
        }
 
161
 
 
162
        public synchronized IIndexFragmentFile[] getFiles(IIndexFileLocation location) throws CoreException {
 
163
                if (fDelegate != null)
 
164
                        return fDelegate.getFiles(location);
 
165
 
 
166
                return IIndexFragmentFile.EMPTY_ARRAY;
 
167
        }
 
168
 
 
169
        public synchronized long getLastWriteAccess() {
 
170
                if (fDelegate != null)
 
171
                        return fDelegate.getLastWriteAccess();
 
172
 
 
173
                return 0;
 
174
        }
 
175
 
 
176
        public synchronized IIndexLinkage[] getLinkages() {
 
177
                if (fDelegate != null)
 
178
                        return fDelegate.getLinkages();
 
179
 
 
180
                return new IIndexLinkage[0];
 
181
        }
 
182
 
 
183
        public synchronized String getProperty(String propertyName) throws CoreException {
 
184
                if (fDelegate != null)
 
185
                        return fDelegate.getProperty(propertyName);
 
186
 
 
187
                return null;
 
188
        }
 
189
 
 
190
        public synchronized void releaseReadLock() {
 
191
                // read-locks not forwarded to delegate need to be released here
 
192
                if (fReadLockCount > 0) {
 
193
                        fReadLockCount--;
 
194
                        if (PDOM.sDEBUG_LOCKS)
 
195
                                PDOM.decReadLock(fLockDebugging);
 
196
                } else if (fDelegate != null) {
 
197
                        fDelegate.releaseReadLock();
 
198
                }
 
199
        }
 
200
 
 
201
        public boolean hasWaitingReaders() {
 
202
                return fDelegate != null && fDelegate.hasWaitingReaders();
 
203
        }
 
204
 
 
205
        public synchronized void resetCacheCounters() {
 
206
                if (fDelegate != null)
 
207
                        fDelegate.resetCacheCounters();
 
208
        }
 
209
 
 
210
        @SuppressWarnings({ "rawtypes", "unchecked" })
 
211
        public synchronized Object getAdapter(Class adapter) {
 
212
                if (adapter.isAssignableFrom(PDOMProxy.class)) {
 
213
                        return this;
 
214
                }
 
215
                return null;
 
216
        }
 
217
 
 
218
        public synchronized void addListener(IListener listener) {
 
219
                if (fDelegate != null) {
 
220
                        fDelegate.addListener(listener);
 
221
                } else {
 
222
                        fListeners.add(listener);
 
223
                }
 
224
        }
 
225
 
 
226
        public synchronized PDOMLinkage[] getLinkageImpls() {
 
227
                if (fDelegate != null)
 
228
                        return fDelegate.getLinkageImpls();
 
229
 
 
230
                return new PDOMLinkage[0];
 
231
        }
 
232
 
 
233
        public synchronized void removeListener(IListener listener) {
 
234
                if (fDelegate != null) {
 
235
                        fDelegate.removeListener(listener);
 
236
                } else {
 
237
                        fListeners.remove(listener);
 
238
                }
 
239
        }
 
240
 
 
241
        public synchronized void setDelegate(WritablePDOM pdom) {
 
242
                fDelegate= pdom;
 
243
                try {
 
244
                        while (fReadLockCount > 0) {
 
245
                                pdom.acquireReadLock();
 
246
                                fReadLockCount--;
 
247
                        }
 
248
                        if (PDOM.sDEBUG_LOCKS) {
 
249
                                pdom.adjustThreadForReadLock(fLockDebugging);
 
250
                        }
 
251
                } catch (InterruptedException e) {
 
252
                        Thread.currentThread().interrupt();
 
253
                }
 
254
                for (IListener listener : fListeners) {
 
255
                        pdom.addListener(listener);
 
256
                }
 
257
                ChangeEvent event= new ChangeEvent();
 
258
                event.setReloaded();
 
259
                for (IListener listener : fListeners) {
 
260
                        listener.handleChange(fDelegate, event);
 
261
                }
 
262
        }
 
263
 
 
264
        public IIndexFragmentFileSet createFileSet() {
 
265
                return new PDOMFileSet();
 
266
        }
 
267
 
 
268
        public synchronized IIndexFragmentFile[] getAllFiles() throws CoreException {
 
269
                if (fDelegate != null)
 
270
                        return fDelegate.getAllFiles();
 
271
                return IIndexFragmentFile.EMPTY_ARRAY;
 
272
        }
 
273
 
 
274
        /* (non-Javadoc)
 
275
         * @see org.eclipse.cdt.internal.core.index.IIndexFragment#findMacroContainers(java.util.regex.Pattern, org.eclipse.cdt.core.index.IndexFilter, org.eclipse.core.runtime.IProgressMonitor)
 
276
         */
 
277
        public synchronized IIndexFragmentBinding[] findMacroContainers(Pattern pattern, IndexFilter filter,
 
278
                        IProgressMonitor monitor) throws CoreException {
 
279
                if (fDelegate != null) {
 
280
                        return fDelegate.findMacroContainers(pattern, filter, monitor);
 
281
                }
 
282
                return IIndexFragmentBinding.EMPTY_INDEX_BINDING_ARRAY;
 
283
        }
 
284
 
 
285
        public Object getCachedResult(Object key) {
 
286
                return null;
 
287
        }
 
288
 
 
289
        public Object putCachedResult(Object key, Object value, boolean replace) {
 
290
                return value;
 
291
        }
 
292
        public void clearResultCache() {
 
293
                if (fDelegate != null)
 
294
                        fDelegate.clearResultCache();
 
295
        }
 
296
        /* (non-Javadoc)
 
297
         * @see org.eclipse.cdt.internal.core.index.IIndexFragment#getInlineNamespaces()
 
298
         */
 
299
        public IIndexScope[] getInlineNamespaces() throws CoreException {
 
300
                if (fDelegate != null)
 
301
                        return fDelegate.getInlineNamespaces();
 
302
 
 
303
                return IIndexScope.EMPTY_INDEX_SCOPE_ARRAY;
 
304
        }
 
305
}