1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core;
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.HashMap;
17 import java.util.HashSet;
18 import java.util.Iterator;
21 import net.sourceforge.phpdt.core.ElementChangedEvent;
22 import net.sourceforge.phpdt.core.IClasspathEntry;
23 import net.sourceforge.phpdt.core.IElementChangedListener;
24 import net.sourceforge.phpdt.core.IJavaElement;
25 import net.sourceforge.phpdt.core.IJavaElementDelta;
26 import net.sourceforge.phpdt.core.IJavaModel;
27 import net.sourceforge.phpdt.core.IJavaProject;
28 import net.sourceforge.phpdt.core.JavaCore;
29 import net.sourceforge.phpdt.core.JavaModelException;
30 import net.sourceforge.phpdt.internal.core.builder.PHPBuilder;
31 import net.sourceforge.phpdt.internal.core.util.Util;
32 import net.sourceforge.phpdt.internal.core.util.PHPFileUtil;
33 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
35 import org.eclipse.core.resources.IFile;
36 import org.eclipse.core.resources.IProject;
37 import org.eclipse.core.resources.IResource;
38 import org.eclipse.core.resources.IResourceChangeEvent;
39 import org.eclipse.core.resources.IResourceChangeListener;
40 import org.eclipse.core.resources.IResourceDelta;
41 import org.eclipse.core.resources.IResourceDeltaVisitor;
42 import org.eclipse.core.resources.IWorkspace;
43 import org.eclipse.core.resources.ResourcesPlugin;
44 import org.eclipse.core.runtime.CoreException;
45 import org.eclipse.core.runtime.IPath;
46 import org.eclipse.core.runtime.ISafeRunnable;
47 //import org.eclipse.core.runtime.Platform;
48 import org.eclipse.core.runtime.QualifiedName;
49 import org.eclipse.core.runtime.SafeRunner;
52 * This class is used by <code>JavaModelManager</code> to convert
53 * <code>IResourceDelta</code>s into <code>IJavaElementDelta</code>s. It
54 * also does some processing on the <code>JavaElement</code>s involved (e.g.
55 * closing them or updating classpaths).
57 public class DeltaProcessor implements IResourceChangeListener {
59 final static int IGNORE = 0;
61 final static int SOURCE = 1;
63 final static int BINARY = 2;
65 final static String EXTERNAL_JAR_ADDED = "external jar added"; //$NON-NLS-1$
67 final static String EXTERNAL_JAR_REMOVED = "external jar removed"; //$NON-NLS-1$
69 final static String EXTERNAL_JAR_CHANGED = "external jar changed"; //$NON-NLS-1$
71 final static String EXTERNAL_JAR_UNCHANGED = "external jar unchanged"; //$NON-NLS-1$
73 final static String INTERNAL_JAR_IGNORE = "internal jar ignore"; //$NON-NLS-1$
75 private final static int NON_JAVA_RESOURCE = -1;
77 public static boolean DEBUG = false;
79 public static boolean VERBOSE = false;
81 public static final int DEFAULT_CHANGE_EVENT = 0; // must not collide with
82 // ElementChangedEvent
86 * The <code>JavaElementDelta</code> corresponding to the
87 * <code>IResourceDelta</code> being translated.
89 protected JavaElementDelta currentDelta;
91 // protected IndexManager indexManager = new IndexManager();
93 /* A table from IPath (from a classpath entry) to RootInfo */
97 * A table from IPath (from a classpath entry) to ArrayList of RootInfo Used
98 * when an IPath corresponds to more than one root
102 /* Whether the roots tables should be recomputed */
103 public boolean rootsAreStale = true;
106 * A table from IPath (from a classpath entry) to RootInfo from the last
107 * time the delta processor was invoked.
112 * A table from IPath (from a classpath entry) to ArrayList of RootInfo from
113 * the last time the delta processor was invoked. Used when an IPath
114 * corresponds to more than one root
119 * A table from IPath (a source attachment path from a classpath entry) to
120 * IPath (a root path)
122 Map sourceAttachments;
125 * The java element that was last created (see createElement(IResource)).
126 * This is used as a stack of java elements (using getParent() to pop it,
127 * and using the various get*(...) to push it.
129 Openable currentElement;
132 * Queue of deltas created explicily by the Java Model that have yet to be
135 public ArrayList javaModelDeltas = new ArrayList();
138 * Queue of reconcile deltas on working copies that have yet to be fired.
139 * This is a table form IWorkingCopy to IJavaElementDelta
141 public HashMap reconcileDeltas = new HashMap();
144 * Turns delta firing on/off. By default it is on.
146 private boolean isFiring = true;
148 public HashMap externalTimeStamps = new HashMap();
150 public HashSet projectsToUpdate = new HashSet();
152 // list of root projects which namelookup caches need to be updated for
154 // TODO: (jerome) is it needed? projectsToUpdate might be sufficient
155 public HashSet projectsForDependentNamelookupRefresh = new HashSet();
158 * The global state of delta processing.
160 private DeltaProcessingState state;
163 * The Java model manager
165 private JavaModelManager manager;
168 * A table from IJavaProject to an array of IPackageFragmentRoot. This table
169 * contains the pkg fragment roots of the project that are being deleted.
174 * A list of IJavaElement used as a scope for external archives refresh
175 * during POST_CHANGE. This is null if no refresh is needed.
177 HashSet refreshedElements;
186 OutputsInfo(IPath[] paths, int[] traverseModes, int outputCount) {
188 this.traverseModes = traverseModes;
189 this.outputCount = outputCount;
192 public String toString() {
193 if (this.paths == null)
194 return "<none>"; //$NON-NLS-1$
195 StringBuffer buffer = new StringBuffer();
196 for (int i = 0; i < this.outputCount; i++) {
197 buffer.append("path="); //$NON-NLS-1$
198 buffer.append(this.paths[i].toString());
199 buffer.append("\n->traverse="); //$NON-NLS-1$
200 switch (this.traverseModes[i]) {
202 buffer.append("BINARY"); //$NON-NLS-1$
205 buffer.append("IGNORE"); //$NON-NLS-1$
208 buffer.append("SOURCE"); //$NON-NLS-1$
211 buffer.append("<unknown>"); //$NON-NLS-1$
213 if (i + 1 < this.outputCount) {
217 return buffer.toString();
222 IJavaProject project;
226 char[][] exclusionPatterns;
228 RootInfo(IJavaProject project, IPath rootPath,
229 char[][] exclusionPatterns) {
230 this.project = project;
231 this.rootPath = rootPath;
232 this.exclusionPatterns = exclusionPatterns;
235 boolean isRootOfProject(IPath path) {
236 return this.rootPath.equals(path)
237 && this.project.getProject().getFullPath().isPrefixOf(path);
240 public String toString() {
241 StringBuffer buffer = new StringBuffer("project="); //$NON-NLS-1$
242 if (this.project == null) {
243 buffer.append("null"); //$NON-NLS-1$
245 buffer.append(this.project.getElementName());
247 buffer.append("\npath="); //$NON-NLS-1$
248 if (this.rootPath == null) {
249 buffer.append("null"); //$NON-NLS-1$
251 buffer.append(this.rootPath.toString());
253 buffer.append("\nexcluding="); //$NON-NLS-1$
254 if (this.exclusionPatterns == null) {
255 buffer.append("null"); //$NON-NLS-1$
257 for (int i = 0, length = this.exclusionPatterns.length; i < length; i++) {
258 buffer.append(new String(this.exclusionPatterns[i]));
259 if (i < length - 1) {
260 buffer.append("|"); //$NON-NLS-1$
264 return buffer.toString();
268 // DeltaProcessor(JavaModelManager manager) {
269 // this.manager = manager;
273 * Type of event that should be processed no matter what the real event type
276 public int overridenEventType = -1;
278 public DeltaProcessor(DeltaProcessingState state, JavaModelManager manager) {
280 this.manager = manager;
284 * Adds the dependents of the given project to the list of the projects to
287 // void addDependentProjects(IPath projectPath, HashSet result) {
289 // IJavaProject[] projects = this.manager.getJavaModel().getJavaProjects();
290 // for (int i = 0, length = projects.length; i < length; i++) {
291 // IJavaProject project = projects[i];
292 // IClasspathEntry[] classpath =
293 // ((JavaProject)project).getExpandedClasspath(true);
294 // for (int j = 0, length2 = classpath.length; j < length2; j++) {
295 // IClasspathEntry entry = classpath[j];
296 // if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT
297 // && entry.getPath().equals(projectPath)) {
298 // result.add(project);
302 // } catch (JavaModelException e) {
306 * Adds the given element to the list of elements used as a scope for
307 * external jars refresh.
309 public void addForRefresh(IJavaElement element) {
310 if (this.refreshedElements == null) {
311 this.refreshedElements = new HashSet();
313 this.refreshedElements.add(element);
317 * Adds the given project and its dependents to the list of the projects to
320 void addToProjectsToUpdateWithDependents(IProject project) {
321 this.projectsToUpdate.add(JavaCore.create(project));
322 // this.addDependentProjects(project.getFullPath(),
323 // this.projectsToUpdate);
327 * Adds the given child handle to its parent's cache of children.
329 protected void addToParentInfo(Openable child) {
331 Openable parent = (Openable) child.getParent();
332 if (parent != null && parent.isOpen()) {
334 JavaElementInfo info = (JavaElementInfo) parent
336 info.addChild(child);
337 } catch (JavaModelException e) {
338 // do nothing - we already checked if open
344 * Check all external archive (referenced by given roots, projects or model)
345 * status and issue a corresponding root delta. Also triggers index updates
347 // public void checkExternalArchiveChanges(IJavaElement[] refreshedElements,
348 // IProgressMonitor monitor) throws JavaModelException {
350 // for (int i = 0, length = refreshedElements.length; i < length; i++) {
351 // this.addForRefresh(refreshedElements[i]);
353 // boolean hasDelta = this.createExternalArchiveDelta(monitor);
354 // if (monitor != null && monitor.isCanceled()) return;
356 // // force classpath marker refresh of affected projects
357 // JavaModel.flushExternalFileCache();
358 // IJavaElementDelta[] projectDeltas =
359 // this.currentDelta.getAffectedChildren();
360 // for (int i = 0, length = projectDeltas.length; i < length; i++) {
361 // IJavaElementDelta delta = projectDeltas[i];
362 // ((JavaProject)delta.getElement()).getResolvedClasspath(
363 // true, // ignoreUnresolvedEntry
364 // true); // generateMarkerOnError
366 // if (this.currentDelta != null) { // if delta has not been fired while
368 // this.manager.fire(this.currentDelta,
369 // JavaModelManager.DEFAULT_CHANGE_EVENT);
373 // this.currentDelta = null;
374 // if (monitor != null) monitor.done();
378 * Check if external archives have changed and create the corresponding
379 * deltas. Returns whether at least on delta was created.
381 // public boolean createExternalArchiveDelta(IProgressMonitor monitor)
382 // throws JavaModelException {
384 // if (this.refreshedElements == null) return false;
386 // HashMap externalArchivesStatus = new HashMap();
387 // boolean hasDelta = false;
389 // // find JARs to refresh
390 // HashSet archivePathsToRefresh = new HashSet();
392 // Iterator iterator = this.refreshedElements.iterator();
393 // while (iterator.hasNext()) {
394 // IJavaElement element = (IJavaElement)iterator.next();
395 // switch(element.getElementType()){
396 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
397 // archivePathsToRefresh.add(element.getPath());
399 // case IJavaElement.JAVA_PROJECT :
400 // IJavaProject project = (IJavaProject) element;
401 // if (!JavaProject.hasJavaNature(project.getProject())) {
402 // // project is not accessible or has lost its Java nature
405 // IClasspathEntry[] classpath = project.getResolvedClasspath(true);
406 // for (int j = 0, cpLength = classpath.length; j < cpLength; j++){
407 // if (classpath[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY){
408 // archivePathsToRefresh.add(classpath[j].getPath());
412 // case IJavaElement.JAVA_MODEL :
413 // IJavaProject[] projects =
414 // manager.getJavaModel().getOldJavaProjectsList();
415 // for (int j = 0, projectsLength = projects.length; j < projectsLength;
417 // project = projects[j];
418 // if (!JavaProject.hasJavaNature(project.getProject())) {
419 // // project is not accessible or has lost its Java nature
422 // classpath = project.getResolvedClasspath(true);
423 // for (int k = 0, cpLength = classpath.length; k < cpLength; k++){
424 // if (classpath[k].getEntryKind() == IClasspathEntry.CPE_LIBRARY){
425 // archivePathsToRefresh.add(classpath[k].getPath());
433 // this.refreshedElements = null;
436 // // perform refresh
437 // IJavaProject[] projects =
438 // manager.getJavaModel().getOldJavaProjectsList();
439 // IWorkspaceRoot wksRoot = ResourcesPlugin.getWorkspace().getRoot();
440 // for (int i = 0, length = projects.length; i < length; i++) {
442 // if (monitor != null && monitor.isCanceled()) break;
444 // IJavaProject project = projects[i];
445 // if (!JavaProject.hasJavaNature(project.getProject())) {
446 // // project is not accessible or has lost its Java nature
449 // IClasspathEntry[] entries = project.getResolvedClasspath(true);
450 // for (int j = 0; j < entries.length; j++){
451 // if (entries[j].getEntryKind() == IClasspathEntry.CPE_LIBRARY) {
453 // IPath entryPath = entries[j].getPath();
455 // if (!archivePathsToRefresh.contains(entryPath)) continue; // not supposed
458 // String status = (String)externalArchivesStatus.get(entryPath);
459 // if (status == null){
461 // // compute shared status
462 // Object targetLibrary = JavaModel.getTarget(wksRoot, entryPath, true);
464 // if (targetLibrary == null){ // missing JAR
465 // if (this.externalTimeStamps.containsKey(entryPath)){
466 // this.externalTimeStamps.remove(entryPath);
467 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
468 // // the jar was physically removed: remove the index
469 // indexManager.removeIndex(entryPath);
472 // } else if (targetLibrary instanceof File){ // external JAR
474 // File externalFile = (File)targetLibrary;
476 // // check timestamp to figure if JAR has changed in some way
477 // Long oldTimestamp =(Long) this.externalTimeStamps.get(entryPath);
478 // long newTimeStamp = getTimeStamp(externalFile);
479 // if (oldTimestamp != null){
481 // if (newTimeStamp == 0){ // file doesn't exist
482 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_REMOVED);
483 // this.externalTimeStamps.remove(entryPath);
484 // // remove the index
485 // indexManager.removeIndex(entryPath);
487 // } else if (oldTimestamp.longValue() != newTimeStamp){
488 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_CHANGED);
489 // this.externalTimeStamps.put(entryPath, new Long(newTimeStamp));
490 // // first remove the index so that it is forced to be re-indexed
491 // indexManager.removeIndex(entryPath);
492 // // then index the jar
493 // indexManager.indexLibrary(entryPath, project.getProject());
495 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
498 // if (newTimeStamp == 0){ // jar still doesn't exist
499 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_UNCHANGED);
501 // externalArchivesStatus.put(entryPath, EXTERNAL_JAR_ADDED);
502 // this.externalTimeStamps.put(entryPath, new Long(newTimeStamp));
503 // // index the new jar
504 // indexManager.indexLibrary(entryPath, project.getProject());
507 // } else { // internal JAR
508 // externalArchivesStatus.put(entryPath, INTERNAL_JAR_IGNORE);
511 // // according to computed status, generate a delta
512 // status = (String)externalArchivesStatus.get(entryPath);
513 // if (status != null){
514 // if (status == EXTERNAL_JAR_ADDED){
515 // PackageFragmentRoot root =
516 // (PackageFragmentRoot)project.getPackageFragmentRoot(entryPath.toString());
518 // System.out.println("- External JAR ADDED, affecting root:
519 // "+root.getElementName()); //$NON-NLS-1$
521 // elementAdded(root, null, null);
523 // } else if (status == EXTERNAL_JAR_CHANGED) {
524 // PackageFragmentRoot root =
525 // (PackageFragmentRoot)project.getPackageFragmentRoot(entryPath.toString());
527 // System.out.println("- External JAR CHANGED, affecting root:
528 // "+root.getElementName()); //$NON-NLS-1$
530 // // reset the corresponding project built state, since the builder would
532 // this.manager.setLastBuiltState(project.getProject(), null /*no state*/);
533 // contentChanged(root, null);
535 // } else if (status == EXTERNAL_JAR_REMOVED) {
536 // PackageFragmentRoot root =
537 // (PackageFragmentRoot)project.getPackageFragmentRoot(entryPath.toString());
539 // System.out.println("- External JAR REMOVED, affecting root:
540 // "+root.getElementName()); //$NON-NLS-1$
542 // elementRemoved(root, null, null);
551 JavaElementDelta currentDelta() {
552 if (this.currentDelta == null) {
553 this.currentDelta = new JavaElementDelta(this.manager
556 return this.currentDelta;
560 * Process the given delta and look for projects being added, opened, closed
561 * or with a java nature being added or removed. Note that projects being
562 * deleted are checked in deleting(IProject). In all cases, add the
563 * project's dependents to the list of projects to update so that the
564 * classpath related markers can be updated.
566 // public void checkProjectsBeingAddedOrRemoved(IResourceDelta delta) {
567 // IResource resource = delta.getResource();
568 // switch (resource.getType()) {
569 // case IResource.ROOT :
570 // // workaround for bug 15168 circular errors not reported
571 // if (this.manager.javaProjectsCache == null) {
573 // this.manager.javaProjectsCache =
574 // this.manager.getJavaModel().getJavaProjects();
575 // } catch (JavaModelException e) {
579 // IResourceDelta[] children = delta.getAffectedChildren();
580 // for (int i = 0, length = children.length; i < length; i++) {
581 // this.checkProjectsBeingAddedOrRemoved(children[i]);
584 // case IResource.PROJECT :
585 // // NB: No need to check project's nature as if the project is not a java
587 // // - if the project is added or changed this is a noop for
588 // projectsBeingDeleted
589 // // - if the project is closed, it has already lost its java nature
590 // int deltaKind = delta.getKind();
591 // if (deltaKind == IResourceDelta.ADDED) {
592 // // remember project and its dependents
593 // IProject project = (IProject)resource;
594 // this.addToProjectsToUpdateWithDependents(project);
596 // // workaround for bug 15168 circular errors not reported
597 // if (JavaProject.hasJavaNature(project)) {
598 // this.addToParentInfo((JavaProject)JavaCore.create(project));
601 // } else if (deltaKind == IResourceDelta.CHANGED) {
602 // IProject project = (IProject)resource;
603 // if ((delta.getFlags() & IResourceDelta.OPEN) != 0) {
604 // // project opened or closed: remember project and its dependents
605 // this.addToProjectsToUpdateWithDependents(project);
607 // // workaround for bug 15168 circular errors not reported
608 // if (project.isOpen()) {
609 // if (JavaProject.hasJavaNature(project)) {
610 // this.addToParentInfo((JavaProject)JavaCore.create(project));
613 // JavaProject javaProject =
614 // (JavaProject)this.manager.getJavaModel().findJavaProject(project);
615 // if (javaProject != null) {
617 // javaProject.close();
618 // } catch (JavaModelException e) {
620 // this.removeFromParentInfo(javaProject);
623 // } else if ((delta.getFlags() & IResourceDelta.DESCRIPTION) != 0) {
624 // boolean wasJavaProject =
625 // this.manager.getJavaModel().findJavaProject(project) != null;
626 // boolean isJavaProject = JavaProject.hasJavaNature(project);
627 // if (wasJavaProject != isJavaProject) {
628 // // java nature added or removed: remember project and its dependents
629 // this.addToProjectsToUpdateWithDependents(project);
631 // // workaround for bug 15168 circular errors not reported
632 // if (isJavaProject) {
633 // this.addToParentInfo((JavaProject)JavaCore.create(project));
635 // JavaProject javaProject = (JavaProject)JavaCore.create(project);
637 // // flush classpath markers
639 // flushClasspathProblemMarkers(
640 // true, // flush cycle markers
641 // true //flush classpath format markers
644 // // remove problems and tasks created by the builder
645 // JavaBuilder.removeProblemsAndTasksFor(project);
649 // javaProject.close();
650 // } catch (JavaModelException e) {
652 // this.removeFromParentInfo(javaProject);
655 // // in case the project was removed then added then changed (see bug
657 // if (JavaProject.hasJavaNature(project)) { // need nature check - 18698
658 // this.addToParentInfo((JavaProject)JavaCore.create(project));
662 // // workaround for bug 15168 circular errors not reported
663 // // in case the project was removed then added then changed
664 // if (JavaProject.hasJavaNature(project)) { // need nature check - 18698
665 // this.addToParentInfo((JavaProject)JavaCore.create(project));
672 // private void checkSourceAttachmentChange(IResourceDelta delta, IResource
674 // IPath rootPath = (IPath)this.sourceAttachments.get(res.getFullPath());
675 // if (rootPath != null) {
676 // RootInfo rootInfo = this.rootInfo(rootPath, delta.getKind());
677 // if (rootInfo != null) {
678 // IJavaProject projectOfRoot = rootInfo.project;
679 // IPackageFragmentRoot root = null;
681 // // close the root so that source attachement cache is flushed
682 // root = projectOfRoot.findPackageFragmentRoot(rootPath);
683 // if (root != null) {
686 // } catch (JavaModelException e) {
688 // if (root == null) return;
689 // switch (delta.getKind()) {
690 // case IResourceDelta.ADDED:
691 // currentDelta().sourceAttached(root);
693 // case IResourceDelta.CHANGED:
694 // currentDelta().sourceDetached(root);
695 // currentDelta().sourceAttached(root);
697 // case IResourceDelta.REMOVED:
698 // currentDelta().sourceDetached(root);
705 * Closes the given element, which removes it from the cache of open
708 // protected static void close(Openable element) {
712 // } catch (JavaModelException e) {
717 * Generic processing for elements with changed contents:
719 * <li>The element is closed such that any subsequent accesses will re-open
720 * the element reflecting its new structure.
721 * <li>An entry is made in the delta reporting a content change (K_CHANGE
722 * with F_CONTENT flag set).
724 * Delta argument could be null if processing an external JAR change
726 // protected void contentChanged(Openable element, IResourceDelta delta) {
729 // int flags = IJavaElementDelta.F_CONTENT;
730 // if (element instanceof JarPackageFragmentRoot){
731 // flags |= IJavaElementDelta.F_ARCHIVE_CONTENT_CHANGED;
733 // currentDelta().changed(element, flags);
737 * Creates the openables corresponding to this resource. Returns null if
740 // protected Openable createElement(IResource resource, int elementType,
741 // RootInfo rootInfo) {
742 // if (resource == null) return null;
744 // IPath path = resource.getFullPath();
745 // IJavaElement element = null;
746 // switch (elementType) {
748 // case IJavaElement.JAVA_PROJECT:
750 // // note that non-java resources rooted at the project level will also
751 // enter this code with
752 // // an elementType JAVA_PROJECT (see #elementType(...)).
753 // if (resource instanceof IProject){
755 // this.popUntilPrefixOf(path);
757 // if (this.currentElement != null
758 // && this.currentElement.getElementType() == IJavaElement.JAVA_PROJECT
759 // && ((IJavaProject)this.currentElement).getProject().equals(resource)) {
760 // return this.currentElement;
762 // if (rootInfo != null && rootInfo.project.getProject().equals(resource)){
763 // element = (Openable)rootInfo.project;
766 // IProject proj = (IProject)resource;
767 // if (JavaProject.hasJavaNature(proj)) {
768 // element = JavaCore.create(proj);
770 // // java project may have been been closed or removed (look for
771 // // element amongst old java project s list).
772 // element = (Openable) manager.getJavaModel().findJavaProject(proj);
776 // case IJavaElement.PACKAGE_FRAGMENT_ROOT:
777 // element = rootInfo == null ? JavaCore.create(resource) :
778 // rootInfo.project.getPackageFragmentRoot(resource);
780 // case IJavaElement.PACKAGE_FRAGMENT:
781 // // find the element that encloses the resource
782 // this.popUntilPrefixOf(path);
784 // if (this.currentElement == null) {
785 // element = rootInfo == null ? JavaCore.create(resource) :
786 // JavaModelManager.create(resource, rootInfo.project);
789 // IPackageFragmentRoot root = this.currentElement.getPackageFragmentRoot();
790 // if (root == null) {
791 // element = rootInfo == null ? JavaCore.create(resource) :
792 // JavaModelManager.create(resource, rootInfo.project);
793 // } else if (((JavaProject)root.getJavaProject()).contains(resource)) {
794 // // create package handle
795 // IPath pkgPath = path.removeFirstSegments(root.getPath().segmentCount());
796 // String pkg = ProjectPrefUtil.packageName(pkgPath);
797 // if (pkg == null) return null;
798 // element = root.getPackageFragment(pkg);
802 // case IJavaElement.COMPILATION_UNIT:
803 // case IJavaElement.CLASS_FILE:
804 // // find the element that encloses the resource
805 // this.popUntilPrefixOf(path);
807 // if (this.currentElement == null) {
808 // element = rootInfo == null ? JavaCore.create(resource) :
809 // JavaModelManager.create(resource, rootInfo.project);
811 // // find the package
812 // IPackageFragment pkgFragment = null;
813 // switch (this.currentElement.getElementType()) {
814 // case IJavaElement.PACKAGE_FRAGMENT_ROOT:
815 // IPackageFragmentRoot root = (IPackageFragmentRoot)this.currentElement;
816 // IPath rootPath = root.getPath();
817 // IPath pkgPath = path.removeLastSegments(1);
819 // ProjectPrefUtil.packageName(pkgPath.removeFirstSegments(rootPath.segmentCount()));
820 // if (pkgName != null) {
821 // pkgFragment = root.getPackageFragment(pkgName);
824 // case IJavaElement.PACKAGE_FRAGMENT:
825 // Openable pkg = (Openable)this.currentElement;
826 // if (pkg.getPath().equals(path.removeLastSegments(1))) {
827 // pkgFragment = (IPackageFragment)pkg;
828 // } // else case of package x which is a prefix of x.y
830 // case IJavaElement.COMPILATION_UNIT:
831 // case IJavaElement.CLASS_FILE:
832 // pkgFragment = (IPackageFragment)this.currentElement.getParent();
835 // if (pkgFragment == null) {
836 // element = rootInfo == null ? JavaCore.create(resource) :
837 // JavaModelManager.create(resource, rootInfo.project);
839 // if (elementType == IJavaElement.COMPILATION_UNIT) {
840 // // create compilation unit handle
841 // // fileName validation has been done in elementType(IResourceDelta, int,
843 // String fileName = path.lastSegment();
844 // element = pkgFragment.getCompilationUnit(fileName);
846 // // create class file handle
847 // // fileName validation has been done in elementType(IResourceDelta, int,
849 // String fileName = path.lastSegment();
850 // element = pkgFragment.getClassFile(fileName);
856 // if (element == null) {
859 // this.currentElement = (Openable)element;
860 // return this.currentElement;
864 * Note that the project is about to be deleted.
866 // public void deleting(IProject project) {
869 // // discard indexing jobs that belong to this project so that the project
871 // // deleted without interferences from the index manager
872 // this.indexManager.discardJobs(project.getName());
874 // JavaProject javaProject = (JavaProject)JavaCore.create(project);
876 // // remember roots of this project
877 // if (this.removedRoots == null) {
878 // this.removedRoots = new HashMap();
880 // if (javaProject.isOpen()) {
881 // this.removedRoots.put(javaProject,
882 // javaProject.getPackageFragmentRoots());
884 // // compute roots without opening project
885 // this.removedRoots.put(
887 // javaProject.computePackageFragmentRoots(
888 // javaProject.getResolvedClasspath(true),
892 // javaProject.close();
894 // // workaround for bug 15168 circular errors not reported
895 // if (this.manager.javaProjectsCache == null) {
896 // this.manager.javaProjectsCache =
897 // this.manager.getJavaModel().getJavaProjects();
899 // this.removeFromParentInfo(javaProject);
901 // } catch (JavaModelException e) {
904 // this.addDependentProjects(project.getFullPath(), this.projectsToUpdate);
908 * Processing for an element that has been added:
910 * <li>If the element is a project, do nothing, and do not process
911 * children, as when a project is created it does not yet have any natures -
912 * specifically a java nature.
913 * <li>If the elemet is not a project, process it as added (see
914 * <code>basicElementAdded</code>.
916 * Delta argument could be null if processing an external JAR change
918 // protected void elementAdded(Openable element, IResourceDelta delta,
919 // RootInfo rootInfo) {
920 // int elementType = element.getElementType();
922 // if (elementType == IJavaElement.JAVA_PROJECT) {
923 // // project add is handled by JavaProject.configure() because
924 // // when a project is created, it does not yet have a java nature
925 // if (delta != null &&
926 // JavaProject.hasJavaNature((IProject)delta.getResource())) {
927 // addToParentInfo(element);
928 // if ((delta.getFlags() & IResourceDelta.MOVED_FROM) != 0) {
929 // Openable movedFromElement =
930 // (Openable)element.getJavaModel().getJavaProject(delta.getMovedFromPath().lastSegment());
931 // currentDelta().movedTo(element, movedFromElement);
933 // currentDelta().added(element);
935 // this.projectsToUpdate.add(element);
936 // this.updateRoots(element.getPath(), delta);
937 // this.projectsForDependentNamelookupRefresh.add((JavaProject) element);
940 // addToParentInfo(element);
942 // // Force the element to be closed as it might have been opened
943 // // before the resource modification came in and it might have a new child
944 // // For example, in an IWorkspaceRunnable:
945 // // 1. create a package fragment p using a java model operation
946 // // 2. open package p
947 // // 3. add file X.java in folder p
948 // // When the resource delta comes in, only the addition of p is notified,
949 // // but the package p is already opened, thus its children are not
951 // // and it appears empty.
954 // if (delta != null && (delta.getFlags() & IResourceDelta.MOVED_FROM) != 0)
956 // IPath movedFromPath = delta.getMovedFromPath();
957 // IResource res = delta.getResource();
958 // IResource movedFromRes;
959 // if (res instanceof IFile) {
960 // movedFromRes = res.getWorkspace().getRoot().getFile(movedFromPath);
962 // movedFromRes = res.getWorkspace().getRoot().getFolder(movedFromPath);
965 // // find the element type of the moved from element
966 // RootInfo movedFromInfo = this.enclosingRootInfo(movedFromPath,
967 // IResourceDelta.REMOVED);
968 // int movedFromType =
971 // IResourceDelta.REMOVED,
972 // element.getParent().getElementType(),
975 // // reset current element as it might be inside a nested root
976 // (popUntilPrefixOf() may use the outer root)
977 // this.currentElement = null;
979 // // create the moved from element
980 // Openable movedFromElement =
981 // elementType != IJavaElement.JAVA_PROJECT && movedFromType ==
982 // IJavaElement.JAVA_PROJECT ?
983 // null : // outside classpath
984 // this.createElement(movedFromRes, movedFromType, movedFromInfo);
985 // if (movedFromElement == null) {
986 // // moved from outside classpath
987 // currentDelta().added(element);
989 // currentDelta().movedTo(element, movedFromElement);
992 // currentDelta().added(element);
995 // switch (elementType) {
996 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
997 // // when a root is added, and is on the classpath, the project must be
999 // JavaProject project = (JavaProject) element.getJavaProject();
1000 // this.projectsToUpdate.add(project);
1001 // this.projectsForDependentNamelookupRefresh.add(project);
1004 // case IJavaElement.PACKAGE_FRAGMENT :
1005 // // get rid of namelookup since it holds onto obsolete cached info
1006 // project = (JavaProject) element.getJavaProject();
1008 // project.getJavaProjectElementInfo().setNameLookup(null);
1009 // this.projectsForDependentNamelookupRefresh.add(project);
1010 // } catch (JavaModelException e) {
1012 // // add subpackages
1013 // if (delta != null){
1014 // PackageFragmentRoot root = element.getPackageFragmentRoot();
1015 // String name = element.getElementName();
1016 // IResourceDelta[] children = delta.getAffectedChildren();
1017 // for (int i = 0, length = children.length; i < length; i++) {
1018 // IResourceDelta child = children[i];
1019 // IResource resource = child.getResource();
1020 // if (resource instanceof IFolder) {
1021 // String folderName = resource.getName();
1022 // if (ProjectPrefUtil.isValidFolderNameForPackage(folderName)) {
1023 // String subpkgName =
1024 // name.length() == 0 ?
1026 // name + "." + folderName; //$NON-NLS-1$
1027 // Openable subpkg = (Openable)root.getPackageFragment(subpkgName);
1028 // this.updateIndex(subpkg, child);
1029 // this.elementAdded(subpkg, child, rootInfo);
1039 * Generic processing for a removed element:
1041 * <li>Close the element, removing its structure from the cache
1042 * <li>Remove the element from its parent's cache of children
1043 * <li>Add a REMOVED entry in the delta
1045 * Delta argument could be null if processing an external JAR change
1047 // protected void elementRemoved(Openable element, IResourceDelta delta,
1048 // RootInfo rootInfo) {
1050 // if (element.isOpen()) {
1053 // removeFromParentInfo(element);
1054 // int elementType = element.getElementType();
1055 // if (delta != null && (delta.getFlags() & IResourceDelta.MOVED_TO) != 0) {
1056 // IPath movedToPath = delta.getMovedToPath();
1057 // IResource res = delta.getResource();
1058 // IResource movedToRes;
1059 // switch (res.getType()) {
1060 // case IResource.PROJECT:
1062 // res.getWorkspace().getRoot().getProject(movedToPath.lastSegment());
1064 // case IResource.FOLDER:
1065 // movedToRes = res.getWorkspace().getRoot().getFolder(movedToPath);
1067 // case IResource.FILE:
1068 // movedToRes = res.getWorkspace().getRoot().getFile(movedToPath);
1074 // // find the element type of the moved from element
1075 // RootInfo movedToInfo = this.enclosingRootInfo(movedToPath,
1076 // IResourceDelta.ADDED);
1077 // int movedToType =
1078 // this.elementType(
1080 // IResourceDelta.ADDED,
1081 // element.getParent().getElementType(),
1084 // // reset current element as it might be inside a nested root
1085 // (popUntilPrefixOf() may use the outer root)
1086 // this.currentElement = null;
1088 // // create the moved To element
1089 // Openable movedToElement =
1090 // elementType != IJavaElement.JAVA_PROJECT && movedToType ==
1091 // IJavaElement.JAVA_PROJECT ?
1092 // null : // outside classpath
1093 // this.createElement(movedToRes, movedToType, movedToInfo);
1094 // if (movedToElement == null) {
1095 // // moved outside classpath
1096 // currentDelta().removed(element);
1098 // currentDelta().movedFrom(element, movedToElement);
1101 // currentDelta().removed(element);
1104 // switch (elementType) {
1105 // case IJavaElement.JAVA_MODEL :
1106 // this.indexManager.reset();
1108 // case IJavaElement.JAVA_PROJECT :
1109 // this.manager.removePerProjectInfo(
1110 // (JavaProject) element);
1111 // this.updateRoots(element.getPath(), delta);
1112 // this.projectsForDependentNamelookupRefresh.add((JavaProject) element);
1114 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
1115 // JavaProject project = (JavaProject) element.getJavaProject();
1116 // this.projectsToUpdate.add(project);
1117 // this.projectsForDependentNamelookupRefresh.add(project);
1119 // case IJavaElement.PACKAGE_FRAGMENT :
1120 // //1G1TW2T - get rid of namelookup since it holds onto obsolete cached
1122 // project = (JavaProject) element.getJavaProject();
1124 // project.getJavaProjectElementInfo().setNameLookup(null);
1125 // this.projectsForDependentNamelookupRefresh.add(project);
1126 // } catch (JavaModelException e) {
1128 // // remove subpackages
1129 // if (delta != null){
1130 // PackageFragmentRoot root = element.getPackageFragmentRoot();
1131 // String name = element.getElementName();
1132 // IResourceDelta[] children = delta.getAffectedChildren();
1133 // for (int i = 0, length = children.length; i < length; i++) {
1134 // IResourceDelta child = children[i];
1135 // IResource resource = child.getResource();
1136 // if (resource instanceof IFolder) {
1137 // String folderName = resource.getName();
1138 // if (ProjectPrefUtil.isValidFolderNameForPackage(folderName)) {
1139 // String subpkgName =
1140 // name.length() == 0 ?
1142 // name + "." + folderName; //$NON-NLS-1$
1143 // Openable subpkg = (Openable)root.getPackageFragment(subpkgName);
1144 // this.updateIndex(subpkg, child);
1145 // this.elementRemoved(subpkg, child, rootInfo);
1154 * Returns the type of the java element the given delta matches to. Returns
1155 * NON_JAVA_RESOURCE if unknown (e.g. a non-java resource or excluded .java
1158 // private int elementType(IResource res, int kind, int parentType, RootInfo
1160 // switch (parentType) {
1161 // case IJavaElement.JAVA_MODEL:
1162 // // case of a movedTo or movedFrom project (other cases are handled in
1163 // processResourceDelta(...)
1164 // return IJavaElement.JAVA_PROJECT;
1165 // case NON_JAVA_RESOURCE:
1166 // case IJavaElement.JAVA_PROJECT:
1167 // if (rootInfo == null) {
1168 // rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
1170 // if (rootInfo != null && rootInfo.isRootOfProject(res.getFullPath())) {
1171 // return IJavaElement.PACKAGE_FRAGMENT_ROOT;
1173 // return NON_JAVA_RESOURCE; // not yet in a package fragment root or root
1174 // of another project
1176 // case IJavaElement.PACKAGE_FRAGMENT_ROOT:
1177 // case IJavaElement.PACKAGE_FRAGMENT:
1178 // if (rootInfo == null) {
1179 // rootInfo = this.enclosingRootInfo(res.getFullPath(), kind);
1181 // if (rootInfo == null || ProjectPrefUtil.isExcluded(res,
1182 // rootInfo.exclusionPatterns)) {
1183 // return NON_JAVA_RESOURCE;
1185 // if (res instanceof IFolder) {
1186 // if (ProjectPrefUtil.isValidFolderNameForPackage(res.getName())) {
1187 // return IJavaElement.PACKAGE_FRAGMENT;
1189 // return NON_JAVA_RESOURCE;
1192 // String fileName = res.getName();
1193 // if (ProjectPrefUtil.isValidCompilationUnitName(fileName)) {
1194 // return IJavaElement.COMPILATION_UNIT;
1195 // } else if (ProjectPrefUtil.isValidClassFileName(fileName)) {
1196 // return IJavaElement.CLASS_FILE;
1197 // } else if (this.rootInfo(res.getFullPath(), kind) != null) {
1198 // // case of proj=src=bin and resource is a jar file on the classpath
1199 // return IJavaElement.PACKAGE_FRAGMENT_ROOT;
1201 // return NON_JAVA_RESOURCE;
1205 // return NON_JAVA_RESOURCE;
1209 * Answer a combination of the lastModified stamp and the size. Used for
1210 * detecting external JAR changes
1212 public static long getTimeStamp(File file) {
1213 return file.lastModified() + file.length();
1216 public void initializeRoots() {
1217 // remember roots infos as old roots infos
1218 this.oldRoots = this.roots == null ? new HashMap() : this.roots;
1219 this.oldOtherRoots = this.otherRoots == null ? new HashMap()
1222 // recompute root infos only if necessary
1226 this.roots = new HashMap();
1227 this.otherRoots = new HashMap();
1228 this.sourceAttachments = new HashMap();
1230 IJavaModel model = this.manager.getJavaModel();
1231 IJavaProject[] projects;
1233 projects = model.getJavaProjects();
1234 } catch (JavaModelException e) {
1235 // nothing can be done
1238 for (int i = 0, length = projects.length; i < length; i++) {
1239 IJavaProject project = projects[i];
1240 IClasspathEntry[] classpath;
1242 classpath = project.getResolvedClasspath(true);
1243 } catch (JavaModelException e) {
1244 // continue with next project
1247 for (int j = 0, classpathLength = classpath.length; j < classpathLength; j++) {
1248 IClasspathEntry entry = classpath[j];
1249 if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT)
1253 IPath path = entry.getPath();
1254 if (this.roots.get(path) == null) {
1255 this.roots.put(path, new RootInfo(project, path,
1256 ((ClasspathEntry) entry)
1257 .fullExclusionPatternChars()));
1259 ArrayList rootList = (ArrayList) this.otherRoots.get(path);
1260 if (rootList == null) {
1261 rootList = new ArrayList();
1262 this.otherRoots.put(path, rootList);
1264 rootList.add(new RootInfo(project, path,
1265 ((ClasspathEntry) entry)
1266 .fullExclusionPatternChars()));
1269 // source attachment path
1270 if (entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY)
1272 QualifiedName qName = new QualifiedName(JavaCore.PLUGIN_ID,
1273 "sourceattachment: " + path.toOSString()); //$NON-NLS-1$;
1274 String propertyString = null;
1276 propertyString = ResourcesPlugin.getWorkspace().getRoot()
1277 .getPersistentProperty(qName);
1278 } catch (CoreException e) {
1281 IPath sourceAttachmentPath;
1282 // if (propertyString != null) {
1284 // propertyString.lastIndexOf(JarPackageFragmentRoot.ATTACHMENT_PROPERTY_DELIMITER);
1285 // sourceAttachmentPath = (index < 0) ? new Path(propertyString)
1286 // : new Path(propertyString.substring(0, index));
1288 sourceAttachmentPath = entry.getSourceAttachmentPath();
1290 if (sourceAttachmentPath != null) {
1291 this.sourceAttachments.put(sourceAttachmentPath, path);
1295 this.rootsAreStale = false;
1299 * Returns whether a given delta contains some information relevant to the
1300 * JavaModel, in particular it will not consider SYNC or MARKER only deltas.
1302 public boolean isAffectedBy(IResourceDelta rootDelta) {
1303 // if (rootDelta == null) System.out.println("NULL DELTA");
1304 // long start = System.currentTimeMillis();
1305 if (rootDelta != null) {
1306 // use local exception to quickly escape from delta traversal
1307 class FoundRelevantDeltaException extends RuntimeException {
1310 rootDelta.accept(new IResourceDeltaVisitor() {
1311 public boolean visit(IResourceDelta delta)
1312 throws CoreException {
1313 switch (delta.getKind()) {
1314 case IResourceDelta.ADDED:
1315 case IResourceDelta.REMOVED:
1316 throw new FoundRelevantDeltaException();
1317 case IResourceDelta.CHANGED:
1318 // if any flag is set but SYNC or MARKER, this delta
1319 // should be considered
1320 if (delta.getAffectedChildren().length == 0 // only
1325 && (delta.getFlags() & ~(IResourceDelta.SYNC | IResourceDelta.MARKERS)) != 0) {
1326 throw new FoundRelevantDeltaException();
1332 } catch (FoundRelevantDeltaException e) {
1333 // System.out.println("RELEVANT DELTA detected in: "+
1334 // (System.currentTimeMillis() - start));
1336 } catch (CoreException e) { // ignore delta if not able to traverse
1339 // System.out.println("IGNORE SYNC DELTA took: "+
1340 // (System.currentTimeMillis() - start));
1345 * Returns whether the given resource is in one of the given output folders
1346 * and if it is filtered out from this output folder.
1348 private boolean isResFilteredFromOutput(OutputsInfo info, IResource res,
1351 IPath resPath = res.getFullPath();
1352 for (int i = 0; i < info.outputCount; i++) {
1353 if (info.paths[i].isPrefixOf(resPath)) {
1354 if (info.traverseModes[i] != IGNORE) {
1356 if (info.traverseModes[i] == SOURCE
1357 && elementType == IJavaElement.CLASS_FILE) {
1360 // case of .class file under project and no source
1363 if (elementType == IJavaElement.JAVA_PROJECT
1364 && res instanceof IFile
1365 && PHPFileUtil.isPHPFile((IFile) res)) {
1379 * Merges all awaiting deltas.
1381 private IJavaElementDelta mergeDeltas(Collection deltas) {
1382 if (deltas.size() == 0)
1384 if (deltas.size() == 1)
1385 return (IJavaElementDelta) deltas.iterator().next();
1389 .println("MERGING " + deltas.size() + " DELTAS [" + Thread.currentThread() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
1392 Iterator iterator = deltas.iterator();
1393 JavaElementDelta rootDelta = new JavaElementDelta(
1394 this.manager.javaModel);
1395 boolean insertedTree = false;
1396 while (iterator.hasNext()) {
1397 JavaElementDelta delta = (JavaElementDelta) iterator.next();
1399 System.out.println(delta.toString());
1401 IJavaElement element = delta.getElement();
1402 if (this.manager.javaModel.equals(element)) {
1403 IJavaElementDelta[] children = delta.getAffectedChildren();
1404 for (int j = 0; j < children.length; j++) {
1405 JavaElementDelta projectDelta = (JavaElementDelta) children[j];
1406 rootDelta.insertDeltaTree(projectDelta.getElement(),
1408 insertedTree = true;
1410 IResourceDelta[] resourceDeltas = delta.getResourceDeltas();
1411 if (resourceDeltas != null) {
1412 for (int i = 0, length = resourceDeltas.length; i < length; i++) {
1413 rootDelta.addResourceDelta(resourceDeltas[i]);
1414 insertedTree = true;
1418 rootDelta.insertDeltaTree(element, delta);
1419 insertedTree = true;
1428 * Check whether the updated file is affecting some of the properties of a
1429 * given project (like its classpath persisted as a file). Also force
1430 * classpath problems to be refresh if not running in autobuild mode. NOTE:
1431 * It can induce resource changes, and cannot be called during POST_CHANGE
1435 // public void performPreBuildCheck(
1436 // IResourceDelta delta,
1437 // IJavaElement parent) {
1439 // IResource resource = delta.getResource();
1440 // IJavaElement element = null;
1441 // boolean processChildren = false;
1443 // switch (resource.getType()) {
1445 // case IResource.ROOT :
1446 // if (delta.getKind() == IResourceDelta.CHANGED) {
1447 // element = JavaCore.create(resource);
1448 // processChildren = true;
1451 // case IResource.PROJECT :
1452 // int kind = delta.getKind();
1454 // case IResourceDelta.CHANGED:
1455 // // do not visit non-java projects (see bug 16140 Non-java project gets
1457 // IProject project = (IProject)resource;
1458 // if (JavaProject.hasJavaNature(project)) {
1459 // element = JavaCore.create(resource);
1460 // processChildren = true;
1462 // (JavaModelManager.getJavaModelManager().getJavaModel().findJavaProject(project)
1464 // // project had the java nature
1465 // this.rootsAreStale = true;
1467 // // remove classpath cache so that initializeRoots() will not consider the
1468 // project has a classpath
1469 // this.manager.removePerProjectInfo((JavaProject)JavaCore.create(project));
1472 // case IResourceDelta.ADDED:
1473 // this.rootsAreStale = true;
1475 // case IResourceDelta.REMOVED:
1476 // // remove classpath cache so that initializeRoots() will not consider the
1477 // project has a classpath
1478 // this.manager.removePerProjectInfo((JavaProject)JavaCore.create(resource));
1480 // this.rootsAreStale = true;
1484 // case IResource.FILE :
1485 // if (parent.getElementType() == IJavaElement.JAVA_PROJECT) {
1486 // IFile file = (IFile) resource;
1487 // JavaProject project = (JavaProject) parent;
1489 // /* check classpath file change */
1490 // if (file.getName().equals(JavaProject.CLASSPATH_FILENAME)) {
1491 // reconcileClasspathFileUpdate(delta, file, project);
1492 // this.rootsAreStale = true;
1495 // // /* check custom preference file change */
1496 // // if (file.getName().equals(JavaProject.PREF_FILENAME)) {
1497 // // reconcilePreferenceFileUpdate(delta, file, project);
1503 // if (processChildren) {
1504 // IResourceDelta[] children = delta.getAffectedChildren();
1505 // for (int i = 0; i < children.length; i++) {
1506 // performPreBuildCheck(children[i], element);
1510 // private void popUntilPrefixOf(IPath path) {
1511 // while (this.currentElement != null) {
1512 // IPath currentElementPath = null;
1513 // if (this.currentElement instanceof IPackageFragmentRoot) {
1514 // currentElementPath =
1515 // ((IPackageFragmentRoot)this.currentElement).getPath();
1517 // IResource currentElementResource = this.currentElement.getResource();
1518 // if (currentElementResource != null) {
1519 // currentElementPath = currentElementResource.getFullPath();
1522 // if (currentElementPath != null) {
1523 // if (this.currentElement instanceof IPackageFragment
1524 // && this.currentElement.getElementName().length() == 0
1525 // && currentElementPath.segmentCount() != path.segmentCount()-1) {
1526 // // default package and path is not a direct child
1527 // this.currentElement = (Openable)this.currentElement.getParent();
1529 // if (currentElementPath.isPrefixOf(path)) {
1533 // this.currentElement = (Openable)this.currentElement.getParent();
1537 * Converts a <code>IResourceDelta</code> rooted in a
1538 * <code>Workspace</code> into the corresponding set of
1539 * <code>IJavaElementDelta</code>, rooted in the relevant
1540 * <code>JavaModel</code>s.
1544 * Update the JavaModel according to a .classpath file change. The file can
1545 * have changed as a result of a previous call to
1546 * JavaProject#setRawClasspath or as a result of some user update (through
1549 // void reconcileClasspathFileUpdate(IResourceDelta delta, IFile file,
1550 // JavaProject project) {
1552 // switch (delta.getKind()) {
1553 // case IResourceDelta.REMOVED : // recreate one based on in-memory
1556 // JavaModelManager.PerProjectInfo info =
1557 // JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project.getProject());
1558 // if (info.classpath != null) { // if there is an in-memory classpath
1559 // project.saveClasspath(info.classpath, info.outputLocation);
1561 // } catch (JavaModelException e) {
1562 // if (project.getProject().isAccessible()) {
1563 // ProjectPrefUtil.log(e, "Could not save classpath for "+
1564 // project.getPath()); //$NON-NLS-1$
1568 // case IResourceDelta.CHANGED :
1569 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0 // only consider
1571 // && (delta.getFlags() & IResourceDelta.MOVED_FROM) == 0) // and also move
1572 // and overide scenario (see
1573 // http://dev.eclipse.org/bugs/show_bug.cgi?id=21420)
1575 // case IResourceDelta.ADDED :
1576 // // check if any actual difference
1577 // project.flushClasspathProblemMarkers(false, true);
1578 // boolean wasSuccessful = false; // flag recording if .classpath file
1579 // change got reflected
1581 // // force to (re)read the property file
1582 // IClasspathEntry[] fileEntries = project.readClasspathFile(true/*create
1583 // markers*/, false/*don't log problems*/);
1584 // if (fileEntries == null)
1585 // break; // could not read, ignore
1586 // JavaModelManager.PerProjectInfo info =
1587 // JavaModelManager.getJavaModelManager().getPerProjectInfoCheckExistence(project.getProject());
1588 // if (info.classpath != null) { // if there is an in-memory classpath
1589 // if (project.isClasspathEqualsTo(info.classpath, info.outputLocation,
1591 // wasSuccessful = true;
1596 // // will force an update of the classpath/output location based on the
1598 // // extract out the output location
1599 // IPath outputLocation = null;
1600 // if (fileEntries != null && fileEntries.length > 0) {
1601 // IClasspathEntry entry = fileEntries[fileEntries.length - 1];
1602 // if (entry.getContentKind() == ClasspathEntry.K_OUTPUT) {
1603 // outputLocation = entry.getPath();
1604 // IClasspathEntry[] copy = new IClasspathEntry[fileEntries.length - 1];
1605 // System.arraycopy(fileEntries, 0, copy, 0, copy.length);
1606 // fileEntries = copy;
1609 // // restore output location
1610 // if (outputLocation == null) {
1611 // outputLocation = SetClasspathOperation.ReuseOutputLocation;
1612 // // clean mode will also default to reusing current one
1614 // project.setRawClasspath(
1618 // true, // canChangeResource
1619 // project.getResolvedClasspath(true), // ignoreUnresolvedVariable
1620 // true, // needValidation
1621 // false); // no need to save
1623 // // if reach that far, the classpath file change got absorbed
1624 // wasSuccessful = true;
1625 // } catch (RuntimeException e) {
1626 // // setRawClasspath might fire a delta, and a listener may throw an
1628 // if (project.getProject().isAccessible()) {
1629 // ProjectPrefUtil.log(e, "Could not set classpath for "+
1630 // project.getPath()); //$NON-NLS-1$
1633 // } catch (JavaModelException e) { // CP failed validation
1634 // if (project.getProject().isAccessible()) {
1635 // if (e.getJavaModelStatus().getException() instanceof CoreException) {
1636 // // happens if the .classpath could not be written to disk
1637 // project.createClasspathProblemMarker(new JavaModelStatus(
1638 // IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
1639 // ProjectPrefUtil.bind("classpath.couldNotWriteClasspathFile",
1640 // project.getElementName(), e.getMessage()))); //$NON-NLS-1$
1642 // project.createClasspathProblemMarker(new JavaModelStatus(
1643 // IJavaModelStatusConstants.INVALID_CLASSPATH_FILE_FORMAT,
1644 // ProjectPrefUtil.bind("classpath.invalidClasspathInClasspathFile",
1645 // project.getElementName(), e.getMessage()))); //$NON-NLS-1$
1650 // if (!wasSuccessful) {
1652 // project.setRawClasspath0(JavaProject.INVALID_CLASSPATH);
1653 // project.updatePackageFragmentRoots();
1654 // } catch (JavaModelException e) {
1661 * Update the JavaModel according to a .jprefs file change. The file can
1662 * have changed as a result of a previous call to JavaProject#setOptions or
1663 * as a result of some user update (through repository) Unused until
1664 * preference file get shared (.jpref)
1666 // void reconcilePreferenceFileUpdate(IResourceDelta delta, IFile file,
1667 // JavaProject project) {
1669 // switch (delta.getKind()) {
1670 // case IResourceDelta.REMOVED : // flush project custom settings
1671 // project.setOptions(null);
1673 // case IResourceDelta.CHANGED :
1674 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0 // only consider
1676 // && (delta.getFlags() & IResourceDelta.MOVED_FROM) == 0) // and also move
1677 // and overide scenario
1679 // identityCheck : { // check if any actual difference
1680 // // force to (re)read the property file
1681 // Preferences filePreferences = project.loadPreferences();
1682 // if (filePreferences == null){
1683 // project.setOptions(null); // should have got removed delta.
1686 // Preferences projectPreferences = project.getPreferences();
1687 // if (projectPreferences == null) return; // not a Java project
1689 // // compare preferences set to their default
1690 // String[] defaultProjectPropertyNames =
1691 // projectPreferences.defaultPropertyNames();
1692 // String[] defaultFilePropertyNames =
1693 // filePreferences.defaultPropertyNames();
1694 // if (defaultProjectPropertyNames.length ==
1695 // defaultFilePropertyNames.length) {
1696 // for (int i = 0; i < defaultProjectPropertyNames.length; i++){
1697 // String propertyName = defaultProjectPropertyNames[i];
1699 // (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){
1700 // break identityCheck;
1703 // } else break identityCheck;
1705 // // compare custom preferences not set to their default
1706 // String[] projectPropertyNames = projectPreferences.propertyNames();
1707 // String[] filePropertyNames = filePreferences.propertyNames();
1708 // if (projectPropertyNames.length == filePropertyNames.length) {
1709 // for (int i = 0; i < projectPropertyNames.length; i++){
1710 // String propertyName = projectPropertyNames[i];
1712 // (!projectPreferences.getString(propertyName).trim().equals(filePreferences.getString(propertyName).trim())){
1713 // break identityCheck;
1716 // } else break identityCheck;
1718 // // identical - do nothing
1721 // case IResourceDelta.ADDED :
1722 // // not identical, create delta and reset cached preferences
1723 // project.setPreferences(null);
1725 // //fCurrentDelta.changed(project, IJavaElementDelta.F_OPTIONS_CHANGED);
1729 * Registers the given delta with this delta processor.
1731 public void registerJavaModelDelta(IJavaElementDelta delta) {
1732 this.javaModelDeltas.add(delta);
1736 * Removes the given element from its parents cache of children. If the
1737 * element does not have a parent, or the parent is not currently open, this
1740 protected void removeFromParentInfo(Openable child) {
1742 Openable parent = (Openable) child.getParent();
1743 if (parent != null && parent.isOpen()) {
1745 JavaElementInfo info = (JavaElementInfo) parent
1747 info.removeChild(child);
1748 } catch (JavaModelException e) {
1749 // do nothing - we already checked if open
1755 * Notification that some resource changes have happened on the platform,
1756 * and that the Java Model should update any required internal structures
1757 * such that its elements remain consistent. Translates
1758 * <code>IResourceDeltas</code> into <code>IJavaElementDeltas</code>.
1760 * @see IResourceDelta
1763 public void resourceChanged(IResourceChangeEvent event) {
1764 if (event.getSource() instanceof IWorkspace) {
1765 int eventType = this.overridenEventType == -1 ? event.getType()
1766 : this.overridenEventType;
1767 IResource resource = event.getResource();
1768 IResourceDelta delta = event.getDelta();
1770 switch (eventType) {
1771 case IResourceChangeEvent.PRE_DELETE:
1773 if (resource.getType() == IResource.PROJECT
1774 && ((IProject) resource)
1775 .hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
1777 deleting((IProject) resource);
1779 } catch (CoreException e) {
1780 // project doesn't exist or is not open: ignore
1784 case IResourceChangeEvent.POST_CHANGE:
1785 if (isAffectedBy(delta)) { // avoid populating for SYNC or
1790 // checkProjectsBeingAddedOrRemoved(delta);
1791 // if (this.refreshedElements != null) {
1792 // createExternalArchiveDelta(null);
1794 IJavaElementDelta translatedDelta = processResourceDelta(delta);
1795 if (translatedDelta != null) {
1796 registerJavaModelDelta(translatedDelta);
1801 // notifyTypeHierarchies(this.state.elementChangedListeners,
1802 // this.state.elementChangedListenerCount);
1803 fire(null, ElementChangedEvent.POST_CHANGE);
1805 // workaround for bug 15168 circular errors not reported
1806 this.state.modelProjectsCache = null;
1807 this.removedRoots = null;
1812 case IResourceChangeEvent.PRE_BUILD:
1813 DeltaProcessingState.ProjectUpdateInfo[] updates = this.state
1814 .removeAllProjectUpdates();
1815 if (updates != null) {
1816 for (int i = 0, length = updates.length; i < length; i++) {
1818 updates[i].updateProjectReferencesIfNecessary();
1819 } catch (JavaModelException e) {
1824 // this.processPostChange = false;
1825 if (isAffectedBy(delta)) { // avoid populating for SYNC or
1827 // updateClasspathMarkers(delta);
1828 PHPBuilder.buildStarting();
1830 // does not fire any deltas
1833 case IResourceChangeEvent.POST_BUILD:
1834 PHPBuilder.buildFinished();
1838 // // jsurfer TODO compare 3.0 sources
1839 // if (event.getSource() instanceof IWorkspace) {
1840 // int eventType = this.overridenEventType == -1 ? event.getType() :
1841 // this.overridenEventType;
1842 // IResource resource = event.getResource();
1843 // IResourceDelta delta = event.getDelta();
1845 // switch(eventType){
1846 // case IResourceChangeEvent.PRE_DELETE :
1848 // if(resource.getType() == IResource.PROJECT
1849 // && ((IProject) resource).hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
1850 // // TODO jsurfer temp-del
1851 // // this.deleting((IProject)resource);
1853 // } catch(CoreException e){
1857 // case IResourceChangeEvent.PRE_BUILD :
1858 // // TODO jsurfer temp-del
1859 // // if(isAffectedBy(delta)) { // avoid populating for SYNC or MARKER
1861 // // this.checkProjectsBeingAddedOrRemoved(delta);
1863 // // // update the classpath related markers
1864 // // this.updateClasspathMarkers();
1866 // // // the following will close project if affected by the property
1869 // // // don't fire classpath change deltas right away, but batch them
1870 // // this.manager.stopDeltas();
1871 // // this.performPreBuildCheck(delta, null);
1873 // // this.manager.startDeltas();
1876 // // only fire already computed deltas (resource ones will be processed
1877 // in post change only)
1878 // this.manager.fire(null, ElementChangedEvent.PRE_AUTO_BUILD);
1881 // case IResourceChangeEvent.POST_BUILD :
1882 // // TODO jsurfer temp-del
1883 // // JavaBuilder.finishedBuilding(event);
1886 // case IResourceChangeEvent.POST_CHANGE :
1887 // // TODO jsurfer temp-del
1888 // // if (isAffectedBy(delta)) {
1890 // // if (this.refreshedElements != null) {
1892 // // createExternalArchiveDelta(null);
1893 // // } catch (JavaModelException e) {
1894 // // e.printStackTrace();
1897 // // IJavaElementDelta translatedDelta =
1898 // this.processResourceDelta(delta);
1899 // // if (translatedDelta != null) {
1900 // // this.manager.registerJavaModelDelta(translatedDelta);
1902 // // this.manager.fire(null, ElementChangedEvent.POST_CHANGE);
1904 // // // workaround for bug 15168 circular errors not reported
1905 // // this.manager.javaProjectsCache = null;
1906 // // this.removedRoots = null;
1914 * Turns the firing mode to on. That is, deltas that are/have been
1915 * registered will be fired.
1917 private void startDeltas() {
1918 this.isFiring = true;
1922 * Turns the firing mode to off. That is, deltas that are/have been
1923 * registered will not be fired until deltas are started again.
1925 private void stopDeltas() {
1926 this.isFiring = false;
1930 * Note that the project is about to be deleted.
1932 private void deleting(IProject project) {
1935 // discard indexing jobs that belong to this project so that the
1937 // deleted without interferences from the index manager
1938 // this.manager.indexManager.discardJobs(project.getName());
1940 JavaProject javaProject = (JavaProject) JavaCore.create(project);
1942 // remember roots of this project
1943 if (this.removedRoots == null) {
1944 this.removedRoots = new HashMap();
1946 if (javaProject.isOpen()) {
1947 this.removedRoots.put(javaProject, javaProject
1948 .getPackageFragmentRoots());
1950 // compute roots without opening project
1951 // this.removedRoots.put(
1953 // javaProject.computePackageFragmentRoots(
1954 // javaProject.getResolvedClasspath(true/*ignoreUnresolvedEntry*/,
1955 // false/*don't generateMarkerOnError*/, false/*don't
1956 // returnResolutionInProgress*/),
1960 javaProject.close();
1962 // workaround for bug 15168 circular errors not reported
1963 if (this.state.modelProjectsCache == null) {
1964 this.state.modelProjectsCache = this.manager.getJavaModel()
1967 this.removeFromParentInfo(javaProject);
1969 } catch (JavaModelException e) {
1970 // java project doesn't exist: ignore
1975 * Converts a <code>IResourceDelta</code> rooted in a <code>Workspace</code>
1976 * into the corresponding set of <code>IJavaElementDelta</code>, rooted
1977 * in the relevant <code>JavaModel</code>s.
1979 private IJavaElementDelta processResourceDelta(IResourceDelta changes) {
1982 IJavaModel model = this.manager.getJavaModel();
1983 if (!model.isOpen()) {
1984 // force opening of java model so that java element delta are
1988 } catch (JavaModelException e) {
1990 e.printStackTrace();
1995 this.state.initializeRoots();
1996 this.currentElement = null;
1998 // get the workspace delta, and start processing there.
1999 IResourceDelta[] deltas = changes.getAffectedChildren();
2000 for (int i = 0; i < deltas.length; i++) {
2001 IResourceDelta delta = deltas[i];
2002 IResource res = delta.getResource();
2004 // find out the element type
2005 // RootInfo rootInfo = null;
2007 IProject proj = (IProject) res;
2008 boolean wasJavaProject = this.manager.getJavaModel()
2009 .findJavaProject(proj) != null;
2010 boolean isJavaProject = JavaProject.hasJavaNature(proj);
2011 if (!wasJavaProject && !isJavaProject) {
2012 elementType = NON_JAVA_RESOURCE;
2014 // rootInfo = this.enclosingRootInfo(res.getFullPath(),
2015 // delta.getKind());
2016 // if (rootInfo != null &&
2017 // rootInfo.isRootOfProject(res.getFullPath())) {
2018 // elementType = IJavaElement.PACKAGE_FRAGMENT_ROOT;
2020 elementType = IJavaElement.JAVA_PROJECT;
2025 // this.traverseDelta(delta, elementType, rootInfo, null);
2027 if (elementType == NON_JAVA_RESOURCE
2028 || (wasJavaProject != isJavaProject && (delta.getKind()) == IResourceDelta.CHANGED)) { // project
2036 // add child as non java resource
2037 nonJavaResourcesChanged((JavaModel) model, delta);
2038 } catch (JavaModelException e) {
2039 // java model could not be opened
2044 // refreshPackageFragmentRoots();
2045 // resetProjectCaches();
2047 return this.currentDelta;
2049 this.currentDelta = null;
2050 // this.rootsToRefresh.clear();
2051 // this.projectCachesToReset.clear();
2056 * Converts an <code>IResourceDelta</code> and its children into the
2057 * corresponding <code>IJavaElementDelta</code>s.
2059 // private void traverseDelta(
2060 // IResourceDelta delta,
2062 // RootInfo rootInfo,
2063 // OutputsInfo outputsInfo) {
2065 // IResource res = delta.getResource();
2067 // // set stack of elements
2068 // if (this.currentElement == null && rootInfo != null) {
2069 // // this.currentElement = rootInfo.project;
2072 // // process current delta
2073 // boolean processChildren = true;
2074 // if (res instanceof IProject) {
2075 // processChildren =
2076 // this.updateCurrentDeltaAndIndex(
2078 // elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ?
2079 // IJavaElement.JAVA_PROJECT : // case of prj=src
2082 // } else if (rootInfo != null) {
2083 // processChildren = this.updateCurrentDeltaAndIndex(delta, elementType,
2086 // // not yet inside a package fragment root
2087 // processChildren = true;
2090 // // get the project's output locations and traverse mode
2091 // if (outputsInfo == null) outputsInfo = this.outputsInfo(rootInfo, res);
2093 // // process children if needed
2094 // if (processChildren) {
2095 // IResourceDelta[] children = delta.getAffectedChildren();
2096 // boolean oneChildOnClasspath = false;
2097 // int length = children.length;
2098 // IResourceDelta[] orphanChildren = null;
2099 // Openable parent = null;
2100 // boolean isValidParent = true;
2101 // for (int i = 0; i < length; i++) {
2102 // IResourceDelta child = children[i];
2103 // IResource childRes = child.getResource();
2105 // // check source attachment change
2106 // this.checkSourceAttachmentChange(child, childRes);
2108 // // find out whether the child is a package fragment root of the current
2110 // IPath childPath = childRes.getFullPath();
2111 // int childKind = child.getKind();
2112 // RootInfo childRootInfo = this.rootInfo(childPath, childKind);
2113 // if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
2114 // // package fragment root of another project (dealt with later)
2115 // childRootInfo = null;
2118 // // compute child type
2120 // this.elementType(
2124 // rootInfo == null ? childRootInfo : rootInfo
2127 // // is childRes in the output folder and is it filtered out ?
2128 // boolean isResFilteredFromOutput =
2129 // this.isResFilteredFromOutput(outputsInfo, childRes, childType);
2131 // boolean isNestedRoot = rootInfo != null && childRootInfo != null;
2132 // if (!isResFilteredFromOutput
2133 // && !isNestedRoot) { // do not treat as non-java rsc if nested root
2135 // this.traverseDelta(child, childType, rootInfo == null ? childRootInfo :
2136 // rootInfo, outputsInfo); // traverse delta for child in the same project
2138 // if (childType == NON_JAVA_RESOURCE) {
2139 // if (rootInfo != null) { // if inside a package fragment root
2140 // if (!isValidParent) continue;
2141 // if (parent == null) {
2142 // // find the parent of the non-java resource to attach to
2143 // if (this.currentElement == null
2144 // || !rootInfo.project.equals(this.currentElement.getJavaProject())) { //
2145 // note if currentElement is the IJavaModel, getJavaProject() is null
2146 // // force the currentProject to be used
2147 // this.currentElement = rootInfo.project;
2149 // if (elementType == IJavaElement.JAVA_PROJECT
2150 // || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT
2151 // && res instanceof IProject)) {
2152 // // NB: attach non-java resource to project (not to its package fragment
2154 // parent = rootInfo.project;
2156 // parent = this.createElement(res, elementType, rootInfo);
2158 // if (parent == null) {
2159 // isValidParent = false;
2163 // // add child as non java resource
2165 // nonJavaResourcesChanged(parent, child);
2166 // } catch (JavaModelException e) {
2170 // // the non-java resource (or its parent folder) will be attached to the
2172 // if (orphanChildren == null) orphanChildren = new IResourceDelta[length];
2173 // orphanChildren[i] = child;
2176 // oneChildOnClasspath = true;
2179 // oneChildOnClasspath = true; // to avoid reporting child delta as non-java
2183 // // if child is a nested root
2184 // // or if it is not a package fragment root of the current project
2185 // // but it is a package fragment root of another project, traverse delta
2188 // || (childRootInfo == null && (childRootInfo = this.rootInfo(childPath,
2189 // childKind)) != null)) {
2190 // this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT,
2191 // childRootInfo, null); // binary output of childRootInfo.project cannot be
2195 // // if the child is a package fragment root of one or several other
2197 // ArrayList rootList;
2198 // if ((rootList = this.otherRootsInfo(childPath, childKind)) != null) {
2199 // Iterator iterator = rootList.iterator();
2200 // while (iterator.hasNext()) {
2201 // childRootInfo = (RootInfo) iterator.next();
2202 // this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT,
2203 // childRootInfo, null); // binary output of childRootInfo.project cannot be
2208 // if (orphanChildren != null
2209 // && (oneChildOnClasspath // orphan children are siblings of a package
2211 // || res instanceof IProject)) { // non-java resource directly under a
2214 // // attach orphan children
2215 // IProject rscProject = res.getProject();
2216 // JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject);
2217 // if (adoptiveProject != null
2218 // && JavaProject.hasJavaNature(rscProject)) { // delta iff Java project
2220 // for (int i = 0; i < length; i++) {
2221 // if (orphanChildren[i] != null) {
2223 // nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]);
2224 // } catch (JavaModelException e) {
2230 // } // else resource delta will be added by parent
2231 // } // else resource delta will be added by parent
2233 private void notifyListeners(IJavaElementDelta deltaToNotify,
2234 int eventType, IElementChangedListener[] listeners,
2235 int[] listenerMask, int listenerCount) {
2236 final ElementChangedEvent extraEvent = new ElementChangedEvent(
2237 deltaToNotify, eventType);
2238 for (int i = 0; i < listenerCount; i++) {
2239 if ((listenerMask[i] & eventType) != 0) {
2240 final IElementChangedListener listener = listeners[i];
2244 .print("Listener #" + (i + 1) + "=" + listener.toString());//$NON-NLS-1$//$NON-NLS-2$
2245 start = System.currentTimeMillis();
2247 // wrap callbacks with Safe runnable for subsequent listeners to
2248 // be called when some are causing grief
2249 SafeRunner.run(new ISafeRunnable() {
2250 public void handleException(Throwable exception) {
2253 "Exception occurred in listener of Java element change notification"); //$NON-NLS-1$
2256 public void run() throws Exception {
2257 listener.elementChanged(extraEvent);
2262 .println(" -> " + (System.currentTimeMillis() - start) + "ms"); //$NON-NLS-1$ //$NON-NLS-2$
2268 // private void notifyTypeHierarchies(IElementChangedListener[] listeners,
2269 // int listenerCount) {
2270 // for (int i= 0; i < listenerCount; i++) {
2271 // final IElementChangedListener listener = listeners[i];
2272 // if (!(listener instanceof TypeHierarchy)) continue;
2274 // // wrap callbacks with Safe runnable for subsequent listeners to be
2275 // called when some are causing grief
2276 // Platform.run(new ISafeRunnable() {
2277 // public void handleException(Throwable exception) {
2278 // ProjectPrefUtil.log(exception, "Exception occurred in listener of Java
2279 // element change notification"); //$NON-NLS-1$
2281 // public void run() throws Exception {
2282 // TypeHierarchy typeHierarchy = (TypeHierarchy)listener;
2283 // if (typeHierarchy.hasFineGrainChanges()) {
2284 // // case of changes in primary working copies
2285 // typeHierarchy.needsRefresh = true;
2286 // typeHierarchy.fireChange();
2293 * Generic processing for elements with changed contents:<ul> <li>The
2294 * element is closed such that any subsequent accesses will re-open the
2295 * element reflecting its new structure. <li>An entry is made in the delta
2296 * reporting a content change (K_CHANGE with F_CONTENT flag set). </ul>
2298 private void nonJavaResourcesChanged(Openable element, IResourceDelta delta)
2299 throws JavaModelException {
2301 // reset non-java resources if element was open
2302 if (element.isOpen()) {
2303 JavaElementInfo info = (JavaElementInfo) element.getElementInfo();
2304 switch (element.getElementType()) {
2305 case IJavaElement.JAVA_MODEL:
2306 ((JavaModelInfo) info).nonJavaResources = null;
2307 currentDelta().addResourceDelta(delta);
2309 case IJavaElement.JAVA_PROJECT:
2310 ((JavaProjectElementInfo) info).setNonJavaResources(null);
2312 // if a package fragment root is the project, clear it too
2313 JavaProject project = (JavaProject) element;
2314 PackageFragmentRoot projectRoot = (PackageFragmentRoot) project
2315 .getPackageFragmentRoot(project.getProject());
2316 if (projectRoot.isOpen()) {
2317 ((PackageFragmentRootInfo) projectRoot.getElementInfo())
2318 .setNonJavaResources(null);
2321 case IJavaElement.PACKAGE_FRAGMENT:
2322 ((PackageFragmentInfo) info).setNonJavaResources(null);
2324 case IJavaElement.PACKAGE_FRAGMENT_ROOT:
2325 ((PackageFragmentRootInfo) info).setNonJavaResources(null);
2329 JavaElementDelta current = currentDelta();
2330 JavaElementDelta elementDelta = current.find(element);
2331 if (elementDelta == null) {
2332 // don't use find after creating the delta as it can be null (see
2333 // https://bugs.eclipse.org/bugs/show_bug.cgi?id=63434)
2334 elementDelta = current
2335 .changed(element, IJavaElementDelta.F_CONTENT);
2337 elementDelta.addResourceDelta(delta);
2341 * Flushes all deltas without firing them.
2343 public void flush() {
2344 this.javaModelDeltas = new ArrayList();
2348 * Finds the root info this path is included in. Returns null if not found.
2350 RootInfo enclosingRootInfo(IPath path, int kind) {
2351 while (path != null && path.segmentCount() > 0) {
2352 RootInfo rootInfo = this.rootInfo(path, kind);
2353 if (rootInfo != null)
2355 path = path.removeLastSegments(1);
2361 * Fire Java Model delta, flushing them after the fact after post_change
2362 * notification. If the firing mode has been turned off, this has no effect.
2364 public void fire(IJavaElementDelta customDelta, int eventType) {
2370 .println("-----------------------------------------------------------------------------------------------------------------------");//$NON-NLS-1$
2373 IJavaElementDelta deltaToNotify;
2374 if (customDelta == null) {
2375 deltaToNotify = this.mergeDeltas(this.javaModelDeltas);
2377 deltaToNotify = customDelta;
2380 // Refresh internal scopes
2381 // if (deltaToNotify != null) {
2382 // Iterator scopes = this.manager.searchScopes.keySet().iterator();
2383 // while (scopes.hasNext()) {
2384 // AbstractSearchScope scope = (AbstractSearchScope)scopes.next();
2385 // scope.processDelta(deltaToNotify);
2391 // Important: if any listener reacts to notification by updating the
2392 // listeners list or mask, these lists will
2393 // be duplicated, so it is necessary to remember original lists in a
2394 // variable (since field values may change under us)
2395 IElementChangedListener[] listeners = this.state.elementChangedListeners;
2396 int[] listenerMask = this.state.elementChangedListenerMasks;
2397 int listenerCount = this.state.elementChangedListenerCount;
2399 switch (eventType) {
2400 case DEFAULT_CHANGE_EVENT:
2401 firePostChangeDelta(deltaToNotify, listeners, listenerMask,
2403 fireReconcileDelta(listeners, listenerMask, listenerCount);
2405 case ElementChangedEvent.POST_CHANGE:
2406 firePostChangeDelta(deltaToNotify, listeners, listenerMask,
2408 fireReconcileDelta(listeners, listenerMask, listenerCount);
2413 private void firePostChangeDelta(IJavaElementDelta deltaToNotify,
2414 IElementChangedListener[] listeners, int[] listenerMask,
2415 int listenerCount) {
2417 // post change deltas
2420 .println("FIRING POST_CHANGE Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$
2422 .println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$
2424 if (deltaToNotify != null) {
2425 // flush now so as to keep listener reactions to post their own
2426 // deltas for subsequent iteration
2429 notifyListeners(deltaToNotify, ElementChangedEvent.POST_CHANGE,
2430 listeners, listenerMask, listenerCount);
2434 private void fireReconcileDelta(IElementChangedListener[] listeners,
2435 int[] listenerMask, int listenerCount) {
2437 IJavaElementDelta deltaToNotify = mergeDeltas(this.reconcileDeltas
2441 .println("FIRING POST_RECONCILE Delta [" + Thread.currentThread() + "]:"); //$NON-NLS-1$//$NON-NLS-2$
2443 .println(deltaToNotify == null ? "<NONE>" : deltaToNotify.toString()); //$NON-NLS-1$
2445 if (deltaToNotify != null) {
2446 // flush now so as to keep listener reactions to post their own
2447 // deltas for subsequent iteration
2448 this.reconcileDeltas = new HashMap();
2450 notifyListeners(deltaToNotify, ElementChangedEvent.POST_RECONCILE,
2451 listeners, listenerMask, listenerCount);
2456 * Returns the root info for the given path. Look in the old roots table if
2459 RootInfo rootInfo(IPath path, int kind) {
2460 if (kind == IResourceDelta.REMOVED) {
2461 return (RootInfo) this.oldRoots.get(path);
2463 return (RootInfo) this.roots.get(path);
2468 * Returns the other root infos for the given path. Look in the old other
2469 * roots table if kind is REMOVED.
2471 ArrayList otherRootsInfo(IPath path, int kind) {
2472 if (kind == IResourceDelta.REMOVED) {
2473 return (ArrayList) this.oldOtherRoots.get(path);
2475 return (ArrayList) this.otherRoots.get(path);
2480 * Converts an <code>IResourceDelta</code> and its children into the
2481 * corresponding <code>IJavaElementDelta</code>s. Return whether the
2482 * delta corresponds to a java element. If it is not a java element, it will
2483 * be added as a non-java resource by the sender of this method.
2485 // protected boolean traverseDelta(
2486 // IResourceDelta delta,
2488 // RootInfo rootInfo,
2489 // OutputsInfo outputsInfo) {
2491 // IResource res = delta.getResource();
2493 // // set stack of elements
2494 // if (this.currentElement == null && rootInfo != null) {
2495 // this.currentElement = (Openable)rootInfo.project;
2498 // // process current delta
2499 // boolean processChildren = true;
2500 // if (res instanceof IProject) {
2501 // processChildren =
2502 // this.updateCurrentDeltaAndIndex(
2504 // elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT ?
2505 // IJavaElement.JAVA_PROJECT : // case of prj=src
2508 // } else if (rootInfo != null) {
2509 // processChildren = this.updateCurrentDeltaAndIndex(delta, elementType,
2512 // // not yet inside a package fragment root
2513 // processChildren = true;
2516 // // get the project's output locations and traverse mode
2517 // if (outputsInfo == null) outputsInfo = this.outputsInfo(rootInfo, res);
2519 // // process children if needed
2520 // if (processChildren) {
2521 // IResourceDelta[] children = delta.getAffectedChildren();
2522 // boolean oneChildOnClasspath = false;
2523 // int length = children.length;
2524 // IResourceDelta[] orphanChildren = null;
2525 // Openable parent = null;
2526 // boolean isValidParent = true;
2527 // for (int i = 0; i < length; i++) {
2528 // IResourceDelta child = children[i];
2529 // IResource childRes = child.getResource();
2531 // // check source attachment change
2532 // this.checkSourceAttachmentChange(child, childRes);
2534 // // find out whether the child is a package fragment root of the current
2536 // IPath childPath = childRes.getFullPath();
2537 // int childKind = child.getKind();
2538 // RootInfo childRootInfo = this.rootInfo(childPath, childKind);
2539 // if (childRootInfo != null && !childRootInfo.isRootOfProject(childPath)) {
2540 // // package fragment root of another project (dealt with later)
2541 // childRootInfo = null;
2544 // // compute child type
2546 // this.elementType(
2550 // rootInfo == null ? childRootInfo : rootInfo
2553 // // is childRes in the output folder and is it filtered out ?
2554 // boolean isResFilteredFromOutput =
2555 // this.isResFilteredFromOutput(outputsInfo, childRes, childType);
2557 // boolean isNestedRoot = rootInfo != null && childRootInfo != null;
2558 // if (!isResFilteredFromOutput
2559 // && !isNestedRoot) { // do not treat as non-java rsc if nested root
2560 // if (!this.traverseDelta(child, childType, rootInfo == null ?
2561 // childRootInfo : rootInfo, outputsInfo)) { // traverse delta for child in
2563 // // it is a non-java resource
2565 // if (rootInfo != null) { // if inside a package fragment root
2566 // if (!isValidParent) continue;
2567 // if (parent == null) {
2568 // // find the parent of the non-java resource to attach to
2569 // if (this.currentElement == null
2570 // || !this.currentElement.getJavaProject().equals(rootInfo.project)) {
2571 // // force the currentProject to be used
2572 // this.currentElement = (Openable)rootInfo.project;
2574 // if (elementType == IJavaElement.JAVA_PROJECT
2575 // || (elementType == IJavaElement.PACKAGE_FRAGMENT_ROOT
2576 // && res instanceof IProject)) {
2577 // // NB: attach non-java resource to project (not to its package fragment
2579 // parent = (Openable)rootInfo.project;
2581 // parent = this.createElement(res, elementType, rootInfo);
2583 // if (parent == null) {
2584 // isValidParent = false;
2588 // // add child as non java resource
2589 // nonJavaResourcesChanged(parent, child);
2591 // // the non-java resource (or its parent folder) will be attached to the
2593 // if (orphanChildren == null) orphanChildren = new IResourceDelta[length];
2594 // orphanChildren[i] = child;
2596 // } catch (JavaModelException e) {
2599 // oneChildOnClasspath = true;
2602 // oneChildOnClasspath = true; // to avoid reporting child delta as non-java
2606 // // if child is a nested root
2607 // // or if it is not a package fragment root of the current project
2608 // // but it is a package fragment root of another project, traverse delta
2611 // || (childRootInfo == null && (childRootInfo = this.rootInfo(childPath,
2612 // childKind)) != null)) {
2613 // this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT,
2614 // childRootInfo, null); // binary output of childRootInfo.project cannot be
2616 // // NB: No need to check the return value as the child can only be on the
2620 // // if the child is a package fragment root of one or several other
2622 // ArrayList rootList;
2623 // if ((rootList = this.otherRootsInfo(childPath, childKind)) != null) {
2624 // Iterator iterator = rootList.iterator();
2625 // while (iterator.hasNext()) {
2626 // childRootInfo = (RootInfo) iterator.next();
2627 // this.traverseDelta(child, IJavaElement.PACKAGE_FRAGMENT_ROOT,
2628 // childRootInfo, null); // binary output of childRootInfo.project cannot be
2633 // if (orphanChildren != null
2634 // && (oneChildOnClasspath // orphan children are siblings of a package
2636 // || res instanceof IProject)) { // non-java resource directly under a
2639 // // attach orphan children
2640 // IProject rscProject = res.getProject();
2641 // JavaProject adoptiveProject = (JavaProject)JavaCore.create(rscProject);
2642 // if (adoptiveProject != null
2643 // && JavaProject.hasJavaNature(rscProject)) { // delta iff Java project
2645 // for (int i = 0; i < length; i++) {
2646 // if (orphanChildren[i] != null) {
2648 // nonJavaResourcesChanged(adoptiveProject, orphanChildren[i]);
2649 // } catch (JavaModelException e) {
2654 // } // else resource delta will be added by parent
2655 // return elementType != NON_JAVA_RESOURCE; // TODO: (jerome) do we still
2656 // need to return? (check could be done by caller)
2658 // return elementType != NON_JAVA_RESOURCE;
2662 * Update the classpath markers and cycle markers for the projects to
2665 // void updateClasspathMarkers() {
2667 // if (!ResourcesPlugin.getWorkspace().isAutoBuilding()) {
2668 // Iterator iterator = this.projectsToUpdate.iterator();
2669 // while (iterator.hasNext()) {
2671 // JavaProject project = (JavaProject)iterator.next();
2673 // // force classpath marker refresh
2674 // project.getResolvedClasspath(
2675 // true, // ignoreUnresolvedEntry
2676 // true); // generateMarkerOnError
2678 // } catch (JavaModelException e) {
2682 // if (!this.projectsToUpdate.isEmpty()){
2684 // // update all cycle markers
2685 // JavaProject.updateAllCycleMarkers();
2686 // } catch (JavaModelException e) {
2690 // this.projectsToUpdate = new HashSet();
2694 * Update the current delta (ie. add/remove/change the given element) and
2695 * update the correponding index. Returns whether the children of the given
2696 * delta must be processed. @throws a JavaModelException if the delta
2697 * doesn't correspond to a java element of the given type.
2699 // private boolean updateCurrentDeltaAndIndex(IResourceDelta delta, int
2700 // elementType, RootInfo rootInfo) {
2701 // Openable element;
2702 // switch (delta.getKind()) {
2703 // case IResourceDelta.ADDED :
2704 // IResource deltaRes = delta.getResource();
2705 // element = this.createElement(deltaRes, elementType, rootInfo);
2706 // if (element == null) {
2707 // // resource might be containing shared roots (see bug 19058)
2708 // this.updateRoots(deltaRes.getFullPath(), delta);
2711 // this.updateIndex(element, delta);
2712 // this.elementAdded(element, delta, rootInfo);
2714 // case IResourceDelta.REMOVED :
2715 // deltaRes = delta.getResource();
2716 // element = this.createElement(deltaRes, elementType, rootInfo);
2717 // if (element == null) {
2718 // // resource might be containing shared roots (see bug 19058)
2719 // this.updateRoots(deltaRes.getFullPath(), delta);
2722 // this.updateIndex(element, delta);
2723 // this.elementRemoved(element, delta, rootInfo);
2725 // if (deltaRes.getType() == IResource.PROJECT){
2726 // // reset the corresponding project built state, since cannot reuse if
2728 // this.manager.setLastBuiltState((IProject)deltaRes, null /*no state*/);
2731 // case IResourceDelta.CHANGED :
2732 // int flags = delta.getFlags();
2733 // if ((flags & IResourceDelta.CONTENT) != 0) {
2734 // // content has changed
2735 // element = this.createElement(delta.getResource(), elementType, rootInfo);
2736 // if (element == null) return false;
2737 // this.updateIndex(element, delta);
2738 // this.contentChanged(element, delta);
2739 // } else if (elementType == IJavaElement.JAVA_PROJECT) {
2740 // if ((flags & IResourceDelta.OPEN) != 0) {
2741 // // project has been opened or closed
2742 // IProject res = (IProject)delta.getResource();
2743 // element = this.createElement(res, elementType, rootInfo);
2744 // if (element == null) {
2745 // // resource might be containing shared roots (see bug 19058)
2746 // this.updateRoots(res.getFullPath(), delta);
2749 // if (res.isOpen()) {
2750 // if (JavaProject.hasJavaNature(res)) {
2751 // this.elementAdded(element, delta, rootInfo);
2752 // this.indexManager.indexAll(res);
2755 // JavaModel javaModel = this.manager.getJavaModel();
2756 // boolean wasJavaProject = javaModel.findJavaProject(res) != null;
2757 // if (wasJavaProject) {
2758 // this.elementRemoved(element, delta, rootInfo);
2759 // this.indexManager.discardJobs(element.getElementName());
2760 // this.indexManager.removeIndexFamily(res.getFullPath());
2764 // return false; // when a project is open/closed don't process children
2766 // if ((flags & IResourceDelta.DESCRIPTION) != 0) {
2767 // IProject res = (IProject)delta.getResource();
2768 // JavaModel javaModel = this.manager.getJavaModel();
2769 // boolean wasJavaProject = javaModel.findJavaProject(res) != null;
2770 // boolean isJavaProject = JavaProject.hasJavaNature(res);
2771 // if (wasJavaProject != isJavaProject) {
2772 // // project's nature has been added or removed
2773 // element = this.createElement(res, elementType, rootInfo);
2774 // if (element == null) return false; // note its resources are still
2775 // visible as roots to other projects
2776 // if (isJavaProject) {
2777 // this.elementAdded(element, delta, rootInfo);
2778 // this.indexManager.indexAll(res);
2780 // this.elementRemoved(element, delta, rootInfo);
2781 // this.indexManager.discardJobs(element.getElementName());
2782 // this.indexManager.removeIndexFamily(res.getFullPath());
2783 // // reset the corresponding project built state, since cannot reuse if
2785 // this.manager.setLastBuiltState(res, null /*no state*/);
2787 // return false; // when a project's nature is added/removed don't process
2797 * Traverse the set of projects which have changed namespace, and refresh
2800 // public void updateDependentNamelookups() {
2801 // Iterator iterator;
2802 // // update namelookup of dependent projects
2803 // iterator = this.projectsForDependentNamelookupRefresh.iterator();
2804 // HashSet affectedDependents = new HashSet();
2805 // while (iterator.hasNext()) {
2806 // JavaProject project = (JavaProject)iterator.next();
2807 // addDependentProjects(project.getPath(), affectedDependents);
2809 // iterator = affectedDependents.iterator();
2810 // while (iterator.hasNext()) {
2811 // JavaProject project = (JavaProject) iterator.next();
2812 // if (project.isOpen()){
2814 // ((JavaProjectElementInfo)project.getElementInfo()).setNameLookup(null);
2815 // } catch (JavaModelException e) {
2820 // protected void updateIndex(Openable element, IResourceDelta delta) {
2822 // if (indexManager == null)
2825 // switch (element.getElementType()) {
2826 // case IJavaElement.JAVA_PROJECT :
2827 // switch (delta.getKind()) {
2828 // case IResourceDelta.ADDED :
2829 // this.indexManager.indexAll(element.getJavaProject().getProject());
2831 // case IResourceDelta.REMOVED :
2832 // this.indexManager.removeIndexFamily(element.getJavaProject().getProject().getFullPath());
2833 // // NB: Discarding index jobs belonging to this project was done during
2836 // // NB: Update of index if project is opened, closed, or its java nature
2837 // is added or removed
2838 // // is done in updateCurrentDeltaAndIndex
2841 // case IJavaElement.PACKAGE_FRAGMENT_ROOT :
2842 // if (element instanceof JarPackageFragmentRoot) {
2843 // JarPackageFragmentRoot root = (JarPackageFragmentRoot)element;
2844 // // index jar file only once (if the root is in its declaring project)
2845 // IPath jarPath = root.getPath();
2846 // switch (delta.getKind()) {
2847 // case IResourceDelta.ADDED:
2848 // // index the new jar
2849 // indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
2851 // case IResourceDelta.CHANGED:
2852 // // first remove the index so that it is forced to be re-indexed
2853 // indexManager.removeIndex(jarPath);
2854 // // then index the jar
2855 // indexManager.indexLibrary(jarPath, root.getJavaProject().getProject());
2857 // case IResourceDelta.REMOVED:
2858 // // the jar was physically removed: remove the index
2859 // this.indexManager.discardJobs(jarPath.toString());
2860 // this.indexManager.removeIndex(jarPath);
2865 // int kind = delta.getKind();
2866 // if (kind == IResourceDelta.ADDED || kind == IResourceDelta.REMOVED) {
2867 // IPackageFragmentRoot root = (IPackageFragmentRoot)element;
2868 // this.updateRootIndex(root, root.getPackageFragment(""), delta);
2873 // // don't break as packages of the package fragment root can be indexed
2875 // case IJavaElement.PACKAGE_FRAGMENT :
2876 // switch (delta.getKind()) {
2877 // case IResourceDelta.ADDED:
2878 // case IResourceDelta.REMOVED:
2879 // IPackageFragment pkg = null;
2880 // if (element instanceof IPackageFragmentRoot) {
2881 // IPackageFragmentRoot root = (IPackageFragmentRoot)element;
2882 // pkg = root.getPackageFragment(""); //$NON-NLS-1$
2884 // pkg = (IPackageFragment)element;
2886 // IResourceDelta[] children = delta.getAffectedChildren();
2887 // for (int i = 0, length = children.length; i < length; i++) {
2888 // IResourceDelta child = children[i];
2889 // IResource resource = child.getResource();
2890 // if (resource instanceof IFile) {
2891 // String name = resource.getName();
2892 // if (ProjectPrefUtil.isJavaFileName(name)) {
2893 // Openable cu = (Openable)pkg.getCompilationUnit(name);
2894 // this.updateIndex(cu, child);
2895 // } else if (ProjectPrefUtil.isClassFileName(name)) {
2896 // Openable classFile = (Openable)pkg.getClassFile(name);
2897 // this.updateIndex(classFile, child);
2904 // case IJavaElement.CLASS_FILE :
2905 // IFile file = (IFile) delta.getResource();
2906 // IJavaProject project = element.getJavaProject();
2907 // IPath binaryFolderPath = element.getPackageFragmentRoot().getPath();
2908 // // if the class file is part of the binary output, it has been created by
2909 // // the java builder -> ignore
2911 // if (binaryFolderPath.equals(project.getOutputLocation())) {
2914 // } catch (JavaModelException e) {
2916 // switch (delta.getKind()) {
2917 // case IResourceDelta.CHANGED :
2918 // // no need to index if the content has not changed
2919 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0)
2921 // case IResourceDelta.ADDED :
2922 // indexManager.addBinary(file, binaryFolderPath);
2924 // case IResourceDelta.REMOVED :
2925 // indexManager.remove(file.getFullPath().toString(), binaryFolderPath);
2929 // case IJavaElement.COMPILATION_UNIT :
2930 // file = (IFile) delta.getResource();
2931 // switch (delta.getKind()) {
2932 // case IResourceDelta.CHANGED :
2933 // // no need to index if the content has not changed
2934 // if ((delta.getFlags() & IResourceDelta.CONTENT) == 0)
2936 // case IResourceDelta.ADDED :
2937 // indexManager.addSource(file,
2938 // file.getProject().getProject().getFullPath());
2940 // case IResourceDelta.REMOVED :
2941 // indexManager.remove(file.getFullPath().toString(),
2942 // file.getProject().getProject().getFullPath());
2948 * Upadtes the index of the given root (assuming it's an addition or a
2949 * removal). This is done recusively, pkg being the current package.
2951 // private void updateRootIndex(IPackageFragmentRoot root, IPackageFragment
2952 // pkg, IResourceDelta delta) {
2953 // this.updateIndex((Openable)pkg, delta);
2954 // IResourceDelta[] children = delta.getAffectedChildren();
2955 // String name = pkg.getElementName();
2956 // for (int i = 0, length = children.length; i < length; i++) {
2957 // IResourceDelta child = children[i];
2958 // IResource resource = child.getResource();
2959 // if (resource instanceof IFolder) {
2960 // String subpkgName =
2961 // name.length() == 0 ?
2962 // resource.getName() :
2963 // name + "." + resource.getName(); //$NON-NLS-1$
2964 // IPackageFragment subpkg = root.getPackageFragment(subpkgName);
2965 // this.updateRootIndex(root, subpkg, child);
2970 * Update the roots that are affected by the addition or the removal of the
2971 * given container resource.
2973 // private void updateRoots(IPath containerPath, IResourceDelta
2974 // containerDelta) {
2977 // if (containerDelta.getKind() == IResourceDelta.REMOVED) {
2978 // roots = this.oldRoots;
2979 // otherRoots = this.oldOtherRoots;
2981 // roots = this.roots;
2982 // otherRoots = this.otherRoots;
2984 // Iterator iterator = roots.keySet().iterator();
2985 // while (iterator.hasNext()) {
2986 // IPath path = (IPath)iterator.next();
2987 // if (containerPath.isPrefixOf(path) && !containerPath.equals(path)) {
2988 // IResourceDelta rootDelta =
2989 // containerDelta.findMember(path.removeFirstSegments(1));
2990 // if (rootDelta == null) continue;
2991 // RootInfo rootInfo = (RootInfo)roots.get(path);
2993 // if (!rootInfo.project.getPath().isPrefixOf(path)) { // only consider
2994 // roots that are not included in the container
2995 // this.updateCurrentDeltaAndIndex(rootDelta,
2996 // IJavaElement.PACKAGE_FRAGMENT_ROOT, rootInfo);
2999 // ArrayList rootList = (ArrayList)otherRoots.get(path);
3000 // if (rootList != null) {
3001 // Iterator otherProjects = rootList.iterator();
3002 // while (otherProjects.hasNext()) {
3003 // rootInfo = (RootInfo)otherProjects.next();
3004 // if (!rootInfo.project.getPath().isPrefixOf(path)) { // only consider
3005 // roots that are not included in the container
3006 // this.updateCurrentDeltaAndIndex(rootDelta,
3007 // IJavaElement.PACKAGE_FRAGMENT_ROOT, rootInfo);