author | timkelly |
Wed, 19 Aug 2009 14:42:39 -0500 | |
changeset 73 | 82f772574273 |
parent 37 | c2bce6dd59e7 |
child 75 | 689d22da9f18 |
permissions | -rw-r--r-- |
37 | 1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2008 QNX Software Systems 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 |
* QNX Software Systems - Initial API and implementation |
|
10 |
* James Blackburn - Modified patch for 149428 |
|
11 |
* Markus Schorn (Wind River Systems) |
|
12 |
* Anton Leherbauer (Wind River Systems) |
|
13 |
* Warren Paul (Nokia) |
|
14 |
* IBM Corporation (EFS Support) |
|
15 |
*******************************************************************************/ |
|
16 |
||
17 |
package org.eclipse.cdt.internal.core.model; |
|
18 |
||
19 |
import java.io.File; |
|
20 |
import java.io.IOException; |
|
21 |
import java.io.InputStream; |
|
22 |
import java.net.URI; |
|
23 |
import java.util.ArrayList; |
|
24 |
import java.util.Collection; |
|
25 |
import java.util.Collections; |
|
26 |
import java.util.HashMap; |
|
27 |
import java.util.HashSet; |
|
28 |
import java.util.List; |
|
29 |
import java.util.Map; |
|
30 |
||
31 |
import org.eclipse.cdt.core.CCProjectNature; |
|
32 |
import org.eclipse.cdt.core.CCorePlugin; |
|
33 |
import org.eclipse.cdt.core.CDescriptorEvent; |
|
34 |
import org.eclipse.cdt.core.CProjectNature; |
|
35 |
import org.eclipse.cdt.core.IBinaryParser; |
|
36 |
import org.eclipse.cdt.core.ICDescriptor; |
|
37 |
import org.eclipse.cdt.core.ICDescriptorListener; |
|
38 |
import org.eclipse.cdt.core.ICExtensionReference; |
|
39 |
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive; |
|
40 |
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; |
|
41 |
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; |
|
42 |
import org.eclipse.cdt.core.model.CModelException; |
|
43 |
import org.eclipse.cdt.core.model.CoreModel; |
|
44 |
import org.eclipse.cdt.core.model.ElementChangedEvent; |
|
45 |
import org.eclipse.cdt.core.model.ICContainer; |
|
46 |
import org.eclipse.cdt.core.model.ICElement; |
|
47 |
import org.eclipse.cdt.core.model.ICElementDelta; |
|
48 |
import org.eclipse.cdt.core.model.ICModel; |
|
49 |
import org.eclipse.cdt.core.model.ICProject; |
|
50 |
import org.eclipse.cdt.core.model.IElementChangedListener; |
|
51 |
import org.eclipse.cdt.core.model.IIncludeReference; |
|
52 |
import org.eclipse.cdt.core.model.IParent; |
|
53 |
import org.eclipse.cdt.core.model.ISourceRoot; |
|
54 |
import org.eclipse.cdt.core.model.ITranslationUnit; |
|
55 |
import org.eclipse.cdt.core.model.IWorkingCopy; |
|
56 |
import org.eclipse.cdt.internal.core.CCoreInternals; |
|
57 |
import org.eclipse.cdt.internal.core.LocalProjectScope; |
|
58 |
import org.eclipse.cdt.internal.core.resources.ResourceLookup; |
|
59 |
import org.eclipse.core.filesystem.EFS; |
|
60 |
import org.eclipse.core.filesystem.IFileInfo; |
|
61 |
import org.eclipse.core.filesystem.IFileStore; |
|
62 |
import org.eclipse.core.filesystem.URIUtil; |
|
63 |
import org.eclipse.core.resources.IFile; |
|
64 |
import org.eclipse.core.resources.IFolder; |
|
65 |
import org.eclipse.core.resources.IProject; |
|
66 |
import org.eclipse.core.resources.IResource; |
|
67 |
import org.eclipse.core.resources.IResourceChangeEvent; |
|
68 |
import org.eclipse.core.resources.IResourceChangeListener; |
|
69 |
import org.eclipse.core.resources.IResourceDelta; |
|
70 |
import org.eclipse.core.resources.IWorkspace; |
|
71 |
import org.eclipse.core.resources.IWorkspaceRoot; |
|
72 |
import org.eclipse.core.resources.ResourcesPlugin; |
|
73 |
import org.eclipse.core.runtime.CoreException; |
|
74 |
import org.eclipse.core.runtime.IPath; |
|
75 |
import org.eclipse.core.runtime.ISafeRunnable; |
|
76 |
import org.eclipse.core.runtime.Platform; |
|
77 |
import org.eclipse.core.runtime.SafeRunner; |
|
78 |
import org.eclipse.core.runtime.content.IContentType; |
|
79 |
import org.eclipse.core.runtime.content.IContentTypeManager; |
|
80 |
import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent; |
|
81 |
import org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeChangeListener; |
|
82 |
||
83 |
public class CModelManager implements IResourceChangeListener, ICDescriptorListener, IContentTypeChangeListener { |
|
84 |
||
85 |
public static boolean VERBOSE = false; |
|
86 |
||
87 |
/** |
|
88 |
* Unique handle onto the CModel |
|
89 |
*/ |
|
90 |
final CModel cModel = new CModel(); |
|
91 |
||
92 |
public static HashSet<String> OptionNames = new HashSet<String>(20); |
|
93 |
||
94 |
public static final int DEFAULT_CHANGE_EVENT = 0; // must not collide with ElementChangedEvent event masks |
|
95 |
||
96 |
/** |
|
97 |
* Used to convert <code>IResourceDelta</code>s into <code>ICElementDelta</code>s. |
|
98 |
*/ |
|
99 |
protected final DeltaProcessor fDeltaProcessor = new DeltaProcessor(); |
|
100 |
||
101 |
/** |
|
102 |
* Queue of deltas created explicitly by the C Model that |
|
103 |
* have yet to be fired. |
|
104 |
*/ |
|
105 |
List<ICElementDelta> fCModelDeltas = Collections.synchronizedList(new ArrayList<ICElementDelta>()); |
|
106 |
||
107 |
/** |
|
108 |
* Queue of reconcile deltas on working copies that have yet to be fired. |
|
109 |
* This is a table form IWorkingCopy to ICElementDelta |
|
110 |
*/ |
|
111 |
HashMap<IWorkingCopy, ICElementDelta> reconcileDeltas = new HashMap<IWorkingCopy, ICElementDelta>(); |
|
112 |
||
113 |
/** |
|
114 |
* Turns delta firing on/off. By default it is on. |
|
115 |
*/ |
|
116 |
protected boolean fFire = true; |
|
117 |
||
118 |
/** |
|
119 |
* Collection of listeners for C element deltas |
|
120 |
*/ |
|
121 |
protected List<IElementChangedListener> fElementChangedListeners = Collections.synchronizedList(new ArrayList<IElementChangedListener>()); |
|
122 |
||
123 |
/** |
|
124 |
* A map from ITranslationUnit to IWorkingCopy of the shared working copies. |
|
125 |
*/ |
|
126 |
public Map<IBufferFactory, Map<ITranslationUnit, WorkingCopy>> sharedWorkingCopies = new HashMap<IBufferFactory, Map<ITranslationUnit, WorkingCopy>>(); |
|
127 |
/** |
|
128 |
* Set of elements which are out of sync with their buffers. |
|
129 |
*/ |
|
130 |
protected Map<ICElement,ICElement> elementsOutOfSynchWithBuffers = new HashMap<ICElement, ICElement>(11); |
|
131 |
||
132 |
/* |
|
133 |
* Temporary cache of newly opened elements |
|
134 |
*/ |
|
135 |
private ThreadLocal<Map<ICElement, CElementInfo>> temporaryCache = new ThreadLocal<Map<ICElement, CElementInfo>>(); |
|
136 |
||
137 |
/** |
|
138 |
* Infos cache. |
|
139 |
*/ |
|
140 |
protected CModelCache cache = new CModelCache(); |
|
141 |
||
142 |
/** |
|
143 |
* This is a cache of the projects before any project addition/deletion has started. |
|
144 |
*/ |
|
145 |
public ICProject[] cProjectsCache; |
|
146 |
||
147 |
/** |
|
148 |
* The list of started BinaryRunners on projects. |
|
149 |
*/ |
|
150 |
private HashMap<IProject, BinaryRunner> binaryRunners = new HashMap<IProject, BinaryRunner>(); |
|
151 |
||
152 |
/** |
|
153 |
* Map of the binary parser for each project. |
|
154 |
*/ |
|
155 |
private HashMap<IProject, BinaryParserConfig[]> binaryParsersMap = new HashMap<IProject, BinaryParserConfig[]>(); |
|
156 |
||
157 |
/** |
|
158 |
* The lis of the SourceMappers on projects. |
|
159 |
*/ |
|
160 |
private HashMap<ICProject, SourceMapper> sourceMappers = new HashMap<ICProject, SourceMapper>(); |
|
161 |
||
162 |
public static final IWorkingCopy[] NoWorkingCopy = new IWorkingCopy[0]; |
|
163 |
||
164 |
static volatile CModelManager factory = null; |
|
165 |
||
166 |
private CModelManager() { |
|
167 |
} |
|
168 |
||
169 |
public static CModelManager getDefault() { |
|
170 |
if (factory == null) { |
|
171 |
synchronized (CModelManager.class) { |
|
172 |
if (factory != null) |
|
173 |
return factory; |
|
174 |
||
175 |
factory = new CModelManager(); |
|
176 |
||
177 |
// Register to the workspace; |
|
178 |
ResourcesPlugin.getWorkspace().addResourceChangeListener(factory, |
|
179 |
IResourceChangeEvent.POST_CHANGE |
|
180 |
| IResourceChangeEvent.PRE_DELETE |
|
181 |
| IResourceChangeEvent.PRE_CLOSE); |
|
182 |
||
183 |
// Register the Core Model on the Descriptor |
|
184 |
// Manager, it needs to know about changes. |
|
185 |
CCorePlugin.getDefault().getCDescriptorManager().addDescriptorListener(factory); |
|
186 |
// Register the Core Model on the ContentTypeManager |
|
187 |
// it needs to know about changes. |
|
188 |
Platform.getContentTypeManager().addContentTypeChangeListener(factory); |
|
189 |
} |
|
190 |
} |
|
191 |
return factory; |
|
192 |
} |
|
193 |
||
194 |
/** |
|
195 |
* Returns the CModel for the given workspace, creating |
|
196 |
* it if it does not yet exist. |
|
197 |
*/ |
|
198 |
public ICModel getCModel(IWorkspaceRoot root) { |
|
199 |
return getCModel(); |
|
200 |
} |
|
201 |
||
202 |
public CModel getCModel() { |
|
203 |
return cModel; |
|
204 |
} |
|
205 |
||
206 |
public ICElement create(IPath path) { |
|
207 |
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); |
|
208 |
// Assume it is fullpath relative to workspace |
|
209 |
IResource res = root.findMember(path); |
|
210 |
if (res == null) { |
|
211 |
IPath rootPath = root.getLocation(); |
|
212 |
if (path.equals(rootPath)) { |
|
213 |
return getCModel(root); |
|
214 |
} |
|
215 |
res = root.getContainerForLocation(path); |
|
216 |
if (res == null || !res.exists()) { |
|
217 |
res = root.getFileForLocation(path); |
|
218 |
} |
|
219 |
if (res != null && !res.exists()) { |
|
220 |
res = null; |
|
221 |
} |
|
222 |
} |
|
223 |
||
224 |
// In case this is an external resource see if we can find |
|
225 |
// a file for it. |
|
226 |
if (res == null) { |
|
227 |
res= ResourceLookup.selectFileForLocation(path, null); |
|
228 |
} |
|
229 |
||
230 |
return create(res, null); |
|
231 |
} |
|
232 |
||
233 |
public ICElement create(IResource resource, ICProject cproject) { |
|
234 |
if (resource == null) { |
|
235 |
return null; |
|
236 |
} |
|
237 |
||
238 |
int type = resource.getType(); |
|
239 |
switch (type) { |
|
240 |
case IResource.PROJECT : |
|
241 |
return create((IProject)resource); |
|
242 |
case IResource.FILE : |
|
243 |
return create((IFile)resource, cproject); |
|
244 |
case IResource.FOLDER : |
|
245 |
return create((IFolder)resource, cproject); |
|
246 |
case IResource.ROOT : |
|
247 |
return getCModel((IWorkspaceRoot)resource); |
|
248 |
default : |
|
249 |
return null; |
|
250 |
} |
|
251 |
} |
|
252 |
||
253 |
public ICProject create(IProject project) { |
|
254 |
if (project == null) { |
|
255 |
return null; |
|
256 |
} |
|
257 |
return cModel.getCProject(project); |
|
258 |
} |
|
259 |
||
260 |
public ICContainer create(IFolder folder, ICProject cproject) { |
|
261 |
if (folder == null) { |
|
262 |
return null; |
|
263 |
} |
|
264 |
if (cproject == null) { |
|
265 |
cproject = create(folder.getProject()); |
|
266 |
} |
|
267 |
try { |
|
268 |
ICElement[] children = cproject.getChildren(); |
|
269 |
for (int i = 0; i < children.length; ++i) { |
|
270 |
if (children[i] instanceof ISourceRoot) { |
|
271 |
ISourceRoot root = (ISourceRoot)children[i]; |
|
73
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
272 |
if (root.isOnSourceEntry(folder) || isParentOfSourceRoot(root, folder)) { |
37 | 273 |
// Get the container |
274 |
IPath path = folder.getFullPath(); |
|
275 |
path = path.removeFirstSegments(root.getPath().segmentCount()); |
|
276 |
String[] segments = path.segments(); |
|
277 |
ICContainer cfolder = root; |
|
278 |
for (int j = 0; j < segments.length; ++j) { |
|
279 |
cfolder = cfolder.getCContainer(segments[j]); |
|
280 |
} |
|
281 |
return cfolder; |
|
282 |
} |
|
283 |
} else if (children[i] instanceof ICContainer) { |
|
284 |
ICContainer root = (ICContainer)children[i]; |
|
285 |
IPath rootPath = root.getPath(); |
|
286 |
IPath path = folder.getFullPath(); |
|
287 |
if (rootPath.isPrefixOf(path) && cproject.isOnOutputEntry(folder)) { |
|
288 |
path = path.removeFirstSegments(root.getPath().segmentCount()); |
|
289 |
String[] segments = path.segments(); |
|
290 |
ICContainer cfolder = root; |
|
291 |
for (int j = 0; j < segments.length; ++j) { |
|
292 |
cfolder = cfolder.getCContainer(segments[j]); |
|
293 |
} |
|
294 |
return cfolder; |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
} catch (CModelException e) { |
|
299 |
// |
|
300 |
} |
|
301 |
return null; |
|
302 |
} |
|
303 |
||
304 |
public ICElement create(IFile file, ICProject cproject) { |
|
305 |
if (file == null) { |
|
306 |
return null; |
|
307 |
} |
|
308 |
if (cproject == null) { |
|
309 |
cproject = create(file.getProject()); |
|
310 |
} |
|
311 |
ICElement celement = null; |
|
312 |
try { |
|
313 |
// First look for TU's |
|
314 |
IPath resourcePath = file.getFullPath(); |
|
315 |
ISourceRoot[] roots = cproject.getSourceRoots(); |
|
316 |
for (int i = 0; i < roots.length; ++i) { |
|
317 |
ISourceRoot root = roots[i]; |
|
318 |
if (root.isOnSourceEntry(file)) { |
|
319 |
IPath rootPath = root.getPath(); |
|
320 |
IPath path = resourcePath.removeFirstSegments(rootPath.segmentCount()); |
|
321 |
String fileName = path.lastSegment(); |
|
322 |
path = path.removeLastSegments(1); |
|
323 |
String[] segments = path.segments(); |
|
324 |
ICContainer cfolder = root; |
|
325 |
for (String segment : segments) { |
|
326 |
cfolder = cfolder.getCContainer(segment); |
|
327 |
} |
|
328 |
if (CoreModel.isValidTranslationUnitName(cproject.getProject(), fileName)) { |
|
329 |
celement = cfolder.getTranslationUnit(fileName); |
|
330 |
} |
|
331 |
break; |
|
332 |
} |
|
333 |
} |
|
334 |
||
335 |
// check for binary on output entry |
|
336 |
if (celement == null && cproject.isOnOutputEntry(file)) { |
|
337 |
IBinaryFile bin = createBinaryFile(file); |
|
338 |
if (bin != null) |
|
339 |
celement = create(file, bin, cproject); |
|
340 |
} |
|
341 |
} catch (CModelException e) { |
|
342 |
// |
|
343 |
} |
|
344 |
return celement; |
|
345 |
} |
|
346 |
||
347 |
public ICElement create(IFile file, IBinaryFile bin, ICProject cproject) { |
|
348 |
if (file == null) { |
|
349 |
return null; |
|
350 |
} |
|
351 |
if (bin == null) { |
|
352 |
return create(file, cproject); |
|
353 |
} |
|
354 |
if (cproject == null) { |
|
355 |
cproject = create(file.getProject()); |
|
356 |
} |
|
357 |
ICElement celement = null; |
|
358 |
try { |
|
359 |
if (cproject.isOnOutputEntry(file)) { |
|
360 |
IPath resourcePath = file.getParent().getFullPath(); |
|
361 |
ICElement cfolder = cproject.findElement(resourcePath); |
|
362 |
||
363 |
// Check if folder is a source root and use that instead |
|
364 |
ISourceRoot sourceRoot = cproject.findSourceRoot(resourcePath); |
|
365 |
if (sourceRoot != null) |
|
366 |
cfolder = sourceRoot; |
|
367 |
||
368 |
if (bin.getType() == IBinaryFile.ARCHIVE) { |
|
369 |
ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer(); |
|
370 |
celement = new Archive(cfolder, file, (IBinaryArchive)bin); |
|
371 |
vlib.addChild(celement); |
|
372 |
} else { |
|
373 |
BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer(); |
|
374 |
celement = new Binary(cfolder, file, (IBinaryObject)bin); |
|
375 |
vbin.addChild(celement); |
|
376 |
} |
|
377 |
} |
|
378 |
} catch (CModelException e) { |
|
379 |
// |
|
380 |
} |
|
381 |
return celement; |
|
382 |
} |
|
383 |
||
384 |
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, IPath path) { |
|
385 |
if (path == null || cproject == null) { |
|
386 |
return null; |
|
387 |
} |
|
388 |
||
389 |
final IProject project= cproject.getProject(); |
|
390 |
final String contentTypeId = CoreModel.getRegistedContentTypeId(project, path.lastSegment()); |
|
391 |
||
392 |
if (path.isAbsolute()) { |
|
393 |
if (! Util.isNonZeroLengthFile(path)) { |
|
394 |
return null; |
|
395 |
} |
|
396 |
||
397 |
try { |
|
398 |
IIncludeReference[] includeReferences = cproject.getIncludeReferences(); |
|
399 |
for (IIncludeReference includeReference : includeReferences) { |
|
400 |
if (includeReference.isOnIncludeEntry(path)) { |
|
401 |
String headerContentTypeId= contentTypeId; |
|
402 |
if (headerContentTypeId == null) { |
|
403 |
headerContentTypeId= CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; |
|
404 |
} |
|
405 |
||
406 |
// TODO: use URI |
|
407 |
return new ExternalTranslationUnit(includeReference, URIUtil.toURI(path), headerContentTypeId); |
|
408 |
} |
|
409 |
} |
|
410 |
} catch (CModelException e) { |
|
411 |
} |
|
412 |
||
413 |
// if the file exists and it has a known C/C++ file extension then just create |
|
414 |
// an external translation unit for it. |
|
415 |
if (contentTypeId != null && path.toFile().exists()) { |
|
416 |
// TODO: use URI |
|
417 |
return new ExternalTranslationUnit(cproject, URIUtil.toURI(path), contentTypeId); |
|
418 |
} |
|
419 |
} else { |
|
420 |
// !path.isAbsolute() |
|
421 |
try { |
|
422 |
IIncludeReference[] includeReferences = cproject.getIncludeReferences(); |
|
423 |
for (IIncludeReference includeReference : includeReferences) { |
|
424 |
IPath includePath = includeReference.getPath().append(path); |
|
425 |
if (Util.isNonZeroLengthFile(includePath)) { |
|
426 |
String headerContentTypeId= contentTypeId; |
|
427 |
if (headerContentTypeId == null) { |
|
428 |
headerContentTypeId= CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; |
|
429 |
} |
|
430 |
||
431 |
// TODO: use URI |
|
432 |
return new ExternalTranslationUnit(includeReference, URIUtil.toURI(includePath), headerContentTypeId); |
|
433 |
} |
|
434 |
} |
|
435 |
} catch (CModelException e) { |
|
436 |
} |
|
437 |
} |
|
438 |
return null; |
|
439 |
} |
|
440 |
||
441 |
/** |
|
442 |
* Creates a translation unit in the given project for the given location. |
|
443 |
* |
|
444 |
* @param cproject |
|
445 |
* @param locationURI |
|
446 |
* @return ITranslationUnit |
|
447 |
*/ |
|
448 |
public ITranslationUnit createTranslationUnitFrom(ICProject cproject, URI locationURI) { |
|
449 |
if (locationURI == null || cproject == null) { |
|
450 |
return null; |
|
451 |
} |
|
452 |
||
453 |
if(!locationURI.isAbsolute()) { |
|
454 |
throw new IllegalArgumentException(); |
|
455 |
} |
|
456 |
||
457 |
final IProject project= cproject.getProject(); |
|
458 |
||
459 |
IFileStore fileStore = null; |
|
460 |
try { |
|
461 |
fileStore = EFS.getStore(locationURI); |
|
462 |
} catch (CoreException e1) { |
|
463 |
// TODO Auto-generated catch block |
|
464 |
e1.printStackTrace(); |
|
465 |
return null; |
|
466 |
} |
|
467 |
||
468 |
final String contentTypeId = CoreModel.getRegistedContentTypeId(project, fileStore.getName()); |
|
469 |
||
470 |
if (! Util.isNonZeroLengthFile(locationURI)) { |
|
471 |
return null; |
|
472 |
} |
|
473 |
||
474 |
try { |
|
475 |
IIncludeReference[] includeReferences = cproject.getIncludeReferences(); |
|
476 |
for (IIncludeReference includeReference : includeReferences) { |
|
477 |
||
478 |
||
479 |
// crecoskie |
|
480 |
// TODO FIXME: include entries don't handle URIs yet |
|
481 |
IPath path = URIUtil.toPath(locationURI); |
|
482 |
if (path != null && includeReference.isOnIncludeEntry(path)) { |
|
483 |
String headerContentTypeId= contentTypeId; |
|
484 |
if (headerContentTypeId == null) { |
|
485 |
headerContentTypeId= CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; |
|
486 |
} |
|
487 |
||
488 |
return new ExternalTranslationUnit(includeReference, locationURI, headerContentTypeId); |
|
489 |
} |
|
490 |
} |
|
491 |
} catch (CModelException e) { |
|
492 |
} |
|
493 |
||
494 |
// if the file exists and it has a known C/C++ file extension then just create |
|
495 |
// an external translation unit for it. |
|
496 |
IFileInfo info = fileStore.fetchInfo(); |
|
497 |
||
498 |
if (contentTypeId != null && info != null && info.exists()) { |
|
499 |
return new ExternalTranslationUnit(cproject, locationURI, contentTypeId); |
|
500 |
} |
|
501 |
||
502 |
return null; |
|
503 |
} |
|
504 |
||
505 |
public void releaseCElement(ICElement celement) { |
|
506 |
||
507 |
// Guard. |
|
508 |
if (celement == null) |
|
509 |
return; |
|
510 |
||
511 |
//System.out.println("RELEASE " + celement.getElementName()); |
|
512 |
||
513 |
// Remove from the containers. |
|
514 |
if (celement instanceof IParent) { |
|
515 |
CElementInfo info = (CElementInfo)peekAtInfo(celement); |
|
516 |
if (info != null) { |
|
517 |
ICElement[] children = info.getChildren(); |
|
518 |
for (ICElement element : children) { |
|
519 |
releaseCElement(element); |
|
520 |
} |
|
521 |
} |
|
522 |
||
523 |
// Make sure any object specifics not part of the children be destroy |
|
524 |
// For example the CProject needs to destroy the BinaryContainer and ArchiveContainer |
|
525 |
if (celement instanceof CElement) { |
|
526 |
try { |
|
527 |
((CElement)celement).closing(info); |
|
528 |
} catch (CModelException e) { |
|
529 |
// |
|
530 |
} |
|
531 |
} |
|
532 |
||
533 |
// If an entire folder was deleted we need to update the |
|
534 |
// BinaryContainer/ArchiveContainer also. |
|
535 |
if (celement.getElementType() == ICElement.C_CCONTAINER) { |
|
536 |
ICProject cproject = celement.getCProject(); |
|
537 |
CProjectInfo pinfo = (CProjectInfo)peekAtInfo(cproject); |
|
538 |
ArrayList<ICElement> list = new ArrayList<ICElement>(5); |
|
539 |
if (pinfo != null && pinfo.vBin != null) { |
|
540 |
if (peekAtInfo(pinfo.vBin) != null) { |
|
541 |
try { |
|
542 |
ICElement[] bins = pinfo.vBin.getChildren(); |
|
543 |
for (ICElement bin : bins) { |
|
544 |
if (celement.getPath().isPrefixOf(bin.getPath())) { |
|
545 |
//pinfo.vBin.removeChild(bins[i]); |
|
546 |
list.add(bin); |
|
547 |
} |
|
548 |
} |
|
549 |
} catch (CModelException e) { |
|
550 |
// .. |
|
551 |
} |
|
552 |
} |
|
553 |
} |
|
554 |
if (pinfo != null && pinfo.vLib != null) { |
|
555 |
if (peekAtInfo(pinfo.vLib) != null) { |
|
556 |
try { |
|
557 |
ICElement[] ars = pinfo.vLib.getChildren(); |
|
558 |
for (ICElement ar : ars) { |
|
559 |
if (celement.getPath().isPrefixOf(ar.getPath())) { |
|
560 |
//pinfo.vLib.removeChild(ars[i]); |
|
561 |
list.add(ar); |
|
562 |
} |
|
563 |
} |
|
564 |
} catch (CModelException e) { |
|
565 |
// .. |
|
566 |
} |
|
567 |
} |
|
568 |
} |
|
569 |
// release any binary/archive that was in the path |
|
570 |
for (int i = 0; i < list.size(); i++) { |
|
571 |
ICElement b = list.get(i); |
|
572 |
releaseCElement(b); |
|
573 |
} |
|
574 |
} |
|
575 |
} |
|
576 |
||
577 |
// Remove the child from the parent list. |
|
578 |
//Parent parent = (Parent)celement.getParent(); |
|
579 |
//if (parent != null && peekAtInfo(parent) != null) { |
|
580 |
// parent.removeChild(celement); |
|
581 |
//} |
|
582 |
||
583 |
removeInfo(celement); |
|
584 |
} |
|
585 |
||
586 |
public BinaryParserConfig[] getBinaryParser(IProject project) { |
|
587 |
BinaryParserConfig[] parsers = binaryParsersMap.get(project); |
|
588 |
if (parsers == null) { |
|
589 |
try { |
|
590 |
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(project, false); |
|
591 |
if (cdesc != null) { |
|
592 |
ICExtensionReference[] cextensions = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID, true); |
|
593 |
if (cextensions.length > 0) { |
|
594 |
ArrayList<BinaryParserConfig> list = new ArrayList<BinaryParserConfig>(cextensions.length); |
|
595 |
for (ICExtensionReference cextension : cextensions) { |
|
596 |
BinaryParserConfig config = new BinaryParserConfig(cextension); |
|
597 |
list.add(config); |
|
598 |
} |
|
599 |
parsers = new BinaryParserConfig[list.size()]; |
|
600 |
list.toArray(parsers); |
|
601 |
} else { |
|
602 |
// no parser configured |
|
603 |
parsers = new BinaryParserConfig[0]; |
|
604 |
} |
|
605 |
} |
|
606 |
} catch (CoreException e) { |
|
607 |
} |
|
608 |
if (parsers == null) { |
|
609 |
try { |
|
610 |
BinaryParserConfig config = new BinaryParserConfig(CCorePlugin.getDefault().getDefaultBinaryParser(), CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID); |
|
611 |
parsers = new BinaryParserConfig[]{config}; |
|
612 |
} catch (CoreException e1) { |
|
613 |
} |
|
614 |
} |
|
615 |
} |
|
616 |
if (parsers != null) { |
|
617 |
binaryParsersMap.put(project, parsers); |
|
618 |
return parsers; |
|
619 |
} |
|
620 |
return new BinaryParserConfig[0]; |
|
621 |
} |
|
622 |
||
623 |
public IBinaryFile createBinaryFile(IFile file) { |
|
624 |
BinaryParserConfig[] parsers = getBinaryParser(file.getProject()); |
|
625 |
if (parsers.length == 0) { |
|
626 |
return null; |
|
627 |
} |
|
628 |
||
629 |
// Only if file has no extension, has an extension that is an integer |
|
630 |
// or is a binary file content type |
|
631 |
String ext = file.getFileExtension(); |
|
632 |
if (ext != null) { |
|
633 |
// shared libraries often have a version number |
|
634 |
boolean isNumber = true; |
|
635 |
for (int i = 0; i < ext.length(); ++i) |
|
636 |
if (!Character.isDigit(ext.charAt(i))) { |
|
637 |
isNumber = false; |
|
638 |
break; |
|
639 |
} |
|
640 |
if (!isNumber) { |
|
641 |
boolean isBinary= false; |
|
642 |
final IContentTypeManager ctm = Platform.getContentTypeManager(); |
|
643 |
final IContentType ctbin = ctm.getContentType(CCorePlugin.CONTENT_TYPE_BINARYFILE); |
|
644 |
final IContentType[] cts= ctm.findContentTypesFor(file.getName()); |
|
645 |
for (int i=0; !isBinary && i < cts.length; i++) { |
|
646 |
isBinary= cts[i].isKindOf(ctbin); |
|
647 |
} |
|
648 |
if (!isBinary) { |
|
649 |
return null; |
|
650 |
} |
|
651 |
} |
|
652 |
} |
|
653 |
||
654 |
URI fileUri = file.getLocationURI(); |
|
655 |
//Avoid name special devices, empty files and the like |
|
656 |
if (! Util.isNonZeroLengthFile(fileUri)) { |
|
657 |
// PR:xxx the EFS does not seem to work for newly created file |
|
658 |
// so before bailing out give another try? |
|
659 |
//Avoid name special devices, empty files and the like |
|
660 |
if("file".equals(fileUri.getScheme())) { //$NON-NLS-1$ |
|
661 |
File f = new File(fileUri); |
|
662 |
if (f.length() == 0) { |
|
663 |
return null; |
|
664 |
} |
|
665 |
} |
|
666 |
//return null; |
|
667 |
} |
|
668 |
||
669 |
||
670 |
int hints = 0; |
|
671 |
||
672 |
for (BinaryParserConfig parser2 : parsers) { |
|
673 |
IBinaryParser parser = null; |
|
674 |
try { |
|
675 |
parser = parser2.getBinaryParser(); |
|
676 |
if (parser.getHintBufferSize() > hints) { |
|
677 |
hints = Math.max(hints, parser.getHintBufferSize()); |
|
678 |
} |
|
679 |
} catch (CoreException e) { |
|
680 |
} |
|
681 |
} |
|
682 |
byte[] bytes = new byte[hints]; |
|
683 |
if (hints > 0) { |
|
684 |
InputStream is = null; |
|
685 |
try { |
|
686 |
is = file.getContents(); |
|
687 |
int count = 0; |
|
688 |
// Make sure we read up to 'hints' bytes if we possibly can |
|
689 |
while (count < hints) { |
|
690 |
int bytesRead = is.read(bytes, count, hints - count); |
|
691 |
if (bytesRead < 0) |
|
692 |
break; |
|
693 |
count += bytesRead; |
|
694 |
} |
|
695 |
if (count > 0 && count < bytes.length) { |
|
696 |
byte[] array = new byte[count]; |
|
697 |
System.arraycopy(bytes, 0, array, 0, count); |
|
698 |
bytes = array; |
|
699 |
} |
|
700 |
} catch (CoreException e) { |
|
701 |
return null; |
|
702 |
} catch (IOException e) { |
|
703 |
return null; |
|
704 |
} finally { |
|
705 |
if (is != null) { |
|
706 |
try { |
|
707 |
is.close(); |
|
708 |
} catch (IOException e) { |
|
709 |
// ignore |
|
710 |
} |
|
711 |
} |
|
712 |
} |
|
713 |
} |
|
714 |
||
715 |
IPath location = file.getLocation(); |
|
716 |
||
717 |
for (BinaryParserConfig parser2 : parsers) { |
|
718 |
try { |
|
719 |
IBinaryParser parser = parser2.getBinaryParser(); |
|
720 |
if (parser.isBinary(bytes, location)) { |
|
721 |
IBinaryFile binFile = parser.getBinary(bytes, location); |
|
722 |
if (binFile != null) { |
|
723 |
return binFile; |
|
724 |
} |
|
725 |
} |
|
726 |
} catch (IOException e) { |
|
727 |
} catch (CoreException e) { |
|
728 |
} |
|
729 |
} |
|
730 |
return null; |
|
731 |
} |
|
732 |
||
733 |
public void resetBinaryParser(IProject project) { |
|
734 |
if (project != null) { |
|
735 |
ICProject cproject = create(project); |
|
736 |
if (cproject != null) { |
|
737 |
// Let the function remove the children |
|
738 |
// but it has the side of effect of removing the CProject also |
|
739 |
// so we have to recall create again. |
|
740 |
try { |
|
741 |
cproject.close(); |
|
742 |
} catch (CModelException e) { |
|
743 |
e.printStackTrace(); |
|
744 |
} |
|
745 |
binaryParsersMap.remove(project); |
|
746 |
||
747 |
// Fired and ICElementDelta.PARSER_CHANGED |
|
748 |
CElementDelta delta = new CElementDelta(getCModel()); |
|
749 |
delta.binaryParserChanged(cproject); |
|
750 |
registerCModelDelta(delta); |
|
751 |
fire(ElementChangedEvent.POST_CHANGE); |
|
752 |
} |
|
753 |
} |
|
754 |
} |
|
755 |
||
756 |
public BinaryRunner getBinaryRunner(ICProject cproject) { |
|
757 |
BinaryRunner runner = null; |
|
758 |
synchronized (binaryRunners) { |
|
759 |
IProject project = cproject.getProject(); |
|
760 |
runner = binaryRunners.get(project); |
|
761 |
if (runner == null) { |
|
762 |
runner = new BinaryRunner(project); |
|
763 |
binaryRunners.put(project, runner); |
|
764 |
runner.start(); |
|
765 |
} |
|
766 |
} |
|
767 |
return runner; |
|
768 |
} |
|
769 |
||
770 |
public void removeBinaryRunner(ICProject cproject) { |
|
771 |
removeBinaryRunner(cproject.getProject()); |
|
772 |
} |
|
773 |
||
774 |
public void removeBinaryRunner(IProject project) { |
|
775 |
BinaryRunner runner = binaryRunners.remove(project); |
|
776 |
if (runner != null) { |
|
777 |
runner.stop(); |
|
778 |
} |
|
779 |
} |
|
780 |
||
781 |
public SourceMapper getSourceMapper(ICProject cProject) { |
|
782 |
SourceMapper mapper = null; |
|
783 |
synchronized (sourceMappers) { |
|
784 |
mapper = sourceMappers.get(cProject); |
|
785 |
if (mapper == null) { |
|
786 |
mapper = new SourceMapper(cProject); |
|
787 |
sourceMappers.put(cProject, mapper); |
|
788 |
} |
|
789 |
} |
|
790 |
return mapper; |
|
791 |
} |
|
792 |
/** |
|
793 |
* addElementChangedListener method comment. |
|
794 |
*/ |
|
795 |
public void addElementChangedListener(IElementChangedListener listener) { |
|
796 |
synchronized (fElementChangedListeners) { |
|
797 |
if (!fElementChangedListeners.contains(listener)) { |
|
798 |
fElementChangedListeners.add(listener); |
|
799 |
} |
|
800 |
} |
|
801 |
} |
|
802 |
||
803 |
/** |
|
804 |
* removeElementChangedListener method comment. |
|
805 |
*/ |
|
806 |
public void removeElementChangedListener(IElementChangedListener listener) { |
|
807 |
synchronized (fElementChangedListeners) { |
|
808 |
int i = fElementChangedListeners.indexOf(listener); |
|
809 |
if (i != -1) { |
|
810 |
fElementChangedListeners.remove(i); |
|
811 |
} |
|
812 |
} |
|
813 |
} |
|
814 |
||
815 |
/** |
|
816 |
* Registers the given delta with this manager. This API is to be |
|
817 |
* used to registerd deltas that are created explicitly by the C |
|
818 |
* Model. Deltas created as translations of <code>IResourceDeltas</code> |
|
819 |
* are to be registered with <code>#registerResourceDelta</code>. |
|
820 |
*/ |
|
821 |
public void registerCModelDelta(ICElementDelta delta) { |
|
822 |
fCModelDeltas.add(delta); |
|
823 |
} |
|
824 |
||
825 |
/** |
|
826 |
* Notifies this C Model Manager that some resource changes have happened |
|
827 |
* on the platform, and that the C Model should update any required |
|
828 |
* internal structures such that its elements remain consistent. |
|
829 |
* Translates <code>IResourceDeltas</code> into <code>ICElementDeltas</code>. |
|
830 |
* |
|
831 |
* @see IResourceDelta |
|
832 |
* @see IResource |
|
833 |
*/ |
|
834 |
public void resourceChanged(IResourceChangeEvent event) { |
|
835 |
||
836 |
if (event.getSource() instanceof IWorkspace) { |
|
837 |
IResourceDelta delta = event.getDelta(); |
|
838 |
IResource resource = event.getResource(); |
|
839 |
switch (event.getType()) { |
|
840 |
case IResourceChangeEvent.PRE_DELETE : |
|
841 |
try { |
|
842 |
if (resource.getType() == IResource.PROJECT && |
|
843 |
( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) || |
|
844 |
((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){ |
|
845 |
this.preDeleteProject((IProject) resource);} |
|
846 |
} catch (CoreException e) { |
|
847 |
} |
|
848 |
break; |
|
849 |
||
850 |
case IResourceChangeEvent.PRE_CLOSE : |
|
851 |
try { |
|
852 |
if (resource.getType() == IResource.PROJECT && |
|
853 |
( ((IProject)resource).hasNature(CProjectNature.C_NATURE_ID) || |
|
854 |
((IProject)resource).hasNature(CCProjectNature.CC_NATURE_ID) )){ |
|
855 |
this.preCloseProject((IProject) resource);} |
|
856 |
} catch (CoreException e) { |
|
857 |
} |
|
858 |
break; |
|
859 |
||
860 |
case IResourceChangeEvent.POST_CHANGE : |
|
861 |
try { |
|
862 |
if (delta != null) { |
|
863 |
checkForProjectRename(delta); |
|
864 |
ICElementDelta[] translatedDeltas = fDeltaProcessor.processResourceDelta(delta); |
|
865 |
if (translatedDeltas.length > 0) { |
|
866 |
for (ICElementDelta translatedDelta : translatedDeltas) { |
|
867 |
registerCModelDelta(translatedDelta); |
|
868 |
} |
|
869 |
} |
|
870 |
fire(ElementChangedEvent.POST_CHANGE); |
|
871 |
} |
|
872 |
} catch (Exception e) { |
|
873 |
e.printStackTrace(); |
|
874 |
} |
|
875 |
break; |
|
876 |
} |
|
877 |
} |
|
878 |
} |
|
879 |
||
880 |
/* (non-Javadoc) |
|
881 |
* @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent) |
|
882 |
*/ |
|
883 |
public void descriptorChanged(CDescriptorEvent event) { |
|
884 |
int flags = event.getFlags(); |
|
885 |
if ( (flags & CDescriptorEvent.EXTENSION_CHANGED) != 0) { |
|
886 |
ICDescriptor cdesc = event.getDescriptor(); |
|
887 |
if (cdesc != null) { |
|
888 |
IProject project = cdesc.getProject(); |
|
889 |
try { |
|
890 |
ICExtensionReference[] newExts = CCorePlugin.getDefault().getBinaryParserExtensions(project); |
|
891 |
BinaryParserConfig[] currentConfigs = getBinaryParser(project); |
|
892 |
// anything added/removed |
|
893 |
if (newExts.length != currentConfigs.length) { |
|
894 |
resetBinaryParser(project); |
|
895 |
} else { // may reorder |
|
896 |
for (int i = 0; i < newExts.length; i++) { |
|
897 |
if (!newExts[i].getID().equals(currentConfigs[i].getId())) { |
|
898 |
resetBinaryParser(project); |
|
899 |
break; |
|
900 |
} |
|
901 |
} |
|
902 |
} |
|
903 |
} catch (CoreException e) { |
|
904 |
resetBinaryParser(project); |
|
905 |
} |
|
906 |
} |
|
907 |
} |
|
908 |
} |
|
909 |
||
910 |
/* (non-Javadoc) |
|
911 |
* @see org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeListener#contentTypeChanged() |
|
912 |
*/ |
|
913 |
public void contentTypeChanged(ContentTypeChangeEvent event) { |
|
914 |
ContentTypeProcessor.processContentTypeChanges(new ContentTypeChangeEvent[]{ event }); |
|
915 |
} |
|
916 |
||
917 |
public void contentTypeChanged(ContentTypeChangeEvent[] events) { |
|
918 |
ContentTypeProcessor.processContentTypeChanges(events); |
|
919 |
} |
|
920 |
||
921 |
public void fire(int eventType) { |
|
922 |
fire(null, eventType); |
|
923 |
} |
|
924 |
||
925 |
public void fireShift(ICElement element, int offset, int size, int lines) { |
|
926 |
ICElementDelta delta = new CShiftData(element, offset, size, lines); |
|
927 |
fire(delta, ElementChangedEvent.POST_SHIFT); |
|
928 |
} |
|
929 |
||
930 |
/** |
|
931 |
* Fire C Model deltas, flushing them after the fact. |
|
932 |
* If the firing mode has been turned off, this has no effect. |
|
933 |
*/ |
|
934 |
@SuppressWarnings("deprecation") |
|
935 |
void fire(ICElementDelta customDeltas, int eventType) { |
|
936 |
if (fFire) { |
|
937 |
ICElementDelta deltaToNotify; |
|
938 |
if (customDeltas == null) { |
|
939 |
deltaToNotify = mergeDeltas(this.fCModelDeltas); |
|
940 |
} else { |
|
941 |
deltaToNotify = customDeltas; |
|
942 |
} |
|
943 |
||
944 |
IElementChangedListener[] listeners; |
|
945 |
int listenerCount; |
|
946 |
int[] listenerMask; |
|
947 |
// Notification |
|
948 |
synchronized (fElementChangedListeners) { |
|
949 |
listeners = new IElementChangedListener[fElementChangedListeners.size()]; |
|
950 |
fElementChangedListeners.toArray(listeners); |
|
951 |
listenerCount = listeners.length; |
|
952 |
listenerMask = null; |
|
953 |
} |
|
954 |
||
955 |
switch (eventType) { |
|
956 |
case DEFAULT_CHANGE_EVENT : |
|
957 |
firePreAutoBuildDelta(deltaToNotify, listeners, listenerMask, listenerCount); |
|
958 |
firePostChangeDelta(deltaToNotify, listeners, listenerMask, listenerCount); |
|
959 |
fireReconcileDelta(listeners, listenerMask, listenerCount); |
|
960 |
break; |
|
961 |
case ElementChangedEvent.PRE_AUTO_BUILD : |
|
962 |
firePreAutoBuildDelta(deltaToNotify, listeners, listenerMask, listenerCount); |
|
963 |
break; |
|
964 |
case ElementChangedEvent.POST_CHANGE : |
|
965 |
firePostChangeDelta(deltaToNotify, listeners, listenerMask, listenerCount); |
|
966 |
fireReconcileDelta(listeners, listenerMask, listenerCount); |
|
967 |
break; |
|
968 |
case ElementChangedEvent.POST_RECONCILE : |
|
969 |
fireReconcileDelta(listeners, listenerMask, listenerCount); |
|
970 |
break; |
|
971 |
case ElementChangedEvent.POST_SHIFT: |
|
972 |
fireShiftEvent(deltaToNotify, listeners, listenerMask, listenerCount); |
|
973 |
return; |
|
974 |
} |
|
975 |
} |
|
976 |
} |
|
977 |
||
978 |
@SuppressWarnings("deprecation") |
|
979 |
private void firePreAutoBuildDelta(ICElementDelta deltaToNotify, |
|
980 |
IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { |
|
981 |
||
982 |
if (Util.VERBOSE_DELTA) { |
|
983 |
System.out.println("FIRING PRE_AUTO_BUILD Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$ |
|
984 |
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$ |
|
985 |
} |
|
986 |
if (deltaToNotify != null) { |
|
987 |
notifyListeners(deltaToNotify, ElementChangedEvent.PRE_AUTO_BUILD, listeners, listenerMask, listenerCount); |
|
988 |
} |
|
989 |
} |
|
990 |
||
991 |
private void firePostChangeDelta(ICElementDelta deltaToNotify, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { |
|
992 |
||
993 |
// post change deltas |
|
994 |
if (Util.VERBOSE_DELTA) { |
|
995 |
System.out.println("FIRING POST_CHANGE Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$ |
|
996 |
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$ |
|
997 |
} |
|
998 |
if (deltaToNotify != null) { |
|
999 |
// flush now so as to keep listener reactions to post their own deltas for subsequent iteration |
|
1000 |
this.flush(); |
|
1001 |
notifyListeners(deltaToNotify, ElementChangedEvent.POST_CHANGE, listeners, listenerMask, listenerCount); |
|
1002 |
} |
|
1003 |
} |
|
1004 |
||
1005 |
private void fireReconcileDelta(IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { |
|
1006 |
ICElementDelta deltaToNotify = mergeDeltas(this.reconcileDeltas.values()); |
|
1007 |
if (Util.VERBOSE_DELTA) { |
|
1008 |
System.out.println("FIRING POST_RECONCILE Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$ |
|
1009 |
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$ |
|
1010 |
} |
|
1011 |
if (deltaToNotify != null) { |
|
1012 |
// flush now so as to keep listener reactions to post their own deltas for subsequent iteration |
|
1013 |
this.reconcileDeltas = new HashMap<IWorkingCopy, ICElementDelta>(); |
|
1014 |
notifyListeners(deltaToNotify, ElementChangedEvent.POST_RECONCILE, listeners, listenerMask, listenerCount); |
|
1015 |
} |
|
1016 |
} |
|
1017 |
||
1018 |
private void fireShiftEvent(ICElementDelta deltaToNotify, IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { |
|
1019 |
||
1020 |
// post change deltas |
|
1021 |
if (Util.VERBOSE_DELTA) { |
|
1022 |
System.out.println("FIRING POST_SHIFT event [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$ |
|
1023 |
System.out.println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$ |
|
1024 |
} |
|
1025 |
if (deltaToNotify != null) { |
|
1026 |
this.flush(); |
|
1027 |
notifyListeners(deltaToNotify, ElementChangedEvent.POST_SHIFT, listeners, listenerMask, listenerCount); |
|
1028 |
} |
|
1029 |
} |
|
1030 |
||
1031 |
public void notifyListeners(ICElementDelta deltaToNotify, int eventType, |
|
1032 |
IElementChangedListener[] listeners, int[] listenerMask, int listenerCount) { |
|
1033 |
||
1034 |
final ElementChangedEvent extraEvent = new ElementChangedEvent(deltaToNotify, eventType); |
|
1035 |
for (int i = 0; i < listenerCount; i++) { |
|
1036 |
if (listenerMask == null || (listenerMask[i] & eventType) != 0) { |
|
1037 |
final IElementChangedListener listener = listeners[i]; |
|
1038 |
long start = -1; |
|
1039 |
if (Util.VERBOSE_DELTA) { |
|
1040 |
System.out.print("Listener #" + (i + 1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$ |
|
1041 |
start = System.currentTimeMillis(); |
|
1042 |
} |
|
1043 |
// wrap callbacks with Safe runnable for subsequent listeners to be called when some are causing grief |
|
1044 |
SafeRunner.run(new ISafeRunnable() { |
|
1045 |
||
1046 |
public void handleException(Throwable exception) { |
|
1047 |
//CCorePlugin.log(exception, "Exception occurred in listener of C element change notification"); //$NON-NLS-1$ |
|
1048 |
CCorePlugin.log(exception); |
|
1049 |
} |
|
1050 |
public void run() throws Exception { |
|
1051 |
listener.elementChanged(extraEvent); |
|
1052 |
} |
|
1053 |
}); |
|
1054 |
if (Util.VERBOSE_DELTA) { |
|
1055 |
System.out.println(" -> " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ |
|
1056 |
} |
|
1057 |
} |
|
1058 |
} |
|
1059 |
} |
|
1060 |
||
1061 |
/** |
|
1062 |
* Flushes all deltas without firing them. |
|
1063 |
*/ |
|
1064 |
protected void flush() { |
|
1065 |
fCModelDeltas.clear(); |
|
1066 |
} |
|
1067 |
||
1068 |
private ICElementDelta mergeDeltas(Collection<ICElementDelta> deltas) { |
|
1069 |
||
1070 |
synchronized (deltas) { |
|
1071 |
if (deltas.size() == 0) |
|
1072 |
return null; |
|
1073 |
if (deltas.size() == 1) |
|
1074 |
return deltas.iterator().next(); |
|
1075 |
if (deltas.size() <= 1) |
|
1076 |
return null; |
|
1077 |
||
1078 |
ICElement cRoot = getCModel(); |
|
1079 |
CElementDelta rootDelta = new CElementDelta(cRoot); |
|
1080 |
boolean insertedTree = false; |
|
1081 |
for (ICElementDelta delta : deltas) { |
|
1082 |
ICElement element = delta.getElement(); |
|
1083 |
if (cRoot.equals(element)) { |
|
1084 |
for (ICElementDelta child : delta.getAffectedChildren()) { |
|
1085 |
CElementDelta projectDelta = (CElementDelta)child; |
|
1086 |
rootDelta.insertDeltaTree(projectDelta.getElement(), projectDelta); |
|
1087 |
insertedTree = true; |
|
1088 |
} |
|
1089 |
IResourceDelta[] resourceDeltas = delta.getResourceDeltas(); |
|
1090 |
if (resourceDeltas != null) { |
|
1091 |
for (IResourceDelta resourceDelta : resourceDeltas) { |
|
1092 |
rootDelta.addResourceDelta(resourceDelta); |
|
1093 |
insertedTree = true; |
|
1094 |
} |
|
1095 |
} |
|
1096 |
} else { |
|
1097 |
rootDelta.insertDeltaTree(element, (CElementDelta)delta); |
|
1098 |
insertedTree = true; |
|
1099 |
} |
|
1100 |
} |
|
1101 |
if (insertedTree) { |
|
1102 |
return rootDelta; |
|
1103 |
} |
|
1104 |
return null; |
|
1105 |
} |
|
1106 |
} |
|
1107 |
||
1108 |
/** |
|
1109 |
* Returns the set of elements which are out of synch with their buffers. |
|
1110 |
*/ |
|
1111 |
protected Map<ICElement,ICElement> getElementsOutOfSynchWithBuffers() { |
|
1112 |
return this.elementsOutOfSynchWithBuffers; |
|
1113 |
} |
|
1114 |
||
1115 |
/** |
|
1116 |
* Returns the info for the element. |
|
1117 |
*/ |
|
1118 |
public synchronized Object getInfo(ICElement element) { |
|
1119 |
Map<ICElement, CElementInfo> tempCache = this.temporaryCache.get(); |
|
1120 |
if (tempCache != null) { |
|
1121 |
Object result = tempCache.get(element); |
|
1122 |
if (result != null) |
|
1123 |
return result; |
|
1124 |
} |
|
1125 |
return this.cache.getInfo(element); |
|
1126 |
} |
|
1127 |
||
1128 |
/** |
|
1129 |
* Returns the info for this element without |
|
1130 |
* disturbing the cache ordering. |
|
1131 |
*/ |
|
1132 |
protected synchronized Object peekAtInfo(ICElement element) { |
|
1133 |
Map<ICElement, CElementInfo> tempCache = this.temporaryCache.get(); |
|
1134 |
if (tempCache != null) { |
|
1135 |
Object result = tempCache.get(element); |
|
1136 |
if (result != null) { |
|
1137 |
return result; |
|
1138 |
} |
|
1139 |
} |
|
1140 |
return this.cache.peekAtInfo(element); |
|
1141 |
} |
|
1142 |
||
1143 |
/* |
|
1144 |
* Puts the infos in the given map (keys are ICElements and values are CElementInfos) |
|
1145 |
* in the C model cache in an atomic way. |
|
1146 |
* First checks that the info for the opened element (or one of its ancestors) has not been |
|
1147 |
* added to the cache. If it is the case, another thread has opened the element (or one of |
|
1148 |
* its ancestors). So returns without updating the cache. |
|
1149 |
*/ |
|
1150 |
protected synchronized void putInfos(ICElement openedElement, Map<ICElement, CElementInfo> newElements) { |
|
1151 |
// remove children |
|
1152 |
Object existingInfo = this.cache.peekAtInfo(openedElement); |
|
1153 |
if (openedElement instanceof IParent && existingInfo instanceof CElementInfo) { |
|
1154 |
ICElement[] children = ((CElementInfo)existingInfo).getChildren(); |
|
1155 |
for (int i = 0, size = children.length; i < size; ++i) { |
|
1156 |
CElement child = (CElement)children[i]; |
|
1157 |
try { |
|
1158 |
child.close(); |
|
1159 |
} catch (CModelException e) { |
|
1160 |
// ignore |
|
1161 |
} |
|
1162 |
} |
|
1163 |
} |
|
1164 |
||
1165 |
for (Map.Entry<ICElement, CElementInfo> element : newElements.entrySet()) |
|
1166 |
this.cache.putInfo(element.getKey(), element.getValue()); |
|
1167 |
} |
|
1168 |
||
1169 |
/** |
|
1170 |
* Removes all cached info from the C Model, including all children, |
|
1171 |
* but does not close this element. |
|
1172 |
*/ |
|
1173 |
protected synchronized void removeChildrenInfo(ICElement openedElement) { |
|
1174 |
// remove children |
|
1175 |
Object existingInfo = this.cache.peekAtInfo(openedElement); |
|
1176 |
if (openedElement instanceof IParent && existingInfo instanceof CElementInfo) { |
|
1177 |
ICElement[] children = ((CElementInfo)existingInfo).getChildren(); |
|
1178 |
for (int i = 0, size = children.length; i < size; ++i) { |
|
1179 |
CElement child = (CElement)children[i]; |
|
1180 |
try { |
|
1181 |
child.close(); |
|
1182 |
} catch (CModelException e) { |
|
1183 |
// ignore |
|
1184 |
} |
|
1185 |
} |
|
1186 |
} |
|
1187 |
} |
|
1188 |
||
1189 |
/** |
|
1190 |
* Removes the info of this model element. |
|
1191 |
*/ |
|
1192 |
protected synchronized void removeInfo(ICElement element) { |
|
1193 |
this.cache.removeInfo(element); |
|
1194 |
} |
|
1195 |
||
1196 |
/* |
|
1197 |
* Returns the temporary cache for newly opened elements for the current thread. |
|
1198 |
* Creates it if not already created. |
|
1199 |
*/ |
|
1200 |
public Map<ICElement, CElementInfo> getTemporaryCache() { |
|
1201 |
Map<ICElement, CElementInfo> result = this.temporaryCache.get(); |
|
1202 |
if (result == null) { |
|
1203 |
result = new HashMap<ICElement, CElementInfo>(); |
|
1204 |
this.temporaryCache.set(result); |
|
1205 |
} |
|
1206 |
return result; |
|
1207 |
} |
|
1208 |
||
1209 |
/* |
|
1210 |
* Returns whether there is a temporary cache for the current thread. |
|
1211 |
*/ |
|
1212 |
public boolean hasTemporaryCache() { |
|
1213 |
return this.temporaryCache.get() != null; |
|
1214 |
} |
|
1215 |
||
1216 |
/* |
|
1217 |
* Resets the temporary cache for newly created elements to null. |
|
1218 |
*/ |
|
1219 |
public void resetTemporaryCache() { |
|
1220 |
this.temporaryCache.set(null); |
|
1221 |
} |
|
1222 |
||
1223 |
/** |
|
1224 |
* |
|
1225 |
*/ |
|
1226 |
public void startup() { |
|
1227 |
// Initialization is performed on the first getDefault()... |
|
1228 |
} |
|
1229 |
||
1230 |
/** |
|
1231 |
* |
|
1232 |
*/ |
|
1233 |
public void shutdown() { |
|
1234 |
// Remove ourself from the DescriptorManager. |
|
1235 |
CCorePlugin.getDefault().getCDescriptorManager().removeDescriptorListener(factory); |
|
1236 |
// Remove ourself from the ContentTypeManager |
|
1237 |
Platform.getContentTypeManager().removeContentTypeChangeListener(factory); |
|
1238 |
||
1239 |
// Do any shutdown of services. |
|
1240 |
ResourcesPlugin.getWorkspace().removeResourceChangeListener(factory); |
|
1241 |
||
1242 |
BinaryRunner[] runners = binaryRunners.values().toArray(new BinaryRunner[0]); |
|
1243 |
for (BinaryRunner runner : runners) { |
|
1244 |
runner.stop(); |
|
1245 |
} |
|
1246 |
||
1247 |
// Nullify the static factory |
|
1248 |
factory = null; |
|
1249 |
} |
|
1250 |
||
1251 |
private void checkForProjectRename(IResourceDelta delta) { |
|
1252 |
IResourceDelta[] rem= delta.getAffectedChildren(IResourceDelta.REMOVED); |
|
1253 |
for (IResourceDelta element : rem) { |
|
1254 |
delta = element; |
|
1255 |
IResource res= delta.getResource(); |
|
1256 |
if (res.getType() == IResource.PROJECT) { |
|
1257 |
IPath movedTo= null; |
|
1258 |
if ((delta.getFlags() & IResourceDelta.MOVED_TO) != 0) { |
|
1259 |
movedTo= delta.getMovedToPath(); |
|
1260 |
} |
|
1261 |
LocalProjectScope.deletePreferences(res.getFullPath(), movedTo); |
|
1262 |
} |
|
1263 |
} |
|
1264 |
} |
|
1265 |
||
1266 |
private void preDeleteProject(IProject project) { |
|
1267 |
// stop the binary runner for this project |
|
1268 |
removeBinaryRunner(project); |
|
1269 |
// stop indexing jobs for this project |
|
1270 |
CCoreInternals.getPDOMManager().preDeleteProject(create(project)); |
|
1271 |
} |
|
1272 |
||
1273 |
private void preCloseProject(IProject project) { |
|
1274 |
// stop the binary runner for this project |
|
1275 |
removeBinaryRunner(project); |
|
1276 |
// stop indexing jobs for this project |
|
1277 |
CCoreInternals.getPDOMManager().preCloseProject(create(project)); |
|
1278 |
} |
|
73
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1279 |
|
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1280 |
/** |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1281 |
* For nested source roots, checks whether or not a source root is a parent of a given folder |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1282 |
* @param root - The source root to check against |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1283 |
* @param folder - Folder to check whether or not the given root is a child |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1284 |
* @return true is the IFolder is a parent of the ISourceRoot |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1285 |
*/ |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1286 |
public boolean isParentOfSourceRoot(ISourceRoot root, IFolder folder) { |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1287 |
if (CCorePlugin.showSourceRootsAtTopOfProject()){ |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1288 |
// not nested source roots so no need to check |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1289 |
return false; |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1290 |
} |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1291 |
|
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1292 |
return folder.getFullPath().isPrefixOf(root.getPath()); |
82f772574273
fix 9513, indexer refresh problems with nested source paths
timkelly
parents:
37
diff
changeset
|
1293 |
} |
37 | 1294 |
|
1295 |
} |